Search in sources :

Example 11 with ServerThread

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

the class TestInitStartLocalClusterInProcess method getProcJarFromCatalog.

InMemoryJarfile getProcJarFromCatalog() throws IOException {
    File jar = File.createTempFile("procedure", ".jar");
    Configuration config = new VoltDB.Configuration(new String[] { "get", "classes", "getvoltdbroot", voltDBRootParentPath, "file", jar.getAbsolutePath(), "forceget" });
    ServerThread server = new ServerThread(config);
    try {
        server.cli();
    } catch (Throwable ex) {
    //Good
    }
    byte[] bytesRead = Files.readAllBytes(Paths.get(jar.getAbsolutePath()));
    assertNotNull(bytesRead);
    assertTrue(bytesRead.length > 0);
    return new InMemoryJarfile(bytesRead);
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ServerThread(org.voltdb.ServerThread) File(java.io.File)

Example 12 with ServerThread

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

the class TestInitStartLocalClusterInProcess method testGetSchema.

// Test get schema
public void testGetSchema() throws Exception {
    File schema = File.createTempFile("schema", ".sql");
    Configuration config = new VoltDB.Configuration(new String[] { "get", "schema", "getvoltdbroot", voltDBRootParentPath, "file", schema.getAbsolutePath(), "forceget" });
    ServerThread server = new ServerThread(config);
    try {
        server.cli();
    } catch (Throwable ex) {
    //Good
    }
    byte[] encoded = Files.readAllBytes(Paths.get(schema.getAbsolutePath()));
    assertNotNull(encoded);
    assertTrue(encoded.length > 0);
    String ddl = new String(encoded, StandardCharsets.UTF_8);
    assertTrue(ddl.toLowerCase().contains("create table blah ("));
    assertTrue(ddl.toLowerCase().contains("ival bigint default '0' not null"));
    assertTrue(ddl.toLowerCase().contains("primary key (ival)"));
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) ServerThread(org.voltdb.ServerThread) File(java.io.File)

Example 13 with ServerThread

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

the class TestVoltBulkLoader method test_Interface.

public void test_Interface(String my_schema, Object[][] my_data, int my_batchSize, ArrayList<Integer> expectedFailList, int flushInterval, boolean upsert) throws Exception {
    try {
        pathToCatalog = Configuration.getPathToCatalogForTest("vbl.jar");
        pathToDeployment = Configuration.getPathToCatalogForTest("vbl.xml");
        builder = new VoltProjectBuilder();
        builder.addLiteralSchema(my_schema);
        builder.addPartitionInfo("BLAH", "clm_integer");
        boolean success = builder.compile(pathToCatalog, 2, 1, 0);
        assertTrue(success);
        MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
        config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        localServer = new ServerThread(config);
        client1 = null;
        localServer.start();
        localServer.waitForInitialization();
        client1 = ClientFactory.createClient();
        client1.createConnection("localhost");
        prepare();
        TestFailureCallback testCallback = new TestFailureCallback();
        VoltBulkLoader bulkLoader = client1.getNewBulkLoader("BLAH", my_batchSize, upsert, testCallback);
        if (flushInterval > 0) {
            bulkLoader.setFlushInterval(0, flushInterval);
        }
        // do the test
        VoltTable modCount;
        modCount = client1.callProcedure("@AdHoc", "SELECT * FROM BLAH;").getResults()[0];
        System.out.println("data inserted to table BLAH:\n" + modCount);
        // Call validate partitioning to check if we are good.
        VoltTable valTable;
        valTable = client1.callProcedure("@ValidatePartitioning", null, null).getResults()[0];
        System.out.println("Validate for BLAH:\n" + valTable);
        while (valTable.advanceRow()) {
            long miscnt = valTable.getLong("MISPARTITIONED_ROWS");
            assertEquals(miscnt, 0);
        }
        int rowCnt = 1;
        try {
            for (Object[] nextRow : my_data) {
                Integer rowId = new Integer(rowCnt);
                bulkLoader.insertRow(rowId, nextRow);
                rowCnt++;
                if (flushInterval <= 0 && (rnd.nextInt() % 30 == 0)) {
                    //  Randomly inject a flush if no timer flush is involved.
                    bulkLoader.flush();
                }
            }
        } catch (Exception e) {
            System.err.print(e.getMessage());
        }
        System.out.println(String.format("Attempted inserting %d rows", --rowCnt));
        if (flushInterval <= 0 && rnd.nextBoolean()) {
            // One in 10 tests generate a sync and VoltBulkLoader internal state verification
            bulkLoader.drain();
            assertEquals(0, bulkLoader.getOutstandingRowCount());
            assertEquals(rowCnt, bulkLoader.getCompletedRowCount());
        }
        if (flushInterval > 0) {
            //Lets get timerFlush in
            Thread.sleep(flushInterval + 500);
            bulkLoader.drain();
            //We should have everything processed callbacked.
            assertEquals(0, bulkLoader.getOutstandingRowCount());
            assertEquals(rowCnt, bulkLoader.getCompletedRowCount());
        }
        bulkLoader.close();
        assertEquals(rowCnt, bulkLoader.getCompletedRowCount());
        assertTrue(testCallback.failureRowListMatches(expectedFailList));
    } finally {
        if (client1 != null)
            client1.close();
        client1 = null;
        if (localServer != null) {
            localServer.shutdown();
            localServer.join();
        }
        localServer = null;
        // no clue how helpful this is
        System.gc();
    }
}
Also used : VoltBulkLoader(org.voltdb.client.VoltBulkLoader.VoltBulkLoader) VoltTable(org.voltdb.VoltTable) VoltDB(org.voltdb.VoltDB) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) ServerThread(org.voltdb.ServerThread)

