[infinispan-commits] Infinispan SVN: r1462 - in trunk/cachestore/cloud: src and 8 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Mon Feb 8 07:03:50 EST 2010


Author: manik.surtani at jboss.com
Date: 2010-02-08 07:03:50 -0500 (Mon, 08 Feb 2010)
New Revision: 1462

Added:
   trunk/cachestore/cloud/src/integrationtest/
   trunk/cachestore/cloud/src/integrationtest/java/
   trunk/cachestore/cloud/src/integrationtest/java/org/
   trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/
   trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/
   trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/
   trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java
   trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java
   trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java
   trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreTest.java
   trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreVamTest.java
   trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/StubCloudServiceBuilder.java
Removed:
   trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java
   trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java
   trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java
Modified:
   trunk/cachestore/cloud/pom.xml
   trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStore.java
   trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStoreConfig.java
Log:
CloudCacheStore and proper unit testing with stubs

Modified: trunk/cachestore/cloud/pom.xml
===================================================================
--- trunk/cachestore/cloud/pom.xml	2010-02-05 22:24:12 UTC (rev 1461)
+++ trunk/cachestore/cloud/pom.xml	2010-02-08 12:03:50 UTC (rev 1462)
@@ -16,7 +16,7 @@
    <properties>
       <jclouds.aws.accesskeyid></jclouds.aws.accesskeyid>
       <jclouds.aws.secretaccesskey></jclouds.aws.secretaccesskey>
-      <version.jclouds>1.0-beta-3</version.jclouds>
+      <version.jclouds>1.0-SNAPSHOT</version.jclouds>
    </properties>
 
    <dependencies>
@@ -56,6 +56,14 @@
          <version>${version.jclouds}</version>
          <scope>optional</scope>
       </dependency>
+
+      <dependency>
+         <groupId>org.jclouds</groupId>
+         <artifactId>jclouds-blobstore</artifactId>
+         <version>${version.jclouds}</version>
+         <type>test-jar</type>
+         <scope>test</scope>
+      </dependency>
       <!-- =========================================================== -->
    </dependencies>
    <repositories>

Copied: trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java (from rev 1461, trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java)
===================================================================
--- trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java	                        (rev 0)
+++ trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.loaders.cloud;
+
+import org.infinispan.loaders.BaseCacheStoreFunctionalTest;
+import org.infinispan.loaders.CacheStoreConfig;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Optional;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+ at Test(groups = "unit", sequential = true, testName = "loaders.cloud.CloudCacheStoreFunctionalIntegrationTest")
+public class CloudCacheStoreFunctionalIntegrationTest extends BaseCacheStoreFunctionalTest {
+
+   private String proxyHost;
+   private String proxyPort = "-1";
+   private int maxConnections = 20;
+   private boolean isSecure = false;
+   private String csBucket;
+   private String accessKey;
+   private String secretKey;
+   private String cs;
+
+   private static final String sysUsername = System.getProperty("infinispan.jclouds.username");
+   private static final String sysPassword = System.getProperty("infinispan.jclouds.password");
+   private static final String sysService = System.getProperty("infinispan.jclouds.service");
+
+   @BeforeTest
+   @Parameters({"infinispan.jclouds.username", "infinispan.jclouds.password", "infinispan.jclouds.service"})
+   protected void setUpClient(@Optional String JcloudsUsername,
+                              @Optional String JcloudsPassword,
+                              @Optional String JcloudsService) throws Exception {
+
+      accessKey = (JcloudsUsername == null) ? sysUsername : JcloudsUsername;
+      secretKey = (JcloudsPassword == null) ? sysPassword : JcloudsPassword;
+      cs = (JcloudsService == null) ? sysService : JcloudsService;
+
+      if (accessKey == null || accessKey.trim().equals("") || secretKey == null || secretKey.trim().equals("")) {
+         accessKey = "dummy";
+         secretKey = "dummy";
+      }
+      csBucket = (System.getProperty("user.name") + "." + this.getClass().getSimpleName()).toLowerCase().replace('.', '-'); // azure limitation on no periods
+      csBucket = csBucket.length() > 32 ? csBucket.substring(0, 32): csBucket;//azure limitation on length
+      System.out.printf("accessKey: %1$s, bucket: %2$s%n", accessKey, csBucket);
+   }
+
+
+   @Override
+   protected CacheStoreConfig createCacheStoreConfig() throws Exception {
+      CloudCacheStoreConfig cfg = new CloudCacheStoreConfig();
+      cfg.setCloudService(cs);
+      cfg.setBucketPrefix(csBucket);
+      cfg.setIdentity(accessKey);
+      cfg.setPassword(secretKey);
+      cfg.setProxyHost(proxyHost);
+      cfg.setProxyPort(proxyPort);
+      cfg.setSecure(isSecure);
+      cfg.setMaxConnections(maxConnections);
+      cfg.setPurgeSynchronously(true); // for more accurate unit testing
+      return cfg;
+   }
+}


