Search in sources :

Example 31 with VoltCompiler

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

the class TestJdbcDatabaseMetaDataGenerator method testGetTables.

public void testGetTables() throws Exception {
    String schema = "create table Table1 (Column1 varchar(10) not null, Column2 integer);" + "partition table Table1 on column Column1;" + "create table Table2 (Column1 integer);" + "create view View1 (Column1, num) as select Column1, count(*) from Table1 group by Column1;" + "create view View2 (Column2, num) as select Column2, count(*) from Table1 group by Column2;" + "create stream Export1 (Column1 integer);" + "create stream Export2 export to target foo (Column1 integer);" + "create procedure sample as select * from Table1;";
    VoltCompiler c = compileForDDLTest2(schema);
    System.out.println(c.getCatalog().serialize());
    JdbcDatabaseMetaDataGenerator dut = new JdbcDatabaseMetaDataGenerator(c.getCatalog(), null, new InMemoryJarfile(testout_jar));
    VoltTable tables = dut.getMetaData("tables");
    System.out.println(tables);
    assertEquals(10, tables.getColumnCount());
    assertEquals(6, tables.getRowCount());
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "Table1"));
    assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("TABLE"));
    assertTrue(tables.get("REMARKS", VoltType.STRING).equals("{\"partitionColumn\":\"COLUMN1\"}"));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "Table2"));
    assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("TABLE"));
    assertEquals(null, tables.get("REMARKS", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "View1"));
    assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("VIEW"));
    assertTrue(tables.get("REMARKS", VoltType.STRING).equals(new JSONObject("{\"partitionColumn\":\"COLUMN1\",\"sourceTable\":\"TABLE1\"}").toString()));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "View2"));
    assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("VIEW"));
    assertTrue(tables.get("REMARKS", VoltType.STRING).equals(new JSONObject("{\"partitionColumn\":\"COLUMN1\",\"sourceTable\":\"TABLE1\"}").toString()));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "Export1"));
    assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("EXPORT"));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "Export2"));
    assertTrue(tables.get("TABLE_TYPE", VoltType.STRING).equals("EXPORT"));
    assertFalse(VoltTableTestHelpers.moveToMatchingRow(tables, "TABLE_NAME", "NotATable"));
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) JSONObject(org.json_voltpatches.JSONObject) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile)

Example 32 with VoltCompiler

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

the class TestCatalogUpdateSuite method testPauseMode.

public void testPauseMode() throws Exception {
    Client adminClient = getAdminClient();
    ClientResponse resp = adminClient.callProcedure("@Pause");
    assertEquals(ClientResponse.SUCCESS, resp.getStatus());
    Client client = getClient();
    String newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.jar");
    String deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.xml");
    try {
        client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
        fail("Update catalog with procs from class should fail in PAUSE mode");
    } catch (ProcCallException e) {
        assertEquals(ClientResponse.SERVER_UNAVAILABLE, e.getClientResponse().getStatus());
    }
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-adhocproc.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-adhocproc.xml");
    try {
        client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
        fail("Update catalog with adhoc procs should fail in PAUSE mode");
    } catch (ProcCallException e) {
        assertEquals(ClientResponse.SERVER_UNAVAILABLE, e.getClientResponse().getStatus());
    }
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-adhocschema.jar");
    deploymentURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-adhocschema.xml");
    try {
        client.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
        fail("Update catalog with adhoc schema change should fail in PAUSE mode");
    } catch (ProcCallException e) {
        assertEquals(ClientResponse.SERVER_UNAVAILABLE, e.getClientResponse().getStatus());
    }
    InMemoryJarfile jarfile = new InMemoryJarfile();
    VoltCompiler comp = new VoltCompiler(false);
    comp.addClassToJar(jarfile, TestProc.class);
    try {
        resp = client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        fail("Update classes should fail in PAUSE mode");
    } catch (ProcCallException e) {
        assertEquals(ClientResponse.SERVER_UNAVAILABLE, e.getClientResponse().getStatus());
    }
    // admin should pass
    resp = adminClient.updateApplicationCatalog(new File(newCatalogURL), new File(deploymentURL));
    assertEquals(ClientResponse.SUCCESS, resp.getStatus());
    resp = adminClient.callProcedure("@Resume");
    assertEquals(ClientResponse.SUCCESS, resp.getStatus());
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Client(org.voltdb.client.Client) File(java.io.File) ProcCallException(org.voltdb.client.ProcCallException)

Example 33 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler 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 34 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler 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)

Example 35 with VoltCompiler

use of org.voltdb.compiler.VoltCompiler 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)

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