Seti seti2 = startSeti(oort2);
new SetiService(seti1);
new SetiService(seti2);
BayeuxClient client1 = startClient(oort1, null);
Assert.assertTrue(client1.waitFor(5000, BayeuxClient.State.CONNECTED));
BayeuxClient client2 = startClient(oort2, null);
Assert.assertTrue(client2.waitFor(5000, BayeuxClient.State.CONNECTED));
CountDownLatch presenceAddedLatch = new CountDownLatch(4);
seti1.addPresenceListener(new UserPresentListener(presenceAddedLatch));
seti2.addPresenceListener(new UserPresentListener(presenceAddedLatch));
// Login user1
final CountDownLatch loginLatch1 = new CountDownLatch(1);
Map<String, Object> login1 = new HashMap<String, Object>();
String userId1 = "user1";
login1.put("user", userId1);
ClientSessionChannel loginChannel1 = client1.getChannel("/service/login");
loginChannel1.publish(login1, new ClientSessionChannel.MessageListener()
{
public void onMessage(ClientSessionChannel channel, Message message)
{
loginLatch1.countDown();
}
});
Assert.assertTrue(loginLatch1.await(5, TimeUnit.SECONDS));
// Login user2
final CountDownLatch loginLatch2 = new CountDownLatch(1);
Map<String, Object> login2 = new HashMap<String, Object>();
String userId2 = "user2";
login2.put("user", userId2);
ClientSessionChannel loginChannel2 = client2.getChannel("/service/login");
loginChannel2.publish(login2, new ClientSessionChannel.MessageListener()
{
public void onMessage(ClientSessionChannel channel, Message message)
{
loginLatch2.countDown();
}
});
Assert.assertTrue(loginLatch2.await(5, TimeUnit.SECONDS));
// Make sure all Setis see all users
Assert.assertTrue(presenceAddedLatch.await(5, TimeUnit.SECONDS));
// Setup test: register a service for the service channel
// that broadcasts to another channel that is not observed
final String serviceChannel = "/service/foo";
final String broadcastChannel = "/foo";
if (forward)
{
oort2.observeChannel(broadcastChannel);
// Give some time for the subscribe to happen
Thread.sleep(1000);
}
new BroadcastService(seti1, serviceChannel, broadcastChannel);
// Subscribe user2
LatchListener subscribeListener = new LatchListener(1);
final CountDownLatch messageLatch = new CountDownLatch(1);
client2.getChannel(Channel.META_SUBSCRIBE).addListener(subscribeListener);
client2.getChannel(broadcastChannel).subscribe(new ClientSessionChannel.MessageListener()
{
public void onMessage(ClientSessionChannel channel, Message message)
{
messageLatch.countDown();
}