Search in sources :

Example 41 with VoltProjectBuilder

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

the class TestJSONInterface method testAdminMode.

public void testAdminMode() throws Exception {
    try {
        String simpleSchema = "create table blah (" + "ival bigint default 23 not null, " + "sval varchar(200) default 'foo', " + "dateval timestamp, " + "fval float, " + "decval decimal, " + "PRIMARY KEY(ival));";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltDB.Configuration config = new VoltDB.Configuration();
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("blah", "ival");
        builder.addStmtProcedure("Insert", "insert into blah values (?,?,?,?,?);");
        builder.addProcedures(CrazyBlahProc.class);
        builder.setHTTPDPort(8095);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"), 1, 1, 0, 0) != null;
        assertTrue(success);
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        config.m_adminPort = 21213;
        config.m_isPaused = true;
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        ParameterSet pset;
        String responseJSON;
        Response response;
        // Call insert on admin port
        pset = ParameterSet.fromArrayNoCopy(1, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // Call insert on closed client port and expect failure
        pset = ParameterSet.fromArrayNoCopy(2, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SERVER_UNAVAILABLE);
        // open client port
        pset = ParameterSet.emptyParameterSet();
        responseJSON = callProcOverJSON("@Resume", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // call insert on open client port
        pset = ParameterSet.fromArrayNoCopy(2, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // call insert on admin port again (now that both ports are open)
        pset = ParameterSet.fromArrayNoCopy(3, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // put the system in admin mode
        pset = ParameterSet.emptyParameterSet();
        responseJSON = callProcOverJSON("@Pause", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // Call insert on admin port
        pset = ParameterSet.fromArrayNoCopy(4, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, true);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SUCCESS);
        // Call insert on closed client port and expect failure
        pset = ParameterSet.fromArrayNoCopy(5, "hello", new TimestampType(System.currentTimeMillis()), 5.0, "5.0");
        responseJSON = callProcOverJSON("Insert", pset, null, null, false, false);
        System.out.println(responseJSON);
        response = responseFromJSON(responseJSON);
        assertTrue(response.status == ClientResponse.SERVER_UNAVAILABLE);
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) HttpResponse(org.apache.http.HttpResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) TimestampType(org.voltdb.types.TimestampType) File(java.io.File)

Example 42 with VoltProjectBuilder

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

the class TestHSQLBackend method testVarbinary.

/*
    public void testAdHocEmptyQuery() throws Exception {
        TPCCProjectBuilder builder = new TPCCProjectBuilder();
        builder.addDefaultSchema();
        builder.addDefaultPartitioning();
        builder.addProcedures(org.voltdb.benchmark.tpcc.procedures.SelectAll.class);

        String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
        String catalogJar = testDir + File.separator + "tpcchsql.jar";

        builder.compile(catalogJar, 1, 1, 0);
        final File jar = new File(catalogJar);
        jar.deleteOnExit();

        ServerThread server = new ServerThread(catalogJar, builder.getPathToDeployment(), BackendTarget.HSQLDB_BACKEND);
        server.start();
        server.waitForInitialization();

        // run the test
        ClientConfig config = new ClientConfig("program", "none");
        Client client = ClientFactory.createClient(config);
        client.createConnection("localhost");

        // call the insert procedure
        VoltTable[] results = client.callProcedure("@AdHoc", "select * from WAREHOUSE").getResults();
        // check one table was returned
        assertTrue(results.length > 0);
        assertTrue(results[0].getRowCount() == 0);

        server.shutdown();
        server.join();
    }

    public void testDateInsertionAsLong() throws Exception {
        TPCCProjectBuilder builder = new TPCCProjectBuilder();
        builder.addDefaultSchema();
        builder.addDefaultPartitioning();
        System.out.println("\n\n\n STARTING STMT PROC ADD\n\n\n");
        builder.addStmtProcedure("InsertHistory", "INSERT INTO HISTORY VALUES (?, ?, ?, ?, ?, ?, ?, ?);", "HISTORY.H_W_ID: 4");

        String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
        String catalogJar = testDir + File.separator + "tpcchsql.jar";
        final File jar = new File(catalogJar);
        jar.deleteOnExit();

        builder.compile(catalogJar, 1, 1, 0);
        String pathToDeployment = builder.getPathToDeployment();

        ServerThread server = new ServerThread(catalogJar, pathToDeployment, BackendTarget.HSQLDB_BACKEND);
        server.start();
        server.waitForInitialization();

        // run the test
        ClientConfig clientConfig = new ClientConfig("program", "none");
        Client client = ClientFactory.createClient(clientConfig);
        client.createConnection("localhost");

        // call the insert procedure
        VoltTable[] results = client.callProcedure("InsertHistory", 5, 5, 5, 5, 5, 100000L, 2.5, "nada").getResults();
        // check one table was returned
        assertTrue(results.length > 0);
        assertTrue(results[0].getRowCount() == 1);

        server.shutdown();
        server.join();
    }

    public void testAdHocDateInsertionAsLong() throws UnknownHostException, IOException, ProcCallException, InterruptedException {
        TPCCProjectBuilder builder = new TPCCProjectBuilder();
        builder.addDefaultSchema();
        builder.addDefaultPartitioning();
        builder.addProcedures(org.voltdb.benchmark.tpcc.procedures.SelectAll.class);

        String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
        String catalogJar = testDir + File.separator + "tpcchsql.jar";
        final File jar = new File(catalogJar);
        jar.deleteOnExit();

        builder.compile(catalogJar, 1, 1, 0);

        ServerThread server = new ServerThread(catalogJar, builder.getPathToDeployment(), BackendTarget.HSQLDB_BACKEND);
        server.start();
        server.waitForInitialization();

        // run the test
        ClientConfig config = new ClientConfig("program", "none");
        Client client = ClientFactory.createClient(config);
        client.createConnection("localhost");

        // call the insert procedure
        VoltTable[] results = client.callProcedure("@AdHoc", "INSERT INTO HISTORY VALUES (5, 5, 5, 5, 5, 100000, 2.5, 'nada');").getResults();
        // check one table was returned
        assertTrue(results.length > 0);
        assertTrue(results[0].getRowCount() == 1);

        server.shutdown();
        server.join();
        client.close();
    }
*/
public void testVarbinary() throws Exception {
    String simpleSchema = "create table blah (" + "ival bigint default 0 not null, " + "b varbinary(1) default null, " + "PRIMARY KEY(ival));";
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema(simpleSchema);
    builder.addPartitionInfo("blah", "ival");
    builder.addStmtProcedure("Insert", "insert into blah values (?, ?);", null);
    boolean success = builder.compile(Configuration.getPathToCatalogForTest("hsqldbbin.jar"), 1, 1, 0);
    assertTrue(success);
    MiscUtils.copyFile(builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("hsqldbbin.xml"));
    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = Configuration.getPathToCatalogForTest("hsqldbbin.jar");
    config.m_pathToDeployment = Configuration.getPathToCatalogForTest("hsqldbbin.xml");
    config.m_backend = BackendTarget.HSQLDB_BACKEND;
    config.m_noLoadLibVOLTDB = true;
    ServerThread localServer = new ServerThread(config);
    localServer.start();
    localServer.waitForInitialization();
    Client client = ClientFactory.createClient();
    client.createConnection("localhost");
    ClientResponse cr = client.callProcedure("Insert", 5, new byte[] { 'a' });
    assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
    // stop execution
    VoltDB.instance().shutdown(localServer);
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) Client(org.voltdb.client.Client)

Example 43 with VoltProjectBuilder

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

the class TestImportSuite method suite.

public static junit.framework.Test suite() throws Exception {
    LocalCluster config;
    Map<String, String> additionalEnv = new HashMap<>();
    //Specify bundle location
    String bundleLocation = System.getProperty("user.dir") + "/bundles";
    System.out.println("Bundle location is: " + bundleLocation);
    additionalEnv.put("voltdbbundlelocation", bundleLocation);
    final MultiConfigSuiteBuilder builder = new MultiConfigSuiteBuilder(TestImportSuite.class);
    VoltProjectBuilder project = new VoltProjectBuilder();
    project.setUseDDLSchema(true);
    project.addSchema(TestSQLTypesSuite.class.getResource("sqltypessuite-import-ddl.sql"));
    // configure socket importer
    Properties props = buildProperties("port", "7001", "decode", "true", "procedure", "importTable.insert");
    project.addImport(true, "custom", "tsv", "socketstream.jar", props);
    project.addPartitionInfo("importTable", "PKEY");
    // configure log4j socket handler importer
    props = buildProperties("port", "6060", "procedure", "log_events.insert", "log-event-table", "log_events");
    project.addImport(true, "custom", null, "log4jsocketimporter.jar", props);
    /*
         * compile the catalog all tests start with
         */
    config = new LocalCluster("import-ddl-cluster-rep.jar", 4, 1, 0, BackendTarget.NATIVE_EE_JNI, LocalCluster.FailureState.ALL_RUNNING, true, false, additionalEnv);
    config.setHasLocalServer(false);
    boolean compile = config.compile(project);
    assertTrue(compile);
    builder.addServerConfig(config, false);
    return builder;
}
Also used : LocalCluster(org.voltdb.regressionsuites.LocalCluster) TestSQLTypesSuite(org.voltdb.regressionsuites.TestSQLTypesSuite) HashMap(java.util.HashMap) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) MultiConfigSuiteBuilder(org.voltdb.regressionsuites.MultiConfigSuiteBuilder) Properties(java.util.Properties)

Example 44 with VoltProjectBuilder

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

the class TestJSONInterface method testGarbageProcs.

public void testGarbageProcs() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE foo (\n" + "    bar BIGINT NOT NULL,\n" + "    PRIMARY KEY (bar)\n" + ");";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("foo", "bar");
        builder.addProcedures(DelayProc.class);
        builder.setHTTPDPort(8095);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        callProcOverJSONRaw(getHTTPURL(null, "api/1.0/Tim"), 400);
        callProcOverJSONRaw(getHTTPURL(null, "api/1.0/Tim?Procedure=foo&Parameters=[x4{]"), 400);
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File)

Example 45 with VoltProjectBuilder

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

the class TestJSONInterface method testJapaneseNastiness.

public void testJapaneseNastiness() throws Exception {
    try {
        String simpleSchema = "CREATE TABLE HELLOWORLD (\n" + "    HELLO VARCHAR(15),\n" + "    WORLD VARCHAR(15),\n" + "    DIALECT VARCHAR(15) NOT NULL,\n" + "    PRIMARY KEY (DIALECT)\n" + ");";
        File schemaFile = VoltProjectBuilder.writeStringToTempFile(simpleSchema);
        String schemaPath = schemaFile.getPath();
        schemaPath = URLEncoder.encode(schemaPath, "UTF-8");
        VoltProjectBuilder builder = new VoltProjectBuilder();
        builder.addSchema(schemaPath);
        builder.addPartitionInfo("HELLOWORLD", "DIALECT");
        builder.addStmtProcedure("Insert", "insert into HELLOWORLD values (?,?,?);");
        builder.addStmtProcedure("Select", "select * from HELLOWORLD;");
        builder.addProcedures(SelectStarHelloWorld.class);
        builder.setHTTPDPort(8095);
        boolean success = builder.compile(Configuration.getPathToCatalogForTest("json.jar"));
        assertTrue(success);
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = config.setPathToCatalogForTest("json.jar");
        config.m_pathToDeployment = builder.getPathToDeployment();
        server = new ServerThread(config);
        server.start();
        server.waitForInitialization();
        String response = callProcOverJSONRaw(japaneseTestVarStrings, 200);
        Response r = responseFromJSON(response);
        assertEquals(1, r.status);
        // If this line doesn't compile, right click the file in the package explorer.
        // Select the properties menu. Set the text file encoding to UTF-8.
        char[] test1 = { 'こ', 'ん', 'に', 'ち', 'は' };
        String test2 = new String(test1);
        ParameterSet pset = ParameterSet.emptyParameterSet();
        response = callProcOverJSON("Select", pset, null, null, false);
        System.out.println(response);
        System.out.println(test2);
        r = responseFromJSON(response);
        assertEquals(1, r.status);
        response = callProcOverJSON("SelectStarHelloWorld", pset, null, null, false);
        r = responseFromJSON(response);
        assertEquals(1, r.status);
        assertTrue(response.contains(test2));
    } finally {
        if (server != null) {
            server.shutdown();
            server.join();
        }
        server = null;
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) HttpResponse(org.apache.http.HttpResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File)

Aggregations

VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)269 Configuration (org.voltdb.VoltDB.Configuration)89 IOException (java.io.IOException)49 Test (org.junit.Test)45 File (java.io.File)40 ProcCallException (org.voltdb.client.ProcCallException)38 ClientResponse (org.voltdb.client.ClientResponse)37 VoltDB (org.voltdb.VoltDB)22 LocalCluster (org.voltdb.regressionsuites.LocalCluster)18 Client (org.voltdb.client.Client)17 Before (org.junit.Before)14 HashMap (java.util.HashMap)13 VoltTable (org.voltdb.VoltTable)13 ServerThread (org.voltdb.ServerThread)12 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)12 VoltCompiler (org.voltdb.compiler.VoltCompiler)11 HttpResponse (org.apache.http.HttpResponse)10 BeforeClass (org.junit.BeforeClass)8 ClientConfig (org.voltdb.client.ClientConfig)7 UserInfo (org.voltdb.compiler.VoltProjectBuilder.UserInfo)7