Search in sources :

Example 21 with NoConnectionsException

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

the class TestSQLTypesSuite method testUpdateToNull.

public void testUpdateToNull() throws IOException, ProcCallException {
    final Client client = this.getClient();
    final Object[] params = new Object[COLS + 2];
    for (int k = 0; k < COLS; ++k) {
        // build the parameter list as described above
        // Fill the row with non-null data and insert
        params[0] = "";
        params[1] = pkey.incrementAndGet();
        for (int i = 0; i < COLS; i++) {
            params[i + 2] = m_midValues[i];
            assert (params[i + 2] != null);
        }
        params[0] = "ALLOW_NULLS";
        client.callProcedure("Insert", params);
        for (int i = 0; i < COLS; i++) {
            params[i + 2] = (i == k) ? m_nullValues[i] : m_midValues[i];
            assert (params[i + 2] != null);
        }
        try {
            client.callProcedure("Update", params);
        } catch (final ProcCallException e) {
            e.printStackTrace();
            fail(e.getMessage());
        } catch (final NoConnectionsException e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
        // verify that the row was updated
        final VoltTable[] result = client.callProcedure("Select", "ALLOW_NULLS", pkey.get()).getResults();
        final VoltTableRow row = result[0].fetchRow(0);
        for (int i = 0; i < COLS; ++i) {
            final Object obj = row.get(i + 1, m_types[i]);
            if (i == k) {
                assertTrue(row.wasNull());
            } else {
                assertTrue(comparisonHelper(obj, params[i + 2], m_types[i]));
            }
        }
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) ProcCallException(org.voltdb.client.ProcCallException)

Example 22 with NoConnectionsException

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

the class TestSQLTypesSuite method testInsertNulls_No_Nulls.

//
// Verify that NULLS are rejected in in NOT NULL columns
//
public void testInsertNulls_No_Nulls() throws IOException {
    final Client client = this.getClient();
    // Insert a NULL value for each column. For the first
    // row, insert null in the first column, for the 5th row
    // in the 5 column, etc.
    final Object[] params = new Object[COLS + 2];
    for (int k = 0; k < COLS; ++k) {
        boolean caught = false;
        // build the parameter list as described above
        params[0] = "NO_NULLS";
        params[1] = pkey.incrementAndGet();
        for (int i = 0; i < COLS; i++) {
            params[i + 2] = (i == k) ? m_nullValues[i] : m_midValues[i];
            assert (params[i + 2] != null);
        }
        // Each insert into the NO_NULLS table must fail with a
        // constraint failure. Verify this.
        System.out.println("testNullsRejected: :" + k + " " + m_types[k]);
        try {
            client.callProcedure("Insert", params);
        } catch (final ProcCallException e) {
            if (e.getMessage().contains("CONSTRAINT VIOLATION"))
                caught = true;
            else {
                e.printStackTrace();
                fail();
            }
        } catch (final NoConnectionsException e) {
            e.printStackTrace();
            fail();
        }
        assertTrue(caught);
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) Client(org.voltdb.client.Client) ProcCallException(org.voltdb.client.ProcCallException)

Example 23 with NoConnectionsException

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

the class TestCatchExceptionsInProcedure method mpChecker.

private void mpChecker(Client client, int hasPreviousBatch, int tryCatchContains1Batch, int hasFollowingBatch) throws NoConnectionsException, IOException, ProcCallException {
    VoltTable vt;
    String sql;
    final String MPErrorMessage = "attempted to execute new batch " + "after hitting EE exception in a previous batch";
    String[] procs = { "MPInsertOnReplicatedTable", "MPInsertOnPartitionTable" };
    String[] tables = { "R1", "P1" };
    int[] followingBatchHasExceptions = { 0, 1 };
    for (int i = 0; i < procs.length; i++) {
        String proc = procs[i];
        String tb = tables[i];
        for (int followingBatchHasException : followingBatchHasExceptions) {
            try {
                vt = client.callProcedure(proc, hasPreviousBatch, tryCatchContains1Batch, hasFollowingBatch, followingBatchHasException).getResults()[0];
                // validate returned value from the procedure calls
                validateRowOfLongs(vt, new long[] { -1 });
            } catch (Exception e) {
                assertTrue(e.getMessage().contains(MPErrorMessage));
            }
            sql = "select ratio from " + tb + " order by 1;";
            // empty table
            validateTableColumnOfScalarFloat(client, sql, new double[] {});
            // empty table
            sql = "select count(*) from " + tb;
            validateTableOfScalarLongs(client, sql, new long[] { 0 });
            client.callProcedure("@AdHoc", "truncate table " + tb);
        }
    }
}
Also used : VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException)

Example 24 with NoConnectionsException

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

the class TestCatchExceptionsInProcedure method bigBatchChecker.

private void bigBatchChecker(Client client, int hasPreviousBatch, int duplicatedID, int hasFollowingBatch, int followingBatchHasException, double[] expected, int tableCount) throws NoConnectionsException, IOException, ProcCallException {
    VoltTable vt;
    String sql;
    try {
        // use the default value for partition column to route this procedure
        vt = client.callProcedure("SPBigBatchOnPartitionTable", 0, hasPreviousBatch, duplicatedID, hasFollowingBatch, followingBatchHasException).getResults()[0];
        if (isTrue(followingBatchHasException)) {
            assertTrue(isTrue(hasFollowingBatch));
            fail("Expected failure but succeeded.");
        }
        // validate returned value from the procedure calls
        validateRowOfLongs(vt, new long[] { duplicatedID > BIGBATCHTESTSIZE ? 0 : -1 });
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("CONSTRAINT VIOLATION"));
        // violated at row (3, 3.2)
        assertTrue(e.getMessage().contains("500.2"));
        assertTrue(isTrue(hasFollowingBatch) && isTrue(followingBatchHasException));
    }
    sql = "select distinct ratio from P1 order by 1; ";
    validateTableColumnOfScalarFloat(client, sql, expected);
    sql = "select count(*) from P1; ";
    validateTableOfScalarLongs(client, sql, new long[] { tableCount });
    client.callProcedure("@AdHoc", "truncate table P1");
}
Also used : VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException)

Example 25 with NoConnectionsException

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

the class JDBC4ClientConnection method dropClient.

/**
     * Drop the client connection, e.g. when a NoConnectionsException is caught.
     * It will try to reconnect as needed and appropriate.
     * @param clientToDrop caller-provided client to avoid re-nulling from another thread that comes in later
     */
protected synchronized void dropClient(ClientImpl clientToDrop) {
    Client currentClient = this.client.get();
    if (currentClient != null && currentClient == clientToDrop) {
        try {
            currentClient.close();
            this.client.set(null);
        } catch (Exception x) {
        // ignore
        }
    }
    this.users = 0;
}
Also used : Client(org.voltdb.client.Client) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Aggregations

NoConnectionsException (org.voltdb.client.NoConnectionsException)50 IOException (java.io.IOException)41 ProcCallException (org.voltdb.client.ProcCallException)38 VoltTable (org.voltdb.VoltTable)27 ClientResponse (org.voltdb.client.ClientResponse)21 Client (org.voltdb.client.Client)19 Date (java.util.Date)7 VoltTableRow (org.voltdb.VoltTableRow)6 ProcedureCallback (org.voltdb.client.ProcedureCallback)5 Timestamp (java.sql.Timestamp)4 File (java.io.File)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)3 ClientResponseImpl (org.voltdb.ClientResponseImpl)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)2 LineString (org.postgis.LineString)2 VoltCompiler (org.voltdb.compiler.VoltCompiler)2