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]));
}
}
}
}
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);
}
}
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);
}
}
}
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");
}
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;
}
Aggregations