Search in sources :

Example 41 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestFunctionsForVoltDBSuite method testFunctionsWithInvalidJSON.

public void testFunctionsWithInvalidJSON() throws Exception {
    Client client = getClient();
    ClientResponse cr;
    cr = client.callProcedure(// OOPS. skipped comma before "bool"
    "JSBAD.insert", // OOPS. skipped comma before "bool"
    1, "{\"id\":1 \"bool\": false}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure(// OOPS. semi-colon in place of colon before "bool"
    "JSBAD.insert", // OOPS. semi-colon in place of colon before "bool"
    2, "{\"id\":2, \"bool\"; false, \"贾鑫Vo\":\"分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません\"}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    // OOPS. trailing comma in array
    final String jsTrailingCommaArray = "[ 0, 100, ]";
    final String jsWithTrailingCommaArray = "{\"id\":3, \"trailer\":" + jsTrailingCommaArray + "}";
    cr = client.callProcedure("JSBAD.insert", 3, jsWithTrailingCommaArray);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JSBAD.insert", 4, jsTrailingCommaArray);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    String[] jsonProcs = { "BadIdFieldProc", "BadIdArrayProc", "BadIdArrayLengthProc" };
    for (String procname : jsonProcs) {
        try {
            cr = client.callProcedure(procname, 1, "id", "1");
            fail("document validity check failed for " + procname);
        } catch (ProcCallException pcex) {
            assertTrue(pcex.getMessage().contains("Invalid JSON * Line 1, Column 9"));
        }
        try {
            cr = client.callProcedure(procname, 2, "id", "2");
            fail("document validity check failed for " + procname);
        } catch (ProcCallException pcex) {
            assertTrue(pcex.getMessage().contains("Invalid JSON * Line 1, Column 16"));
        }
        try {
            cr = client.callProcedure(procname, 3, "id", "3");
            fail("document validity check failed for " + procname);
        } catch (ProcCallException pcex) {
            assertTrue(pcex.getMessage().contains("Invalid JSON * Line 1, Column 30"));
        }
        try {
            cr = client.callProcedure(procname, 4, "id", "4");
            fail("document validity check failed for " + procname);
        } catch (ProcCallException pcex) {
            assertTrue(pcex.getMessage().contains("Invalid JSON * Line 1, Column 11"));
        }
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) ProcCallException(org.voltdb.client.ProcCallException)

Example 42 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestMaterializedViewNonemptyTablesSuite method testCreateView.

/**
     * Test to see if we can create a view.  The view name is
     * necessary because we drop the view after creation.
     *
     * @param client The Client object.
     * @param sql The sql string.  This should start "create view name ",
     *            where "name" is the view name.
     * @param expectedDiagnostic The expected diagnostic string.  This
     *                           should be null if the creation is
     *                           expected to succeed.
     * @throws IOException
     * @throws NoConnectionsException
     * @throws ProcCallException
     */
private void testCreateView(Client client, String sql, String expectedDiagnostic) throws IOException, NoConnectionsException, ProcCallException {
    ClientResponse cr = null;
    assertTrue("SQL string should start with \"create view \"", sql.startsWith("create view "));
    int pos = sql.indexOf(" ", 12);
    String viewName = sql.substring(12, pos);
    // Try to drop the view.  Even if it doesn't
    // exist, this should succeed.
    dropView(client, viewName);
    // Truncate all the tables.
    truncateTables(client, TABLE_NAMES);
    // This should always succeed.
    try {
        cr = client.callProcedure("@AdHoc", sql);
    } catch (Exception ex) {
        fail("Unexpected exception: \"" + ex.getMessage() + "\"");
    }
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    // Drop the view and populate the tables.
    dropView(client, viewName);
    populateTables(client);
    // Try the view creation again.  This may or may
    // not succeed.
    boolean expectedSuccess = (expectedDiagnostic == null);
    try {
        cr = client.callProcedure("@AdHoc", sql);
        if (!expectedSuccess) {
            fail("Unexpected SQL compilation success");
        }
    } catch (ProcCallException ex) {
        cr = ex.getClientResponse();
        if (expectedSuccess) {
            fail(String.format("Unexpected SQL compilation failure:\n%s", cr.getStatusString()));
        }
        assertTrue(String.format("Did not find \"%s\" in diagnostic message \"%s\"", expectedDiagnostic, cr.getStatusString()), cr.getStatusString().contains(expectedDiagnostic));
    }
    // Drop the view..
    dropView(client, viewName);
    truncateTables(client, TABLE_NAMES);
    // Try creating the view again.  Sometimes after a
    // population and then truncation things go awry.
    // Again, this should always succeed.
    cr = client.callProcedure("@AdHoc", sql);
    assertEquals("View creation on empty tables should always succeed.", ClientResponse.SUCCESS, cr.getStatus());
    dropView(client, viewName);
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException)

Example 43 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestMaterializedViewSuite method testEng11203.

public void testEng11203() throws Exception {
    // This test case has AdHoc DDL, so it cannot be ran in the HSQL backend.
    if (!isHSQL()) {
        Client client = getClient();
        Object[][] initialRows = { { "ENG_11203_A", 1, 2, 4 }, { "ENG_11203_B", 1, 2, 4 } };
        Object[][] secondRows = { { "ENG_11203_A", 6, 2, 4 }, { "ENG_11203_B", 6, 2, 4 } };
        // This test case tests ENG-11203, verifying that on single table views,
        // if a new index was created on the view target table, this new index
        // will be properly tracked by the MaterializedViewTriggerForInsert.
        // - 1 - Insert the initial data into the view source table.
        insertRow(client, initialRows[0]);
        insertRow(client, initialRows[1]);
        VoltTable vt = client.callProcedure("@AdHoc", "SELECT * FROM V_ENG_11203_SINGLE").getResults()[0];
        assertContentOfTable(new Object[][] { { 2, 1, 1 } }, vt);
        vt = client.callProcedure("@AdHoc", "SELECT * FROM V_ENG_11203_JOIN").getResults()[0];
        assertContentOfTable(new Object[][] { { 2, 1, 1 } }, vt);
        // - 2 - Now add a new index on the view target table.
        try {
            client.callProcedure("@AdHoc", "CREATE INDEX I_ENG_11203_SINGLE ON V_ENG_11203_SINGLE(a, b);");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to create an index on the single table view V_ENG_11203_SINGLE.");
        }
        try {
            client.callProcedure("@AdHoc", "CREATE INDEX I_ENG_11203_JOIN ON V_ENG_11203_JOIN(a, b);");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to create an index on the joined table view V_ENG_11203_JOIN.");
        }
        // - 3 - Insert another row of data.
        insertRow(client, secondRows[0]);
        insertRow(client, secondRows[1]);
        vt = client.callProcedure("@AdHoc", "SELECT * FROM V_ENG_11203_SINGLE").getResults()[0];
        assertContentOfTable(new Object[][] { { 2, 2, 6 } }, vt);
        vt = client.callProcedure("@AdHoc", "SELECT * FROM V_ENG_11203_JOIN").getResults()[0];
        assertContentOfTable(new Object[][] { { 2, 4, 6 } }, vt);
        // - 4 - Start to delete rows.
        // If the new index was not tracked properly, the server will start to crash
        // because the newly-inserted row was not inserted into the index.
        deleteRow(client, initialRows[0]);
        deleteRow(client, initialRows[1]);
        deleteRow(client, secondRows[0]);
        deleteRow(client, secondRows[1]);
        vt = client.callProcedure("@AdHoc", "SELECT * FROM V_ENG_11203_SINGLE").getResults()[0];
        assertContentOfTable(new Object[][] {}, vt);
        vt = client.callProcedure("@AdHoc", "SELECT * FROM V_ENG_11203_JOIN").getResults()[0];
        assertContentOfTable(new Object[][] {}, vt);
        // Restore catalog changes:
        try {
            client.callProcedure("@AdHoc", "DROP INDEX I_ENG_11203_JOIN;" + "DROP INDEX I_ENG_11203_SINGLE;");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to drop indexes on the joined table views V_ENG_11203_JOIN and V_ENG_11203_SINGLE.");
        }
    }
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Example 44 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestMaterializedViewSuite method truncateBeforeTest.

private void truncateBeforeTest(Client client) {
    // TODO Auto-generated method stub
    VoltTable[] results = null;
    try {
        results = client.callProcedure("TruncateMatViewDataMP").getResults();
    } catch (NoConnectionsException e) {
        e.printStackTrace();
        fail("Unexpected:" + e);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected:" + e);
    } catch (ProcCallException e) {
        e.printStackTrace();
        fail("Unexpected:" + e);
    }
    int nStatement = 0;
    for (VoltTable countTable : results) {
        ++nStatement;
        try {
            long count = countTable.asScalarLong();
            assertEquals("COUNT statement " + nStatement + "/" + results.length + " should have found no undeleted rows.", 0, count);
        } catch (Exception exc) {
            System.out.println("validation query " + nStatement + " got a bad result: " + exc);
            throw exc;
        }
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 45 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestMaterializedViewSuite method testViewOnJoinQuery.

public void testViewOnJoinQuery() throws IOException, ProcCallException {
    Client client = getClient();
    truncateBeforeTest(client);
    ArrayList<Object[]> dataList1 = Lists.newArrayList(new Object[][] { { "CUSTOMERS", 1, "Tom", "VoltDB" }, { "CUSTOMERS", 2, "Jerry", "Bedford" }, { "CUSTOMERS", 3, "Rachael", "USA" }, { "CUSTOMERS", 4, "Ross", "Massachusetts" }, { "CUSTOMERS", 5, "Stephen", "Houston TX" }, { "ORDERS", 1, 2, "2016-04-23 13:24:57.671000" }, { "ORDERS", 2, 7, "2015-04-12 10:24:10.671400" }, { "ORDERS", 3, 5, "2016-01-20 09:24:15.943000" }, { "ORDERS", 4, 1, "2015-10-30 19:24:00.644000" }, { "PRODUCTS", 1, "H MART", 20.97 }, { "PRODUCTS", 2, "COSTCO WHOLESALE", 62.66 }, { "PRODUCTS", 3, "CENTRAL ROCK GYM", 22.00 }, { "PRODUCTS", 4, "ATT*BILL PAYMENT", 48.90 }, { "PRODUCTS", 5, "APL* ITUNES", 16.23 }, { "PRODUCTS", 6, "GOOGLE *YouTube", 10.81 }, { "PRODUCTS", 7, "UNIV OF HOUSTON SYSTEM", 218.35 }, { "PRODUCTS", 8, "THE UPS STORE 2287", 36.31 }, { "PRODUCTS", 9, "NNU*XFINITYWIFI", 7.95 }, { "PRODUCTS", 10, "IKEA STOUGHTON", 61.03 }, { "PRODUCTS", 11, "WM SUPERCENTER #5752", 9.74 }, { "PRODUCTS", 12, "STOP & SHOP 0831", 12.28 }, { "PRODUCTS", 13, "VERANDA NOODLE HOUSE", 29.81 }, { "PRODUCTS", 14, "AMC 34TH ST 14 #2120", 38.98 }, { "PRODUCTS", 15, "STARBUCKS STORE 19384", 5.51 }, { "ORDERITEMS", 1, 2, 1 }, { "ORDERITEMS", 1, 7, 1 }, { "ORDERITEMS", 2, 5, 2 }, { "ORDERITEMS", 3, 1, 3 }, { "ORDERITEMS", 3, 15, 1 }, { "ORDERITEMS", 3, 20, 1 }, { "ORDERITEMS", 3, 4, 2 }, { "ORDERITEMS", 3, 26, 5 }, { "ORDERITEMS", 4, 30, 1 }, { "ORDERITEMS", 5, 8, 1 } });
    ArrayList<Object[]> dataList2 = Lists.newArrayList(new Object[][] { { "CUSTOMERS", 6, "Mike", "WPI" }, { "CUSTOMERS", 7, "Max", "New York" }, { "CUSTOMERS", 8, "Ethan", "Beijing China" }, { "CUSTOMERS", 9, "Selina", "France" }, { "CUSTOMERS", 10, "Harry Potter", "Hogwarts" }, { "ORDERS", 5, 3, "2015-04-23 00:24:45.768000" }, { "ORDERS", 6, 2, "2016-07-05 16:24:31.384000" }, { "ORDERS", 7, 4, "2015-03-09 21:24:15.768000" }, { "ORDERS", 8, 2, "2015-09-01 16:24:42.279300" }, { "PRODUCTS", 16, "SAN SOO KAP SAN SHUSHI", 10.69 }, { "PRODUCTS", 17, "PLASTC INC.", 155.00 }, { "PRODUCTS", 18, "MANDARIN MALDEN", 34.70 }, { "PRODUCTS", 19, "MCDONALDS F16461", 7.25 }, { "PRODUCTS", 20, "UBER US JUL20 M2E3D", 31.33 }, { "PRODUCTS", 21, "TOUS LES JOURS", 13.25 }, { "PRODUCTS", 22, "GINGER JAPANESE RESTAU", 69.20 }, { "PRODUCTS", 23, "WOO JEON II", 9.58 }, { "PRODUCTS", 24, "INFLIGHT WI-FI - LTV", 7.99 }, { "PRODUCTS", 25, "EXPEDIA INC", 116.70 }, { "PRODUCTS", 26, "THE ICE CREAM STORE", 5.23 }, { "PRODUCTS", 27, "WEGMANS BURLINGTON #59", 22.13 }, { "PRODUCTS", 28, "ACADEMY EXPRESS", 46.80 }, { "PRODUCTS", 29, "TUCKS CANDY FACTORY INC", 7.00 }, { "PRODUCTS", 30, "SICHUAN GOURMET", 37.12 }, { "ORDERITEMS", 5, 12, 6 }, { "ORDERITEMS", 5, 1, 0 }, { "ORDERITEMS", 5, 27, 1 }, { "ORDERITEMS", 6, 0, 1 }, { "ORDERITEMS", 6, 21, 1 }, { "ORDERITEMS", 7, 8, 1 }, { "ORDERITEMS", 7, 19, 1 }, { "ORDERITEMS", 7, 30, 4 }, { "ORDERITEMS", 7, 1, 1 }, { "ORDERITEMS", 8, 25, 2 } });
    assertEquals(dataList1.size(), dataList2.size());
    // -- 1 -- Test updating the data in the source tables.
    // There are two lists of data, we first insert the data in the first list
    // into the corresponding source tables, then update each row with the data
    // from the second data list.
    System.out.println("Now testing updating the join query view source table.");
    for (int i = 0; i < dataList1.size(); i++) {
        insertRow(client, dataList1.get(i));
        verifyViewOnJoinQueryResult(client);
    }
    for (int i = 0; i < dataList2.size(); i++) {
        updateRow(client, dataList1.get(i), dataList2.get(i));
        verifyViewOnJoinQueryResult(client);
    }
    // -- 2 -- Test inserting the data into the source tables.
    // We do a shuffle here and in the delete test. But I do believe we still
    // have the full coverage of all the cases because we are inserting and deleting
    // all the rows. The cases updating values of all kinds of aggregations will be
    // tested in one row or another.
    truncateBeforeTest(client);
    // Merge two sub-lists for the following tests.
    dataList1.addAll(dataList2);
    // For more deterministic debugging, consider this instead of shuffle:
    // Collections.reverse(dataList1);
    Collections.shuffle(dataList1);
    System.out.println("Now testing inserting data to the join query view source table.");
    for (int i = 0; i < dataList1.size(); i++) {
        insertRow(client, dataList1.get(i));
        verifyViewOnJoinQueryResult(client);
    }
    // This is fine because we don't use HSQL as reference in this test anyway.
    if (!isHSQL()) {
        System.out.println("Now testing altering the source table of a view.");
        // 3.1 add column
        try {
            client.callProcedure("@AdHoc", "ALTER TABLE ORDERITEMS ADD COLUMN x FLOAT;" + "ALTER TABLE WAS_ORDERITEMS ADD COLUMN x FLOAT;");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to add column to a view source table.");
        }
        verifyViewOnJoinQueryResult(client);
        // 3.2 drop column
        try {
            client.callProcedure("@AdHoc", "ALTER TABLE ORDERITEMS DROP COLUMN x;" + "ALTER TABLE WAS_ORDERITEMS DROP COLUMN x;");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to drop column on a view source table.");
        }
        verifyViewOnJoinQueryResult(client);
        // 3.3 alter column
        try {
            client.callProcedure("@AdHoc", "ALTER TABLE CUSTOMERS ALTER COLUMN ADDRESS VARCHAR(100);" + "ALTER TABLE WAS_CUSTOMERS ALTER COLUMN ADDRESS VARCHAR(100);");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to alter column in a view source table.");
        }
        verifyViewOnJoinQueryResult(client);
    }
    //         The test is crafted to include only safe operations.
    if (!isHSQL()) {
        System.out.println("Now testing view data catching-up.");
        try {
            client.callProcedure("@AdHoc", "DROP VIEW ORDER_DETAIL_WITHPCOL;");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to drop a view.");
        }
        try {
            client.callProcedure("@AdHoc", "CREATE VIEW ORDER_DETAIL_WITHPCOL (NAME, ORDER_ID, CNT, MINUNIT, MAXUNIT) AS " + "SELECT " + "CUSTOMERS.NAME, " + "ORDERS.ORDER_ID, " + "COUNT(*), " + "MIN(PRODUCTS.PRICE), " + "MAX(PRODUCTS.PRICE) " + "FROM CUSTOMERS JOIN ORDERS ON CUSTOMERS.CUSTOMER_ID = ORDERS.CUSTOMER_ID " + "JOIN ORDERITEMS ON ORDERS.ORDER_ID = ORDERITEMS.ORDER_ID " + "JOIN PRODUCTS ON ORDERITEMS.PID = PRODUCTS.PID " + "GROUP BY CUSTOMERS.NAME, ORDERS.ORDER_ID;");
        } catch (ProcCallException pce) {
            pce.printStackTrace();
            fail("Should be able to create a view.");
        }
        verifyViewOnJoinQueryResult(client);
    }
    // -- 5 -- Test truncating one or more tables,
    // then explicitly restoring their content.
    System.out.println("Now testing truncating the join query view source table.");
    // want to bypass testing of rollback after truncate.
    for (int forceRollback : /*default:*/
    yesAndNo) {
        //alt:*/ never) {
        for (int truncateTable1 : yesAndNo) {
            // combinations of truncate operations.
            for (int truncateTable2 : /*default:*/
            yesAndNo) {
                // Substitute yesAndNo below for test overkill
                for (int truncateTable3 : /**/
                never) {
                    //*/ yesAndNo) {
                    for (int truncateTable4 : /**/
                    never) {
                        //*/ yesAndNo) {
                        // truncateSourceTable verifies the short-term effects
                        // of truncation and restoration within the transaction.
                        truncateSourceTables(client, forceRollback, truncateTable1, truncateTable2, truncateTable3, truncateTable4);
                        // Verify the correctness outside the transaction.
                        verifyViewOnJoinQueryResult(client);
                    }
                }
            }
        }
    }
    // -- 6 -- Test deleting the data from the source tables.
    // For more deterministic debugging, consider this instead of shuffle:
    // Collections.reverse(dataList1);
    Collections.shuffle(dataList1);
    System.out.println("Now testing deleting data from the join query view source table.");
    for (int i = 0; i < dataList1.size(); i++) {
        deleteRow(client, dataList1.get(i));
        verifyViewOnJoinQueryResult(client);
    }
    // Restore catalog changes:
    try {
        client.callProcedure("@AdHoc", "TRUNCATE TABLE CUSTOMERS;" + "TRUNCATE TABLE WAS_CUSTOMERS;");
        client.callProcedure("@AdHoc", "ALTER TABLE CUSTOMERS ALTER COLUMN ADDRESS VARCHAR(50);" + "ALTER TABLE WAS_CUSTOMERS ALTER COLUMN ADDRESS VARCHAR(50);");
    } catch (ProcCallException pce) {
        pce.printStackTrace();
        fail("Should be able to alter column in a view source table.");
    }
    verifyViewOnJoinQueryResult(client);
}
Also used : Client(org.voltdb.client.Client) ProcCallException(org.voltdb.client.ProcCallException)

Aggregations

ProcCallException (org.voltdb.client.ProcCallException)239 Client (org.voltdb.client.Client)151 VoltTable (org.voltdb.VoltTable)120 ClientResponse (org.voltdb.client.ClientResponse)91 IOException (java.io.IOException)81 NoConnectionsException (org.voltdb.client.NoConnectionsException)55 Test (org.junit.Test)44 Configuration (org.voltdb.VoltDB.Configuration)41 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)36 File (java.io.File)21 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)19 VoltCompiler (org.voltdb.compiler.VoltCompiler)15 VoltDB (org.voltdb.VoltDB)10 VoltTableRow (org.voltdb.VoltTableRow)10 Timestamp (java.sql.Timestamp)5 TimestampType (org.voltdb.types.TimestampType)5 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 HashSet (java.util.HashSet)3 ClientResponseImpl (org.voltdb.ClientResponseImpl)3