Search in sources :

Example 26 with VoltCompiler

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

the class TestInitStartAction method testInitWithClassesAndArtifacts.

/** Tests that when there are base classes and non-class files in the stored procedures,
     * that these also exist in the staged catalog.
     * @throws Exception upon failure or error
     */
@Test
public void testInitWithClassesAndArtifacts() throws Exception {
    System.out.println("Loading the schema from testprocs");
    File resource = new File("tests/testprocs/org/voltdb_testprocs/fakeusecase/greetings/ddl.sql");
    InputStream schemaReader = new FileInputStream(resource);
    assertNotNull("Could not find " + resource, schemaReader);
    String schema = CharStreams.toString(new InputStreamReader(schemaReader));
    System.out.println("Creating a .jar file using all of the classes associated with this test.");
    InMemoryJarfile originalInMemoryJar = new InMemoryJarfile();
    VoltCompiler compiler = new VoltCompiler(false, false);
    ClassPath classpath = ClassPath.from(this.getClass().getClassLoader());
    String packageName = "org.voltdb_testprocs.fakeusecase.greetings";
    int classesFound = 0;
    for (ClassInfo myclass : classpath.getTopLevelClassesRecursive(packageName)) {
        compiler.addClassToJar(originalInMemoryJar, myclass.load());
        classesFound++;
    }
    // check that classes were found and loaded. If another test modifies "fakeusecase.greetings" it should modify this assert also.
    assertEquals(5, classesFound);
    System.out.println("Writing " + classesFound + " classes to jar file");
    File classesJarfile = File.createTempFile("TestInitStartWithClasses-procedures", ".jar");
    classesJarfile.deleteOnExit();
    originalInMemoryJar.writeToFile(classesJarfile);
    Configuration c1 = new Configuration(new String[] { "initialize", "voltdbroot", rootDH.getPath(), "force", "schema", resource.getPath(), "classes", classesJarfile.getPath() });
    ServerThread server = new ServerThread(c1);
    server.setUncaughtExceptionHandler(handleUncaught);
    server.start();
    server.join();
    validateStagedCatalog(schema, originalInMemoryJar);
}
Also used : ClassPath(com.google_voltpatches.common.reflect.ClassPath) VoltCompiler(org.voltdb.compiler.VoltCompiler) InputStreamReader(java.io.InputStreamReader) Configuration(org.voltdb.VoltDB.Configuration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) FileInputStream(java.io.FileInputStream) ClassInfo(com.google_voltpatches.common.reflect.ClassPath.ClassInfo) Test(org.junit.Test)

Example 27 with VoltCompiler

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

the class TestLiveDDLSchemaSwitch method verifyMasterWithAdhocDDL.

void verifyMasterWithAdhocDDL() throws Exception {
    // UAC with schema should fail
    assertFalse(findTableInSystemCatalogResults("FOO"));
    boolean threw = false;
    try {
        m_client.updateApplicationCatalog(new File(m_pathToCatalog), null);
    } catch (ProcCallException pce) {
        threw = true;
        assertTrue(pce.getMessage().contains("Use of @UpdateApplicationCatalog is forbidden"));
    }
    assertTrue("@UAC should have failed", threw);
    assertFalse(findTableInSystemCatalogResults("FOO"));
    // But, we can create that table with Adhoc DDL
    try {
        m_client.callProcedure("@AdHoc", "create table FOO (ID integer, VAL varchar(50));");
    } catch (ProcCallException pce) {
        fail("Should be able to use Adhoc DDL to create a table.");
    }
    assertTrue(findTableInSystemCatalogResults("FOO"));
    // And so should adhoc queries
    verifyAdhocQuery();
    // If the procedure doesn't already exist, add it using @UpdateClasses
    if (!findClassInSystemCatalog("org.voltdb_testprocs.fullddlfeatures.testImportProc")) {
        // Also, @UpdateClasses should only work with adhoc DDL
        InMemoryJarfile jarfile = new InMemoryJarfile();
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.fullddlfeatures.testImportProc.class);
        try {
            m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        } catch (ProcCallException pce) {
            fail("Should be able to call @UpdateClasses when adhoc DDL enabled.");
        }
        assertTrue(findClassInSystemCatalog("org.voltdb_testprocs.fullddlfeatures.testImportProc"));
    }
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) File(java.io.File) ProcCallException(org.voltdb.client.ProcCallException)

Example 28 with VoltCompiler

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

the class TestInitStartAction method validateStagedCatalog.

/*
     * "voltdb init --schema --procedures" tests:
     * 1.  Positive test with valid schema that requires no procedures
     * 2a. Positive test with valid schema and procedures that are in CLASSPATH
     * 2b. Negative test with valid files but not "init --force"
     * 3.  Negative test with a bad schema
     * 4.  Negative test with procedures missing
     *
     * Note that SimulatedExitException is thrown by the command line parser with no descriptive details.
     * VoltDB.crashLocalVoltDB() throws an AssertionError with the message "Faux crash of VoltDB successful."
     */
/** Verifies that the staged catalog matches what VoltCompiler emits given the supplied schema.
     * @param schema Schema used to generate the staged catalog
     * @throws Exception upon test failure or error (unable to write temp file for example)
     */
