c3=createChannel(c1);
c3.connect("testConcurrentFlushAndPartialFlush");
assertViewsReceived(c1, c2, c3);
final CountDownLatch startFlushLatch=new CountDownLatch(1);
final CountDownLatch stopFlushLatch=new CountDownLatch(1);
// 2 because either total or partial has to finish first
final CountDownLatch flushStartReceived=new CountDownLatch(2);
// 5 because we have total and partial flush
final CountDownLatch flushStopReceived=new CountDownLatch(5);
Thread t1=new Thread() {
public void run() {
try {
startFlushLatch.await();
boolean rc=Util.startFlush(c1);
System.out.println("t1: rc=" + rc);
}
catch(InterruptedException e) {
interrupt();
}
try {
stopFlushLatch.await();
}
catch(InterruptedException e) {
interrupt();
}
finally {
c1.stopFlush();
}
}
};
Thread t2=new Thread() {
public void run() {
try {
startFlushLatch.await();
// partial, only between c2 and c3
boolean rc=Util.startFlush(c2, (Arrays.asList(c2.getLocalAddress(), c3.getLocalAddress())));
System.out.println("t2: partial flush rc=" + rc);
}
catch(InterruptedException e) {
interrupt();
}
try {
stopFlushLatch.await();
}
catch(InterruptedException e) {
interrupt();
}
finally {
c2.stopFlush(Arrays.asList(c2.getLocalAddress(), c3.getLocalAddress()));
}
}
};
Listener l1=new Listener("c1", c1, flushStartReceived, flushStopReceived);
Listener l2=new Listener("c2", c2, flushStartReceived, flushStopReceived);
Listener l3=new Listener("c3", c3, flushStartReceived, flushStopReceived);
t1.start();
t2.start();
startFlushLatch.countDown();
assertTrue(flushStartReceived.await(60, TimeUnit.SECONDS));
// at this stage both channels should have started a flush?
stopFlushLatch.countDown();
t1.join();
t2.join();
assertTrue(flushStopReceived.await(60, TimeUnit.SECONDS));
assert l1.blockReceived;
assert l1.unblockReceived;
assert l2.blockReceived;
assert l2.unblockReceived;