use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.
the class TestCatalogUtil method testImportSettings.
public void testImportSettings() throws Exception {
File formatjar = CatalogUtil.createTemporaryEmptyCatalogJarFile(false);
final String withBadImport1 = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + " <import>" + " <configuration type=\"custom\" module=\"///\" " + "format=\"file:" + formatjar.toString() + "/csv\" >" + " <property name=\"foo\">false</property>" + " <property name=\"type\">CSV</property>" + " <property name=\"with-schema\">false</property>" + " </configuration>" + " </import>" + "</deployment>";
final String withBadImport2 = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + " <import>" + " <configuration type=\"custom\" module=\"file:/tmp/foobar.jar\" " + "format=\"file:" + formatjar.toString() + "/csv\" >" + " <property name=\"foo\">false</property>" + " <property name=\"type\">CSV</property>" + " <property name=\"with-schema\">false</property>" + " </configuration>" + " </import>" + "</deployment>";
//Use catalog jar to point to a file to do dup test.
File catjar = CatalogUtil.createTemporaryEmptyCatalogJarFile(false);
final String withBadImport3 = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + " <import>" + " <configuration type=\"custom\" module=\"file:/" + catjar.toString() + "\" format=\"file:" + formatjar.toString() + "/csv\" >" + " <property name=\"foo\">false</property>" + " <property name=\"type\">CSV</property>" + " <property name=\"with-schema\">false</property>" + " </configuration>" + " <configuration type=\"custom\" module=\"file:/" + catjar.toString() + "\" format=\"file:" + formatjar.toString() + "/csv\" >" + " <property name=\"foo\">false</property>" + " <property name=\"type\">CSV</property>" + " <property name=\"with-schema\">false</property>" + " </configuration>" + " </import>" + "</deployment>";
final String withGoodImport0 = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + " <import>" + " <configuration type=\"custom\" module=\"file:" + catjar.toString() + "\" format=\"file:" + formatjar.toString() + "/csv\" >" + " <property name=\"foo\">false</property>" + " <property name=\"type\">CSV</property>" + " <property name=\"with-schema\">false</property>" + " </configuration>" + " <configuration type=\"custom\" module=\"file:" + catjar.toString() + "\" format=\"file:" + formatjar.toString() + "/csv\" >" + " <property name=\"foo\">false</property>" + " <property name=\"type\">CSV</property>" + " <property name=\"with-schema\">false</property>" + " </configuration>" + " </import>" + "</deployment>";
final String goodImport1 = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + " <import>" + " <configuration type=\"custom\" module=\"file:" + catjar.toString() + "\" format=\"file:" + formatjar.toString() + "/csv\" >" + " <property name=\"foo\">false</property>" + " <property name=\"type\">CSV</property>" + " <property name=\"with-schema\">false</property>" + " </configuration>" + " </import>" + "</deployment>";
final String withBadFormatter1 = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + "<cluster hostcount='3' kfactor='1' sitesperhost='2'/>" + " <import>" + " <configuration type=\"custom\" module=\"file:" + catjar.toString() + "\" format=\"badformatter.jar/csv\" >" + " <property name=\"foo\">false</property>" + " <property name=\"type\">CSV</property>" + " <property name=\"with-schema\">false</property>" + " </configuration>" + " </import>" + "</deployment>";
final String ddl = "CREATE TABLE data ( id BIGINT default 0 , value BIGINT DEFAULT 0 );\n";
final File tmpDdl = VoltProjectBuilder.writeStringToTempFile(ddl);
//import with bad bundlename
final File tmpBad = VoltProjectBuilder.writeStringToTempFile(withBadImport1);
DeploymentType bad_deployment = CatalogUtil.getDeployment(new FileInputStream(tmpBad));
VoltCompiler compiler = new VoltCompiler(false);
String[] x = { tmpDdl.getAbsolutePath() };
Catalog cat = compiler.compileCatalogFromDDL(x);
String msg = CatalogUtil.compileDeployment(cat, bad_deployment, false);
assertTrue(msg, msg.contains("Error validating deployment configuration: Import failed to configure, failed to load module by URL or classname provided"));
//import with bad bundlename
final File tmpBad2 = VoltProjectBuilder.writeStringToTempFile(withBadImport2);
DeploymentType bad_deployment2 = CatalogUtil.getDeployment(new FileInputStream(tmpBad2));
VoltCompiler compiler2 = new VoltCompiler(false);
String[] x2 = { tmpDdl.getAbsolutePath() };
Catalog cat2 = compiler2.compileCatalogFromDDL(x2);
String msg2 = CatalogUtil.compileDeployment(cat2, bad_deployment2, false);
assertTrue("compilation should have failed", msg2.contains("Error validating deployment configuration: Import failed to configure, failed to load module by URL or classname provided"));
//import with bad url for bundlename
final File tmpBad3 = VoltProjectBuilder.writeStringToTempFile(withBadImport3);
DeploymentType bad_deployment3 = CatalogUtil.getDeployment(new FileInputStream(tmpBad3));
VoltCompiler compiler3 = new VoltCompiler(false);
String[] x3 = { tmpDdl.getAbsolutePath() };
Catalog cat3 = compiler3.compileCatalogFromDDL(x3);
String msg3 = CatalogUtil.compileDeployment(cat3, bad_deployment3, false);
assertTrue("compilation should have failed", msg3.contains("Error validating deployment configuration: Import failed to configure, failed to load module by URL or classname provided"));
//import with dup should be ok now
final File tmpBad4 = VoltProjectBuilder.writeStringToTempFile(withGoodImport0);
DeploymentType bad_deployment4 = CatalogUtil.getDeployment(new FileInputStream(tmpBad4));
VoltCompiler compiler4 = new VoltCompiler(false);
String[] x4 = { tmpDdl.getAbsolutePath() };
Catalog cat4 = compiler4.compileCatalogFromDDL(x4);
String msg4 = CatalogUtil.compileDeployment(cat4, bad_deployment4, false);
assertNull(msg4);
//import good bundle not necessary loadable by felix.
final File good1 = VoltProjectBuilder.writeStringToTempFile(goodImport1);
DeploymentType good_deployment1 = CatalogUtil.getDeployment(new FileInputStream(good1));
VoltCompiler good_compiler1 = new VoltCompiler(false);
String[] x5 = { tmpDdl.getAbsolutePath() };
Catalog cat5 = good_compiler1.compileCatalogFromDDL(x5);
String msg5 = CatalogUtil.compileDeployment(cat5, good_deployment1, false);
assertNull(msg5);
//formatter with invalid jar
final File tmpBad5 = VoltProjectBuilder.writeStringToTempFile(withBadFormatter1);
DeploymentType bad_deployment5 = CatalogUtil.getDeployment(new FileInputStream(tmpBad5));
VoltCompiler compiler6 = new VoltCompiler(false);
String[] x6 = { tmpDdl.getAbsolutePath() };
Catalog cat6 = compiler6.compileCatalogFromDDL(x6);
String msg6 = CatalogUtil.compileDeployment(cat6, bad_deployment5, false);
assertTrue("compilation should have failed", msg6.contains("Error validating deployment configuration: Import failed to configure, failed to load module by URL or classname provided"));
System.out.println("Import deployment tests done.");
}
use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.
the class TestCatalogUtil method testDiskLimitNegative.
public void testDiskLimitNegative() throws Exception {
final String deploymentString = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + " <cluster hostcount=\"1\" kfactor=\"0\" />" + " <httpd enabled=\"true\">" + " <jsonapi enabled=\"true\" />" + " </httpd>" + " <systemsettings>" + " <resourcemonitor>" + " <disklimit>" + " <feature name=\"commandlog\" size=\"xx\"/>" + " </disklimit>" + " </resourcemonitor>" + " </systemsettings>" + "</deployment>";
final String ddl = "CREATE TABLE T (D1 INTEGER NOT NULL, D2 INTEGER);\n";
final File tmpWithDefault = VoltProjectBuilder.writeStringToTempFile(deploymentString);
DeploymentType deploymentWithDefault = CatalogUtil.getDeployment(new FileInputStream(tmpWithDefault));
final File tmpDdl = VoltProjectBuilder.writeStringToTempFile(ddl);
VoltCompiler compiler = new VoltCompiler(false);
String[] x = { tmpDdl.getAbsolutePath() };
Catalog cat = compiler.compileCatalogFromDDL(x);
String msg = CatalogUtil.compileDeployment(cat, deploymentWithDefault, false);
assertTrue(msg.contains("Invalid value"));
}
use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.
the class TestCatalogUtil method testMemoryLimitNegative.
public void testMemoryLimitNegative() throws Exception {
final String deploymentString = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<deployment>" + " <cluster hostcount=\"1\" kfactor=\"0\" />" + " <httpd enabled=\"true\">" + " <jsonapi enabled=\"true\" />" + " </httpd>" + " <systemsettings>" + " <resourcemonitor>" + " <memorylimit size=\"90.5%\"/>" + " </resourcemonitor>" + " </systemsettings>" + "</deployment>";
final String ddl = "CREATE TABLE T (D1 INTEGER NOT NULL, D2 INTEGER);\n";
final File tmpWithDefault = VoltProjectBuilder.writeStringToTempFile(deploymentString);
DeploymentType deploymentWithDefault = CatalogUtil.getDeployment(new FileInputStream(tmpWithDefault));
final File tmpDdl = VoltProjectBuilder.writeStringToTempFile(ddl);
VoltCompiler compiler = new VoltCompiler(false);
String[] x = { tmpDdl.getAbsolutePath() };
Catalog cat = compiler.compileCatalogFromDDL(x);
String msg = CatalogUtil.compileDeployment(cat, deploymentWithDefault, false);
assertTrue(msg.contains("Invalid memory limit"));
}
use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.
the class TestInMemoryJarfile method testJarfileRemoveClassRemovesInnerClasses.
public void testJarfileRemoveClassRemovesInnerClasses() throws Exception {
InMemoryJarfile dut = new InMemoryJarfile();
// Add a class file that we know has inner classes
// Someday this seems like it should be an operation directly on InMemoryJarfile
VoltCompiler comp = new VoltCompiler(false);
// This will pull in all the inner classes (currently 4 of them), but check anyway
comp.addClassToJar(dut, org.voltdb_testprocs.updateclasses.InnerClassesTestProc.class);
JarLoader loader = dut.getLoader();
assertEquals(5, loader.getClassNames().size());
System.out.println(loader.getClassNames());
assertTrue(loader.getClassNames().contains("org.voltdb_testprocs.updateclasses.InnerClassesTestProc$InnerNotPublic"));
assertTrue(dut.get("org/voltdb_testprocs/updateclasses/InnerClassesTestProc$InnerNotPublic.class") != null);
// Now, remove the outer class and verify that all the inner classes go away.
dut.removeClassFromJar("org.voltdb_testprocs.updateclasses.InnerClassesTestProc");
assertTrue(loader.getClassNames().isEmpty());
assertTrue(dut.get("org/voltdb_testprocs/updateclasses/InnerClassesTestProc$InnerNotPublic.class") == null);
}
use of org.voltdb.compiler.VoltCompiler 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();
}
}
Aggregations