Property changes on: trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java (from rev 1461, trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java)
===================================================================
--- trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java	                        (rev 0)
+++ trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -0,0 +1,250 @@
+package org.infinispan.loaders.cloud;
+
+import org.infinispan.CacheDelegate;
+import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.container.entries.InternalEntryFactory;
+import org.infinispan.io.UnclosableObjectInputStream;
+import org.infinispan.io.UnclosableObjectOutputStream;
+import org.infinispan.loaders.BaseCacheStoreTest;
+import org.infinispan.loaders.CacheLoaderException;
+import org.infinispan.loaders.CacheStore;
+import org.infinispan.marshall.Marshaller;
+import org.jclouds.blobstore.BlobStoreContext;
+import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Optional;
+import org.testng.annotations.Parameters;
+import org.testng.annotations.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.testng.Assert.assertEquals;
+
+ at Test(groups = "unit", sequential = true, testName = "loaders.cloud.CloudCacheStoreIntegrationTest")
+public class CloudCacheStoreIntegrationTest extends BaseCacheStoreTest {
+
+   private String proxyHost;
+   private String proxyPort = "-1";
+   private int maxConnections = 20;
+   private boolean isSecure = false;
+   private String csBucket;
+   private String cs2Bucket;
+   private String accessKey;
+   private String secretKey;
+   private String service;
+
+   private static final String sysUsername = System.getProperty("infinispan.jclouds.username");
+   private static final String sysPassword = System.getProperty("infinispan.jclouds.password");
+   private static final String sysService = System.getProperty("infinispan.jclouds.service");
+
+   @BeforeTest
+   @Parameters({"infinispan.jclouds.username", "infinispan.jclouds.password", "infinispan.jclouds.service"})
+   protected void setUpClient(@Optional String JcloudsUsername,
+                              @Optional String JcloudsPassword,
+                              @Optional String JcloudsService) throws Exception {
+
+      accessKey = (JcloudsUsername == null) ? sysUsername : JcloudsUsername;
+      secretKey = (JcloudsPassword == null) ? sysPassword : JcloudsPassword;
+      service = (JcloudsService == null) ? sysService : JcloudsService;
+
+      if (accessKey == null || accessKey.trim().equals("") || secretKey == null || secretKey.trim().equals("")) {
+         accessKey = "dummy";
+         secretKey = "dummy";
+      }
+      csBucket = (System.getProperty("user.name")
+            + "." + this.getClass().getSimpleName()).toLowerCase();
+      System.out.printf("accessKey: %1$s, bucket: %2$s%n", accessKey, csBucket);
+
+      cs2Bucket = csBucket + "2";
+   }
+
+   protected CacheStore createCacheStore() throws Exception {
+      return createAndStartCacheStore(csBucket);
+   }
+
+   protected CacheStore createAnotherCacheStore() throws Exception {
+      return createAndStartCacheStore(cs2Bucket);
+   }
+
+   private CacheStore createAndStartCacheStore(String bucket) throws Exception {
+      CloudCacheStore cs = new CloudCacheStore();
+      CloudCacheStoreConfig cfg = new CloudCacheStoreConfig();
+      cfg.setBucketPrefix(bucket);
+      cfg.setCloudService(service);
+      cfg.setIdentity(accessKey);
+      cfg.setPassword(secretKey);
+      cfg.setProxyHost(proxyHost);
+      cfg.setProxyPort(proxyPort);
+      cfg.setSecure(isSecure);
+      cfg.setMaxConnections(maxConnections);
+      cfg.setPurgeSynchronously(true); // for more accurate unit testing
+      StubBlobStoreContextBuilder cb = new StubBlobStoreContextBuilder();
+      BlobStoreContext ctx = cb.buildBlobStoreContext();
+      cs.init(cfg, new CacheDelegate("aName"), getMarshaller(), ctx, ctx.getBlobStore(), ctx.getAsyncBlobStore(), false);
+      cs.start();
+      return cs;
+   }
+
+   /*  Changes below are needed to support testing of multiple cache stores */
+
+   protected CacheStore cs2;
+
+   @BeforeMethod
+   @Override
+   public void setUp() throws Exception {
+      super.setUp();
+      cs.clear();
+      Set entries = cs.loadAll();
+      assert entries.size() == 0;
+      cs2 = createAnotherCacheStore();
+      cs2.clear();
+      entries = cs2.loadAll();
+      assert entries.size() == 0;
+   }
+
+
+   @AfterMethod
+   @Override
+   public void tearDown() throws CacheLoaderException {
+      if (cs != null) {
+         cs.clear();
+         cs.stop();
+
+      }
+      cs = null;
+      if (cs2 != null) {
+         cs2.clear();
+
+         cs2.stop();
+      }
+      cs2 = null;
+   }
+
+
+   @SuppressWarnings("unchecked")
+   @Override
+   @Test (enabled = false, description = "Disabled until JClouds gains a proper streaming API")
+   public void testStreamingAPI() throws IOException, ClassNotFoundException, CacheLoaderException {
+      cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
+      cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
+      cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
+
+      Marshaller marshaller = getMarshaller();
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+      ObjectOutput oo = marshaller.startObjectOutput(out, false);
+      try {
+         cs.toStream(new UnclosableObjectOutputStream(oo));
+      } finally {
+         marshaller.finishObjectOutput(oo);
+         out.close();
+      }
+
+      ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+      ObjectInput oi = marshaller.startObjectInput(in, false);
+      try {
+         cs2.fromStream(new UnclosableObjectInputStream(oi));
+      } finally {
+         marshaller.finishObjectInput(oi);
+         in.close();
+      }
+
+      Set<InternalCacheEntry> set = cs2.loadAll();
+      assertEquals(set.size(), 3);
+      Set expected = new HashSet();
+      expected.add("k1");
+      expected.add("k2");
+      expected.add("k3");
+      for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
+      assert expected.isEmpty();
+   }
+
+   public void testNegativeHashCodes() throws CacheLoaderException {
+      ObjectWithNegativeHashcode objectWithNegativeHashcode = new ObjectWithNegativeHashcode();
+      cs.store(InternalEntryFactory.create(objectWithNegativeHashcode, "hello", -1, -1));
+      InternalCacheEntry ice = cs.load(objectWithNegativeHashcode);
+      assert ice.getKey().equals(objectWithNegativeHashcode);
+      assert ice.getValue().equals("hello");
+   }
+
+   private static class ObjectWithNegativeHashcode {
+      String s = "hello";
+
+      @Override
+      public boolean equals(Object o) {
+         if (this == o) return true;
+         if (o == null || getClass() != o.getClass()) return false;
+
+         ObjectWithNegativeHashcode blah = (ObjectWithNegativeHashcode) o;
+         return !(s != null ? !s.equals(blah.s) : blah.s != null);
+      }
+
+      @Override
+      public int hashCode() {
+         return -700;
+      }
+   }
+
+   @Override
+   @Test (enabled = false, description = "Disabled until we can build the blobstore stub to retain state somewhere.")
+   public void testStopStartDoesntNukeValues() throws InterruptedException, CacheLoaderException {
+
+   }
+
+   @SuppressWarnings("unchecked")
+   @Override
+   @Test (enabled = false, description = "Disabled until JClouds gains a proper streaming API")
+   public void testStreamingAPIReusingStreams() throws IOException, ClassNotFoundException, CacheLoaderException {
+      cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
+      cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
+      cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
+
+      Marshaller marshaller = getMarshaller();
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+      byte[] dummyStartBytes = {1, 2, 3, 4, 5, 6, 7, 8};
+      byte[] dummyEndBytes = {8, 7, 6, 5, 4, 3, 2, 1};
+      ObjectOutput oo = marshaller.startObjectOutput(out, false);
+      try {
+         oo.write(dummyStartBytes);
+         cs.toStream(new UnclosableObjectOutputStream(oo));
+         oo.flush();
+         oo.write(dummyEndBytes);
+      } finally {
+         marshaller.finishObjectOutput(oo);
+         out.close();
+      }
+
+      // first pop the start bytes
+      byte[] dummy = new byte[8];
+      ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+      ObjectInput oi = marshaller.startObjectInput(in, false);
+      try {
+         int bytesRead = oi.read(dummy, 0, 8);
+         assert bytesRead == 8;
+         for (int i = 1; i < 9; i++) assert dummy[i - 1] == i : "Start byte stream corrupted!";
+         cs2.fromStream(new UnclosableObjectInputStream(oi));
+         bytesRead = oi.read(dummy, 0, 8);
+         assert bytesRead == 8;
+         for (int i = 8; i > 0; i--) assert dummy[8 - i] == i : "Start byte stream corrupted!";
+      } finally {
+         marshaller.finishObjectInput(oi);
+         in.close();
+      }
+
+      Set<InternalCacheEntry> set = cs2.loadAll();
+      assertEquals(set.size(), 3);
+      Set expected = new HashSet();
+      expected.add("k1");
+      expected.add("k2");
+      expected.add("k3");
+      for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
+      assert expected.isEmpty();
+   }
+}
\ No newline at end of file


