/**
* testConflictingTxns
*/
public void testConflictingTxns() throws Exception {
Client client = this.getClient();
RegressionSuiteUtil.initializeTM1Database(this.getCatalogContext(), client);
// Submit a distributed txn and make sure that our conflicting
// txn is not speculatively executed
final int sleepTime = 5000; // ms
final LatchableProcedureCallback dtxnCallback = new LatchableProcedureCallback(1);
// We're going to first execute a dtxn that updates all SUBSCRIBER records
String dtxnProcName = UpdateAll.class.getSimpleName();
Object dtxnParams[] = { 0, sleepTime };
client.callProcedure(dtxnCallback, dtxnProcName, dtxnParams);
// Then fire off a proc that updates SUBSCRIBER as well. This should never
// be allowed to execute speculatively
String spProcName = UpdateOne.class.getSimpleName();
Object spParams[] = new Object[]{ 1 };
LatchableProcedureCallback spCallback = new LatchableProcedureCallback(1);
ThreadUtil.sleep(100);
client.callProcedure(spCallback, spProcName, spParams);
// Wait until we have both latches
dtxnCallback.latch.await(sleepTime*2, TimeUnit.MILLISECONDS);
spCallback.latch.await(sleepTime*2, TimeUnit.MILLISECONDS);
// Then verify the DTXN results
ClientResponse dtxnResponse = CollectionUtil.first(dtxnCallback.responses);
assertNotNull(dtxnResponse);
assertEquals(Status.OK, dtxnResponse.getStatus());
assertTrue(dtxnResponse.hasDebug());
assertFalse(dtxnResponse.isSinglePartition());
assertFalse(dtxnResponse.isSpeculative());
// And the SP results. Where is your god now?
ClientResponse spResponse = CollectionUtil.first(spCallback.responses);
assertNotNull(spResponse);
assertEquals(Status.OK, spResponse.getStatus());
assertTrue(spResponse.hasDebug());
assertTrue(spResponse.isSinglePartition());
// There is currently a race condition for whether the txn will get
// speculatively executed or not, so for now we'll just disable this
// one check.
// sassertTrue(spResponse.isSpeculative());
// SANITY CHECK
// We should have exaclty two different MSC_LOCATION values
String procName = VoltSystemProcedure.procCallName(AdHoc.class);
String query = "SELECT COUNT(DISTINCT MSC_LOCATION) FROM " + TM1Constants.TABLENAME_SUBSCRIBER;
ClientResponse cresponse = client.callProcedure(procName, query);
assertEquals(Status.OK, cresponse.getStatus());
assertEquals(2, cresponse.getResults()[0].asScalarLong());
System.err.println(cresponse);
}