[infinispan-commits] Infinispan SVN: r1731 - in trunk/cachestore/cloud: src/integrationtest/java/org/infinispan/loaders/cloud and 2 other directories.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Apr 29 12:28:39 EDT 2010


Author: manik.surtani at jboss.com
Date: 2010-04-29 12:28:38 -0400 (Thu, 29 Apr 2010)
New Revision: 1731

Removed:
   trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/StubCloudServiceBuilder.java
Modified:
   trunk/cachestore/cloud/pom.xml
   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/main/java/org/infinispan/loaders/cloud/CloudCacheStore.java
   trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStoreConfig.java
   trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreTest.java
Log:
[ISPN-334] (Use metadata for expiry info)

Modified: trunk/cachestore/cloud/pom.xml
===================================================================
--- trunk/cachestore/cloud/pom.xml	2010-04-28 14:43:23 UTC (rev 1730)
+++ trunk/cachestore/cloud/pom.xml	2010-04-29 16:28:38 UTC (rev 1731)
@@ -15,7 +15,7 @@
 
    <properties>
       <test.src.dir>src/test/java</test.src.dir>
-      <version.jclouds>1.0-beta-4</version.jclouds>
+      <version.jclouds>1.0-SNAPSHOT</version.jclouds>
    </properties>
 
    <dependencies>
@@ -56,13 +56,6 @@
          <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>
       <!-- =========================================================== -->
       
       <dependency>

Modified: trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java
===================================================================
--- trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java	2010-04-28 14:43:23 UTC (rev 1730)
+++ trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreFunctionalIntegrationTest.java	2010-04-29 16:28:38 UTC (rev 1731)
@@ -75,6 +75,8 @@
       cfg.setProxyPort(proxyPort);
       cfg.setSecure(isSecure);
       cfg.setMaxConnections(maxConnections);
+      // TODO remove compress = false once ISPN-409 is closed.
+      cfg.setCompress(false);
       cfg.setPurgeSynchronously(true); // for more accurate unit testing
       return cfg;
    }

Modified: trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java
===================================================================
--- trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java	2010-04-28 14:43:23 UTC (rev 1730)
+++ trunk/cachestore/cloud/src/integrationtest/java/org/infinispan/loaders/cloud/CloudCacheStoreIntegrationTest.java	2010-04-29 16:28:38 UTC (rev 1731)
@@ -15,7 +15,7 @@
 import org.jclouds.blobstore.domain.Blob;
 import org.jclouds.blobstore.domain.PageSet;
 import org.jclouds.blobstore.domain.StorageMetadata;
-import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
+import org.jclouds.blobstore.options.ListContainerOptions;
 import org.jgroups.protocols.TUNNEL;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
@@ -87,12 +87,15 @@
       CloudCacheStoreConfig cfg = new CloudCacheStoreConfig();
       cfg.setBucketPrefix(bucket);
       cfg.setCloudService(service);
+      cfg.setCloudServiceLocation("Some-Gibberish");
       cfg.setIdentity(accessKey);
       cfg.setPassword(secretKey);
       cfg.setProxyHost(proxyHost);
       cfg.setProxyPort(proxyPort);
       cfg.setSecure(isSecure);
       cfg.setMaxConnections(maxConnections);
+      // TODO remove compress = false once ISPN-409 is closed.
+      cfg.setCompress(false);
       cfg.setPurgeSynchronously(true); // for more accurate unit testing
       cs.init(cfg, new CacheDelegate("aName"), getMarshaller());
       cs.start();
@@ -269,8 +272,8 @@
 
       b = blobStore.getBlob(containerName, blobName);
       assert "world".equals(b.getMetadata().getUserMetadata().get("hello"));
-
-      PageSet<? extends StorageMetadata> ps = blobStore.list(containerName);
+      
+      PageSet<? extends StorageMetadata> ps = blobStore.list(containerName, ListContainerOptions.Builder.withDetails());
       for (StorageMetadata sm: ps) assert "world".equals(sm.getUserMetadata().get("hello"));
    }
 }
\ No newline at end of file

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-04-28 14:43:23 UTC (rev 1730)
+++ trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStore.java	2010-04-29 16:28:38 UTC (rev 1731)
@@ -37,6 +37,8 @@
 import org.jclouds.blobstore.domain.Blob;
 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.enterprise.config.EnterpriseConfigurationModule;
 import org.jclouds.logging.log4j.config.Log4JLoggingModule;
 
@@ -52,7 +54,7 @@
  * This file store stores stuff in the following format:
  * <tt>http://{cloud-storage-provider}/{bucket}/{bucket_number}.bucket</tt>
  * <p/>