Property changes on: trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java (from rev 1461, trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java)
===================================================================
--- trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java	                        (rev 0)
+++ trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.loaders.cloud;
+
+import org.infinispan.commands.RemoteCommandsFactory;
+import org.infinispan.marshall.Marshaller;
+import org.infinispan.marshall.VersionAwareMarshaller;
+import org.testng.annotations.Test;
+
+/**
+ * CloudCacheStoreIntegrationTest using production level marshaller.
+ * 
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+ at Test(groups = "unit", sequential = true, testName = "loaders.cloud.CloudCacheStoreIntegrationVamTest")
+public class CloudCacheStoreIntegrationVamTest extends CloudCacheStoreIntegrationTest {
+   @Override
+   protected Marshaller getMarshaller() {
+      VersionAwareMarshaller marshaller = new VersionAwareMarshaller();
+      marshaller.inject(Thread.currentThread().getContextClassLoader(), new RemoteCommandsFactory());
+      marshaller.start();
+      return marshaller;
+   }
+}


Property changes on: trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStore.java
===================================================================
--- trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStore.java	2010-02-05 22:24:12 UTC (rev 1461)
+++ trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStore.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -57,6 +57,7 @@
    private BlobStore blobStore;
    private AsyncBlobStore asyncBlobStore;
    private boolean pollFutures = false;
+   private boolean constructInternalBlobstores = true;
 
    @Override
    public Class<? extends CacheStoreConfig> getConfigurationClass() {
@@ -75,10 +76,11 @@
    @Override
    public void init(CacheLoaderConfig cfg, Cache<?, ?> cache, Marshaller m) throws CacheLoaderException {
       this.cfg = (CloudCacheStoreConfig) cfg;
-      init(cfg, cache, m, null, null, null);
+      init(cfg, cache, m, null, null, null, true);
    }
 
-   public void init(CacheLoaderConfig cfg, Cache<?, ?> cache, Marshaller m, BlobStoreContext ctx, BlobStore blobStore, AsyncBlobStore asyncBlobStore) throws CacheLoaderException {
+   public void init(CacheLoaderConfig cfg, Cache<?, ?> cache, Marshaller m, BlobStoreContext ctx,
+                    BlobStore blobStore, AsyncBlobStore asyncBlobStore, boolean constructInternalBlobstores) throws CacheLoaderException {
       super.init(cfg, cache, m);
       this.cfg = (CloudCacheStoreConfig) cfg;
       this.cache = cache;
@@ -86,25 +88,30 @@
       this.ctx = ctx;
       this.blobStore = blobStore;
       this.asyncBlobStore = asyncBlobStore;
+      this.constructInternalBlobstores = constructInternalBlobstores;
    }
 
    @Override
    public void start() throws CacheLoaderException {
       super.start();
-      if (cfg.getCloudService() == null) throw new ConfigurationException("CloudService must be set!");
-      if (cfg.getIdentity() == null) throw new ConfigurationException("Identity must be set");
-      if (cfg.getPassword() == null) throw new ConfigurationException("Password must be set");
+      if (constructInternalBlobstores) {
+         if (cfg.getCloudService() == null) throw new ConfigurationException("CloudService must be set!");
+         if (cfg.getIdentity() == null) throw new ConfigurationException("Identity must be set");
+         if (cfg.getPassword() == null) throw new ConfigurationException("Password must be set");
+      }
       if (cfg.getBucketPrefix() == null) throw new ConfigurationException("CloudBucket must be set");
       containerName = getThisContainerName();
       try {
-         // add an executor as a constructor param to EnterpriseConfigurationModule, pass property overrides instead of Properties()
-         ctx = new BlobStoreContextFactory().createContext(cfg.getCloudService(), cfg.getIdentity(), cfg.getPassword(),
+         if (constructInternalBlobstores) {
+            // add an executor as a constructor param to EnterpriseConfigurationModule, pass property overrides instead of Properties()
+            ctx = new BlobStoreContextFactory().createContext(cfg.getCloudService(), cfg.getIdentity(), cfg.getPassword(),
                                                            ImmutableSet.of(new EnterpriseConfigurationModule(), new Log4JLoggingModule()), new Properties());
-         blobStore = ctx.getBlobStore();
-         asyncBlobStore = ctx.getAsyncBlobStore();
+            blobStore = ctx.getBlobStore();
+            asyncBlobStore = ctx.getAsyncBlobStore();
+         }
 
          // the "location" is not currently used.
-         if (!blobStore.containerExists(containerName)) blobStore.createContainerInLocation("DEFAULT", containerName);
+         if (!blobStore.containerExists(containerName)) blobStore.createContainerInLocation(cfg.getCloudServiceLocation(), containerName);
          pollFutures = !cfg.getAsyncStoreConfig().isEnabled();
       } catch (IOException ioe) {
          throw new CacheLoaderException("Unable to create context", ioe);

Modified: trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStoreConfig.java
===================================================================
--- trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStoreConfig.java	2010-02-05 22:24:12 UTC (rev 1461)
+++ trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStoreConfig.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -17,6 +17,7 @@
  * <li><tt>cloudService</tt> - The cloud service to use.  Supported values are <tt>s3</tt> (Amazon AWS), <tt>cloudfiles</tt> (Rackspace Cloud), <tt>azureblob</tt> (Microsoft Azure), and <tt>atmos</tt> (Atmos Online Storage Service).</li>
  * <li><tt>maxConnections</tt> - The maximum number of concurrent connections to make to the cloud provider.  Defaults to 10.</li>
  * <li><tt>secure</tt> - Whether to use secure (SSL) connections or not.  Defaults to <tt>true</tt>.</li>
+ * <li><tt>cloudServiceLocation</tt> - the data center to use.  Note that this is specific to the cloud provider in question.  E.g., Amazon's S3 service supports storage buckets in several different locations.  Valid strings for S3, for example, are <a href="http://github.com/jclouds/jclouds/blob/master/aws/core/src/main/java/org/jclouds/aws/domain/Region.java">here</a>.  Optional, and defaults to <tt>DEFAULT</tt>.</li>
  * </ul>
  *
  * @author Manik Surtani
@@ -33,6 +34,7 @@
    private String cloudService;
    private int maxConnections = 10000;
    private boolean secure = true;
+   private String cloudServiceLocation = "DEFAULT";
 
    public CloudCacheStoreConfig() {
       setCacheLoaderClassName(CloudCacheStore.class.getName());
@@ -132,6 +134,8 @@
       if (secure != that.secure) return false;
       if (bucketPrefix != null ? !bucketPrefix.equals(that.bucketPrefix) : that.bucketPrefix != null) return false;
       if (cloudService != null ? !cloudService.equals(that.cloudService) : that.cloudService != null) return false;
+      if (cloudServiceLocation != null ? !cloudServiceLocation.equals(that.cloudServiceLocation) : that.cloudServiceLocation != null)
+         return false;
       if (identity != null ? !identity.equals(that.identity) : that.identity != null) return false;
       if (password != null ? !password.equals(that.password) : that.password != null) return false;
       if (proxyHost != null ? !proxyHost.equals(that.proxyHost) : that.proxyHost != null) return false;
@@ -153,6 +157,7 @@
       result = 31 * result + (cloudService != null ? cloudService.hashCode() : 0);
       result = 31 * result + maxConnections;
       result = 31 * result + (secure ? 1 : 0);
+      result = 31 * result + (cloudServiceLocation != null ? cloudServiceLocation.hashCode() : 0);
       return result;
    }
 
@@ -161,7 +166,7 @@
       return "CloudCacheStoreConfig{" +
             "bucketPrefix='" + bucketPrefix + '\'' +
             ", identity='" + identity + '\'' +
-            ", password=(hidden)" +
+            ", password='" + password + '\'' +
             ", proxyHost='" + proxyHost + '\'' +
             ", proxyPort='" + proxyPort + '\'' +
             ", requestTimeout=" + requestTimeout +
@@ -169,6 +174,11 @@
             ", cloudService='" + cloudService + '\'' +
             ", maxConnections=" + maxConnections +
             ", secure=" + secure +
+            ", cloudServiceLocation='" + cloudServiceLocation + '\'' +
             '}';
    }
+
+   public String getCloudServiceLocation() {
+      return cloudServiceLocation;
+   }
 }
\ No newline at end of file

Deleted: trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java
===================================================================
--- trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java	2010-02-05 22:24:12 UTC (rev 1461)
+++ trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -1,84 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.loaders.cloud;
-
-import org.infinispan.loaders.BaseCacheStoreFunctionalTest;
-import org.infinispan.loaders.CacheStoreConfig;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Optional;
-import org.testng.annotations.Parameters;
-import org.testng.annotations.Test;
-
-// TODO figure out why a disabled test is still run in Hudson!!
-public class CloudCacheStoreFunctionalIntegrationTest {}
-
-//@Test(groups = "unit", sequential = true, testName = "loaders.cloud.CloudCacheStoreFunctionalIntegrationTest", enabled = false)
-//public class CloudCacheStoreFunctionalIntegrationTest extends BaseCacheStoreFunctionalTest {
-//
-//   private String proxyHost;
-//   private String proxyPort = "-1";
-//   private int maxConnections = 20;
-//   private boolean isSecure = false;
-//   private String csBucket;
-//   private String accessKey;
-//   private String secretKey;
-//   private String cs;
-//
-//   private static final String sysUsername = System.getProperty("infinispan.jclouds.username");
-//   private static final String sysPassword = System.getProperty("infinispan.jclouds.password");
-//   private static final String sysService = System.getProperty("infinispan.jclouds.service");
-//
-//   @BeforeTest
-//   @Parameters({"infinispan.jclouds.username", "infinispan.jclouds.password", "infinispan.jclouds.service"})
-//   protected void setUpClient(@Optional String JcloudsUsername,
-//                              @Optional String JcloudsPassword,
-//                              @Optional String JcloudsService) throws Exception {
-//
-//      accessKey = (JcloudsUsername == null) ? sysUsername : JcloudsUsername;
-//      secretKey = (JcloudsPassword == null) ? sysPassword : JcloudsPassword;
-//      cs = (JcloudsService == null) ? sysService : JcloudsService;
-//
-//      if (accessKey == null || accessKey.trim().equals("") || secretKey == null || secretKey.trim().equals("")) {
-//         accessKey = "dummy";
-//         secretKey = "dummy";
-//      }
-//      csBucket = (System.getProperty("user.name") + "." + this.getClass().getSimpleName()).toLowerCase().replace('.', '-'); // azure limitation on no periods
-//      csBucket = csBucket.length() > 32 ? csBucket.substring(0, 32): csBucket;//azure limitation on length
-//      System.out.printf("accessKey: %1$s, bucket: %2$s%n", accessKey, csBucket);
-//   }
-//
-//
-//   @Override
-//   protected CacheStoreConfig createCacheStoreConfig() throws Exception {
-//      CloudCacheStoreConfig cfg = new CloudCacheStoreConfig();
-//      cfg.setCloudService(cs);
-//      cfg.setBucketPrefix(csBucket);
-//      cfg.setIdentity(accessKey);
-//      cfg.setPassword(secretKey);
-//      cfg.setProxyHost(proxyHost);
-//      cfg.setProxyPort(proxyPort);
-//      cfg.setSecure(isSecure);
-//      cfg.setMaxConnections(maxConnections);
-//      cfg.setPurgeSynchronously(true); // for more accurate unit testing
-//      return cfg;
-//   }
-//}

Deleted: trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java
===================================================================
--- trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java	2010-02-05 22:24:12 UTC (rev 1461)
+++ trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -1,241 +0,0 @@
-package org.infinispan.loaders.cloud;
-
-import org.infinispan.CacheDelegate;
-import org.infinispan.container.entries.InternalCacheEntry;
-import org.infinispan.container.entries.InternalEntryFactory;
-import org.infinispan.io.UnclosableObjectInputStream;
-import org.infinispan.io.UnclosableObjectOutputStream;
-import org.infinispan.loaders.BaseCacheStoreTest;
-import org.infinispan.loaders.CacheLoaderException;
-import org.infinispan.loaders.CacheStore;
-import org.infinispan.marshall.Marshaller;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Optional;
-import org.testng.annotations.Parameters;
-import org.testng.annotations.Test;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.testng.Assert.assertEquals;
-
-// TODO figure out why a disabled test is still run in Hudson!!
-public class CloudCacheStoreIntegrationTest{}
-
-//@Test(groups = "unit", sequential = true, testName = "loaders.cloud.CloudCacheStoreIntegrationTest", enabled = true)
-//public class CloudCacheStoreIntegrationTest extends BaseCacheStoreTest {
-//
-//   private String proxyHost;
-//   private String proxyPort = "-1";
-//   private int maxConnections = 20;
-//   private boolean isSecure = false;
-//   private String csBucket;
-//   private String cs2Bucket;
-//   private String accessKey;
-//   private String secretKey;
-//   private String service;
-//
-//   private static final String sysUsername = System.getProperty("infinispan.jclouds.username");
-//   private static final String sysPassword = System.getProperty("infinispan.jclouds.password");
-//   private static final String sysService = System.getProperty("infinispan.jclouds.service");
-//
-//   @BeforeTest
-//   @Parameters({"infinispan.jclouds.username", "infinispan.jclouds.password", "infinispan.jclouds.service"})
-//   protected void setUpClient(@Optional String JcloudsUsername,
-//                              @Optional String JcloudsPassword,
-//                              @Optional String JcloudsService) throws Exception {
-//
-//      accessKey = (JcloudsUsername == null) ? sysUsername : JcloudsUsername;
-//      secretKey = (JcloudsPassword == null) ? sysPassword : JcloudsPassword;
-//      service = (JcloudsService == null) ? sysService : JcloudsService;
-//
-//      if (accessKey == null || accessKey.trim().equals("") || secretKey == null || secretKey.trim().equals("")) {
-//         accessKey = "dummy";
-//         secretKey = "dummy";
-//      }
-//      csBucket = (System.getProperty("user.name")
-//            + "." + this.getClass().getSimpleName()).toLowerCase();
-//      System.out.printf("accessKey: %1$s, bucket: %2$s%n", accessKey, csBucket);
-//
-//      cs2Bucket = csBucket + "2";
-//   }
-//
-//   protected CacheStore createCacheStore() throws Exception {
-//      return createAndStartCacheStore(csBucket);
-//   }
-//
-//   protected CacheStore createAnotherCacheStore() throws Exception {
-//      return createAndStartCacheStore(cs2Bucket);
-//   }
-//
-//   private CacheStore createAndStartCacheStore(String bucket) throws Exception {
-//      CloudCacheStore cs = new CloudCacheStore();
-//      CloudCacheStoreConfig cfg = new CloudCacheStoreConfig();
-//      cfg.setBucketPrefix(bucket);
-//      cfg.setCloudService(service);
-//      cfg.setIdentity(accessKey);
-//      cfg.setPassword(secretKey);
-//      cfg.setProxyHost(proxyHost);
-//      cfg.setProxyPort(proxyPort);
-//      cfg.setSecure(isSecure);
-//      cfg.setMaxConnections(maxConnections);
-//      cfg.setPurgeSynchronously(true); // for more accurate unit testing
-//      cs.init(cfg, new CacheDelegate("aName"), getMarshaller());
-//      cs.start();
-//      return cs;
-//   }
-//
-//   /*  Changes below are needed to support testing of multiple cache stores */
-//
-//   protected CacheStore cs2;
-//
-//   @BeforeMethod
-//   @Override
-//   public void setUp() throws Exception {
-//      super.setUp();
-//      cs.clear();
-//      Set entries = cs.loadAll();
-//      assert entries.size() == 0;
-//      cs2 = createAnotherCacheStore();
-//      cs2.clear();
-//      entries = cs2.loadAll();
-//      assert entries.size() == 0;
-//   }
-//
-//
-//   @AfterMethod
-//   @Override
-//   public void tearDown() throws CacheLoaderException {
-//      if (cs != null) {
-//         cs.clear();
-//         cs.stop();
-//
-//      }
-//      cs = null;
-//      if (cs2 != null) {
-//         cs2.clear();
-//
-//         cs2.stop();
-//      }
-//      cs2 = null;
-//   }
-//
-//
-//   @SuppressWarnings("unchecked")
-//   @Override
-//   public void testStreamingAPI() throws IOException, ClassNotFoundException, CacheLoaderException {
-//      cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
-//      cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
-//      cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
-//
-//      Marshaller marshaller = getMarshaller();
-//      ByteArrayOutputStream out = new ByteArrayOutputStream();
-//      ObjectOutput oo = marshaller.startObjectOutput(out, false);
-//      try {
-//         cs.toStream(new UnclosableObjectOutputStream(oo));
-//      } finally {
-//         marshaller.finishObjectOutput(oo);
-//         out.close();
-//      }
-//
-//      ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-//      ObjectInput oi = marshaller.startObjectInput(in, false);
-//      try {
-//         cs2.fromStream(new UnclosableObjectInputStream(oi));
-//      } finally {
-//         marshaller.finishObjectInput(oi);
-//         in.close();
-//      }
-//
-//      Set<InternalCacheEntry> set = cs2.loadAll();
-//      assertEquals(set.size(), 3);
-//      Set expected = new HashSet();
-//      expected.add("k1");
-//      expected.add("k2");
-//      expected.add("k3");
-//      for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
-//      assert expected.isEmpty();
-//   }
-//
-//   public void testNegativeHashCodes() throws CacheLoaderException {
-//      ObjectWithNegativeHashcode objectWithNegativeHashcode = new ObjectWithNegativeHashcode();
-//      cs.store(InternalEntryFactory.create(objectWithNegativeHashcode, "hello", -1, -1));
-//      InternalCacheEntry ice = cs.load(objectWithNegativeHashcode);
-//      assert ice.getKey().equals(objectWithNegativeHashcode);
-//      assert ice.getValue().equals("hello");
-//   }
-//
-//   private static class ObjectWithNegativeHashcode {
-//      String s = "hello";
-//
-//      @Override
-//      public boolean equals(Object o) {
-//         if (this == o) return true;
-//         if (o == null || getClass() != o.getClass()) return false;
-//
-//         ObjectWithNegativeHashcode blah = (ObjectWithNegativeHashcode) o;
-//         return !(s != null ? !s.equals(blah.s) : blah.s != null);
-//      }
-//
-//      @Override
-//      public int hashCode() {
-//         return -700;
-//      }
-//   }
-//
-//   @SuppressWarnings("unchecked")
-//   @Override
-//   public void testStreamingAPIReusingStreams() throws IOException, ClassNotFoundException, CacheLoaderException {
-//      cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
-//      cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
-//      cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
-//
-//      Marshaller marshaller = getMarshaller();
-//      ByteArrayOutputStream out = new ByteArrayOutputStream();
-//      byte[] dummyStartBytes = {1, 2, 3, 4, 5, 6, 7, 8};
-//      byte[] dummyEndBytes = {8, 7, 6, 5, 4, 3, 2, 1};
-//      ObjectOutput oo = marshaller.startObjectOutput(out, false);
-//      try {
-//         oo.write(dummyStartBytes);
-//         cs.toStream(new UnclosableObjectOutputStream(oo));
-//         oo.flush();
-//         oo.write(dummyEndBytes);
-//      } finally {
-//         marshaller.finishObjectOutput(oo);
-//         out.close();
-//      }
-//
-//      // first pop the start bytes
-//      byte[] dummy = new byte[8];
-//      ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-//      ObjectInput oi = marshaller.startObjectInput(in, false);
-//      try {
-//         int bytesRead = oi.read(dummy, 0, 8);
-//         assert bytesRead == 8;
-//         for (int i = 1; i < 9; i++) assert dummy[i - 1] == i : "Start byte stream corrupted!";
-//         cs2.fromStream(new UnclosableObjectInputStream(oi));
-//         bytesRead = oi.read(dummy, 0, 8);
-//         assert bytesRead == 8;
-//         for (int i = 8; i > 0; i--) assert dummy[8 - i] == i : "Start byte stream corrupted!";
-//      } finally {
-//         marshaller.finishObjectInput(oi);
-//         in.close();
-//      }
-//
-//      Set<InternalCacheEntry> set = cs2.loadAll();
-//      assertEquals(set.size(), 3);
-//      Set expected = new HashSet();
-//      expected.add("k1");
-//      expected.add("k2");
-//      expected.add("k3");
-//      for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
-//      assert expected.isEmpty();
-//   }
-//}
\ No newline at end of file

