accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [4/7] accumulo git commit: ACCUMULO-3383 Fix for AccumuloVFSClassloader conflicting cache directories
Date Thu, 18 Dec 2014 21:55:42 GMT
ACCUMULO-3383 Fix for AccumuloVFSClassloader conflicting cache directories

 . AccumuloVFSClassloader no longer creates conflicting local cache directory names when vfs.cache.dir
property is set.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/97f16db4
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/97f16db4
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/97f16db4

Branch: refs/heads/1.6
Commit: 97f16db4d31db63b46985da07228b89f0c346270
Parents: e572d56
Author: Drew Farris <drew@apache.org>
Authored: Sat Dec 13 23:36:24 2014 -0500
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Thu Dec 18 16:47:32 2014 -0500

----------------------------------------------------------------------
 .../classloader/vfs/AccumuloVFSClassLoader.java |  8 +-
 .../vfs/AccumuloVFSClassLoaderTest.java         | 80 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/97f16db4/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
----------------------------------------------------------------------
diff --git a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
index 983ad7c..bd1f943 100644
--- a/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
+++ b/start/src/main/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoader.java
@@ -92,8 +92,6 @@ public class AccumuloVFSClassLoader {
 
   public static final String VFS_CACHE_DIR = "general.vfs.cache.dir";
   
-  public static final AtomicInteger uniqueDirectoryGenerator = new AtomicInteger(0);
-
   private static ClassLoader parent = null;
   private static volatile ReloadingClassLoader loader = null;
   private static final Object lock = new Object();
@@ -279,10 +277,7 @@ public class AccumuloVFSClassLoader {
     vfs.addMimeTypeMap("application/zip", "zip");
     vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
     vfs.setFilesCache(new SoftRefFilesCache());
-    String cacheDirPath = AccumuloClassLoader.getAccumuloString(VFS_CACHE_DIR, "");
     File cacheDir = computeTopCacheDir(); 
-    if (!cacheDirPath.isEmpty())
-      cacheDir = new File(cacheDirPath, "" + uniqueDirectoryGenerator.getAndIncrement());
     vfs.setReplicator(new UniqueFileReplicator(cacheDir));
     vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
     vfs.init();
@@ -291,8 +286,9 @@ public class AccumuloVFSClassLoader {
   }
 
   private static File computeTopCacheDir() {
+    String cacheDirPath = AccumuloClassLoader.getAccumuloString(VFS_CACHE_DIR, System.getProperty("java.io.tmpdir"));
     String procName = ManagementFactory.getRuntimeMXBean().getName();
-    return new File(System.getProperty("java.io.tmpdir"), "accumulo-vfs-cache-" + procName
+ "-" + System.getProperty("user.name", "nouser"));
+    return new File(cacheDirPath, "accumulo-vfs-cache-" + procName + "-" + System.getProperty("user.name",
"nouser"));
   }
 
   public interface Printer {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/97f16db4/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
----------------------------------------------------------------------
diff --git a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
index e7c369e..522c870 100644
--- a/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
+++ b/start/src/test/java/org/apache/accumulo/start/classloader/vfs/AccumuloVFSClassLoaderTest.java
@@ -23,6 +23,7 @@ import java.net.URLClassLoader;
 
 import org.apache.accumulo.start.classloader.AccumuloClassLoader;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.vfs2.impl.DefaultFileSystemManager;
 import org.apache.commons.vfs2.impl.VFSClassLoader;
 import org.junit.After;
 import org.junit.Assert;
@@ -126,4 +127,83 @@ public class AccumuloVFSClassLoaderTest {
     Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader)
null);
   }
 
+  @Test
+  public void testDefaultCacheDirectory() throws Exception {
+
+    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader)
null);
+
+    File conf = folder1.newFile("accumulo-site.xml");
+    FileWriter out = new FileWriter(conf);
+    out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+    out.append("<configuration>\n");
+    out.append("<property>\n");
+    out.append("<name>general.classpaths</name>\n");
+    out.append("<value></value>\n");
+    out.append("</property>\n");
+    out.append("<property>\n");
+    out.append("<name>general.vfs.classpaths</name>\n");
+    out.append("<value></value>\n");
+    out.append("</property>\n");
+    out.append("</configuration>\n");
+    out.close();
+
+    Whitebox.setInternalState(AccumuloClassLoader.class, "SITE_CONF", conf.toURI().toURL().toString());
+    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
+    AccumuloVFSClassLoader.getClassLoader();
+    AccumuloReloadingVFSClassLoader loader = Whitebox.getInternalState(AccumuloVFSClassLoader.class,
"loader");
+    DefaultFileSystemManager manager = Whitebox.getInternalState(loader, "vfs");
+    UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator");
+    File tempDir = Whitebox.getInternalState(replicator, "tempDir");
+    String tempDirParent = tempDir.getParent();
+    String tempDirName = tempDir.getName();
+    String javaIoTmpDir = System.getProperty("java.io.tmpdir");
+
+    // trim off any final separator, because java.io.File does the same.
+    if (javaIoTmpDir.endsWith(File.separator)) {
+      javaIoTmpDir = javaIoTmpDir.substring(0, javaIoTmpDir.length() - File.separator.length());
+    }
+
+    Assert.assertTrue(javaIoTmpDir.equals(tempDirParent));
+    Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-"));
+    Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser")));
+
+    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader)
null);
+  }
+
+  @Test
+  public void testCacheDirectoryConfigured() throws Exception {
+
+    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader)
null);
+    String cacheDir = "/some/random/cache/dir";
+
+    File conf = folder1.newFile("accumulo-site.xml");
+    FileWriter out = new FileWriter(conf);
+    out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+    out.append("<configuration>\n");
+    out.append("<property>\n");
+    out.append("<name>general.classpaths</name>\n");
+    out.append("<value></value>\n");
+    out.append("</property>\n");
+    out.append("<property>\n");
+    out.append("<name>" + AccumuloVFSClassLoader.VFS_CACHE_DIR + "</name>\n");
+    out.append("<value>" + cacheDir + "</value>\n");
+    out.append("</property>\n");
+    out.append("</configuration>\n");
+    out.close();
+
+    Whitebox.setInternalState(AccumuloClassLoader.class, "SITE_CONF", conf.toURI().toURL().toString());
+    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
+    AccumuloVFSClassLoader.getClassLoader();
+    AccumuloReloadingVFSClassLoader loader = Whitebox.getInternalState(AccumuloVFSClassLoader.class,
"loader");
+    DefaultFileSystemManager manager = Whitebox.getInternalState(loader, "vfs");
+    UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator");
+    File tempDir = Whitebox.getInternalState(replicator, "tempDir");
+    String tempDirParent = tempDir.getParent();
+    String tempDirName = tempDir.getName();
+    Assert.assertTrue(cacheDir.equals(tempDirParent));
+    Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-"));
+    Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser")));
+
+    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader)
null);
+  }
 }


Mime
View raw message