Search in sources :

Example 61 with VFS

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);
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 62 with VFS

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);
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 63 with VFS

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<>());
}
Also used : VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) ContextConfig(org.apache.accumulo.start.classloader.vfs.ContextManager.ContextConfig) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) FileObject(org.apache.commons.vfs2.FileObject) FileObject(org.apache.commons.vfs2.FileObject) ContextsConfig(org.apache.accumulo.start.classloader.vfs.ContextManager.ContextsConfig) Test(org.junit.Test)

Example 64 with VFS

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);
}
Also used : ContextConfig(org.apache.accumulo.start.classloader.vfs.ContextManager.ContextConfig) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) ContextsConfig(org.apache.accumulo.start.classloader.vfs.ContextManager.ContextsConfig) Test(org.junit.Test)

Example 65 with VFS

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);
}
Also used : Path(org.apache.hadoop.fs.Path) VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) FileObject(org.apache.commons.vfs2.FileObject) URL(java.net.URL) Before(org.junit.Before)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)50 IOException (java.io.IOException)27 KettleException (org.pentaho.di.core.exception.KettleException)23 FileSystemException (org.apache.commons.vfs2.FileSystemException)22 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)20 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)20 Result (org.pentaho.di.core.Result)19 File (java.io.File)18 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)11 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)11 ResultFile (org.pentaho.di.core.ResultFile)11 VFSClassLoader (org.apache.commons.vfs2.impl.VFSClassLoader)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)7 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)6 URL (java.net.URL)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4