Deleted: trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java
===================================================================
--- trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java	2010-02-05 22:24:12 UTC (rev 1461)
+++ trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.infinispan.loaders.cloud;
-
-import org.infinispan.commands.RemoteCommandsFactory;
-import org.infinispan.marshall.Marshaller;
-import org.infinispan.marshall.VersionAwareMarshaller;
-import org.testng.annotations.Test;
-
-// TODO figure out why a disabled test is still run in Hudson!!
-public class CloudCacheStoreIntegrationVamTest{}
-
-
-/**
- * CloudCacheStoreIntegrationTest using production level marshaller.
- * 
- * @author Galder Zamarreño
- * @since 4.0
- */
-//@Test(groups = "unit", sequential = true, testName = "loaders.cloud.CloudCacheStoreIntegrationVamTest", enabled = false)
-//public class CloudCacheStoreIntegrationVamTest extends CloudCacheStoreIntegrationTest {
-//   @Override
-//   protected Marshaller getMarshaller() {
-//      VersionAwareMarshaller marshaller = new VersionAwareMarshaller();
-//      marshaller.inject(Thread.currentThread().getContextClassLoader(), new RemoteCommandsFactory());
-//      marshaller.start();
-//      return marshaller;
-//   }
-//}

Copied: trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreTest.java (from rev 1461, trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java)
===================================================================
--- trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreTest.java	                        (rev 0)
+++ trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreTest.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -0,0 +1,195 @@
+package org.infinispan.loaders.cloud;
+
+import org.infinispan.CacheDelegate;
+import org.infinispan.container.entries.InternalCacheEntry;
+import org.infinispan.container.entries.InternalEntryFactory;
+import org.infinispan.io.UnclosableObjectInputStream;
+import org.infinispan.io.UnclosableObjectOutputStream;
+import org.infinispan.loaders.BaseCacheStoreTest;
+import org.infinispan.loaders.CacheLoaderException;
+import org.infinispan.loaders.CacheStore;
+import org.infinispan.marshall.Marshaller;
+import org.jclouds.blobstore.BlobStoreContext;
+import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.infinispan.loaders.cloud.StubCloudServiceBuilder.buildCloudCacheStoreWithStubCloudService;
+import static org.testng.Assert.assertEquals;
+
+ at Test(groups = "unit", testName = "loaders.cloud.CloudCacheStoreTest")
+public class CloudCacheStoreTest extends BaseCacheStoreTest {
+
+   private static final String csBucket = "Bucket1";
+   private static final String cs2Bucket = "Bucket2";
+   protected CacheStore cs2;
+
+   protected CacheStore createCacheStore() throws Exception {
+      CacheStore store = buildCloudCacheStoreWithStubCloudService(csBucket, getMarshaller());
+      store.start();
+      return store;
+   }
+
+   protected CacheStore createAnotherCacheStore() throws Exception {
+      CacheStore store = buildCloudCacheStoreWithStubCloudService(cs2Bucket, getMarshaller());
+      store.start();
+      return store;
+   }
+
+   @BeforeMethod
+   @Override
+   public void setUp() throws Exception {
+      super.setUp();
+      cs.clear();
+      Set entries = cs.loadAll();
+      assert entries.size() == 0;
+      cs2 = createAnotherCacheStore();
+      cs2.clear();
+      entries = cs2.loadAll();
+      assert entries.size() == 0;
+   }
+
+
+   @AfterMethod
+   @Override
+   public void tearDown() throws CacheLoaderException {
+      for (CacheStore cacheStore : Arrays.asList(cs, cs2)) {
+         if (cacheStore != null) {
+            cacheStore.clear();
+            cacheStore.stop();
+         }
+      }
+      cs = null; cs2 = null;
+   }
+
+
+   @SuppressWarnings("unchecked")
+   @Override
+   @Test(enabled = false, description = "Disabled until JClouds gains a proper streaming API")
+   public void testStreamingAPI() throws IOException, ClassNotFoundException, CacheLoaderException {
+      cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
+      cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
+      cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
+
+      Marshaller marshaller = getMarshaller();
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+      ObjectOutput oo = marshaller.startObjectOutput(out, false);
+      try {
+         cs.toStream(new UnclosableObjectOutputStream(oo));
+      } finally {
+         marshaller.finishObjectOutput(oo);
+         out.close();
+      }
+
+      ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+      ObjectInput oi = marshaller.startObjectInput(in, false);
+      try {
+         cs2.fromStream(new UnclosableObjectInputStream(oi));
+      } finally {
+         marshaller.finishObjectInput(oi);
+         in.close();
+      }
+
+      Set<InternalCacheEntry> set = cs2.loadAll();
+      assertEquals(set.size(), 3);
+      Set expected = new HashSet();
+      expected.add("k1");
+      expected.add("k2");
+      expected.add("k3");
+      for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
+      assert expected.isEmpty();
+   }
+
+   public void testNegativeHashCodes() throws CacheLoaderException {
+      ObjectWithNegativeHashcode objectWithNegativeHashcode = new ObjectWithNegativeHashcode();
+      cs.store(InternalEntryFactory.create(objectWithNegativeHashcode, "hello", -1, -1));
+      InternalCacheEntry ice = cs.load(objectWithNegativeHashcode);
+      assert ice.getKey().equals(objectWithNegativeHashcode);
+      assert ice.getValue().equals("hello");
+   }
+
+   private static class ObjectWithNegativeHashcode implements Serializable {
+      String s = "hello";
+
+      @Override
+      public boolean equals(Object o) {
+         if (this == o) return true;
+         if (o == null || getClass() != o.getClass()) return false;
+
+         ObjectWithNegativeHashcode blah = (ObjectWithNegativeHashcode) o;
+         return !(s != null ? !s.equals(blah.s) : blah.s != null);
+      }
+
+      @Override
+      public int hashCode() {
+         return -700;
+      }
+   }
+
+   @Override
+   @Test(enabled = false, description = "Disabled until we can build the blobstore stub to retain state somewhere.")
+   public void testStopStartDoesntNukeValues() throws InterruptedException, CacheLoaderException {
+
+   }
+
+   @SuppressWarnings("unchecked")
+   @Override
+   @Test(enabled = false, description = "Disabled until JClouds gains a proper streaming API")
+   public void testStreamingAPIReusingStreams() throws IOException, ClassNotFoundException, CacheLoaderException {
+      cs.store(InternalEntryFactory.create("k1", "v1", -1, -1));
+      cs.store(InternalEntryFactory.create("k2", "v2", -1, -1));
+      cs.store(InternalEntryFactory.create("k3", "v3", -1, -1));
+
+      Marshaller marshaller = getMarshaller();
+      ByteArrayOutputStream out = new ByteArrayOutputStream();
+      byte[] dummyStartBytes = {1, 2, 3, 4, 5, 6, 7, 8};
+      byte[] dummyEndBytes = {8, 7, 6, 5, 4, 3, 2, 1};
+      ObjectOutput oo = marshaller.startObjectOutput(out, false);
+      try {
+         oo.write(dummyStartBytes);
+         cs.toStream(new UnclosableObjectOutputStream(oo));
+         oo.flush();
+         oo.write(dummyEndBytes);
+      } finally {
+         marshaller.finishObjectOutput(oo);
+         out.close();
+      }
+
+      // first pop the start bytes
+      byte[] dummy = new byte[8];
+      ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+      ObjectInput oi = marshaller.startObjectInput(in, false);
+      try {
+         int bytesRead = oi.read(dummy, 0, 8);
+         assert bytesRead == 8;
+         for (int i = 1; i < 9; i++) assert dummy[i - 1] == i : "Start byte stream corrupted!";
+         cs2.fromStream(new UnclosableObjectInputStream(oi));
+         bytesRead = oi.read(dummy, 0, 8);
+         assert bytesRead == 8;
+         for (int i = 8; i > 0; i--) assert dummy[8 - i] == i : "Start byte stream corrupted!";
+      } finally {
+         marshaller.finishObjectInput(oi);
+         in.close();
+      }
+
+      Set<InternalCacheEntry> set = cs2.loadAll();
+      assertEquals(set.size(), 3);
+      Set expected = new HashSet();
+      expected.add("k1");
+      expected.add("k2");
+      expected.add("k3");
+      for (InternalCacheEntry se : set) assert expected.remove(se.getKey());
+      assert expected.isEmpty();
+   }
+}
\ No newline at end of file

