for(QNode qnode : getqNodes()) {
// Make sure all QNodes are aware of the the first deploy
// There might be some delay as they have to receive notifications via Hazelcast etc
long waitedSoFar = 0;
QueryStatus status = null;
SploutClient perQNodeClient = new SploutClient(qnode.getAddress());
do {
status = perQNodeClient.query(TABLESPACE, "0", "SELECT * FROM " + TABLE + ";", null);
Thread.sleep(100);
waitedSoFar += 100;
if(waitedSoFar > 5000) {
throw new AssertionError("Waiting too much on a test condition");
}
} while(status == null || status.getError() != null);
log.info("QNode [" + qnode.getAddress() + "] is ready to serve deploy 0.");
}
try {
// Business logic here
ExecutorService service = Executors.newFixedThreadPool(N_THREADS);
// This is the "mother-fucker" thread.
// It will bring DNodes down on purpose.
// And then bring them up again.
service.submit(new Runnable() {
@Override
public void run() {
while(true) {
try {
Thread.sleep(1000);
log.info("Time to kill some DNode...");
int whichOne = (int) (Math.random() * getdNodes().size());
getdNodes().get(whichOne).testCommand(TestCommands.SHUTDOWN.toString());
Thread.sleep(1000);
log.info("Time to bring the DNode back to life...");
getdNodes().get(whichOne).testCommand(TestCommands.RESTART.toString());
} catch(InterruptedException e) {
log.info("MFT - Bye bye!");
} catch(DNodeException e) {
failed.set(true);
e.printStackTrace();
throw new RuntimeException(e);
} catch(TException e) {
failed.set(true);
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
});
// These threads will continuously perform queries and check that the results are consistent.
for(int i = 0; i < N_THREADS; i++) {
service.submit(new Runnable() {
@SuppressWarnings("unchecked")
@Override
public void run() {
try {
while(true) {
int randomDNode = Math.abs(random.nextInt()) % N_DNODES;
QueryStatus status = client.query(TABLESPACE, ((randomDNode * 10) - 1) + "", "SELECT * FROM "
+ TABLE + ";", null);
log.info("Query status -> " + status);
assertEquals(1, status.getResult().size());
Map<String, Object> jsonResult = (Map<String, Object>) status.getResult().get(0);
assertEquals(randomDNode, jsonResult.get("dnode"));
Thread.sleep(100);
}
} catch(InterruptedException ie) {
// Bye bye