Search in sources :

Example 36 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class TestDDLSource method compileAndGenerateCatalogReport.

private static String compileAndGenerateCatalogReport(String ddl) throws IOException {
    UUID uuid = UUID.randomUUID();
    String jarName = uuid + ".jar";
    String ddlName = uuid + ".sql";
    String report = null;
    PrintWriter ddlWriter = null;
    try {
        ddlWriter = new PrintWriter(ddlName);
        ddlWriter.println(ddl);
        ddlWriter.close();
        // trick it into behaving like standalone
        VoltCompiler vc = new VoltCompiler(true, false);
        boolean success = vc.compileFromDDL(jarName, ddlName);
        assertTrue("Catalog compilation failed!", success);
        report = new String(Files.readAllBytes(Paths.get("catalog-report.html")), Charsets.UTF_8);
    } catch (Exception e) {
    } finally {
        if (ddlWriter != null)
            ddlWriter.close();
        Path ddlPath = Paths.get(ddlName);
        if (ddlPath.toFile().exists()) {
            Files.delete(ddlPath);
        }
        Path jarPath = Paths.get(jarName);
        if (jarPath.toFile().exists()) {
            Files.delete(jarPath);
        }
    }
    return report;
}
Also used : Path(java.nio.file.Path) VoltCompiler(org.voltdb.compiler.VoltCompiler) UUID(java.util.UUID) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 37 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class TestReportMaker method compileAndGenerateCatalogReport.

private static String compileAndGenerateCatalogReport(String ddl, boolean isXDCR) throws IOException {
    // Let's try not to "drool" files into the current directory.
    // Generate random temporary names for the .jar and DDL files,
    // and delete them before we exit this method.  We will still
    // drool the catalog-report.html file, though (many tests seem
    // to do this).
    UUID uuid = UUID.randomUUID();
    String jarName = uuid + ".jar";
    String ddlName = uuid + ".sql";
    String report = null;
    PrintWriter ddlWriter = null;
    try {
        ddlWriter = new PrintWriter(ddlName);
        ddlWriter.println(ddl);
        ddlWriter.close();
        // trick it into behaving like standalone
        VoltCompiler vc = new VoltCompiler(true, isXDCR);
        boolean success = vc.compileFromDDL(jarName, ddlName);
        assertTrue("Catalog compilation failed!", success);
        report = new String(Files.readAllBytes(Paths.get("catalog-report.html")), Charsets.UTF_8);
    } catch (Exception e) {
    } finally {
        if (ddlWriter != null)
            ddlWriter.close();
        Path ddlPath = Paths.get(ddlName);
        if (ddlPath.toFile().exists()) {
            Files.delete(ddlPath);
        }
        Path jarPath = Paths.get(jarName);
        if (jarPath.toFile().exists()) {
            Files.delete(jarPath);
        }
    }
    return report;
}
Also used : Path(java.nio.file.Path) VoltCompiler(org.voltdb.compiler.VoltCompiler) UUID(java.util.UUID) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 38 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class TestUpdateClasses method testStatsAfterUpdateClasses.

