@Override protected Properties setupProperties() { Properties props = super.setupProperties(); props.setProperty(FilesystemConstants.PROPERTY_BASEDIR, TestUtils.TARGET_BASE_DIR); return props; }
@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 deleteContainerWithContents() throws InterruptedException { String containerName = getContainerName(); try { addBlobToContainer(containerName, "test"); view.getBlobStore().deleteContainer(containerName); awaitConsistency(); assertNotExists(containerName); } finally { recycleContainerAndAddToPool(containerName); } }
@Test(groups = { "integration", "live" }) public void deleteContainerWithContents() throws InterruptedException { String containerName = getContainerName(); try { addBlobToContainer(containerName, "test"); view.getBlobStore().deleteContainer(containerName); assertNotExists(containerName); } finally { recycleContainer(containerName); } }
@Test public void testListMarkerAfterLastKey() 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()); validateContent(containerName, key); awaitConsistency(); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, afterMarker(key)); assertThat(container).isEmpty(); } 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 testClearWithOptions() throws InterruptedException { String containerName = getContainerName(); try { ListContainerOptions options; add5NestedBlobsToContainer(containerName); options = new ListContainerOptions(); options.prefix("path/1/"); options.recursive(); view.getBlobStore().clearContainer(containerName, options); assertConsistencyAwareContainerSize(containerName, 0); add5NestedBlobsToContainer(containerName); options = new ListContainerOptions(); options.prefix("path/1/2/3"); options.recursive(); view.getBlobStore().clearContainer(containerName, options); assertConsistencyAwareBlobExists(containerName, "path/1/a"); assertConsistencyAwareBlobExists(containerName, "path/1/2/b"); assertConsistencyAwareBlobDoesntExist(containerName, "path/1/2/3"); add5NestedBlobsToContainer(containerName); options = new ListContainerOptions(); options.prefix("path/1/2/3/4/"); options.recursive(); view.getBlobStore().clearContainer(containerName, options); assertConsistencyAwareBlobExists(containerName, "path/1/a"); assertConsistencyAwareBlobExists(containerName, "path/1/2/b"); assertConsistencyAwareBlobExists(containerName, "path/1/2/3/5/e");
@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 deleteContainerIfEmpty() throws InterruptedException { final String containerName = getContainerName(); try { view.getBlobStore().deleteContainer(containerName); assertNotExists(containerName); } finally { // this container is now deleted, so we can't reuse it directly recycleContainer(containerName); } }
@Test(dataProvider = "ignoreOnWindows", groups = { "integration", "live" }) public void testDelimiter() throws Exception { String containerName = getContainerName(); try { for (String blobName : new String[] { "asdf", "boo" + File.separator + "bar", "boo" + File.separator + "bla" }) { Blob blob = view.getBlobStore().blobBuilder(blobName).payload(TEST_STRING).build(); addBlobToContainer(containerName, blob); assertThat(pageSet.getNextMarker()).isNull(); } finally { returnContainer(containerName);
@Test(groups = { "integration", "live" }) public void testDirectory() throws InterruptedException { String containerName = getContainerName(); try { String directory = "directory"; assert container.size() == 0 : container; addTenObjectsUnderPrefix(containerName, directory); assert container.size() == 0 : container; } finally { returnContainer(containerName);
protected void assertContainerSize(final String containerName, final int size) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { try { assertEquals(view.getBlobStore().countBlobs(containerName), size); } catch (Exception e) { propagateIfPossible(e); } } }); }
protected void addAlphabetUnderRoot(String containerName) throws InterruptedException { for (char letter = 'a'; letter <= 'z'; letter++) { view.getBlobStore().putBlob(containerName, view.getBlobStore().blobBuilder(letter + "").payload(letter + "content").build()); } assertContainerSize(containerName, 26); }
@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(groups = { "integration", "live" }) public void deleteContainerWithoutContents() throws InterruptedException { final String containerName = getContainerName(); try { view.getBlobStore().deleteContainer(containerName); awaitConsistency(); assertNotExists(containerName); } finally { // this container is now deleted, so we can't reuse it directly recycleContainerAndAddToPool(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); } }
protected void assertContainerSize(final String containerName, final int size) throws InterruptedException { assertConsistencyAware(new Runnable() { public void run() { try { assertEquals(view.getBlobStore().countBlobs(containerName), size); } catch (Exception e) { propagateIfPossible(e); } } }); }
protected void addAlphabetUnderRoot(String containerName) throws InterruptedException { for (char letter = 'a'; letter <= 'z'; letter++) { view.getBlobStore().putBlob(containerName, view.getBlobStore().blobBuilder(letter + "").payload(letter + "content").build()); } assertContainerSize(containerName, 26); }
@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); } }