Move tests to test the file system API.

Move the prefix and delimiter tests from BaseContainerLiveTest to
BaseContainerIntegrationTest, as that class is subclassed in
Filesystem integration tests. This will make sure the file system blob
store will not regress.

The ListContainerTest is updated to _not_ use a file separator
character, as that leads to a possible creation of directories.
Instead, "-" is used as the delimiter for the delimiter option tests.
This commit is contained in:
Timur Alperovich 2015-07-13 17:20:50 -07:00 committed by Andrew Gaul
parent 613b6bf045
commit e4161a59bb
8 changed files with 81 additions and 98 deletions

View File

@ -50,4 +50,14 @@ public class AtmosContainerIntegrationLiveTest extends BaseContainerIntegrationT
public void testListContainerWithZeroMaxResults() throws Exception {
throw new SkipException("Atmos requires a positive integer for max results");
}
@Override
public void testContainerListWithPrefix() {
throw new SkipException("Prefix option has not been plumbed down to Atmos");
}
@Override
public void testDelimiterList() {
throw new SkipException("Delimiter support is not yet implemented");
}
}

View File

@ -17,7 +17,6 @@
package org.jclouds.atmos.blobstore.integration;
import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
import org.testng.SkipException;
import org.testng.annotations.Test;
@Test(groups = { "live" })
@ -25,14 +24,4 @@ public class AtmosContainerLiveTest extends BaseContainerLiveTest {
public AtmosContainerLiveTest() {
provider = "atmos";
}
@Override
public void testContainerListWithPrefix() {
throw new SkipException("Prefix option has not been plumbed down to Atmos");
}
@Override
public void testDelimiterList() {
throw new SkipException("Delimiter support is not yet implemented");
}
}

View File

@ -22,7 +22,6 @@ import java.util.Properties;
import org.jclouds.blobstore.integration.internal.BaseContainerLiveTest;
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
import org.testng.SkipException;
import org.testng.annotations.Test;
@Test(groups = "live", testName = "SwiftContainerLiveTest" )
@ -53,14 +52,4 @@ public class SwiftContainerLiveTest extends BaseContainerLiveTest {
IOException {
super.testPublicAccessInNonDefaultLocationWithBigBlob();
}
@Override
public void testContainerListWithPrefix() {
throw new SkipException("Prefix option has not been plumbed down to Swift");
}
@Override
public void testDelimiterList() {
throw new SkipException("The test fails as the path parameter elides subdirectories");
}
}

View File

