@Test(groups = { "integration", "live" }) public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException { String containerName = getContainerName(); try { add15UnderRoot(containerName); Set<? extends StorageMetadata> container = view.getBlobStore().list(containerName); assertEquals(container.size(), 15); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void containerExists() throws InterruptedException { String containerName = getContainerName(); try { assert view.getBlobStore().containerExists(containerName); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void containerExists() throws InterruptedException { String containerName = getContainerName(); try { assert view.getBlobStore().containerExists(containerName); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testListContainer() throws InterruptedException, ExecutionException, TimeoutException { String containerName = getContainerName(); try { add15UnderRoot(containerName); awaitConsistency(); Set<? extends StorageMetadata> container = view.getBlobStore().list(containerName); assertEquals(container.size(), 15); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testClearWhenContentsUnderPath() throws InterruptedException { String containerName = getContainerName(); try { add5BlobsUnderPathAnd5UnderRootToContainer(containerName); view.getBlobStore().clearContainer(containerName); assertConsistencyAwareContainerSize(containerName, 0); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testClearWhenContentsUnderPath() throws InterruptedException { String containerName = getContainerName(); try { add5BlobsUnderPathAnd5UnderRootToContainer(containerName); view.getBlobStore().clearContainer(containerName); assertConsistencyAwareContainerSize(containerName, 0); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testListContainerMaxResults() throws InterruptedException { String containerName = getContainerName(); try { addAlphabetUnderRoot(containerName); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, maxResults(5)); assertEquals(container.size(), 5); assert container.getNextMarker() != null; } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testListRootUsesDelimiter() throws InterruptedException { String containerName = getContainerName(); try { String prefix = "rootdelimiter"; addTenObjectsUnderPrefix(containerName, prefix); add15UnderRoot(containerName); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName); assert container.getNextMarker() == null; assertEquals(container.size(), 16); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testListContainerPrefix() throws InterruptedException { String containerName = getContainerName(); try { String prefix = "containerprefix"; addTenObjectsUnderPrefix(containerName, prefix); add15UnderRoot(containerName); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, inDirectory(prefix)); assert container.getNextMarker() == null; assertEquals(container.size(), 10); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testListRootUsesDelimiter() throws InterruptedException { String containerName = getContainerName(); try { String prefix = "rootdelimiter"; addTenObjectsUnderPrefix(containerName, prefix); add15UnderRoot(containerName); awaitConsistency(); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName); assert container.getNextMarker() == null; assertEquals(container.size(), 16); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testWithDetails() throws InterruptedException, IOException { String key = "hello"; String containerName = getContainerName(); try { addBlobToContainer(containerName, // NOTE all metadata in jclouds comes out as lowercase, in an effort to // normalize the providers. view.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff")) .payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN).calculateMD5().build()); validateContent(containerName, key); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, maxResults(1).withDetails()); BlobMetadata metadata = BlobMetadata.class.cast(get(container, 0)); assert metadata.getContentMetadata().getContentType().startsWith("text/plain") : metadata.getContentMetadata() .getContentType(); assertEquals(metadata.getContentMetadata().getContentLength(), Long.valueOf(TEST_STRING.length())); assertEquals(metadata.getUserMetadata().get("adrian"), "powderpuff"); checkMD5(metadata); } finally { returnContainer(containerName); } }
@Test public void testListContainerWithZeroMaxResults() throws Exception { String key = "hello"; String containerName = getContainerName(); try { addBlobToContainer(containerName, // NOTE all metadata in jclouds comes out as lowercase, in an effort to // normalize the providers. view.getBlobStore().blobBuilder(key).userMetadata(ImmutableMap.of("Adrian", "powderpuff")) .payload(TEST_STRING).contentType(MediaType.TEXT_PLAIN) .contentMD5(md5().hashString(TEST_STRING, UTF_8).asBytes()) .build()); awaitConsistency(); validateContent(containerName, key); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, maxResults(0)); assertThat(container).isEmpty(); } finally { returnContainer(containerName); } }
@Test(dataProvider = "getBlobsToEscape", groups = {"integration", "live"}) public void testBlobNameEscaping(Set<String> blobNames) throws InterruptedException { final String containerName = getContainerName(); BlobStore blobStore = view.getBlobStore(); try { for (String name : blobNames) { Blob blob = blobStore.blobBuilder(name).payload(ByteSource.wrap("test".getBytes())).contentLength(4) .build(); blobStore.putBlob(containerName, blob); } checkEqualNames(blobNames, blobStore.list(containerName)); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testListContainerMarker() throws InterruptedException { String containerName = getContainerName(); try { addAlphabetUnderRoot(containerName); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, maxResults(1)); assert container.getNextMarker() != null; assertEquals(container.size(), 1); String marker = container.getNextMarker(); container = view.getBlobStore().list(containerName, afterMarker(marker)); assertEquals(container.getNextMarker(), null); assert container.size() == 25 : String.format("size should have been 25, but was %d: %s", container.size(), container); assert container.getNextMarker() == null; } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testPutTwiceIsOkAndDoesntOverwrite() throws InterruptedException { String containerName = getContainerName(); try { view.getBlobStore().createContainerInLocation(null, containerName); Blob blob = view.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build(); view.getBlobStore().putBlob(containerName, blob); view.getBlobStore().createContainerInLocation(null, containerName); assertEquals(view.getBlobStore().countBlobs(containerName), 1); } finally { returnContainer(containerName); } }
/** Test that listing with a marker prefix matches the first key with that prefix. */ @Test public void testListMarkerPrefix() throws Exception { BlobStore blobStore = view.getBlobStore(); final String container = getContainerName(); try { blobStore.createContainerInLocation(null, container); blobStore.putBlob(container, blobStore.blobBuilder("a/a").payload("").build()); blobStore.putBlob(container, blobStore.blobBuilder("b/b").payload("").build()); ListContainerOptions options = new ListContainerOptions().afterMarker("b/").recursive(); PageSet<? extends StorageMetadata> res = blobStore.list(container, options); assertThat(res).hasSize(1); assertThat(res.iterator().next().getName()).isEqualTo("b/b"); } finally { returnContainer(container); } }
@Test(groups = { "integration", "live" }) public void testListContainerPrefix() throws InterruptedException { String containerName = getContainerName(); try { String prefix = "containerprefix"; addTenObjectsUnderPrefix(containerName, prefix); add15UnderRoot(containerName); awaitConsistency(); PageSet<? extends StorageMetadata> container = view.getBlobStore().list( containerName, new ListContainerOptions().prefix(prefix + "/").delimiter("/")); assert container.getNextMarker() == null; assertEquals(container.size(), 10); } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testListContainerMarker() throws InterruptedException { String containerName = getContainerName(); try { addAlphabetUnderRoot(containerName); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, maxResults(1)); assert container.getNextMarker() != null; assertEquals(container.size(), 1); String marker = container.getNextMarker(); container = view.getBlobStore().list(containerName, afterMarker(marker)); assertEquals(container.getNextMarker(), null); assert container.size() == 25 : String.format("size should have been 25, but was %d: %s", container.size(), container); assert container.getNextMarker() == null; } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) // TODO: the test name does not describe its behavior public void testPutTwiceIsOkAndDoesntOverwrite() throws InterruptedException { String containerName = getContainerName(); try { view.getBlobStore().createContainerInLocation(null, containerName); Blob blob = view.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build(); view.getBlobStore().putBlob(containerName, blob); view.getBlobStore().createContainerInLocation(null, containerName); awaitConsistency(); assertEquals(view.getBlobStore().countBlobs(containerName), 1); } finally { returnContainer(containerName); } }
@Test(groups = {"integration", "live"}) public void testContainerListWithPrefix() throws InterruptedException { final String containerName = getContainerName(); BlobStore blobStore = view.getBlobStore(); String prefix = "blob"; try { blobStore.putBlob(containerName, blobStore.blobBuilder(prefix).payload("").build()); blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "foo").payload("").build()); blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "bar").payload("").build()); blobStore.putBlob(containerName, blobStore.blobBuilder("foo").payload("").build()); checkEqualNames(ImmutableSet.of(prefix, prefix + "foo", prefix + "bar"), blobStore.list(containerName, ListContainerOptions.Builder.prefix(prefix))); } finally { returnContainer(containerName); } }