Search in sources :

Example 51 with ClientResponse

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

the class TestFunctionsForJSON method testProcWithValidJSON.

private void testProcWithValidJSON(long[][] expectedResult, Client client, String procName, Object... parameters) throws Exception {
    ClientResponse cr = client.callProcedure(procName, parameters);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    VoltTable result = cr.getResults()[0];
    validateTableOfLongs(result, expectedResult);
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltTable(org.voltdb.VoltTable)

Example 52 with ClientResponse

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

the class TestFunctionsForJSON method testProcWithValidJSON.

private void testProcWithValidJSON(String expectedResult, Client client, String procName, Object... parameters) throws Exception {
    ClientResponse cr = client.callProcedure(procName, parameters);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    VoltTable result = cr.getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(expectedResult, result.get(0, result.getColumnType(0)));
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltTable(org.voltdb.VoltTable)

Example 53 with ClientResponse

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

the class TestFunctionsForJSON method loadJS1.

/**
     * @return
     * @throws IOException
     * @throws NoConnectionsException
     * @throws ProcCallException
     */
private void loadJS1(Client client) throws IOException, NoConnectionsException, ProcCallException {
    final String jstemplate = "{\n" + "    \"id\": %d,\n" + "    \"bool\": true,\n" + "    \"numeric\": 1.2,\n" + "    \"inner\": {\n" + "        \"veggies\": \"good for you\",\n" + "        \"贾鑫Vo\": \"wakarimasen\",\n" + "        \"second\": {\n" + "            \"fruits\": 1,\n" + "            \"third\": {\n" + "                \"meats\": \"yum\",\n" + "                \"dairy\": \"%d\",\n" + "                \"numeric\": 2.3\n" + "            }\n" + "        },\n" + "        \"arr\": [\n" + "            0,\n" + "            %d,\n" + "            3.4\n" + "        ]\n" + "    },\n" + "    \"arr\": [\n" + "        0,\n" + "        %d,\n" + "        100\n" + "    ],\n" + "    \"arr3d\": [\n" + "        0,\n" + "        [\n" + "            \"One\",\n" + "            [\n" + "                2,\n" + "                %d,\n" + "                4.5\n" + "            ]\n" + "        ],\n" + "        {\n" + "            \"veggies\": \"good for you\",\n" + "            \"dairy\": \"%d\",\n" + "            \"numeric\": 5.6\n" + "        }\n" + "    ],\n" + "    \"dot.char\": \"foo.bar\",\n" + "    \"bracket][[] [ ] chars\": \"[foo]\",\n" + "    \"tag\": \"%s\",\n" + "    \"last\": \"\\\"foobar\\\"\"\n" + "}";
    ClientResponse cr;
    cr = client.callProcedure("JS1.insert", 1, String.format(jstemplate, 1, 1, 1, 1, 1, 1, "One"));
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 2, String.format(jstemplate, 2, 2, 2, 2, 2, 2, "Two"));
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 3, String.format(jstemplate, 3, 3, 3, 3, 3, 3, "Three"));
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 4, "{\"id\":4,\"bool\": false}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 5, "{}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 6, "[]");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 7, "{\"id\":7,\"funky\": null}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 8, null);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 9, "{\"id\":9, \"贾鑫Vo\":\"分かりません\"}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 10, "[1,2,3]");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 11, "{\"null\": \"foo\", \"\\\"null\\\"\": \"bar\"}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 12, "{\"foo\": \"null\", \"\\\"foo\\\"\": \"bar\"}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 13, "\"foobar\"");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 14, "true");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JS1.insert", 15, 42);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
}
Also used : ClientResponse(org.voltdb.client.ClientResponse)

Example 54 with ClientResponse

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

the class TestFixedSQLSuite method subTestInlineVarcharAggregation.