- * 
+ *
  * @author Manik Surtani
  * @author Adrian Cole
  * @since 4.0
@@ -78,7 +80,7 @@
 
    private String getThisContainerName() {
       return cfg.getBucketPrefix() + "-"
-               + cache.getName().toLowerCase().replace("_", "").replace(".", "");
+              + cache.getName().toLowerCase().replace("_", "").replace(".", "");
    }
 
    @Override
@@ -88,14 +90,14 @@
 
    @Override
    public void init(CacheLoaderConfig cfg, Cache<?, ?> cache, Marshaller m)
-            throws CacheLoaderException {
+           throws CacheLoaderException {
       this.cfg = (CloudCacheStoreConfig) cfg;
       init(cfg, cache, m, null, null, null, true);
    }
 
    public void init(CacheLoaderConfig cfg, Cache<?, ?> cache, Marshaller m, BlobStoreContext ctx,
-            BlobStore blobStore, AsyncBlobStore asyncBlobStore, boolean constructInternalBlobstores)
-            throws CacheLoaderException {
+                    BlobStore blobStore, AsyncBlobStore asyncBlobStore, boolean constructInternalBlobstores)
+           throws CacheLoaderException {
       super.init(cfg, cache, m);
       this.cfg = (CloudCacheStoreConfig) cfg;
       this.cache = cache;
@@ -126,16 +128,28 @@
             // 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());
+                    .getIdentity(), cfg.getPassword(), ImmutableSet.of(
+                    new EnterpriseConfigurationModule(), new Log4JLoggingModule()),
+                    new Properties());
             blobStore = ctx.getBlobStore();
             asyncBlobStore = ctx.getAsyncBlobStore();
          }
 
          // the "location" is not currently used.
