jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From am...@apache.org
Subject svn commit: r1665148 - in /jackrabbit/trunk: jackrabbit-aws-ext/ jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/ jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/a...
Date Mon, 09 Mar 2015 08:26:00 GMT
Author: amitj
Date: Mon Mar  9 08:25:59 2015
New Revision: 1665148

URL: http://svn.apache.org/r1665148
Log:
JCR-3852: [jackrabbit-aws-ext] Refactor code to open S3 service & consolidate testcases
Patch from Shashank Gupta

Modified:
    jackrabbit/trunk/jackrabbit-aws-ext/pom.xml
    jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/Utils.java
    jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java
    jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/S3TestDataStore.java
    jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSAsyncTouch.java
    jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSWithSmallCache.java
    jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3Ds.java
    jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DsCacheOff.java
    jackrabbit/trunk/jackrabbit-aws-ext/src/test/resources/log4j.properties
    jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java
    jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java
    jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestLocalCache.java

Modified: jackrabbit/trunk/jackrabbit-aws-ext/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/pom.xml?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/pom.xml Mon Mar  9 08:25:59 2015
@@ -43,8 +43,8 @@
         </dependency>
         <dependency>
             <groupId>com.amazonaws</groupId>
-            <artifactId>aws-java-sdk</artifactId>
-            <version>1.9.11</version>
+            <artifactId>aws-java-sdk-s3</artifactId>
+            <version>1.9.22</version>
         </dependency>
         <dependency>
             <groupId>org.apache.jackrabbit</groupId>

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/Utils.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/Utils.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/Utils.java
(original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/Utils.java
Mon Mar  9 08:25:59 2015
@@ -30,6 +30,7 @@ import com.amazonaws.ClientConfiguration
 import com.amazonaws.Protocol;
 import com.amazonaws.auth.AWSCredentials;
 import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.s3.model.Region;
 import com.amazonaws.services.s3.AmazonS3;
 import com.amazonaws.services.s3.AmazonS3Client;
 import com.amazonaws.services.s3.model.ObjectListing;
@@ -47,6 +48,22 @@ public final class Utils {
     private static final String DELETE_CONFIG_SUFFIX = ";burn";
 
     /**
+     * The default value AWS bucket region.
+     */
+    public static final String DEFAULT_AWS_BUCKET_REGION = "us-standard";
+
+    /**
+     * constants to define endpoint to various AWS region
+     */
+    public static final String AWSDOTCOM = "amazonaws.com";
+
+    public static final String S3 = "s3";
+
+    public static final String DOT = ".";
+
+    public static final String DASH = "-";
+
+    /**
      * private constructor so that class cannot initialized from outside.
      */
     private Utils() {
@@ -63,20 +80,29 @@ public final class Utils {
         AWSCredentials credentials = new BasicAWSCredentials(
             prop.getProperty(S3Constants.ACCESS_KEY),
             prop.getProperty(S3Constants.SECRET_KEY));
-        int connectionTimeOut = Integer.parseInt(prop.getProperty(S3Constants.S3_CONN_TIMEOUT));
-        int socketTimeOut = Integer.parseInt(prop.getProperty(S3Constants.S3_SOCK_TIMEOUT));
-        int maxConnections = Integer.parseInt(prop.getProperty(S3Constants.S3_MAX_CONNS));
-        int maxErrorRetry = Integer.parseInt(prop.getProperty(S3Constants.S3_MAX_ERR_RETRY));
-        ClientConfiguration cc = new ClientConfiguration();
-        String protocol = prop.getProperty(S3Constants.S3_CONN_PROTOCOL);
-        if ( protocol != null && protocol.equalsIgnoreCase("http")) {
-            cc.setProtocol(Protocol.HTTP);
+        AmazonS3Client s3service =  new AmazonS3Client(credentials, getClientConfiguration(prop));
+        String region = prop.getProperty(S3Constants.S3_REGION);
+        String endpoint = null;
+        String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT);
+        if ((propEndPoint != null) & !"".equals(propEndPoint)) {
+            endpoint = propEndPoint;
+        } else {
+            if (DEFAULT_AWS_BUCKET_REGION.equals(region)) {
+                endpoint = S3 + DOT + AWSDOTCOM;
+            } else if (Region.EU_Ireland.toString().equals(region)) {
+                endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM;
+            } else {
+                endpoint = S3 + DASH + region + DOT + AWSDOTCOM;
+            }
         }
-        cc.setConnectionTimeout(connectionTimeOut);
-        cc.setSocketTimeout(socketTimeOut);
-        cc.setMaxConnections(maxConnections);
-        cc.setMaxErrorRetry(maxErrorRetry);
-        return new AmazonS3Client(credentials, cc);
+        /*
+         * setting endpoint to remove latency of redirection. If endpoint is
+         * not set, invocation first goes us standard region, which
+         * redirects it to correct location.
+         */
+        s3service.setEndpoint(endpoint);
+        LOG.info("S3 service endpoint [{}] ", endpoint);
+        return s3service;
     }
 
     /**
@@ -142,4 +168,21 @@ public final class Utils {
         }
     }
 
+    private static ClientConfiguration getClientConfiguration(Properties prop) {
+        int connectionTimeOut = Integer.parseInt(prop.getProperty(S3Constants.S3_CONN_TIMEOUT));
+        int socketTimeOut = Integer.parseInt(prop.getProperty(S3Constants.S3_SOCK_TIMEOUT));
+        int maxConnections = Integer.parseInt(prop.getProperty(S3Constants.S3_MAX_CONNS));
+        int maxErrorRetry = Integer.parseInt(prop.getProperty(S3Constants.S3_MAX_ERR_RETRY));
+        ClientConfiguration cc = new ClientConfiguration();
+        String protocol = prop.getProperty(S3Constants.S3_CONN_PROTOCOL);
+        if (protocol != null && protocol.equalsIgnoreCase("http")) {
+            cc.setProtocol(Protocol.HTTP);
+        }
+        cc.setConnectionTimeout(connectionTimeOut);
+        cc.setSocketTimeout(socketTimeOut);
+        cc.setMaxConnections(maxConnections);
+        cc.setMaxErrorRetry(maxErrorRetry);
+        return cc;
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java
(original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/main/java/org/apache/jackrabbit/aws/ext/ds/S3Backend.java
Mon Mar  9 08:25:59 2015
@@ -77,22 +77,6 @@ public class S3Backend implements Backen
 
     private static final String KEY_PREFIX = "dataStore_";
 
-    /**
-     * The default value AWS bucket region.
-     */
-    private static final String DEFAULT_AWS_BUCKET_REGION = "us-standard";
-
-    /**
-     * constants to define endpoint to various AWS region
-     */
-    private static final String AWSDOTCOM = "amazonaws.com";
-
-    private static final String S3 = "s3";
-
-    private static final String DOT = ".";
-
-    private static final String DASH = "-";
-    
     private AmazonS3Client s3service;
 
     private String bucket;
@@ -150,33 +134,19 @@ public class S3Backend implements Backen
             }
             String region = prop.getProperty(S3Constants.S3_REGION);
             Region s3Region = null;
-            String endpoint = null;
-            if (DEFAULT_AWS_BUCKET_REGION.equals(region)) {
+            if (Utils.DEFAULT_AWS_BUCKET_REGION.equals(region)) {
                 s3Region =  Region.US_Standard;
-                endpoint = S3 + DOT + AWSDOTCOM;
             } else if (Region.EU_Ireland.toString().equals(region)) {
                 s3Region = Region.EU_Ireland;
-                endpoint = "s3-eu-west-1" + DOT + AWSDOTCOM;
             } else {
                 s3Region = Region.fromValue(region);
-                endpoint = S3 + DASH + region + DOT + AWSDOTCOM;
             }
             
-            String propEndPoint = prop.getProperty(S3Constants.S3_END_POINT);
-            if ((propEndPoint != null) & !"".equals(propEndPoint)) {
-                endpoint = propEndPoint;
-            }
-            /*
-             * setting endpoint to remove latency of redirection. If endpoint is
-             * not set, invocation first goes us standard region, which
-             * redirects it to correct location.
-             */
-            s3service.setEndpoint(endpoint);
-            LOG.info("S3 service endpoint [{}] ", endpoint);
-           
             if (!s3service.doesBucketExist(bucket)) {
                 s3service.createBucket(bucket, s3Region);
                 LOG.info("Created bucket [{}] in [{}] ", bucket, region);
+            } else {
+                LOG.info("Using bucket [{}] in [{}] ", bucket, region);
             }
            
             int writeThreads = 10;
@@ -200,8 +170,9 @@ public class S3Backend implements Backen
                 asyncWritePoolSize, new NamedThreadFactory("s3-write-worker"));
             String renameKeyProp = prop.getProperty(S3Constants.S3_RENAME_KEYS);
             boolean renameKeyBool = (renameKeyProp == null || "".equals(renameKeyProp))
-                    ? true
+                    ? false
                     : Boolean.parseBoolean(renameKeyProp);
+            LOG.info("Rename keys [{}]", renameKeyBool);
             if (renameKeyBool) {
                 renameKeys();
             }
@@ -796,7 +767,7 @@ public class S3Backend implements Backen
                 + "] doesn't start with prefix [" + KEY_PREFIX + "]");
         }
         String key = oldKey.substring(KEY_PREFIX.length());
