Search in sources :

Example 1 with TableHelper

use of org.voltdb.TableHelper in project voltdb by VoltDB.

the class TestClientFeatures method testPerCallTimeout.

public void testPerCallTimeout() throws Exception {
    CSL csl = new CSL();
    ClientConfig config = new ClientConfig(null, null, csl, ClientAuthScheme.HASH_SHA1);
    config.setProcedureCallTimeout(500);
    Client client = ClientFactory.createClient(config);
    client.createConnection("localhost");
    ClientResponse response = client.callProcedure("ArbitraryDurationProc", 0);
    assertEquals(ClientResponse.SUCCESS, response.getStatus());
    try {
        client.callProcedure("ArbitraryDurationProc", 3000);
        fail();
    } catch (ProcCallException e) {
        assertTrue(e.getMessage().startsWith("No response received in the allotted time"));
    }
    // make sure the callback gets called
    assertTrue(csl.waitForCall(6000));
    if (MiscUtils.isPro()) {
        // build a catalog with a ton of indexes so catalog update will be slow
        CatalogBuilder builder = new CatalogBuilder();
        builder.addSchema(getClass().getResource("clientfeatures-wellindexed.sql"));
        builder.addProcedures(ArbitraryDurationProc.class);
        byte[] catalogToUpdate = builder.compileToBytes();
        assert (catalogToUpdate != null);
        // make a copy of the table from ddl for loading
        // (shouldn't have to do this, but for now, the table loader requires
        //  a VoltTable, and can't read schema. Could fix by using this VoltTable
        //  to generate schema or by teaching to loader how to discover tables)
        TableHelper.Configuration helperConfig = new TableHelper.Configuration();
        helperConfig.rand = new Random();
        TableHelper helper = new TableHelper(helperConfig);
        VoltTable t = TableHelper.quickTable("indexme (pkey:bigint, " + "c01:varchar63, " + "c02:varchar63, " + "c03:varchar63, " + "c04:varchar63, " + "c05:varchar63, " + "c06:varchar63, " + "c07:varchar63, " + "c08:varchar63, " + "c09:varchar63, " + "c10:varchar63) " + "PKEY(pkey)");
        // get a client with a normal timout
        Client client2 = ClientFactory.createClient();
        client2.createConnection("localhost");
        helper.fillTableWithBigintPkey(t, 400, 0, client2, 0, 1);
        long start;
        double duration;
        // run a catalog update that *might* normally timeout
        start = System.nanoTime();
        response = client.callProcedure("@UpdateApplicationCatalog", catalogToUpdate, depBuilder.getXML());
        duration = (System.nanoTime() - start) / 1000000000.0;
        System.out.printf("Catalog update duration in seconds: %.2f\n", duration);
        assertEquals(ClientResponse.SUCCESS, response.getStatus());
        // run a blocking snapshot that *might* normally timeout
        start = System.nanoTime();
        response = client.callProcedure("@SnapshotSave", Configuration.getPathToCatalogForTest(""), "slow", 1);
        duration = (System.nanoTime() - start) / 1000000000.0;
        System.out.printf("Snapshot save duration in seconds: %.2f\n", duration);
        assertEquals(ClientResponse.SUCCESS, response.getStatus());
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltTable(org.voltdb.VoltTable) Random(java.util.Random) CatalogBuilder(org.voltdb.compiler.CatalogBuilder) TableHelper(org.voltdb.TableHelper)

Example 2 with TableHelper

use of org.voltdb.TableHelper in project voltdb by VoltDB.

the class TestLiveTableSchemaMigration method migrateSchema.

/**
     * Assuming given tables have schema metadata, fill them with random data
     * and compare a pure-java schema migration with an EE schema migration.
     */
void migrateSchema(VoltTable t1, VoltTable t2, boolean withData) throws Exception {
    ServerThread server = null;
    Client client = null;
    TableHelper helper = new TableHelper();
    try {
        if (withData) {
            helper.randomFill(t1, 1000, 1024);
        }
        String catPath1 = catalogPathForTable(t1, "t1.jar");
        String catPath2 = catalogPathForTable(t2, "t2.jar");
        byte[] catBytes2 = MiscUtils.fileToBytes(new File(catPath2));
        DeploymentBuilder depBuilder = new DeploymentBuilder(1, 1, 0);
        depBuilder.setVoltRoot("/tmp/rootbar");
        // disable logging
        depBuilder.configureLogging("/tmp/foobar", "/tmp/goobar", false, false, 1, 1, 3);
        String deployment = depBuilder.getXML();
        File deploymentFile = VoltProjectBuilder.writeStringToTempFile(deployment);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToDeployment = deploymentFile.getAbsolutePath();
        config.m_pathToCatalog = catPath1;
        config.m_ipcPort = 10000;
        //config.m_backend = BackendTarget.NATIVE_EE_IPC;
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        System.out.printf("PRE:  %s\n", TableHelper.ddlForTable(t1, false));
        System.out.printf("POST: %s\n", TableHelper.ddlForTable(t2, false));
        ClientConfig clientConfig = new ClientConfig();
        client = ClientFactory.createClient(clientConfig);
        client.createConnection("localhost");
        TableHelper.loadTable(client, t1);
        ClientResponseImpl response = (ClientResponseImpl) client.callProcedure("@UpdateApplicationCatalog", catBytes2, null);
        System.out.println(response.toJSONString());
        VoltTable t3 = client.callProcedure("@AdHoc", "select * from FOO").getResults()[0];
        t3 = TableHelper.sortTable(t3);
        // compute the migrated table entirely in Java for comparison purposes
        TableHelper.migrateTable(t1, t2);
        t2 = TableHelper.sortTable(t2);
        // compare the tables
        StringBuilder sb = new StringBuilder();
        if (!TableHelper.deepEqualsWithErrorMsg(t2, t3, sb)) {
            System.out.println("Table Mismatch");
            //System.out.printf("PRE:  %s\n", t2.toFormattedString());
            //System.out.printf("POST: %s\n", t3.toFormattedString());
            System.out.println(sb.toString());
            fail();
        }
    } finally {
        if (client != null) {
            client.close();
        }
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltTable(org.voltdb.VoltTable) VoltDB(org.voltdb.VoltDB) ServerThread(org.voltdb.ServerThread) TableHelper(org.voltdb.TableHelper) Configuration(org.voltdb.VoltDB.Configuration) ClientResponseImpl(org.voltdb.ClientResponseImpl) Client(org.voltdb.client.Client) ClientConfig(org.voltdb.client.ClientConfig) File(java.io.File) DeploymentBuilder(org.voltdb.compiler.DeploymentBuilder)

Example 3 with TableHelper

use of org.voltdb.TableHelper in project voltdb by VoltDB.

the class TestLiveTableSchemaMigration method testRandomSchemas.

//
// Create and mutate a bunch of random schemas and data in java,
// then compare the mutated results with a schema change in the EE.
//
// The number of times the loop is run can be changed to make the test
// better at the cost of runtime.
//
public void testRandomSchemas() throws Exception {
    int count = 15;
    TableHelper helper = new TableHelper();
    for (int i = 0; i < count; i++) {
        TableHelper.RandomTable trt = helper.getTotallyRandomTable("foo");
        VoltTable t1 = trt.table;
        VoltTable t2 = helper.mutateTable(t1, true);
        migrateSchema(t1, t2);
        System.out.printf("testRandomSchemas tested %d/%d\n", i + 1, count);
    }
}
Also used : TableHelper(org.voltdb.TableHelper) VoltTable(org.voltdb.VoltTable)

Example 4 with TableHelper

use of org.voltdb.TableHelper in project voltdb by VoltDB.

the class TestLiveTableSchemaMigration method testRandomSchemasUsingAlter.

public void testRandomSchemasUsingAlter() throws Exception {
    int count = 15;
    TableHelper helper = new TableHelper();
    for (int i = 0; i < count; i++) {
        TableHelper.RandomTable trt = helper.getTotallyRandomTable("foo");
        VoltTable t1 = trt.table;
        VoltTable t2 = helper.mutateTable(t1, true);
        migrateSchemaUsingAlter(t1, t2, true);
        System.out.printf("testRandomSchemasUsingAlter tested %d/%d\n", i + 1, count);
    }
}
Also used : TableHelper(org.voltdb.TableHelper) VoltTable(org.voltdb.VoltTable)

Example 5 with TableHelper

use of org.voltdb.TableHelper in project voltdb by VoltDB.

the class TestLiveTableSchemaMigration method migrateSchemaUsingAlter.

/**
     * Assuming given tables have schema metadata, fill them with random data
     * and compare a pure-java schema migration with an EE schema migration.
     */
void migrateSchemaUsingAlter(VoltTable t1, VoltTable t2, boolean withData) throws Exception {
    ServerThread server = null;
    Client client = null;
    TableHelper helper = new TableHelper();
    try {
        String alterText = TableHelper.getAlterTableDDLToMigrate(t1, t2);
        if (withData) {
            helper.randomFill(t1, 1000, 1024);
        }
        String catPath1 = catalogPathForTable(t1, "t1.jar");
        DeploymentBuilder depBuilder = new DeploymentBuilder(1, 1, 0);
        depBuilder.setVoltRoot("/tmp/rootbar");
        depBuilder.setUseDDLSchema(true);
        // disable logging
        depBuilder.configureLogging("/tmp/foobar", "/tmp/goobar", false, false, 1, 1, 3);
        String deployment = depBuilder.getXML();
        File deploymentFile = VoltProjectBuilder.writeStringToTempFile(deployment);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToDeployment = deploymentFile.getAbsolutePath();
        config.m_pathToCatalog = catPath1;
        config.m_ipcPort = 10000;
        //config.m_backend = BackendTarget.NATIVE_EE_IPC;
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        System.out.printf("PRE:  %s\n", TableHelper.ddlForTable(t1, false));
        System.out.printf("POST: %s\n", TableHelper.ddlForTable(t2, false));
        TableHelper.migrateTable(t1, t2);
        t2 = TableHelper.sortTable(t2);
        ClientConfig clientConfig = new ClientConfig();
        client = ClientFactory.createClient(clientConfig);
        client.createConnection("localhost");
        TableHelper.loadTable(client, t1);
        if (alterText.trim().length() > 0) {
            ClientResponseImpl response = (ClientResponseImpl) client.callProcedure("@AdHoc", alterText, null);
            System.out.println(response.toJSONString());
        }
        VoltTable t3 = client.callProcedure("@AdHoc", "select * from FOO").getResults()[0];
        t3 = TableHelper.sortTable(t3);
        // compare the tables
        StringBuilder sb = new StringBuilder();
        if (!TableHelper.deepEqualsWithErrorMsg(t2, t3, sb)) {
            System.out.println("Table Mismatch");
            //System.out.printf("PRE:  %s\n", t2.toFormattedString());
            //System.out.printf("POST: %s\n", t3.toFormattedString());
            System.out.println(sb.toString());
            fail();
        }
    } finally {
        if (client != null) {
            client.close();
        }
        if (server != null) {
            server.shutdown();
        }
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltTable(org.voltdb.VoltTable) VoltDB(org.voltdb.VoltDB) ServerThread(org.voltdb.ServerThread) TableHelper(org.voltdb.TableHelper) Configuration(org.voltdb.VoltDB.Configuration) ClientResponseImpl(org.voltdb.ClientResponseImpl) Client(org.voltdb.client.Client) ClientConfig(org.voltdb.client.ClientConfig) File(java.io.File) DeploymentBuilder(org.voltdb.compiler.DeploymentBuilder)

Aggregations

TableHelper (org.voltdb.TableHelper)5 VoltTable (org.voltdb.VoltTable)5 Configuration (org.voltdb.VoltDB.Configuration)3 File (java.io.File)2 ClientResponseImpl (org.voltdb.ClientResponseImpl)2 ServerThread (org.voltdb.ServerThread)2 VoltDB (org.voltdb.VoltDB)2 Client (org.voltdb.client.Client)2 ClientConfig (org.voltdb.client.ClientConfig)2 DeploymentBuilder (org.voltdb.compiler.DeploymentBuilder)2 Random (java.util.Random)1 CatalogBuilder (org.voltdb.compiler.CatalogBuilder)1