private void validateStagedCatalog(String schema, InMemoryJarfile proceduresJar) throws Exception {
    // setup reference point for the supplied schema
    File schemaFile = VoltProjectBuilder.writeStringToTempFile(schema);
    schemaFile.deleteOnExit();
    File referenceFile = File.createTempFile("reference", ".jar");
    referenceFile.deleteOnExit();
    VoltCompiler compiler = new VoltCompiler(false);
    compiler.setInitializeDDLWithFiltering(true);
    final boolean success = compiler.compileFromDDL(referenceFile.getAbsolutePath(), schemaFile.getPath());
    assertEquals(true, success);
    InMemoryJarfile referenceCatalogJar = new InMemoryJarfile(referenceFile);
    Catalog referenceCatalog = new Catalog();
    referenceCatalog.execute(CatalogUtil.getSerializedCatalogStringFromJar(referenceCatalogJar));
    // verify that the staged catalog is identical
    File stagedJarFile = new VoltFile(RealVoltDB.getStagedCatalogPath(rootDH.getPath() + File.separator + "voltdbroot"));
    assertEquals(true, stagedJarFile.isFile());
    InMemoryJarfile stagedCatalogJar = new InMemoryJarfile(stagedJarFile);
    Catalog stagedCatalog = new Catalog();
    stagedCatalog.execute(CatalogUtil.getSerializedCatalogStringFromJar(stagedCatalogJar));
    assertEquals(true, referenceCatalog.equals(stagedCatalog));
    assertEquals(true, stagedCatalog.equals(referenceCatalog));
    assertEquals(true, referenceFile.delete());
    assertEquals(true, schemaFile.delete());
    if (proceduresJar != null) {
        // Validate that the list of files in the supplied jarfile are present in the staged catalog also.
        InMemoryJarfile strippedReferenceJar = CatalogUtil.getCatalogJarWithoutDefaultArtifacts(proceduresJar);
        InMemoryJarfile strippedTestJar = CatalogUtil.getCatalogJarWithoutDefaultArtifacts(stagedCatalogJar);
        for (Entry<String, byte[]> entry : strippedReferenceJar.entrySet()) {
            System.out.println("Checking " + entry.getKey());
            byte[] testClass = strippedTestJar.get(entry.getKey());
            assertNotNull(entry.getKey() + " was not found in staged catalog", testClass);
            assertArrayEquals(entry.getValue(), testClass);
        }
    }
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) VoltFile(org.voltdb.utils.VoltFile) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File) Catalog(org.voltdb.catalog.Catalog)

Example 29 with VoltCompiler

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

the class TestJdbcDatabaseMetaDataGenerator method compileForDDLTest2.

private VoltCompiler compileForDDLTest2(String ddl) throws Exception {
    String ddlPath = getPathForSchema(ddl);
    final VoltCompiler compiler = new VoltCompiler(false);
    boolean success = compiler.compileFromDDL(testout_jar, ddlPath);
    assertTrue("Catalog compile failed!", success);
    return compiler;
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler)

Example 30 with VoltCompiler

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

the class TestJdbcDatabaseMetaDataGenerator method testGetPrimaryKeys.

public void testGetPrimaryKeys() throws Exception {
    String schema = "create table Table1 (Column1 smallint not null, constraint primary1 primary key (Column1));" + "partition table Table1 on column Column1;" + "create table Table2 (Column2 smallint not null, Column3 smallint not null, Column4 smallint not null, " + "  constraint primary2 primary key (Column2, Column3, Column4));" + "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 pkeys = dut.getMetaData("PrimaryKeys");
    System.out.println(pkeys);
    assertEquals(6, pkeys.getColumnCount());
    assertEquals(4, pkeys.getRowCount());
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(pkeys, "COLUMN_NAME", "Column1"));
    assertEquals("TABLE1", pkeys.get("TABLE_NAME", VoltType.STRING));
    assertEquals((short) 1, pkeys.get("KEY_SEQ", VoltType.SMALLINT));
    assertEquals("PRIMARY1", pkeys.get("PK_NAME", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(pkeys, "COLUMN_NAME", "Column2"));
    assertEquals("TABLE2", pkeys.get("TABLE_NAME", VoltType.STRING));
    assertEquals((short) 1, pkeys.get("KEY_SEQ", VoltType.SMALLINT));
    assertEquals("PRIMARY2", pkeys.get("PK_NAME", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(pkeys, "COLUMN_NAME", "Column3"));
    assertEquals("TABLE2", pkeys.get("TABLE_NAME", VoltType.STRING));
    assertEquals((short) 2, pkeys.get("KEY_SEQ", VoltType.SMALLINT));
    assertEquals("PRIMARY2", pkeys.get("PK_NAME", VoltType.STRING));
    assertTrue(VoltTableTestHelpers.moveToMatchingRow(pkeys, "COLUMN_NAME", "Column4"));
    assertEquals("TABLE2", pkeys.get("TABLE_NAME", VoltType.STRING));
    assertEquals((short) 3, pkeys.get("KEY_SEQ", VoltType.SMALLINT));
    assertEquals("PRIMARY2", pkeys.get("PK_NAME", VoltType.STRING));
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile)

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