From 8ab9904481dda7ad3d76a0cf3d5fb1ed7db65dca Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 1 May 2012 08:22:31 -0700 Subject: [PATCH] added tests --- .../ConcatenateContainerListsTest.java | 82 +++++++++++++++++++ .../internal/DeleteAllKeysInListTest.java | 77 +++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/ConcatenateContainerListsTest.java create mode 100644 blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInListTest.java diff --git a/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/ConcatenateContainerListsTest.java b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/ConcatenateContainerListsTest.java new file mode 100644 index 0000000000..6a98a5c634 --- /dev/null +++ b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/ConcatenateContainerListsTest.java @@ -0,0 +1,82 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.blobstore.strategy.internal; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.ContextBuilder; +import org.jclouds.blobstore.BlobStore; +import org.jclouds.blobstore.domain.StorageMetadata; +import org.jclouds.blobstore.options.ListContainerOptions; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; +import com.google.common.io.Closeables; +import com.google.inject.Injector; + +/** + * + * @author Adrian Cole + */ +@Test(testName = "ConcatenateContainerListsTest", singleThreaded = true) +public class ConcatenateContainerListsTest { + private BlobStore blobstore; + private ConcatenateContainerLists concatter; + + @BeforeClass + void setupBlobStore() { + Injector injector = ContextBuilder.newBuilder("transient").buildInjector(); + blobstore = injector.getInstance(BlobStore.class); + concatter = injector.getInstance(ConcatenateContainerLists.class); + } + + public void testLargerThanOnePageNoOptions() { + blobstore.createContainerInLocation(null, "goodies"); + for (int i = 0; i < 1001; i++) { + blobstore.putBlob("goodies", blobstore.blobBuilder(i + "").payload(i + "").build()); + } + Iterable listing = concatter.execute("goodies", new ListContainerOptions()); + assertEquals(Iterables.size(listing), 1001); + } + + public void testLargerThanOnePageInDirAndRecursive() { + blobstore.createContainerInLocation(null, "foo"); + for (int i = 0; i < 1001; i++) { + blobstore.putBlob("foo", blobstore.blobBuilder(i + "").payload(i + "").build()); + } + for (int i = 0; i < 1001; i++) { + blobstore.putBlob("foo", blobstore.blobBuilder("dir/" + i + "").payload(i + "").build()); + } + Iterable listing = concatter.execute("foo", new ListContainerOptions()); + // TODO: this looks broke. seems we should have 1002 (1001 + directory foo), not 1003 + assertEquals(Iterables.size(listing), 1003); + listing = concatter.execute("foo", ListContainerOptions.Builder.inDirectory("dir")); + assertEquals(Iterables.size(listing), 1001); + listing = concatter.execute("foo", ListContainerOptions.Builder.recursive()); + assertEquals(Iterables.size(listing), 2002); + } + + @AfterClass + void close() { + if (blobstore != null) + Closeables.closeQuietly(blobstore.getContext()); + } +} diff --git a/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInListTest.java b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInListTest.java new file mode 100644 index 0000000000..47de7565e5 --- /dev/null +++ b/blobstore/src/test/java/org/jclouds/blobstore/strategy/internal/DeleteAllKeysInListTest.java @@ -0,0 +1,77 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.jclouds.blobstore.strategy.internal; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.ContextBuilder; +import org.jclouds.blobstore.BlobStore; +import org.jclouds.blobstore.options.ListContainerOptions; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.google.common.io.Closeables; +import com.google.inject.Injector; + +/** + * + * @author Adrian Cole + */ +@Test(testName = "DeleteAllKeysInListTest", singleThreaded = true) +public class DeleteAllKeysInListTest { + private BlobStore blobstore; + private DeleteAllKeysInList deleter; + + @BeforeClass + void setupBlobStore() { + Injector injector = ContextBuilder.newBuilder("transient").buildInjector(); + blobstore = injector.getInstance(BlobStore.class); + deleter = injector.getInstance(DeleteAllKeysInList.class); + } + + public void testExecuteWithoutOptionsClearsRecursively() { + blobstore.createContainerInLocation(null, "goodies"); + for (int i = 0; i < 1001; i++) { + blobstore.putBlob("goodies", blobstore.blobBuilder(i + "").payload(i + "").build()); + } + assertEquals(blobstore.countBlobs("goodies"), 1001); + deleter.execute("goodies"); + assertEquals(blobstore.countBlobs("goodies"), 0); + } + + public void testExecuteNonRecursive() { + blobstore.createContainerInLocation(null, "foo"); + for (int i = 0; i < 1001; i++) { + blobstore.putBlob("foo", blobstore.blobBuilder(i + "").payload(i + "").build()); + } + for (int i = 0; i < 1001; i++) { + blobstore.putBlob("foo", blobstore.blobBuilder("dir/" + i + "").payload(i + "").build()); + } + assertEquals(blobstore.countBlobs("foo"), 2002); + deleter.execute("foo", ListContainerOptions.Builder.inDirectory("dir")); + assertEquals(blobstore.countBlobs("foo"), 1001); + } + + @AfterClass + void close() { + if (blobstore != null) + Closeables.closeQuietly(blobstore.getContext()); + } +}