use of org.apache.commons.vfs2.VFS in project accumulo by apache.
the class AccumuloVFSClassLoaderTest method testDefaultCacheDirectory.
@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, "accumuloConfigUrl", conf.toURI().toURL());
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
AccumuloVFSClassLoader.getClassLoader();
FileSystemManager manager = AccumuloVFSClassLoader.generateVfs();
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);
}
use of org.apache.commons.vfs2.VFS in project accumulo by apache.
the class AccumuloVFSClassLoaderTest method testCacheDirectoryConfigured.
@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, "accumuloConfigUrl", conf.toURI().toURL());
Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
AccumuloVFSClassLoader.getClassLoader();
FileSystemManager manager = AccumuloVFSClassLoader.generateVfs();
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);
}
use of org.apache.commons.vfs2.VFS in project accumulo by apache.
the class ContextManagerTest method differentContexts.
@Test
public void differentContexts() throws Exception {
ContextManager cm = new ContextManager(vfs, new ReloadingClassLoader() {
@Override
public ClassLoader getClassLoader() {
return ClassLoader.getSystemClassLoader();
}
});
cm.setContextConfig(new ContextsConfig() {
@Override
public ContextConfig getContextConfig(String context) {
if (context.equals("CX1")) {
return new ContextConfig(uri1, true);
} else if (context.equals("CX2")) {
return new ContextConfig(uri2, true);
}
return null;
}
});
FileObject testDir = vfs.resolveFile(folder1.getRoot().toURI().toString());
FileObject[] dirContents = testDir.getChildren();
ClassLoader cl1 = cm.getClassLoader("CX1");
FileObject[] files = ((VFSClassLoader) cl1).getFileObjects();
Assert.assertArrayEquals(createFileSystems(dirContents), files);
FileObject testDir2 = vfs.resolveFile(folder2.getRoot().toURI().toString());
FileObject[] dirContents2 = testDir2.getChildren();
ClassLoader cl2 = cm.getClassLoader("CX2");
FileObject[] files2 = ((VFSClassLoader) cl2).getFileObjects();
Assert.assertArrayEquals(createFileSystems(dirContents2), files2);
Class<?> defaultContextClass = cl1.loadClass("test.HelloWorld");
Object o1 = defaultContextClass.newInstance();
Assert.assertEquals("Hello World!", o1.toString());
Class<?> myContextClass = cl2.loadClass("test.HelloWorld");
Object o2 = myContextClass.newInstance();
Assert.assertEquals("Hello World!", o2.toString());
Assert.assertFalse(defaultContextClass.equals(myContextClass));
cm.removeUnusedContexts(new HashSet<>());
}
use of org.apache.commons.vfs2.VFS in project accumulo by apache.
the class ContextManagerTest method testPostDelegation.
@Test
public void testPostDelegation() throws Exception {
final VFSClassLoader parent = new VFSClassLoader(new FileObject[] { vfs.resolveFile(uri1) }, vfs);
Class<?> pclass = parent.loadClass("test.HelloWorld");
ContextManager cm = new ContextManager(vfs, new ReloadingClassLoader() {
@Override
public ClassLoader getClassLoader() {
return parent;
}
});
cm.setContextConfig(new ContextsConfig() {
@Override
public ContextConfig getContextConfig(String context) {
if (context.equals("CX1")) {
return new ContextConfig(uri2.toString(), true);
} else if (context.equals("CX2")) {
return new ContextConfig(uri2.toString(), false);
}
return null;
}
});
Assert.assertTrue(cm.getClassLoader("CX1").loadClass("test.HelloWorld") == pclass);
Assert.assertFalse(cm.getClassLoader("CX2").loadClass("test.HelloWorld") == pclass);
}
use of org.apache.commons.vfs2.VFS in project accumulo by apache.
the class VfsClassLoaderTest method setup.
@Before
public void setup() throws Exception {
this.hdfs = cluster.getFileSystem();
this.hdfs.mkdirs(TEST_DIR);
// Copy jar file to TEST_DIR
URL jarPath = this.getClass().getResource("/HelloWorld.jar");
Path src = new Path(jarPath.toURI().toString());
Path dst = new Path(TEST_DIR, src.getName());
this.hdfs.copyFromLocalFile(src, dst);
FileObject testDir = vfs.resolveFile(TEST_DIR.toUri().toString());
FileObject[] dirContents = testDir.getChildren();
// Point the VFSClassLoader to all of the objects in TEST_DIR
this.cl = new VFSClassLoader(dirContents, vfs);
}
Aggregations