Example 14 with ServerThread

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

the class TestClientFeatures method setUp.

@Override
public void setUp() {
    try {
        CatalogBuilder catBuilder = new CatalogBuilder();
        catBuilder.addSchema(getClass().getResource("clientfeatures.sql"));
        catBuilder.addProcedures(ArbitraryDurationProc.class);
        boolean success = catBuilder.compile(Configuration.getPathToCatalogForTest("timeouts.jar"));
        assert (success);
        depBuilder = new DeploymentBuilder(1, 1, 0);
        depBuilder.writeXML(Configuration.getPathToCatalogForTest("timeouts.xml"));
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = Configuration.getPathToCatalogForTest("timeouts.jar");
        config.m_pathToDeployment = Configuration.getPathToCatalogForTest("timeouts.xml");
        localServer = new ServerThread(config);
        localServer.start();
        localServer.waitForInitialization();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : VoltDB(org.voltdb.VoltDB) Configuration(org.voltdb.VoltDB.Configuration) CatalogBuilder(org.voltdb.compiler.CatalogBuilder) Configuration(org.voltdb.VoltDB.Configuration) ServerThread(org.voltdb.ServerThread) DeploymentBuilder(org.voltdb.compiler.DeploymentBuilder) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 15 with ServerThread

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

Aggregations

ServerThread (org.voltdb.ServerThread)36 Configuration (org.voltdb.VoltDB.Configuration)24 VoltDB (org.voltdb.VoltDB)16 File (java.io.File)12 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)12 VoltTable (org.voltdb.VoltTable)9 Client (org.voltdb.client.Client)7 ClientResponse (org.voltdb.client.ClientResponse)6 IOException (java.io.IOException)5 ClientConfig (org.voltdb.client.ClientConfig)5 DeploymentBuilder (org.voltdb.compiler.DeploymentBuilder)5 BeforeClass (org.junit.BeforeClass)2 ClientResponseImpl (org.voltdb.ClientResponseImpl)2 TableHelper (org.voltdb.TableHelper)2 TPCCProjectBuilder (org.voltdb.benchmark.tpcc.TPCCProjectBuilder)2 ProcCallException (org.voltdb.client.ProcCallException)2 VoltBulkLoader (org.voltdb.client.VoltBulkLoader.VoltBulkLoader)2 CatalogBuilder (org.voltdb.compiler.CatalogBuilder)2 DeploymentType (org.voltdb.compiler.deploymentfile.DeploymentType)2 CommandLine (org.voltdb.utils.CommandLine)2