-        return key.substring(0, 4) + DASH + key.substring(4);
+        return key.substring(0, 4) + Utils.DASH + key.substring(4);
     }
 
     /**
@@ -804,14 +775,14 @@ public class S3Backend implements Backen
      */
     private static String getKeyName(DataIdentifier identifier) {
         String key = identifier.toString();
-        return key.substring(0, 4) + DASH + key.substring(4);
+        return key.substring(0, 4) + Utils.DASH + key.substring(4);
     }
 
     /**
      * Get data identifier from key.
      */
     private static String getIdentifierName(String key) {
-        if (!key.contains(DASH)) {
+        if (!key.contains(Utils.DASH)) {
             return null;
         }
         return key.substring(0, 4) + key.substring(5);

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/S3TestDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/S3TestDataStore.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/S3TestDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/S3TestDataStore.java
Mon Mar  9 08:25:59 2015
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.aws.ext.ds;
 
+import java.util.Properties;
+
 import org.apache.jackrabbit.core.data.Backend;
 
 /**
@@ -25,20 +27,21 @@ import org.apache.jackrabbit.core.data.B
  * bucket are not immediately reflected in the next test case.
  */
 public class S3TestDataStore extends S3DataStore {
-    String bucket;
+
+    Properties props;
 
     public S3TestDataStore() {
         super();
     }
 
-    public S3TestDataStore(String bucket) {
+    public S3TestDataStore(Properties props) {
         super();
-        this.bucket = bucket;
+        this.props = props;
     }
 
     protected Backend createBackend() {
         Backend backend = new S3Backend();
-        ((S3Backend) backend).setBucket(bucket);
+        ((S3Backend) backend).setProperties(props);
         return backend;
     }
 }

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSAsyncTouch.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSAsyncTouch.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSAsyncTouch.java
(original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSAsyncTouch.java
Mon Mar  9 08:25:59 2015
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.aws.ext.ds;
 
+import java.io.IOException;
+
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.core.data.CachingDataStore;
@@ -31,14 +33,15 @@ import org.slf4j.LoggerFactory;
  */
 public class TestS3DSAsyncTouch extends TestS3Ds {
 
-    public TestS3DSAsyncTouch() {
+    protected static final Logger LOG = LoggerFactory.getLogger(TestS3DSAsyncTouch.class);
 
+    public TestS3DSAsyncTouch() throws IOException {
         config = System.getProperty(CONFIG);
         memoryBackend = false;
         noCache = false;
     }
     
     protected CachingDataStore createDataStore() throws RepositoryException {
-        ds = new S3TestDataStore(String.valueOf(randomGen.nextInt(9999)) + "-test");
+        ds = new S3TestDataStore(props);
         ds.setConfig(config);
         ds.init(dataStoreDir);
         ds.setTouchAsync(true);

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSWithSmallCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSWithSmallCache.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSWithSmallCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DSWithSmallCache.java
Mon Mar  9 08:25:59 2015
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.aws.ext.ds;
 
+import java.io.IOException;
+
 import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.core.data.CachingDataStore;
@@ -31,14 +33,16 @@ import org.slf4j.LoggerFactory;
  */
 public class TestS3DSWithSmallCache extends TestS3Ds {
 
-    public TestS3DSWithSmallCache() {
+    protected static final Logger LOG = LoggerFactory.getLogger(TestS3DSWithSmallCache.class);
+    
+    public TestS3DSWithSmallCache() throws IOException {
         config = System.getProperty(CONFIG);
         memoryBackend = false;
         noCache = false;
     }
     
     protected CachingDataStore createDataStore() throws RepositoryException {
-        ds = new S3TestDataStore(String.valueOf(randomGen.nextInt(9999)) + "-test");
+        ds = new S3TestDataStore(props);
         ds.setConfig(config);
         ds.setCacheSize(dataLength * 10);
         ds.setCachePurgeTrigFactor(0.5d);

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3Ds.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3Ds.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3Ds.java
(original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3Ds.java
Mon Mar  9 08:25:59 2015
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.aws.ext.ds;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -23,6 +24,7 @@ import java.util.Properties;
 
 import javax.jcr.RepositoryException;
 
+import org.apache.jackrabbit.aws.ext.S3Constants;
 import org.apache.jackrabbit.aws.ext.Utils;
 import org.apache.jackrabbit.core.data.Backend;
 import org.apache.jackrabbit.core.data.CachingDataStore;
@@ -48,23 +50,35 @@ public class TestS3Ds extends TestCaseBa
 
     private Date startTime = null;
 
-    public TestS3Ds() {
+    protected Properties props;
+
+    public TestS3Ds() throws IOException {
       config = System.getProperty(CONFIG);
       memoryBackend = false;
       noCache = false;
+      props = Utils.readConfig(config);
   }
 
     protected void setUp() throws Exception {
         startTime = new Date();
         super.setUp();
+        String bucket = String.valueOf(randomGen.nextInt(9999)) + "-"
+                        + String.valueOf(randomGen.nextInt(9999)) + "-test";
+        props.setProperty(S3Constants.S3_BUCKET, bucket );
+        // delete bucket if exists
+        deleteBucket(bucket);
     }
-    protected void tearDown() throws Exception {
-        deleteBucket();
-        super.tearDown();
+    protected void tearDown()  {
+        try {
+            deleteBucket();
+            super.tearDown();
+        } catch ( Exception ignore ) {
+            
+        }
     }
     
     protected CachingDataStore createDataStore() throws RepositoryException {
-        ds = new S3TestDataStore(String.valueOf(randomGen.nextInt(9999)) + "-test");
+        ds = new S3TestDataStore(props);
         ds.setConfig(config);
         if (noCache) {
             ds.setCacheSize(0);
@@ -80,23 +94,30 @@ public class TestS3Ds extends TestCaseBa
      * Cleaning of bucket after test run.
      */
     public void deleteBucket() throws Exception {
-        Properties props = Utils.readConfig(config);
-        AmazonS3Client s3service = Utils.openService(props);
         Backend backend = ds.getBackend();
         String bucket = ((S3Backend)backend).getBucket();
-        LOG.info("delete bucket [" + bucket + "]");
+        deleteBucket(bucket);
+    }
+    
+    public void deleteBucket(String bucket) throws Exception {
+        LOG.info("deleting bucket [" + bucket + "]");
+        Properties props = Utils.readConfig(config);
+        AmazonS3Client s3service = Utils.openService(props);
         TransferManager tmx = new TransferManager(s3service);
+
         if (s3service.doesBucketExist(bucket)) {
-            for (int i = 0; i < 3; i++) {
+            for (int i = 0; i < 4; i++) {
                 tmx.abortMultipartUploads(bucket, startTime);
                 ObjectListing prevObjectListing = s3service.listObjects(bucket);
-                while (prevObjectListing != null ) {
+                while (prevObjectListing != null) {
                     List<DeleteObjectsRequest.KeyVersion> deleteList = new ArrayList<DeleteObjectsRequest.KeyVersion>();
                     for (S3ObjectSummary s3ObjSumm : prevObjectListing.getObjectSummaries())
{
-                        deleteList.add(new DeleteObjectsRequest.KeyVersion(s3ObjSumm.getKey()));
+                        deleteList.add(new DeleteObjectsRequest.KeyVersion(
+                            s3ObjSumm.getKey()));
                     }
                     if (deleteList.size() > 0) {
-                        DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(bucket);
+                        DeleteObjectsRequest delObjsReq = new DeleteObjectsRequest(
+                            bucket);
                         delObjsReq.setKeys(deleteList);
                         s3service.deleteObjects(delObjsReq);
                     }
@@ -105,10 +126,13 @@ public class TestS3Ds extends TestCaseBa
                 }
             }
             s3service.deleteBucket(bucket);
-            LOG.info("bucket: " + bucket + " deleted");
-            tmx.shutdownNow();
-            s3service.shutdown();
+            LOG.info("bucket [ " + bucket + "] deleted");
+
+        } else {
+            LOG.info("bucket [" + bucket + "] doesn't exists");
         }
+        tmx.shutdownNow();
+        s3service.shutdown();
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DsCacheOff.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DsCacheOff.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DsCacheOff.java
(original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/test/java/org/apache/jackrabbit/aws/ext/ds/TestS3DsCacheOff.java
Mon Mar  9 08:25:59 2015
@@ -16,6 +16,8 @@
  */
 package org.apache.jackrabbit.aws.ext.ds;
 
+import java.io.IOException;
+
 import org.apache.jackrabbit.core.data.CachingDataStore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -30,7 +32,7 @@ public class TestS3DsCacheOff extends Te
 
     protected static final Logger LOG = LoggerFactory.getLogger(TestS3DsCacheOff.class);
 
-    public TestS3DsCacheOff() {
+    public TestS3DsCacheOff() throws IOException {
         config = System.getProperty(CONFIG);
         memoryBackend = false;
         noCache = true;

Modified: jackrabbit/trunk/jackrabbit-aws-ext/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-aws-ext/src/test/resources/log4j.properties?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-aws-ext/src/test/resources/log4j.properties (original)
+++ jackrabbit/trunk/jackrabbit-aws-ext/src/test/resources/log4j.properties Mon Mar  9 08:25:59
2015
@@ -17,8 +17,8 @@
 
 # this is the log4j configuration for the JCR API tests
 log4j.rootLogger=INFO, file
-log4j.logger.org.apache.jackrabbit.core.data=DEBUG
-log4j.logger.org.apache.jackrabbit.aws.ext.ds=DEBUG
+log4j.logger.org.apache.jackrabbit.core.data.CachingDataStore=ERROR
+log4j.logger.org.apache.jackrabbit.aws.ext.ds=INFO
 
 #log4j.logger.org.apache.jackrabbit.test=DEBUG
 

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/LocalCache.java
Mon Mar  9 08:25:59 2015
@@ -24,12 +24,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -218,8 +215,11 @@ public class LocalCache {
             if (destExists) {
                 dest.setLastModified(System.currentTimeMillis());
             }
-            LOG.debug("file [{}]  exists= [{}] and adding to local cache.",
-                fileName, destExists);
+            LOG.debug(
+                "file [{}]  exists= [{}] added to local cache, isLastModified [{}]",
+                new Object[] { dest.getAbsolutePath(), dest.exists(),
+                    destExists });
+            
             cache.put(fileName, dest.length());
             result.setFile(dest);
             if (tryForAsyncUpload) {
@@ -251,7 +251,7 @@ public class LocalCache {
         if (!f.exists() || (isInPurgeMode() && !asyncUploadCache.hasEntry(fileName,
false))) {
             LOG.debug(
                 "getFileIfStored returned: purgeMode=[{}], file=[{}] exists=[{}]",
-                new Object[] { isInPurgeMode(), fileName, f.exists() });
+                new Object[] { isInPurgeMode(), f.getAbsolutePath(), f.exists() });
             return null;
         } else {
             // touch entry in LRU caches
@@ -365,7 +365,7 @@ public class LocalCache {
         LOG.debug("try deleting file [{}]", fileName);
         File f = getFile(fileName);
         if (f.exists() && f.delete()) {
-            LOG.debug("File [{}]  deleted successfully", fileName);
+            LOG.info("File [{}]  deleted successfully", f.getAbsolutePath());
             toBeDeleted.remove(fileName);
             while (true) {
                 f = f.getParentFile();

Modified: jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCaseBase.java
Mon Mar  9 08:25:59 2015
@@ -93,15 +93,25 @@ public abstract class TestCaseBase exten
      */
     @Override
     protected void setUp() throws Exception {
-        dataStoreDir = TEST_DIR + "-"
-            + String.valueOf(randomGen.nextInt(dataLength));
+        dataStoreDir = TEST_DIR + "-" + String.valueOf(randomGen.nextInt(9999))
+            + "-" + String.valueOf(randomGen.nextInt(9999));
+        // delete directory if it exists
+        File directory = new File(dataStoreDir);
+        if (directory.exists()) {
+            boolean delSuccessFul = FileUtils.deleteQuietly(directory);
+            int retry = 2, count = 0;
+            while (!delSuccessFul && count <= retry) {
+                // try once more
+                delSuccessFul = FileUtils.deleteQuietly(new File(dataStoreDir));
+                count++;
+            }
+            LOG.info("setup : directory [" + dataStoreDir + "] deleted ["
+                + delSuccessFul + "]");
+        }
     }
 
-    /**
-     * Delete temporary directory.
-     */
     @Override
-    protected void tearDown() throws Exception {
+    protected void tearDown() {
         boolean delSuccessFul = FileUtils.deleteQuietly(new File(dataStoreDir));
         int retry = 2, count = 0;
         while (!delSuccessFul && count <= retry) {
@@ -112,7 +122,6 @@ public abstract class TestCaseBase exten
         LOG.info("tearDown : directory [" + dataStoreDir + "] deleted ["
             + delSuccessFul + "]");
     }
-
     /**
      * Testcase to validate {@link DataStore#addRecord(InputStream)} API.
      */

Modified: jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestLocalCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestLocalCache.java?rev=1665148&r1=1665147&r2=1665148&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestLocalCache.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestLocalCache.java
Mon Mar  9 08:25:59 2015
@@ -32,7 +32,6 @@ import junit.framework.TestCase;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.core.data.util.NamedThreadFactory;
-import org.apache.jackrabbit.core.fs.local.FileUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,18 +45,31 @@ public class TestLocalCache extends Test
     private static final String TEMP_DIR = "target/temp";
 
     private static final String TARGET_DIR = "target";
+    
+    protected String  cacheDirPath;
+
+    protected String tempDirPath;
+
+    /**
+     * Random number generator to populate data
+     */
+    protected Random randomGen = new Random();
 
     private static final Logger LOG = LoggerFactory.getLogger(TestLocalCache.class);
 
     @Override
     protected void setUp() {
         try {
-            File cachedir = new File(CACHE_DIR);
-            if (cachedir.exists()) FileUtil.delete(cachedir);
+            cacheDirPath = CACHE_DIR + "-"
+                + String.valueOf(randomGen.nextInt(9999));
+            File cachedir = new File(cacheDirPath);
+            if (cachedir.exists()) FileUtils.deleteQuietly(cachedir);
             cachedir.mkdirs();
 
-            File tempdir = new File(TEMP_DIR);
-            if (tempdir.exists()) FileUtil.delete(tempdir);
+            tempDirPath = TEMP_DIR + "-"
+                + String.valueOf(randomGen.nextInt(9999));
+            File tempdir = new File(tempDirPath);
+            if (tempdir.exists()) FileUtils.deleteQuietly(tempdir);
             tempdir.mkdirs();
         } catch (Exception e) {
             LOG.error("error:", e);
@@ -67,12 +79,12 @@ public class TestLocalCache extends Test
 
     @Override
     protected void tearDown() throws IOException {
-        File cachedir = new File(CACHE_DIR);
+        File cachedir = new File(cacheDirPath);
         if (cachedir.exists()) {
             FileUtils.deleteQuietly(cachedir);
         }
 
-        File tempdir = new File(TEMP_DIR);
+        File tempdir = new File(tempDirPath);
         if (tempdir.exists()) {
             FileUtils.deleteQuietly(tempdir);
         }
@@ -82,15 +94,11 @@ public class TestLocalCache extends Test
      * Test to validate store retrieve in cache.
      */
     public void testStoreRetrieve() {
-        // FIXME: JCR-3806
-        if (true) {
-            return;
-        }
         try {
             AsyncUploadCache pendingFiles = new AsyncUploadCache();
-            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
+            pendingFiles.init(tempDirPath, cacheDirPath, 100);
             pendingFiles.reset();
-            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
+            LocalCache cache = new LocalCache(cacheDirPath, tempDirPath, 400, 0.95,
                 0.70, pendingFiles);
             Random random = new Random(12345);
             byte[] data = new byte[100];
@@ -126,15 +134,11 @@ public class TestLocalCache extends Test
      * cachePurgeTrigFactor * size.
      */
     public void testAutoPurge() {
-        // FIXME: JCR-3806
-        if (true) {
-            return;
-        }
         try {
             AsyncUploadCache pendingFiles = new AsyncUploadCache();
-            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
+            pendingFiles.init(tempDirPath, cacheDirPath, 100);
             pendingFiles.reset();
-            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
+            LocalCache cache = new LocalCache(cacheDirPath, tempDirPath, 400, 0.95,
                 0.70, pendingFiles);
             Random random = new Random(12345);
             byte[] data = new byte[100];
@@ -193,15 +197,11 @@ public class TestLocalCache extends Test
      * cachePurgeTrigFactor * size.
      */
     public void testAutoPurgeWithPendingUpload() {
-        // FIXME: JCR-3806
-        if (true) {
-            return;
-        }
         try {
             AsyncUploadCache pendingFiles = new AsyncUploadCache();
-            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
+            pendingFiles.init(tempDirPath, cacheDirPath, 100);
             pendingFiles.reset();
-            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 400, 0.95,
+            LocalCache cache = new LocalCache(cacheDirPath, tempDirPath, 400, 0.95,
                 0.70, pendingFiles);
             Random random = new Random(12345);
             byte[] data = new byte[125];
@@ -220,7 +220,7 @@ public class TestLocalCache extends Test
             data = new byte[100];
             random.nextBytes(data);
             byteMap.put("a4", data);
-            File tempDir = new File(TEMP_DIR);
+            File tempDir = new File(tempDirPath);
             File f = File.createTempFile("test", "tmp", tempDir);
             FileOutputStream fos = new FileOutputStream(f);
             fos.write(byteMap.get("a1"));
@@ -286,9 +286,9 @@ public class TestLocalCache extends Test
     public void testConcurrentInitWithStore() {
         try {
             AsyncUploadCache pendingFiles = new AsyncUploadCache();
-            pendingFiles.init(TARGET_DIR, CACHE_DIR, 100);
+            pendingFiles.init(tempDirPath, cacheDirPath, 100);
             pendingFiles.reset();
-            LocalCache cache = new LocalCache(CACHE_DIR, TEMP_DIR, 10000000,
+            LocalCache cache = new LocalCache(cacheDirPath, tempDirPath, 10000000,
                 0.95, 0.70, pendingFiles);
             Random random = new Random(12345);
             int fileUploads = 1000;
@@ -302,9 +302,11 @@ public class TestLocalCache extends Test
                 byteMap.put(key, data);
                 cache.store(key, new ByteArrayInputStream(byteMap.get(key)));
             }
+            cache.close();
+            
             ExecutorService executor = Executors.newFixedThreadPool(10,
                 new NamedThreadFactory("localcache-store-worker"));
-            cache = new LocalCache(CACHE_DIR, TEMP_DIR, 10000000, 0.95, 0.70,
+            cache = new LocalCache(cacheDirPath, tempDirPath, 10000000, 0.95, 0.70,
                 pendingFiles);
             executor.execute(new StoreWorker(cache, byteMap));
             executor.shutdown();



Mime
View raw message