Search in sources :

Example 41 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestLiveDDLSchemaSwitch method verifyMasterWithUAC.

// GOing to want to retest this after we promote a replica, so bust it out
void verifyMasterWithUAC() throws Exception {
    // UAC should work.
    ClientResponse results = m_client.updateApplicationCatalog(new File(m_pathToCatalog), null);
    assertEquals(ClientResponse.SUCCESS, results.getStatus());
    assertTrue(findTableInSystemCatalogResults("FOO"));
    // Adhoc DDL should be rejected
    assertFalse(findTableInSystemCatalogResults("BAR"));
    boolean threw = false;
    try {
        results = m_client.callProcedure("@AdHoc", "create table BAR (ID integer, VAL varchar(50));");
    } catch (ProcCallException pce) {
        threw = true;
        assertTrue(pce.getMessage().contains("AdHoc DDL is forbidden"));
    }
    assertTrue("Adhoc DDL should have failed", threw);
    assertFalse(findTableInSystemCatalogResults("BAR"));
    // @UpdateClasses should be rejected
    assertFalse(findClassInSystemCatalog("org.voltdb_testprocs.fullddlfeatures.testImportProc"));
    threw = false;
    try {
        InMemoryJarfile jarfile = new InMemoryJarfile();
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.fullddlfeatures.testImportProc.class);
        m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
    } catch (ProcCallException pce) {
        threw = true;
        assertTrue(pce.getMessage().contains("@UpdateClasses is forbidden"));
    }
    assertTrue("@UpdateClasses should have failed", threw);
    assertFalse(findClassInSystemCatalog("org.voltdb_testprocs.fullddlfeatures.testImportProc"));
    verifyAdhocQuery();
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) File(java.io.File) ProcCallException(org.voltdb.client.ProcCallException)

Example 42 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile 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 43 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile 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 44 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestUpdateClasses method testUpdateClassesWithSQLStmtChanges.

// See ENG-12536: Test UpdateClasses with changed SQLStmts
@Test
public void testUpdateClassesWithSQLStmtChanges() throws Exception {
    System.out.println("\n\n-----\n testUpdateClassesWithSQLStmtChanges \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("create table tt (PID varchar(20 BYTES) NOT NULL, CITY varchar(6 BYTES), " + "CONSTRAINT IDX_TT_PKEY PRIMARY KEY (PID)); \n" + "PARTITION TABLE TT ON COLUMN PID;\n");
    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;
        // Testing system can load jar file from class path, but not the internal class files
        try {
            resp = m_client.callProcedure("TestProcedure", "12345", "boston");
            fail("TestProcedure is not loaded");
        } catch (ProcCallException e) {
            assertTrue(e.getMessage().contains("Procedure TestProcedure was not found"));
        }
        try {
            Class.forName("voter.TestProcedure");
            fail("Should not load the class file from the jar file on disk automatically");
        } catch (ClassNotFoundException e) {
            assertTrue(e.getMessage().contains("voter.TestProcedure"));
        }
        InMemoryJarfile boom = new InMemoryJarfile(TestProcedure.class.getResource("addSQLStmt.jar"));
        resp = m_client.callProcedure("@UpdateClasses", boom.getFullJarBytes(), null);
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        resp = m_client.callProcedure("@AdHoc", "create procedure partition ON TABLE tt COLUMN pid from class voter.TestProcedure;");
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        resp = m_client.callProcedure("TestProcedure", "12345", "boston");
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        // UpdateClass with the new changed StmtSQL jar
        boom = new InMemoryJarfile(TestProcedure.class.getResource("addSQLStmtNew.jar"));
        resp = m_client.callProcedure("@UpdateClasses", boom.getFullJarBytes(), null);
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        // run with a new query without problems
        resp = m_client.callProcedure("TestProcedure", "12345", "boston");
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        // Invalid SQLStmt should fail during UpdateClasses
        boom = new InMemoryJarfile(TestProcedure.class.getResource("addSQLStmtInvalid.jar"));
        try {
            resp = m_client.callProcedure("@UpdateClasses", boom.getFullJarBytes(), null);
            fail("Invalid SQLStmt should fail during UpdateClasses");
        } catch (ProcCallException e) {
            assertTrue(e.getMessage().contains("Failed to plan for statement"));
            assertTrue(e.getMessage().contains("user lacks privilege or object not found: TT_INVALID_QUERY"));
        }
    } finally {
        teardownSystem();
    }
}
Also used : VoltDB(org.voltdb.VoltDB) ClientResponse(org.voltdb.client.ClientResponse) TestProcedure(org.voltdb_testprocs.updateclasses.jars.TestProcedure) 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 45 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile 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

InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)52 VoltCompiler (org.voltdb.compiler.VoltCompiler)26 File (java.io.File)20 ProcCallException (org.voltdb.client.ProcCallException)19 ClientResponse (org.voltdb.client.ClientResponse)18 Test (org.junit.Test)15 Configuration (org.voltdb.VoltDB.Configuration)15 IOException (java.io.IOException)14 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)12 VoltDB (org.voltdb.VoltDB)9 Catalog (org.voltdb.catalog.Catalog)6 VoltTable (org.voltdb.VoltTable)5 VoltFile (org.voltdb.utils.VoltFile)5 ArrayList (java.util.ArrayList)4 JSONObject (org.json_voltpatches.JSONObject)3 CatalogContext (org.voltdb.CatalogContext)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JAXBException (javax.xml.bind.JAXBException)2