use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.
the class TestDeterminism method testDeterminismReadOnlyNoWarning.
/*
* A test that runs some read-only non-deterministic DDLs, check that the output does not contain
* any ND warnings
*/
public void testDeterminismReadOnlyNoWarning() throws Exception {
// Should the members be reused here?
HSQLInterface hsql = HSQLInterface.loadHsqldb();
VoltCompiler compiler = new VoltCompiler(false);
VoltCompiler.DdlProceduresToLoad all_procs = DdlProceduresToLoad.NO_DDL_PROCEDURES;
URL path = TestDeterminism.class.getResource("testplans-determinism-read-only.sql");
String pathStr = URLDecoder.decode(path.getPath(), "UTF-8");
compiler.loadSchema(hsql, all_procs, pathStr);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
compiler.summarizeSuccess(new PrintStream(outputStream), null, "");
System.out.println(outputStream.toString());
// There is no warnings generated for read-only ND queries
String msg = outputStream.toString();
assertFalse(stringContains(msg, "ND"));
assertFalse(stringContains(msg, "WARN"));
assertTrue(stringContains(msg, "Successfully created"));
assertTrue(stringContains(msg, "Catalog contains"));
outputStream.close();
}
use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.
the class TestInitStartLocalClusterAllOutOfProcess 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);
} 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 TestDRCatalogDiffs method createCatalog.
private Catalog createCatalog(String schema) throws Exception {
File jarOut = new File(UUID.randomUUID() + ".jar");
jarOut.deleteOnExit();
File schemaFile = VoltProjectBuilder.writeStringToTempFile(schema);
String schemaPath = schemaFile.getPath();
VoltCompiler compiler = new VoltCompiler(false);
boolean success = compiler.compileFromDDL(jarOut.getPath(), schemaPath);
assertTrue("Compilation failed unexpectedly", success);
Catalog catalog = new Catalog();
catalog.execute(CatalogUtil.getSerializedCatalogStringFromJar(CatalogUtil.loadAndUpgradeCatalogFromJar(MiscUtils.fileToBytes(new File(jarOut.getPath())), false).getFirst()));
return catalog;
}
use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.
the class UpdateApplicationBase method modifyCatalogClasses.
/**
* @return NUll if no classes changed, otherwise return the update jar file.
* @throws ClassNotFoundException
* @throws IOException
*/
private static InMemoryJarfile modifyCatalogClasses(Catalog catalog, InMemoryJarfile jarfile, String deletePatterns, InMemoryJarfile newJarfile, boolean isXDCR) throws ClassNotFoundException, IOException {
// modify the old jar in place based on the @UpdateClasses inputs, and then
// recompile it if necessary
boolean deletedClasses = false;
if (deletePatterns != null) {
String[] patterns = deletePatterns.split(",");
ClassMatcher matcher = new ClassMatcher();
// Need to concatenate all the classnames together for ClassMatcher
String currentClasses = "";
for (String classname : jarfile.getLoader().getClassNames()) {
currentClasses = currentClasses.concat(classname + "\n");
}
matcher.m_classList = currentClasses;
for (String pattern : patterns) {
ClassNameMatchStatus status = matcher.addPattern(pattern.trim());
if (status == ClassNameMatchStatus.MATCH_FOUND) {
deletedClasses = true;
}
}
for (String classname : matcher.getMatchedClassList()) {
jarfile.removeClassFromJar(classname);
}
}
boolean foundClasses = false;
if (newJarfile != null) {
for (Entry<String, byte[]> e : newJarfile.entrySet()) {
String filename = e.getKey();
if (!filename.endsWith(".class")) {
continue;
}
foundClasses = true;
jarfile.put(e.getKey(), e.getValue());
}
}
if (!deletedClasses && !foundClasses) {
return null;
}
compilerLog.info("Updating java classes available to stored procedures");
VoltCompiler compiler = new VoltCompiler(isXDCR);
compiler.compileInMemoryJarfile(jarfile);
return jarfile;
}
use of org.voltdb.compiler.VoltCompiler in project voltdb by VoltDB.
the class UpdateApplicationBase method addDDLToCatalog.
/**
* Append the supplied adhoc DDL to the current catalog's DDL and recompile the
* jarfile
* @throws VoltCompilerException
*/
protected static InMemoryJarfile addDDLToCatalog(Catalog oldCatalog, InMemoryJarfile jarfile, String[] adhocDDLStmts, boolean isXDCR) throws IOException, VoltCompilerException {
StringBuilder sb = new StringBuilder();
compilerLog.info("Applying the following DDL to cluster:");
for (String stmt : adhocDDLStmts) {
compilerLog.info("\t" + stmt);
sb.append(stmt);
sb.append(";\n");
}
String newDDL = sb.toString();
compilerLog.trace("Adhoc-modified DDL:\n" + newDDL);
VoltCompiler compiler = new VoltCompiler(isXDCR);
compiler.compileInMemoryJarfileWithNewDDL(jarfile, newDDL, oldCatalog);
return jarfile;
}
Aggregations