@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 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); } }
@Test(groups = { "integration", "live" }) public void testPutObjectStream() throws InterruptedException, IOException, ExecutionException { PayloadBlobBuilder blobBuilder = view.getBlobStore().blobBuilder("streaming").payload( new ByteSourcePayload(ByteSource.wrap("foo".getBytes()))); addContentMetadata(blobBuilder); Blob blob = blobBuilder.build(); String container = getContainerName(); try { assertNotNull(view.getBlobStore().putBlob(container, blob)); awaitConsistency(); blob = view.getBlobStore().getBlob(container, blob.getMetadata().getName()); String returnedString = getContentAsStringOrNullAndClose(blob); assertEquals(returnedString, "foo"); validateMetadata(blob.getMetadata(), container, blob.getMetadata().getName()); checkContentMetadata(blob); PageSet<? extends StorageMetadata> set = view.getBlobStore().list(container); assert set.size() == 1 : set; } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testPutObjectStream() throws InterruptedException, IOException, ExecutionException { PayloadBlobBuilder blobBuilder = view.getBlobStore().blobBuilder("streaming").payload( new StreamingPayload(new WriteTo() { @Override public void writeTo(OutputStream outstream) throws IOException { outstream.write("foo".getBytes()); } })); addContentMetadata(blobBuilder); Blob blob = blobBuilder.build(); String container = getContainerName(); try { assertNotNull(view.getBlobStore().putBlob(container, blob)); blob = view.getBlobStore().getBlob(container, blob.getMetadata().getName()); String returnedString = getContentAsStringOrNullAndClose(blob); assertEquals(returnedString, "foo"); validateMetadata(blob.getMetadata(), container, blob.getMetadata().getName()); checkContentMetadata(blob); PageSet<? extends StorageMetadata> set = view.getBlobStore().list(container); assert set.size() == 1 : set; } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }, dataProvider = "putTests") public void testPutObject(String name, String type, Object content, Object realObject) throws InterruptedException, IOException { PayloadBlobBuilder blobBuilder = view.getBlobStore().blobBuilder(name).payload(Payloads.newPayload(content)) .contentType(type); addContentMetadata(blobBuilder); if (content instanceof InputStream) { blobBuilder.calculateMD5(); } Blob blob = blobBuilder.build(); String container = getContainerName(); try { assertNotNull(view.getBlobStore().putBlob(container, blob)); blob = view.getBlobStore().getBlob(container, blob.getMetadata().getName()); validateMetadata(blob.getMetadata(), container, name); checkContentMetadata(blob); String returnedString = getContentAsStringOrNullAndClose(blob); assertEquals(returnedString, realObject); PageSet<? extends StorageMetadata> set = view.getBlobStore().list(container); assert set.size() == 1 : set; } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }, dataProvider = "putTests") public void testPutObject(String name, String type, Object content, Object realObject) throws InterruptedException, IOException { PayloadBlobBuilder blobBuilder = view.getBlobStore().blobBuilder(name).payload(Payloads.newPayload(content)) .contentType(type); addContentMetadata(blobBuilder); Blob blob = blobBuilder.build(); String container = getContainerName(); try { assertNotNull(view.getBlobStore().putBlob(container, blob)); awaitConsistency(); blob = view.getBlobStore().getBlob(container, blob.getMetadata().getName()); validateMetadata(blob.getMetadata(), container, name); checkContentMetadata(blob); String returnedString = getContentAsStringOrNullAndClose(blob); assertEquals(returnedString, realObject); PageSet<? extends StorageMetadata> set = view.getBlobStore().list(container); assert set.size() == 1 : set; } finally { returnContainer(container); } }