@ -30,6 +30,7 @@ import static org.testng.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ExecutionException;
@ -49,6 +50,7 @@ import org.jclouds.blobstore.options.ListContainerOptions;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.ByteSource;
import com.google.common.util.concurrent.Uninterruptibles;
@ -516,6 +518,59 @@ public class BaseContainerIntegrationTest extends BaseBlobStoreIntegrationTest {
}
}
@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);
}
}
@Test(groups = {"integration", "live"})
public void testDelimiterList() throws InterruptedException {
final String containerName = getContainerName();
BlobStore blobStore = view.getBlobStore();
String payload = "foo";
try {
blobStore.putBlob(containerName, blobStore.blobBuilder("test-foo-foo").payload(payload).build());
blobStore.putBlob(containerName, blobStore.blobBuilder("test-bar-foo").payload(payload).build());
blobStore.putBlob(containerName, blobStore.blobBuilder("foo").payload(payload).build());
// NOTE: the test does not work if we use a file separator character ("/" or "\"), as the file system blob
// store will create directories when putting such a blob. When listing results, these directories will also
// show up in the result set.
checkEqualNames(ImmutableSet.of("foo", "test-"), blobStore.list(containerName,
ListContainerOptions.Builder.delimiter("-")));
checkEqualNames(ImmutableSet.of("test-foo-foo", "test-bar-foo", "foo"),
blobStore.list(containerName, ListContainerOptions.Builder.delimiter(".")));
blobStore.putBlob(containerName, blobStore.blobBuilder("bar").payload(payload).build());
blobStore.putBlob(containerName, blobStore.blobBuilder("bazar").payload(payload).build());
checkEqualNames(ImmutableSet.of("bar", "baza"), blobStore.list(containerName,
ListContainerOptions.Builder.delimiter("a").prefix("ba")));
} finally {
returnContainer(containerName);
}
}
private void checkEqualNames(ImmutableSet<String> expectedSet, PageSet<? extends StorageMetadata> results) {
Set<String> names = new HashSet<String>();
for (StorageMetadata sm : results) {
names.add(sm.getName());
}
assertThat(names).containsOnlyElementsOf(expectedSet);
}
protected void addAlphabetUnderRoot(String containerName) throws InterruptedException {
for (char letter = 'a'; letter <= 'z'; letter++) {
view.getBlobStore().putBlob(containerName,

View File

@ -18,7 +18,6 @@ package org.jclouds.blobstore.integration.internal;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.jclouds.blobstore.options.CreateContainerOptions.Builder.publicRead;
import static org.jclouds.util.Predicates2.retry;
import static org.testng.Assert.assertEquals;
@ -28,17 +27,12 @@ import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;
import com.google.common.net.HostAndPort;
import org.jclouds.blobstore.BlobStore;
import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.blobstore.domain.PageSet;
import org.jclouds.blobstore.domain.StorageMetadata;
import org.jclouds.blobstore.options.ListContainerOptions;
import org.jclouds.domain.Location;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.predicates.SocketOpen;
@ -49,9 +43,9 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.net.HostAndPort;
public class BaseContainerLiveTest extends BaseBlobStoreIntegrationTest {
@ -121,60 +115,6 @@ public class BaseContainerLiveTest extends BaseBlobStoreIntegrationTest {
runCreateContainerInLocation(payload, nonDefault);
}
@Test(groups = "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);
}
}
@Test(groups = "live")
public void testDelimiterList() throws InterruptedException {
final String containerName = getContainerName();
BlobStore blobStore = view.getBlobStore();
String payload = "foo";
try {
blobStore.putBlob(containerName, blobStore.blobBuilder("test/foo/foo").payload(payload).build());
blobStore.putBlob(containerName, blobStore.blobBuilder("test/bar/foo").payload(payload).build());
blobStore.putBlob(containerName, blobStore.blobBuilder("foo").payload(payload).build());
blobStore.putBlob(containerName, blobStore.blobBuilder("test-foo").payload(payload).build());
blobStore.putBlob(containerName, blobStore.blobBuilder("test-bar").payload(payload).build());
checkEqualNames(ImmutableSet.of("foo", "test/", "test-foo", "test-bar"), blobStore.list(
containerName, ListContainerOptions.Builder.delimiter("/")));
checkEqualNames(ImmutableSet.of("test/foo/foo", "test/bar/foo", "foo", "test-foo", "test-bar"),
blobStore.list(containerName, ListContainerOptions.Builder.delimiter("\\")));
checkEqualNames(ImmutableSet.of("test-", "test/foo/foo", "test/bar/foo", "foo"), blobStore.list(
containerName, ListContainerOptions.Builder.delimiter("-")));
blobStore.putBlob(containerName, blobStore.blobBuilder("bar").payload(payload).build());
blobStore.putBlob(containerName, blobStore.blobBuilder("bazar").payload(payload).build());
checkEqualNames(ImmutableSet.of("bar", "baza"), blobStore.list(containerName,
ListContainerOptions.Builder.delimiter("a").prefix("ba")));
} finally {
returnContainer(containerName);
}
}
private void checkEqualNames(ImmutableSet<String> expectedSet, PageSet<? extends StorageMetadata> results) {
Set<String> names = new HashSet<String>();
for (StorageMetadata sm : results) {
names.add(sm.getName());
}
assertThat(names).containsOnlyElementsOf(expectedSet);
}
private void runCreateContainerInLocation(String payload, Location nonDefault) throws InterruptedException,
IOException {
String blobName = "hello";

View File

@ -71,25 +71,25 @@ public class ListContainerTest {
assertThat(Iterables.get(results, 2).getType()).isEqualTo(StorageType.BLOB);
}
public void testListWithPrefixAndSeparator() {
public void testListWithPrefixAndDelimiter() {
String containerName = "prefixWithSeparator";
String prefix = "foo";
blobStore.createContainerInLocation(null, containerName);
blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "/object").payload("").build());
blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "bar/object").payload("")
blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "-object").payload("").build());
blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "bar-object").payload("")
.build());
blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "baz/object").payload("")
blobStore.putBlob(containerName, blobStore.blobBuilder(prefix + "baz-object").payload("")
.build());
blobStore.putBlob(containerName, blobStore.blobBuilder("bar/object").payload("").build());
blobStore.putBlob(containerName, blobStore.blobBuilder("bar-object").payload("").build());
Iterable<? extends StorageMetadata> results = concatter.execute(containerName,
ListContainerOptions.Builder.prefix(prefix));
ListContainerOptions.Builder.prefix(prefix).delimiter("-"));
assertThat(Iterables.size(results)).isEqualTo(3);
assertThat(Iterables.get(results, 0).getType()).isEqualTo(StorageType.RELATIVE_PATH);
assertThat(Iterables.get(results, 0).getName()).isEqualTo(prefix + "/");
assertThat(Iterables.get(results, 1).getName()).isEqualTo(prefix + "bar/");
assertThat(Iterables.get(results, 0).getName()).isEqualTo(prefix + "-");
assertThat(Iterables.get(results, 1).getName()).isEqualTo(prefix + "bar-");
assertThat(Iterables.get(results, 1).getType()).isEqualTo(StorageType.RELATIVE_PATH);
assertThat(Iterables.get(results, 2).getName()).isEqualTo(prefix + "baz/");
assertThat(Iterables.get(results, 2).getName()).isEqualTo(prefix + "baz-");
assertThat(Iterables.get(results, 2).getType()).isEqualTo(StorageType.RELATIVE_PATH);
}

View File

@ -17,6 +17,7 @@
package org.jclouds.hpcloud.objectstorage.blobstore.integration;
import org.jclouds.openstack.swift.blobstore.integration.SwiftContainerIntegrationLiveTest;
import org.testng.SkipException;
import org.testng.annotations.Test;
@Test(groups = "live")
@ -25,4 +26,9 @@ public class HPCloudObjectStorageContainerIntegrationLiveTest extends SwiftConta
provider = "hpcloud-objectstorage";
}
@Override
@Test
public void testDelimiterList() {
throw new SkipException("\"path\" parameter elides subdirectories");
}
}

View File

@ -33,10 +33,4 @@ public class HPCloudObjectStorageContainerLiveTest extends BaseContainerLiveTest
@Override
@Test
public void testPublicAccessInNonDefaultLocationWithBigBlob() { throw new SkipException("Locations are ignored"); }
@Override
@Test
public void testDelimiterList() {
throw new SkipException("\"path\" parameter elides subdirectories");
}
}