@Test(groups = { "integration", "live" }) public void testGetRangeOutOfRange() throws InterruptedException, IOException { String container = getContainerName(); try { String name = "apples"; addObjectAndValidateContent(container, name); try { view.getBlobStore().getBlob(container, name, range(TEST_STRING.length(), TEST_STRING.length() + 1)); failBecauseExceptionWasNotThrown(HttpResponseException.class); } catch (HttpResponseException e) { assertThat(e.getResponse().getStatusCode()).isEqualTo(416); } } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetIfModifiedSince() throws InterruptedException { String container = getContainerName(); try { String name = "apples"; Date before = new Date(System.currentTimeMillis() - 1000); // first create the blob addObjectAndValidateContent(container, name); // now, modify it addObjectAndValidateContent(container, name); Date after = new Date(System.currentTimeMillis() + 1000); view.getBlobStore().getBlob(container, name, ifModifiedSince(before)); validateContent(container, name); try { view.getBlobStore().getBlob(container, name, ifModifiedSince(after)); validateContent(container, name); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 304); } } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetIfModifiedSince() throws InterruptedException { String container = getContainerName(); try { String name = "apples"; Date before = new Date(System.currentTimeMillis() - 1000); // first create the blob addObjectAndValidateContent(container, name); // now, modify it addObjectAndValidateContent(container, name); Date after = new Date(System.currentTimeMillis() + 1000); view.getBlobStore().getBlob(container, name, ifModifiedSince(before)); validateContent(container, name); try { view.getBlobStore().getBlob(container, name, ifModifiedSince(after)); validateContent(container, name); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 304); } } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetIfUnmodifiedSince() throws InterruptedException { String container = getContainerName(); try { String name = "apples"; Date before = new Date(System.currentTimeMillis() - 1000); addObjectAndValidateContent(container, name); Date after = new Date(System.currentTimeMillis() + 1000); view.getBlobStore().getBlob(container, name, ifUnmodifiedSince(after)); validateContent(container, name); try { view.getBlobStore().getBlob(container, name, ifUnmodifiedSince(before)); validateContent(container, name); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 412); } } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetRange() throws InterruptedException, IOException { String container = getContainerName(); try { String name = "apples"; addObjectAndValidateContent(container, name); Blob blob1 = view.getBlobStore().getBlob(container, name, range(0, 5)); validateMetadata(blob1.getMetadata(), container, name); assertEquals(getContentAsStringOrNullAndClose(blob1), TEST_STRING.substring(0, 6)); Blob blob2 = view.getBlobStore().getBlob(container, name, range(6, TEST_STRING.length())); validateMetadata(blob2.getMetadata(), container, name); assertEquals(getContentAsStringOrNullAndClose(blob2), TEST_STRING.substring(6, TEST_STRING.length())); } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetTwoRanges() throws InterruptedException, IOException { String container = getContainerName(); try { String name = "apples"; addObjectAndValidateContent(container, name); Blob blob = view.getBlobStore().getBlob(container, name, range(0, 5).range(6, TEST_STRING.length())); validateMetadata(blob.getMetadata(), container, name); assertEquals(getContentAsStringOrNullAndClose(blob), TEST_STRING); } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetTwoRanges() throws InterruptedException, IOException { String container = getContainerName(); try { String name = "apples"; addObjectAndValidateContent(container, name); Blob blob = view.getBlobStore().getBlob(container, name, range(0, 5).range(6, TEST_STRING.length())); validateMetadata(blob.getMetadata(), container, name); assertEquals(getContentAsStringOrNullAndClose(blob), TEST_STRING); } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetIfUnmodifiedSince() throws InterruptedException { String container = getContainerName(); try { String name = "apples"; Date before = new Date(System.currentTimeMillis() - 10000); addObjectAndValidateContent(container, name); Date after = new Date(System.currentTimeMillis() + 10000); awaitConsistency(); view.getBlobStore().getBlob(container, name, ifUnmodifiedSince(after)); validateContent(container, name); try { view.getBlobStore().getBlob(container, name, ifUnmodifiedSince(before)); validateContent(container, name); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 412); } } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetIfNoneMatch() throws InterruptedException { String container = getContainerName(); try { String name = "apples"; String goodETag = addObjectAndValidateContent(container, name); view.getBlobStore().getBlob(container, name, ifETagDoesntMatch("powerfrisbee")); validateContent(container, name); try { view.getBlobStore().getBlob(container, name, ifETagDoesntMatch(goodETag)); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 304); } } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetIfNoneMatch() throws InterruptedException { String container = getContainerName(); try { String name = "apples"; String goodETag = addObjectAndValidateContent(container, name); view.getBlobStore().getBlob(container, name, ifETagDoesntMatch("powerfrisbee")); validateContent(container, name); try { view.getBlobStore().getBlob(container, name, ifETagDoesntMatch(goodETag)); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 304); } } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetIfMatch() throws InterruptedException { String container = getContainerName(); try { String name = "apples"; String goodETag = addObjectAndValidateContent(container, name); view.getBlobStore().getBlob(container, name, ifETagMatches(goodETag)); validateContent(container, name); try { view.getBlobStore().getBlob(container, name, ifETagMatches("powerfrisbee")); validateContent(container, name); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 412); } } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetIfMatch() throws InterruptedException { String container = getContainerName(); try { String name = "apples"; String goodETag = addObjectAndValidateContent(container, name); view.getBlobStore().getBlob(container, name, ifETagMatches(goodETag)); validateContent(container, name); try { view.getBlobStore().getBlob(container, name, ifETagMatches("powerfrisbee")); validateContent(container, name); } catch (HttpResponseException ex) { assertEquals(ex.getResponse().getStatusCode(), 412); } } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testGetRange() throws InterruptedException, IOException { String container = getContainerName(); try { String name = "apples"; addObjectAndValidateContent(container, name); Blob blob1 = view.getBlobStore().getBlob(container, name, range(0, 5)); validateMetadata(blob1.getMetadata(), container, name); assertEquals(getContentAsStringOrNullAndClose(blob1), TEST_STRING.substring(0, 6)); assertThat(blob1.getAllHeaders().get(HttpHeaders.CONTENT_RANGE)).containsExactly("bytes 0-5/46"); Blob blob2 = view.getBlobStore().getBlob(container, name, range(6, TEST_STRING.length())); validateMetadata(blob2.getMetadata(), container, name); assertEquals(getContentAsStringOrNullAndClose(blob2), TEST_STRING.substring(6, TEST_STRING.length())); assertThat(blob2.getAllHeaders().get(HttpHeaders.CONTENT_RANGE)).containsExactly("bytes 6-45/46"); /* RFC 2616 14.35.1 "If the entity is shorter than the specified suffix-length, the entire entity-body is used." */ Blob blob3 = view.getBlobStore().getBlob(container, name, new GetOptions().tail(TEST_STRING.length() + 10)); validateMetadata(blob3.getMetadata(), container, name); assertEquals(getContentAsStringOrNullAndClose(blob3), TEST_STRING); // not all providers return Content-Range for non-partial responses } finally { returnContainer(container); } }