Search in sources :

Example 1 with ClassInfo

use of com.google_voltpatches.common.reflect.ClassPath.ClassInfo in project voltdb by VoltDB.

the class TestInitStartAction method testInitWithClassesAndArtifacts.

/** Tests that when there are base classes and non-class files in the stored procedures,
     * that these also exist in the staged catalog.
     * @throws Exception upon failure or error
     */
@Test
public void testInitWithClassesAndArtifacts() throws Exception {
    System.out.println("Loading the schema from testprocs");
    File resource = new File("tests/testprocs/org/voltdb_testprocs/fakeusecase/greetings/ddl.sql");
    InputStream schemaReader = new FileInputStream(resource);
    assertNotNull("Could not find " + resource, schemaReader);
    String schema = CharStreams.toString(new InputStreamReader(schemaReader));
    System.out.println("Creating a .jar file using all of the classes associated with this test.");
    InMemoryJarfile originalInMemoryJar = new InMemoryJarfile();
    VoltCompiler compiler = new VoltCompiler(false, false);
    ClassPath classpath = ClassPath.from(this.getClass().getClassLoader());
    String packageName = "org.voltdb_testprocs.fakeusecase.greetings";
    int classesFound = 0;
    for (ClassInfo myclass : classpath.getTopLevelClassesRecursive(packageName)) {
        compiler.addClassToJar(originalInMemoryJar, myclass.load());
        classesFound++;
    }
    // check that classes were found and loaded. If another test modifies "fakeusecase.greetings" it should modify this assert also.
    assertEquals(5, classesFound);
    System.out.println("Writing " + classesFound + " classes to jar file");
    File classesJarfile = File.createTempFile("TestInitStartWithClasses-procedures", ".jar");
    classesJarfile.deleteOnExit();
    originalInMemoryJar.writeToFile(classesJarfile);
    Configuration c1 = new Configuration(new String[] { "initialize", "voltdbroot", rootDH.getPath(), "force", "schema", resource.getPath(), "classes", classesJarfile.getPath() });
    ServerThread server = new ServerThread(c1);
    server.setUncaughtExceptionHandler(handleUncaught);
    server.start();
    server.join();
    validateStagedCatalog(schema, originalInMemoryJar);
}
Also used : ClassPath(com.google_voltpatches.common.reflect.ClassPath) VoltCompiler(org.voltdb.compiler.VoltCompiler) InputStreamReader(java.io.InputStreamReader) Configuration(org.voltdb.VoltDB.Configuration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) FileInputStream(java.io.FileInputStream) ClassInfo(com.google_voltpatches.common.reflect.ClassPath.ClassInfo) Test(org.junit.Test)

Aggregations

ClassPath (com.google_voltpatches.common.reflect.ClassPath)1 ClassInfo (com.google_voltpatches.common.reflect.ClassPath.ClassInfo)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Test (org.junit.Test)1 Configuration (org.voltdb.VoltDB.Configuration)1 VoltCompiler (org.voltdb.compiler.VoltCompiler)1 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)1 VoltFile (org.voltdb.utils.VoltFile)1