public void testSimple() throws Exception {
final Backchannel backchannel = Backchannel.getInstance();
backchannel.push( "mici",
new PushResponse( "m",
"b" ) );
backchannel.push( "davos",
new PushResponse( "d",
"b" ) );
List<PushResponse> r = backchannel.await( "mici" );
assertEquals( 1,
r.size() );
assertEquals( "m",
r.get( 0 ).messageType );
r = backchannel.await( "davos" );
assertEquals( 1,
r.size() );
assertEquals( "d",
r.get( 0 ).messageType );
final boolean[] check = new boolean[1];
Thread t = new Thread( new Runnable() {
public void run() {
try {
@SuppressWarnings("unused")
List<PushResponse> list = backchannel.await( "mici" );
/*
for (PushResponse resp: list) {
System.err.println(resp.messageType + "," + resp.message);
}
*/
check[0] = true;
} catch ( InterruptedException e ) {
fail( "Should not interrupt" );
}
}
} );
t.setDaemon( true );
t.start();
Thread.sleep( 400 );
assertFalse( check[0] );
backchannel.push( "davos",
new PushResponse( "x",
"y" ) );
//bc.push("mic", new PushResponse("Q", "W"));
t.join();
check[0] = false;
backchannel.push( "mici",
new PushResponse( "R",
"T" ) );
backchannel.push( "mici",
new PushResponse( "Q",
"A" ) );
final List<List<PushResponse>> container = new ArrayList<List<PushResponse>>();
t = new Thread( new Runnable() {