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"));
}
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());
}
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());
}
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();
}
}
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();
}
Aggregations