jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From am...@apache.org
Subject svn commit: r1759933 - in /jackrabbit/trunk/jackrabbit-data/src: main/java/org/apache/jackrabbit/core/data/FSBackend.java test/java/org/apache/jackrabbit/core/data/TestCachingFDS.java test/java/org/apache/jackrabbit/core/data/TestCachingFDSCacheOff.java
Date Fri, 09 Sep 2016 03:25:15 GMT
Author: amitj
Date: Fri Sep  9 03:25:14 2016
New Revision: 1759933

URL: http://svn.apache.org/viewvc?rev=1759933&view=rev
Log:
JCR-4008: Restore TestCachingFDS.testDeleteRecord() to fix it with disabling AsyncUpload in
unit tests

Patch from Woonsan Ko

Modified:
    jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FSBackend.java
    jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDS.java
    jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDSCacheOff.java

Modified: jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FSBackend.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FSBackend.java?rev=1759933&r1=1759932&r2=1759933&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FSBackend.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/main/java/org/apache/jackrabbit/core/data/FSBackend.java
Fri Sep  9 03:25:14 2016
@@ -32,6 +32,8 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
 import java.util.Set;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadPoolExecutor;
 
@@ -55,7 +57,7 @@ public class FSBackend implements Backen
 
     File fsPathDir;
 
-    private ThreadPoolExecutor asyncWriteExecuter;
+    private Executor asyncWriteExecuter;
 
     public static final String FS_BACKEND_PATH = "fsBackendPath";
 
@@ -117,8 +119,7 @@ public class FSBackend implements Backen
                     + fsPathDir.getAbsolutePath());
             }
         }
-        asyncWriteExecuter = (ThreadPoolExecutor) Executors.newFixedThreadPool(
-            10, new NamedThreadFactory("fs-write-worker"));
+        asyncWriteExecuter = createAsyncWriteExecutor();
 
     }
 
@@ -292,8 +293,11 @@ public class FSBackend implements Backen
 
     @Override
     public void close() throws DataStoreException {
-        asyncWriteExecuter.shutdownNow();
+        Executor asyncExecutor = getAsyncWriteExecutor();
 
+        if (asyncExecutor != null && asyncExecutor instanceof ExecutorService) {
+            ((ExecutorService) asyncExecutor).shutdownNow();
+        }
     }
 
     @Override
@@ -333,6 +337,32 @@ public class FSBackend implements Backen
     }
 
     /**
+     * Creates a {@link Executor}.
+     * This method is invoked during the initialization for asynchronous write/touch job
executions.
+     * @return a {@link Executor}
+     */
+    protected Executor createAsyncWriteExecutor() {
+        Executor asyncExecutor;
+
+        if (store.getAsyncUploadLimit() > 0) {
+            asyncExecutor = Executors.newFixedThreadPool(10,
+                    new NamedThreadFactory("fs-write-worker"));
+        } else {
+            asyncExecutor = new ImmediateExecutor();
+        }
+
+        return asyncExecutor;
+    }
+
+    /**
+     * Returns ThreadPoolExecutor used to execute asynchronous write or touch jobs.
+     * @return ThreadPoolExecutor used to execute asynchronous write or touch jobs
+     */
+    protected Executor getAsyncWriteExecutor() {
+        return asyncWriteExecuter;
+    }
+
+    /**
      * Returns the identified file. This method implements the pattern used to
      * avoid problems with too many files in a single directory.
      * <p>
@@ -493,4 +523,15 @@ public class FSBackend implements Backen
         }
     }
 
+    /**
+     * This class implements {@link Executor} interface to run {@code command} right away,
+     * resulting in non-asynchronous mode executions.
+     */
+    private class ImmediateExecutor implements Executor {
+        @Override
+        public void execute(Runnable command) {
+            command.run();
+        }
+    }
+
 }

Modified: jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDS.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDS.java?rev=1759933&r1=1759932&r2=1759933&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDS.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDS.java
Fri Sep  9 03:25:14 2016
@@ -50,16 +50,12 @@ public class TestCachingFDS extends Test
         LOG.info("fsBackendPath [{}] set.", fsPath);
         cacheFDS.setProperties(props);
         cacheFDS.setSecret("12345");
+        // disable asynchronous writing in testing.
+        cacheFDS.setAsyncUploadLimit(0);
         cacheFDS.init(dataStoreDir);
         return cacheFDS;
     }
 
-    @Override
-    protected void doDeleteRecordTest() throws Exception {
-        ds = createDataStore();
-        LOG.info("Skip deleteRecordTest on CachingFDS (JCR-4006)");
-    }
-
     /**
      * Test robustness of {@link AsyncUploadCache} corruption.
      */

Modified: jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDSCacheOff.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDSCacheOff.java?rev=1759933&r1=1759932&r2=1759933&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDSCacheOff.java
(original)
+++ jackrabbit/trunk/jackrabbit-data/src/test/java/org/apache/jackrabbit/core/data/TestCachingFDSCacheOff.java
Fri Sep  9 03:25:14 2016
@@ -42,6 +42,8 @@ public class TestCachingFDSCacheOff exte
         props.setProperty(FSBackend.FS_BACKEND_PATH, fsPath);
         cacheFDS.setProperties(props);
         cacheFDS.setSecret("12345");
+        // disable asynchronous writing in testing.
+        cacheFDS.setAsyncUploadLimit(0);
         cacheFDS.setCacheSize(0);
         cacheFDS.init(dataStoreDir);
         return cacheFDS;



Mime
View raw message