use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.
the class HTTPAdminListenerStarter method main.
/**
* Added a main here for manual test purposes. It just starts up
* a brain-dead VoltDB server so you can look at the admin page.
*/
public static void main(String[] args) throws Exception {
String simpleSchema = "create table blah (" + "ival bigint default 0 not null, " + "PRIMARY KEY(ival));";
VoltProjectBuilder builder = new VoltProjectBuilder();
builder.addLiteralSchema(simpleSchema);
builder.addPartitionInfo("blah", "ival");
builder.addStmtProcedure("Insert", "insert into blah values (?);", null);
builder.setHTTPDPort(8080);
builder.setJSONAPIEnabled(true);
boolean success = builder.compile(Configuration.getPathToCatalogForTest("rejoin.jar"), 1, 1, 0);
assert (success);
MiscUtils.copyFile(builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("rejoin.xml"));
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToCatalog = Configuration.getPathToCatalogForTest("rejoin.jar");
config.m_pathToDeployment = Configuration.getPathToCatalogForTest("rejoin.xml");
ServerThread localServer = new ServerThread(config);
localServer.start();
localServer.waitForInitialization();
Thread.sleep(240000);
}
use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.
the class TestCatalogUtil method verifyDrTableSignature.
private void verifyDrTableSignature(boolean shouldEqual, String schemaA, String schemaB) throws IOException {
String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
final File fileA = VoltFile.createTempFile("catA", ".jar", new File(testDir));
final File fileB = VoltFile.createTempFile("catB", ".jar", new File(testDir));
VoltProjectBuilder builder = new VoltProjectBuilder();
builder.addLiteralSchema(schemaA);
builder.compile(fileA.getPath());
Catalog catA = TestCatalogDiffs.catalogForJar(fileA.getPath());
builder = new VoltProjectBuilder();
builder.addLiteralSchema(schemaB);
builder.compile(fileB.getPath());
Catalog catB = TestCatalogDiffs.catalogForJar(fileB.getPath());
fileA.delete();
fileB.delete();
final Pair<Long, String> sigA = CatalogUtil.calculateDrTableSignatureAndCrc(catA.getClusters().get("cluster").getDatabases().get("database"));
final Pair<Long, String> sigB = CatalogUtil.calculateDrTableSignatureAndCrc(catB.getClusters().get("cluster").getDatabases().get("database"));
assertFalse(sigA.getFirst() == 0);
assertFalse(sigA.getSecond().isEmpty());
assertEquals(shouldEqual, sigA.equals(sigB));
}
use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.
the class TestAdhocCreateDropJavaProc method testBasic.
@Test
public void testBasic() throws Exception {
System.out.println("\n\n-----\n testBasic \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 {
LocalCluster cluster = new LocalCluster("updateclasses.jar", 2, 1, 0, BackendTarget.NATIVE_EE_JNI);
cluster.compile(builder);
cluster.setHasLocalServer(false);
cluster.startUp();
m_client = ClientFactory.createClient();
m_client.createConnection(cluster.getListenerAddress(0));
ClientResponse resp;
// Can't create a procedure without a class
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
System.out.println("CLASSES: " + resp.getResults()[0]);
try {
resp = m_client.callProcedure("@AdHoc", "create procedure from class org.voltdb_testprocs.updateclasses.testImportProc");
fail("Shouldn't be able to create a procedure backed by no class");
} catch (ProcCallException pce) {
}
assertFalse(findProcedureInSystemCatalog("testImportProc"));
InMemoryJarfile jarfile = new InMemoryJarfile();
VoltCompiler comp = new VoltCompiler(false);
comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
// call the procedure. Maybe this gets better in the future
try {
resp = m_client.callProcedure("@AdHoc", "create procedure from class org.voltdb_testprocs.updateclasses.testImportProc");
} catch (ProcCallException pce) {
fail("We allow procedures to be created with unsatisfied dependencies");
}
assertTrue(findProcedureInSystemCatalog("testImportProc"));
// Make sure we don't crash when we call it though
try {
resp = m_client.callProcedure("testImportProc");
fail("Should return an error and not crash calling procedure w/ bad dependencies");
} catch (ProcCallException pce) {
assertTrue(pce.getMessage().contains("ClassNotFoundException"));
}
// Okay, add the missing dependency
jarfile = new InMemoryJarfile();
comp = new VoltCompiler(false);
comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.NoMeaningClass.class);
resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
// now we should be able to call it
try {
resp = m_client.callProcedure("testImportProc");
} catch (ProcCallException pce) {
fail("Should be able to call fully consistent procedure");
}
assertEquals(10L, resp.getResults()[0].asScalarLong());
// Now try to remove the procedure class
try {
resp = m_client.callProcedure("@UpdateClasses", null, "org.voltdb_testprocs.updateclasses.*");
fail("Shouldn't be able to rip a class out from under an active proc");
} catch (ProcCallException pce) {
assertTrue(pce.getMessage(), pce.getMessage().contains("Cannot load class for procedure: org.voltdb_testprocs.updateclasses.testImportProc"));
}
// Make sure we didn't purge anything (even the extra dependency)
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
assertEquals(2, resp.getResults()[0].getRowCount());
// Okay, drop the procedure first
try {
resp = m_client.callProcedure("@AdHoc", "drop procedure testImportProc");
} catch (ProcCallException pce) {
fail("Should be able to drop a stored procedure");
}
assertFalse(findProcedureInSystemCatalog("testImportProc"));
// Now try to remove the procedure class again
try {
resp = m_client.callProcedure("@UpdateClasses", null, "org.voltdb_testprocs.updateclasses.*");
} catch (ProcCallException pce) {
fail("Should be able to remove the classes for an inactive procedure");
}
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
// no classes in catalog
assertEquals(0, resp.getResults()[0].getRowCount());
m_client.close();
cluster.shutDown();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.
the class TestAdhocCreateDropJavaProc method testCreateUsingExistingImport.
// This test should trigger the same failure seen in ENG-6611
@Test
public void testCreateUsingExistingImport() throws Exception {
System.out.println("\n\n-----\n testCreateUsingExistingImport \n-----\n\n");
String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
VoltProjectBuilder builder = new VoltProjectBuilder();
// Start off with the dependency imported
builder.addLiteralSchema("import class org.voltdb_testprocs.updateclasses.NoMeaningClass;");
builder.setUseDDLSchema(true);
boolean success = builder.compile(pathToCatalog, 2, 1, 0);
assertTrue("Schema compilation failed", success);
MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
try {
LocalCluster cluster = new LocalCluster("updateclasses.jar", 2, 1, 0, BackendTarget.NATIVE_EE_JNI);
cluster.compile(builder);
cluster.setHasLocalServer(false);
cluster.startUp();
m_client = ClientFactory.createClient();
m_client.createConnection(cluster.getListenerAddress(0));
ClientResponse resp;
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
System.out.println(resp.getResults()[0]);
// Now load the procedure requiring the already-resident dependency
InMemoryJarfile jarfile = new InMemoryJarfile();
VoltCompiler comp = new VoltCompiler(false);
comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
try {
resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Triggered ENG-6611!");
}
resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
assertEquals(2, resp.getResults()[0].getRowCount());
// create the proc and make sure it runs
try {
resp = m_client.callProcedure("@AdHoc", "create procedure from class org.voltdb_testprocs.updateclasses.testImportProc");
} catch (ProcCallException pce) {
fail("Should be able to create testImportProc procedure");
}
assertTrue(findProcedureInSystemCatalog("testImportProc"));
try {
resp = m_client.callProcedure("testImportProc");
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Should be able to call fully consistent procedure");
}
assertEquals(10L, resp.getResults()[0].asScalarLong());
m_client.close();
cluster.shutDown();
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.voltdb.compiler.VoltProjectBuilder in project voltdb by VoltDB.
the class TestAdhocDropCreateTable method testDropCreateTableError.
@Test
public void testDropCreateTableError() throws Exception {
String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
VoltProjectBuilder builder = new VoltProjectBuilder();
builder.addLiteralSchema("create table FOO (ID integer);");
builder.setUseDDLSchema(true);
boolean success = builder.compile(pathToCatalog, 2, 1, 0);
assertTrue("Schema compilation failed", success);
MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToCatalog = pathToCatalog;
config.m_pathToDeployment = pathToDeployment;
try {
startSystem(config);
// separate commands (succeed)
assertTrue(findTableInSystemCatalogResults("FOO"));
try {
m_client.callProcedure("@AdHoc", "drop table FOO;");
m_client.callProcedure("@AdHoc", "create table FOO (ID integer);");
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Separate DROP/CREATE commands should have worked.");
}
// batch with conflicting DROP/CREATE for same table (fail)
assertTrue(findTableInSystemCatalogResults("FOO"));
boolean threw = false;
try {
m_client.callProcedure("@AdHoc", "drop table FOO; create table FOO (ID integer);");
} catch (ProcCallException pce) {
threw = true;
boolean correct = pce.getMessage().contains("contains both DROP and CREATE");
assertTrue("Wrong error received for DROP/CREATE batch.", correct);
}
assertTrue("DROP/CREATE batch didn't fail.", threw);
// batch with non-conflicting DROP/CREATE for different tables (succeed)
assertTrue(findTableInSystemCatalogResults("FOO"));
assertFalse(findTableInSystemCatalogResults("FO"));
try {
m_client.callProcedure("@AdHoc", "drop table FOO; create table FO (NAME varchar(20));");
} catch (ProcCallException pce) {
fail("Non-conflicting DROP/CREATE commands should have worked.");
}
assertFalse(findTableInSystemCatalogResults("FOO"));
assertTrue(findTableInSystemCatalogResults("FO"));
} finally {
teardownSystem();
}
}
Aggregations