Search in sources :

Example 36 with InMemoryJarfile

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

the class RegressionSuite method getCurrentCatalog.

private static Catalog getCurrentCatalog() {
    CatalogContext context = VoltDB.instance().getCatalogContext();
    if (context == null) {
        return null;
    }
    InMemoryJarfile currentCatalogJar = context.getCatalogJar();
    String serializedCatalogString = CatalogUtil.getSerializedCatalogStringFromJar(currentCatalogJar);
    assertNotNull(serializedCatalogString);
    Catalog c = new Catalog();
    c.execute(serializedCatalogString);
    return c;
}
Also used : InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) CatalogContext(org.voltdb.CatalogContext) Catalog(org.voltdb.catalog.Catalog)

Example 37 with InMemoryJarfile

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

the class TestInitStartLocalClusterAllOutOfProcess method getProcJarFromCatalog.

InMemoryJarfile getProcJarFromCatalog() throws IOException {
    File jar = File.createTempFile("procedure", ".jar");
    Configuration config = new VoltDB.Configuration(new String[] { "get", "classes", "getvoltdbroot", voltDBRootParentPath, "file", jar.getAbsolutePath(), "forceget" });
    ServerThread server = new ServerThread(config);
    try {
        server.cli();
    } catch (Throwable ex) {
    //Good
    }
    byte[] bytesRead = Files.readAllBytes(Paths.get(jar.getAbsolutePath()));
    assertNotNull(bytesRead);
    assertTrue(bytesRead.length > 0);
    return new InMemoryJarfile(bytesRead);
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ServerThread(org.voltdb.ServerThread) File(java.io.File)

Example 38 with InMemoryJarfile

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

the class TestInitStartLocalClusterInProcess method testGetClasses.

public void testGetClasses() throws IOException {
    InMemoryJarfile jarFile = getProcJarFromCatalog();
    assertTrue(!anyCatalogDefaultArtifactsExists(jarFile));
    org.voltdb.client.ClientResponse resp = null;
    // No java stored proc at this time, will give jar with no classes
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    assertTrue(jarFile.getLoader().getClassNames().size() == resp.getResults()[0].getRowCount());
    // load java stored proc classes and verify the retrieved classes count
    loadAndAddProcs();
    jarFile = getProcJarFromCatalog();
    assertTrue(!anyCatalogDefaultArtifactsExists(jarFile));
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    assertTrue(jarFile.getLoader().getClassNames().size() == resp.getResults()[0].getRowCount());
}
Also used : InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ClientResponse(org.voltdb.client.ClientResponse) ProcCallException(org.voltdb.client.ProcCallException)

Example 39 with InMemoryJarfile

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

the class TestInitStartLocalClusterInProcess method loadAndAddProcs.

void loadAndAddProcs() throws IOException, NoConnectionsException {
    ClientResponse resp = null;
    long numberOfClasses = 0;
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    numberOfClasses = resp.getResults()[0].getRowCount();
    InMemoryJarfile jarfile = new InMemoryJarfile();
    VoltCompiler comp = new VoltCompiler(false);
    try {
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testCreateProcFromClassProc.class);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.InnerClassesTestProc.class);
        comp.addClassToJar(jarfile, RangeCount.class);
    } catch (Exception e) {
        assert false : "Failed add class to jar: " + e.getMessage();
    }
    try {
        client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
    } catch (ProcCallException excp) {
        assert false : "Failed updating the class";
    }
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    assertTrue((numberOfClasses + jarfile.getLoader().getClassNames().size()) == resp.getResults()[0].getRowCount());
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ProcCallException(org.voltdb.client.ProcCallException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 40 with InMemoryJarfile

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

the class TestLiveDDLSchemaSwitch method testReplicaWithUAC.

@Test
public void testReplicaWithUAC() throws Exception {
    generateCatalogsAndDeployments(false);
    // Fire up a cluster with no catalog
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = m_pathToOtherCatalog;
    config.m_pathToDeployment = m_pathToReplicaDeployment;
    try {
        startSystem(config);
        // UAC with schema should succeed
        assertFalse(findTableInSystemCatalogResults("FOO"));
        boolean threw = false;
        try {
            m_client.updateApplicationCatalog(new File(m_pathToCatalog), null);
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertFalse("@UAC add table should be accepted on the consumer cluster", threw);
        assertTrue(findTableInSystemCatalogResults("FOO"));
        // deployment-only UAC should succeed
        threw = false;
        try {
            m_client.updateApplicationCatalog(null, new File(m_pathToOtherReplicaDeployment));
        } catch (ProcCallException pce) {
            threw = true;
        }
        assertFalse("@UAC to new catalog on consumer cluster should have succeed", threw);
        assertEquals(getHeartbeatTimeout(), 6);
        // Adhoc DDL should be rejected
        assertFalse(findTableInSystemCatalogResults("BAR"));
        threw = false;
        try {
            m_client.callProcedure("@AdHoc", "create table BAR (ID integer, VAL varchar(50));");
        } catch (ProcCallException pce) {
            threw = true;
            System.out.println(pce.getMessage());
            assertTrue(pce.getMessage().contains("AdHoc DDL is forbidden"));
        }
        assertTrue("Adhoc DDL should have failed", threw);
        assertFalse(findTableInSystemCatalogResults("BAR"));
        // @UpdateClasses (which is an AdHoc capability) 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"));
        // Promote, should behave like the original master test
        m_client.callProcedure("@Promote");
        verifyMasterWithUAC();
    } finally {
        teardownSystem();
    }
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) Configuration(org.voltdb.VoltDB.Configuration) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File) 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