Copied: trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreVamTest.java (from rev 1461, trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationVamTest.java)
===================================================================
--- trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreVamTest.java	                        (rev 0)
+++ trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreVamTest.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.loaders.cloud;
+
+import org.infinispan.commands.RemoteCommandsFactory;
+import org.infinispan.marshall.Marshaller;
+import org.infinispan.marshall.VersionAwareMarshaller;
+import org.testng.annotations.Test;
+
+/**
+ * CloudCacheStoreVamTest using production level marshaller.
+ * 
+ * @author Galder Zamarreño
+ * @since 4.0
+ */
+ at Test(groups = "unit", testName = "loaders.cloud.CloudCacheStoreVamTest")
+public class CloudCacheStoreVamTest extends CloudCacheStoreTest {
+   @Override
+   protected Marshaller getMarshaller() {
+      VersionAwareMarshaller marshaller = new VersionAwareMarshaller();
+      marshaller.inject(Thread.currentThread().getContextClassLoader(), new RemoteCommandsFactory());
+      marshaller.start();
+      return marshaller;
+   }
+}

Added: trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/StubCloudServiceBuilder.java
===================================================================
--- trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/StubCloudServiceBuilder.java	                        (rev 0)
+++ trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/StubCloudServiceBuilder.java	2010-02-08 12:03:50 UTC (rev 1462)
@@ -0,0 +1,25 @@
+package org.infinispan.loaders.cloud;
+
+import org.infinispan.CacheDelegate;
+import org.infinispan.loaders.CacheLoaderException;
+import org.infinispan.marshall.Marshaller;
+import org.jclouds.blobstore.BlobStoreContext;
+import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
+
+public class StubCloudServiceBuilder {
+   public static CloudCacheStore buildCloudCacheStoreWithStubCloudService(String bucket, Marshaller marshaller) throws CacheLoaderException {
+      CloudCacheStore cs = new CloudCacheStore();
+      CloudCacheStoreConfig cfg = new CloudCacheStoreConfig();
+      cfg.setBucketPrefix(bucket);
+      cfg.setCloudService("unit-test-stub");
+      cfg.setIdentity("unit-test-stub");
+      cfg.setPassword("unit-test-stub");
+      cfg.setProxyHost("unit-test-stub");
+      cfg.setProxyPort("unit-test-stub");
+      cfg.setPurgeSynchronously(true); // for more accurate unit testing
+      StubBlobStoreContextBuilder cb = new StubBlobStoreContextBuilder();
+      BlobStoreContext ctx = cb.buildBlobStoreContext();
+      cs.init(cfg, new CacheDelegate("aName"), marshaller, ctx, ctx.getBlobStore(), ctx.getAsyncBlobStore(), false);
+      return cs;
+   }
+}


Property changes on: trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/StubCloudServiceBuilder.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF



More information about the infinispan-commits mailing list