-         if (!blobStore.containerExists(containerName))
-            blobStore.createContainerInLocation(cfg.getCloudServiceLocation(), containerName);
+         if (!blobStore.containerExists(containerName)) {
+            Location chosenLoc = null;
+            if (cfg.getCloudServiceLocation() != null && cfg.getCloudServiceLocation().trim().length() > 0) {
+               Map<String, ? extends Location> availableLocations = blobStore.getLocations();
+               String loc = cfg.getCloudServiceLocation().trim().toLowerCase();
+               chosenLoc = availableLocations.get(loc);
+               if (chosenLoc == null) {
+                  log.warn(
+                     String.format("Unable to use configured Cloud Service Location [%s].  Available locations for Cloud Service [%s] are %s",
+                     loc, cfg.getCloudService(), availableLocations.keySet()));
+               }
+            }
+            blobStore.createContainerInLocation(chosenLoc, containerName);
+         }
          pollFutures = !cfg.getAsyncStoreConfig().isEnabled();
       } catch (IOException ioe) {
          throw new CacheLoaderException("Unable to create context", ioe);
@@ -206,9 +220,8 @@
 
    private void purge() throws CacheLoaderException {
       long currentTime = System.currentTimeMillis();
-      PageSet<? extends StorageMetadata> ps = blobStore.list(containerName);
+      PageSet<? extends StorageMetadata> ps = blobStore.list(containerName, ListContainerOptions.Builder.withDetails());
 
-      // TODO do we need to scroll through the PageSet?
       for (StorageMetadata sm : ps) {
          long lastExpirableEntry = readLastExpirableEntryFromMetadata(sm.getUserMetadata());
          if (lastExpirableEntry < currentTime)
@@ -278,7 +291,7 @@
 
    @Override
    public void applyModifications(List<? extends Modification> modifications)
-            throws CacheLoaderException {
+           throws CacheLoaderException {
       List<Future<?>> futures = new LinkedList<Future<?>>();
       asyncCommandFutures.set(futures);
 
@@ -299,7 +312,7 @@
                Thread.currentThread().interrupt();
             } catch (ExecutionException ee) {
                exception = convertToCacheLoaderException("Caught exception in async process", ee
-                        .getCause());
+                       .getCause());
             }
             if (exception != null)
                throw exception;
@@ -329,7 +342,7 @@
             blob.setPayload(payloadBuffer);
          if (earliestExpiryTime > -1) {
             Map<String, String> md = Collections.singletonMap(EARLIEST_EXPIRY_TIME, String
-                     .valueOf(earliestExpiryTime));
+                    .valueOf(earliestExpiryTime));
             blob.getMetadata().setUserMetadata(md);
          }
 
@@ -359,10 +372,10 @@
                final byte[] byteArray2 = bos2.toByteArray();
 
                log.debug("Decompressed " + bucketName + " from " + byteArray.length + " -> "
-                        + byteArray2.length);
+                       + byteArray2.length);
 
                bucket = (Bucket) marshaller.objectFromInputStream(new ByteArrayInputStream(
-                        byteArray2));
+                       byteArray2));
             } finally {
                is.close();
                bis.close();
@@ -398,7 +411,7 @@
 
    private String encodeBucketName(String decodedName) {
       final String name = (decodedName.startsWith("-")) ? decodedName.replace('-', 'A')
-               : decodedName;
+              : decodedName;
       if (cfg.isCompress())
          return name + ".bz2";
       return name;

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-04-28 14:43:23 UTC (rev 1730)
+++ trunk/cachestore/cloud/src/main/java/org/infinispan/loaders/cloud/CloudCacheStoreConfig.java	2010-04-29 16:28:38 UTC (rev 1731)
@@ -52,7 +52,7 @@
    private boolean secure = true;
    private boolean compress = true;
 
-   private final String cloudServiceLocation = "DEFAULT";
+   private String cloudServiceLocation = "DEFAULT";
    private static final long serialVersionUID = -9011054600279256849L;
 
    public CloudCacheStoreConfig() {
@@ -220,4 +220,8 @@
    public String getCloudServiceLocation() {
       return cloudServiceLocation;
    }
+
+   public void setCloudServiceLocation(String loc) {
+      this.cloudServiceLocation = loc;
+   }
 }
\ No newline at end of file

Modified: trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreTest.java
===================================================================
--- trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreTest.java	2010-04-28 14:43:23 UTC (rev 1730)
+++ trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/CloudCacheStoreTest.java	2010-04-29 16:28:38 UTC (rev 1731)
@@ -10,7 +10,8 @@
 import org.infinispan.loaders.CacheStore;
 import org.infinispan.marshall.Marshaller;
 import org.jclouds.blobstore.BlobStoreContext;
-import org.jclouds.blobstore.integration.StubBlobStoreContextBuilder;
+import org.jclouds.blobstore.BlobStoreContextBuilder;
+import org.jclouds.blobstore.TransientBlobStoreContextBuilder;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -25,7 +26,6 @@
 import java.util.HashSet;
 import java.util.Set;
 
-import static org.infinispan.loaders.cloud.StubCloudServiceBuilder.buildCloudCacheStoreWithStubCloudService;
 import static org.testng.Assert.assertEquals;
 
 @Test(groups = "unit", testName = "loaders.cloud.CloudCacheStoreTest")
@@ -35,14 +35,31 @@
    private static final String cs2Bucket = "Bucket2";
    protected CacheStore cs2;
 
+   private CacheStore buildCloudCacheStoreWithStubCloudService(String bucketName) throws CacheLoaderException {
+      CloudCacheStore cs = new CloudCacheStore();
+      CloudCacheStoreConfig cfg = new CloudCacheStoreConfig();
+      cfg.setBucketPrefix(bucketName);
+      cfg.setCloudService("transient");
+      cfg.setIdentity("unit-test-stub");
+      cfg.setPassword("unit-test-stub");
+      cfg.setProxyHost("unit-test-stub");
+      cfg.setProxyPort("unit-test-stub");
+
+      // TODO remove compress = false once ISPN-409 is closed.
+      cfg.setCompress(false);
+      cfg.setPurgeSynchronously(true); // for more accurate unit testing
+      cs.init(cfg, new CacheDelegate("aName"), getMarshaller());
+      return cs;
+   }
+
    protected CacheStore createCacheStore() throws Exception {
-      CacheStore store = buildCloudCacheStoreWithStubCloudService(csBucket, getMarshaller());
+      CacheStore store = buildCloudCacheStoreWithStubCloudService(csBucket);
       store.start();
       return store;
    }
 
    protected CacheStore createAnotherCacheStore() throws Exception {
-      CacheStore store = buildCloudCacheStoreWithStubCloudService(cs2Bucket, getMarshaller());
+      CacheStore store = buildCloudCacheStoreWithStubCloudService(cs2Bucket);
       store.start();
       return store;
    }

Deleted: trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/StubCloudServiceBuilder.java
===================================================================
--- trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/StubCloudServiceBuilder.java	2010-04-28 14:43:23 UTC (rev 1730)
+++ trunk/cachestore/cloud/src/test/java/org/infinispan/loaders/cloud/StubCloudServiceBuilder.java	2010-04-29 16:28:38 UTC (rev 1731)
@@ -1,25 +0,0 @@
-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;
-   }
-}



More information about the infinispan-commits mailing list