Search in sources :

Example 31 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile 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 32 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile 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)

Example 33 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile 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"));
}
Also used : VoltCompiler(org.voltdb.compiler.VoltCompiler) JSONObject(org.json_voltpatches.JSONObject) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile)

Example 34 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile 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());
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Client(org.voltdb.client.Client) File(java.io.File) ProcCallException(org.voltdb.client.ProcCallException)

Example 35 with InMemoryJarfile

use of org.voltdb.utils.InMemoryJarfile in project voltdb by VoltDB.

the class TestStartWithSchema method countNodesWithStagedCatalog.

/** Counts how many nodes contain staged catalogs (user-initialized schemas)
     * @param cluster
     * @return number of nodes in cluster that have staged catalogs
     */
static int countNodesWithStagedCatalog(LocalCluster cluster) throws IOException {
    final String pathWithinSubroot = File.separator + Constants.DBROOT + File.separator + CatalogUtil.STAGED_CATALOG_PATH;
    int total = 0;
    for (Map.Entry<String, String> entry : cluster.getHostRoots().entrySet()) {
        assert (entry.getValue().contains(Constants.DBROOT) == false) : entry.getValue();
        File testFile = new VoltFile(entry.getValue() + pathWithinSubroot);
        if (testFile.canRead() && (testFile.length() > 0)) {
            InMemoryJarfile jar = new InMemoryJarfile(testFile);
            ensureAllCatalogDefaultArtifactsExists(jar, testFile.getAbsolutePath());
            total++;
        }
    }
    return total;
}
Also used : VoltFile(org.voltdb.utils.VoltFile) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Map(java.util.Map) VoltFile(org.voltdb.utils.VoltFile) File(java.io.File)

Aggregations

InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)52 VoltCompiler (org.voltdb.compiler.VoltCompiler)26 File (java.io.File)20 ProcCallException (org.voltdb.client.ProcCallException)19 ClientResponse (org.voltdb.client.ClientResponse)18 Test (org.junit.Test)15 Configuration (org.voltdb.VoltDB.Configuration)15 IOException (java.io.IOException)14 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)12 VoltDB (org.voltdb.VoltDB)9 Catalog (org.voltdb.catalog.Catalog)6 VoltTable (org.voltdb.VoltTable)5 VoltFile (org.voltdb.utils.VoltFile)5 ArrayList (java.util.ArrayList)4 JSONObject (org.json_voltpatches.JSONObject)3 CatalogContext (org.voltdb.CatalogContext)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JAXBException (javax.xml.bind.JAXBException)2