// This is a regression test for ENG-6792
private void subTestInlineVarcharAggregation() throws IOException, ProcCallException {
    Client client = getClient();
    ClientResponse cr;
    cr = client.callProcedure("VARCHARTB.insert", 1, "zz", "panda");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("VARCHARTB.insert", 6, "a", "panda");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("VARCHARTB.insert", 7, "mm", "panda");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("VARCHARTB.insert", 8, "z", "orangutan");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("VARCHARTB.insert", 9, "aa", "orangutan");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("VARCHARTB.insert", 10, "n", "orangutan");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("@AdHoc", "select max(var2), min(var2) from VarcharTB");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    VoltTable vt = cr.getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals("zz", vt.getString(0));
    assertEquals("a", vt.getString(1));
    // Hash aggregation may have the same problem, so let's
    // test it here as well.
    String sql = "select var80, max(var2) as maxvar2, min(var2) as minvar2 " + "from VarcharTB " + "group by var80 " + "order by maxvar2, minvar2";
    cr = client.callProcedure("@AdHoc", sql);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    assertTrue(vt.advanceRow());
    // row 1: panda, zz, a
    // row 2: orangutan, z, aa
    assertEquals("orangutan", vt.getString(0));
    assertEquals("z", vt.getString(1));
    assertEquals("aa", vt.getString(2));
    assertTrue(vt.advanceRow());
    assertEquals("panda", vt.getString(0));
    assertEquals("zz", vt.getString(1));
    assertEquals("a", vt.getString(2));
    cr = client.callProcedure("PWEE_WITH_INDEX.insert", 0, "MM", 88);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("PWEE_WITH_INDEX.insert", 1, "ZZ", 88);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("PWEE_WITH_INDEX.insert", 2, "AA", 88);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("PWEE_WITH_INDEX.insert", 3, "NN", 88);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("@AdHoc", "select num, max(wee), min(wee) " + "from pwee_with_index group by num order by num");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = cr.getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals("ZZ", vt.getString(1));
    assertEquals("AA", vt.getString(2));
    truncateTables(client, new String[] { "VARCHARTB", "PWEE_WITH_INDEX" });
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable)

Example 55 with ClientResponse

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

the class TestFunctionsForVoltDBSuite method invalidIPAddr.

private void invalidIPAddr(Client client, String tableName, String presentation) throws Exception {
    ClientResponse cr;
    VoltTable vt;
    cr = client.callProcedure("@AdHoc", "TRUNCATE TABLE " + tableName + ";");
    String ipVersion = tableName.startsWith("INET4_") ? "" : "6";
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    if (ipVersion.length() == 0) {
        cr = client.callProcedure(tableName.toUpperCase() + ".INSERT", presentation, 0x0);
    } else {
        byte[] zeros = new byte[16];
        cr = client.callProcedure(tableName.toUpperCase() + ".INSERT", presentation, zeros);
    }
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    Exception ex = null;
    try {
        String sql = String.format("select inet%s_aton(pres) from %s;", ipVersion, tableName);
        client.callProcedure("@AdHoc", sql);
        fail(String.format("Expected inet address %s to fail.", presentation));
    } catch (Exception e) {
        ex = e;
    } finally {
        assertNotNull(ex);
        assertTrue("Expected a SQL ERROR here", ex.getMessage().contains("SQL ERROR"));
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltTable(org.voltdb.VoltTable) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Aggregations

ClientResponse (org.voltdb.client.ClientResponse)381 VoltTable (org.voltdb.VoltTable)193 Client (org.voltdb.client.Client)184 ProcCallException (org.voltdb.client.ProcCallException)105 IOException (java.io.IOException)52 NoConnectionsException (org.voltdb.client.NoConnectionsException)33 Test (org.junit.Test)32 ProcedureCallback (org.voltdb.client.ProcedureCallback)32 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)29 Configuration (org.voltdb.VoltDB.Configuration)28 File (java.io.File)18 Timestamp (java.sql.Timestamp)16 VoltDB (org.voltdb.VoltDB)16 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)16 VoltCompiler (org.voltdb.compiler.VoltCompiler)15 JSONException (org.json_voltpatches.JSONException)11 BigDecimal (java.math.BigDecimal)10 ExecutionException (java.util.concurrent.ExecutionException)10 ClientResponseImpl (org.voltdb.ClientResponseImpl)10 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)9