@Test
public void testStatsAfterUpdateClasses() throws Exception {
    System.out.println("\n\n-----\n testStatsAfterUpdateClasses \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table tb1 (a int);");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 1, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    // This is maybe cheating a little bit?
    InMemoryJarfile jarfile = new InMemoryJarfile();
    for (Class<?> clazz : PROC_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    for (Class<?> clazz : EXTRA_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    // Add a deployment file just to have something other than classes in the jar
    jarfile.put("deployment.xml", new File(pathToDeployment));
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        startSystem(config);
        ClientResponse resp;
        VoltTable vt;
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        // New cluster, you're like summer vacation...
        assertEquals(0, resp.getResults()[0].getRowCount());
        assertFalse(VoltTableTestHelpers.moveToMatchingRow(resp.getResults()[0], "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        // check stats after UAC
        vt = m_client.callProcedure("@Statistics", "PROCEDURE", 0).getResults()[0];
        assertEquals(1, vt.getRowCount());
        vt.advanceRow();
        assertEquals("org.voltdb.sysprocs.UpdateCore", vt.getString(5));
        // create procedure 0
        resp = m_client.callProcedure("@AdHoc", "create procedure from class " + PROC_CLASSES[0].getCanonicalName() + ";");
        // check stats after UAC
        vt = m_client.callProcedure("@Statistics", "PROCEDURE", 0).getResults()[0];
        assertEquals(vt.getRowCount(), 1);
        vt.advanceRow();
        assertEquals("org.voltdb.sysprocs.UpdateCore", vt.getString(5));
        // invoke a new user procedure
        vt = m_client.callProcedure(PROC_CLASSES[0].getSimpleName()).getResults()[0];
        assertEquals(10L, vt.asScalarLong());
        vt = m_client.callProcedure(PROC_CLASSES[0].getSimpleName()).getResults()[0];
        assertEquals(10L, vt.asScalarLong());
        vt = m_client.callProcedure(PROC_CLASSES[0].getSimpleName()).getResults()[0];
        assertEquals(10L, vt.asScalarLong());
        // check stats
        vt = m_client.callProcedure("@Statistics", "PROCEDURE", 0).getResults()[0];
        assertEquals(2, vt.getRowCount());
        assertTrue(vt.toString().contains("org.voltdb_testprocs.updateclasses.testImportProc"));
        assertTrue(vt.toString().contains("org.voltdb.sysprocs.UpdateCore"));
        // create procedure 1
        resp = m_client.callProcedure("@AdHoc", "create procedure from class " + PROC_CLASSES[1].getCanonicalName() + ";");
        // check stats
        vt = m_client.callProcedure("@Statistics", "PROCEDURE", 0).getResults()[0];
        assertEquals(1, vt.getRowCount());
        vt.advanceRow();
        assertEquals("org.voltdb.sysprocs.UpdateCore", vt.getString(5));
        resp = m_client.callProcedure(PROC_CLASSES[1].getSimpleName(), 1l, "", "");
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        vt = m_client.callProcedure("@Statistics", "PROCEDURE", 0).getResults()[0];
        assertEquals(2, vt.getRowCount());
        vt = m_client.callProcedure(PROC_CLASSES[0].getSimpleName()).getResults()[0];
        assertEquals(10L, vt.asScalarLong());
        vt = m_client.callProcedure("@Statistics", "PROCEDURE", 0).getResults()[0];
        assertEquals(3, vt.getRowCount());
    } finally {
        teardownSystem();
    }
}
Also used : VoltDB(org.voltdb.VoltDB) ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File) VoltTable(org.voltdb.VoltTable) Test(org.junit.Test)

Example 39 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class TestUpdateClasses method testInnerClasses.

@Test
public void testInnerClasses() throws Exception {
    System.out.println("\n\n-----\n testInnerClasses \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("-- Don't care");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        startSystem(config);
        // Something sane ought to work
        ClientResponse resp;
        InMemoryJarfile boom = new InMemoryJarfile();
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(boom, org.voltdb_testprocs.updateclasses.InnerClassesTestProc.class);
        try {
            resp = m_client.callProcedure("@UpdateClasses", boom.getFullJarBytes(), null);
            System.out.println(((ClientResponseImpl) resp).toJSONString());
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Loading proc with inner classes should succeed");
        }
        // Error in non-visible inner class static initializer?
        boolean threw = false;
        boom = new InMemoryJarfile();
        comp = new VoltCompiler(false);
        comp.addClassToJar(boom, org.voltdb_testprocs.updateclasses.BadInnerClassesTestProc.class);
        try {
            resp = m_client.callProcedure("@UpdateClasses", boom.getFullJarBytes(), null);
            System.out.println(((ClientResponseImpl) resp).toJSONString());
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            threw = true;
        }
        assertTrue("Bad inner class should have failed", threw);
    } finally {
        teardownSystem();
    }
}
Also used : VoltDB(org.voltdb.VoltDB) ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 40 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.

the class TestUpdateClasses method testCreateProceduresBeforeUpdateClasses.

@Test
public void testCreateProceduresBeforeUpdateClasses() throws Exception {
    System.out.println("\n\n-----\n testCreateProceduresBeforeUpdateClasses \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table t1 (a int, b int); \n" + "create procedure proc1 as select a from t1 where b = ?;");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        startSystem(config);
        ClientResponse resp;
        InMemoryJarfile boom = new InMemoryJarfile();
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(boom, org.voltdb_testprocs.updateclasses.NoMeaningClass.class);
        comp.addClassToJar(boom, org.voltdb_testprocs.updateclasses.testImportProc.class);
        try {
            resp = m_client.callProcedure("@UpdateClasses", boom.getFullJarBytes(), null);
            assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        } catch (ProcCallException pce) {
            fail("@UpdateClasses should not fail with message: " + pce.getMessage());
        }
    } finally {
        teardownSystem();
    }
}
Also used : VoltDB(org.voltdb.VoltDB) ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Aggregations

VoltCompiler (org.voltdb.compiler.VoltCompiler)43 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)26 File (java.io.File)16 ClientResponse (org.voltdb.client.ClientResponse)15 ProcCallException (org.voltdb.client.ProcCallException)15 Test (org.junit.Test)13 Configuration (org.voltdb.VoltDB.Configuration)12 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)11 VoltDB (org.voltdb.VoltDB)9 IOException (java.io.IOException)5 FileInputStream (java.io.FileInputStream)4 VoltTable (org.voltdb.VoltTable)4 Catalog (org.voltdb.catalog.Catalog)4 URL (java.net.URL)3 DeploymentType (org.voltdb.compiler.deploymentfile.DeploymentType)3 VoltFile (org.voltdb.utils.VoltFile)3 PrintWriter (java.io.PrintWriter)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2