log.debug("-----------------------------------------------------------------testBug631");
final String message = "This is a test";
//create our sender conn and set local
IClientRegistry dummyReg = (IClientRegistry) applicationContext.getBean("global.clientRegistry");
final IScope scp = (WebScope) applicationContext.getBean("web.scope"); //conn.getScope();
final IContext ctx = (Context) applicationContext.getBean("web.context"); //scope.getContext();
final IConnection recipient = new SvcCapableTestConnection("localhost", "/junit", "1");//host, path, session id
IClient rClient = dummyReg.newClient(new Object[] { "recipient" });
((TestConnection) recipient).setClient(rClient);
((TestConnection) recipient).setScope((Scope) scp);
((DummyClient) rClient).registerConnection(recipient);
final IConnection sender = new SvcCapableTestConnection("localhost", "/junit", "2");//host, path, session id
IClient sClient = dummyReg.newClient(new Object[] { "sender" });
((TestConnection) sender).setClient(sClient);
((TestConnection) sender).setScope((Scope) scp);
((DummyClient) sClient).registerConnection(sender);
Thread r = new Thread(new Runnable() {
public void run() {
Red5.setConnectionLocal(recipient);
IConnection conn = Red5.getConnectionLocal();
assertTrue(scp.connect(conn));
try {
Thread.sleep(120L);
} catch (InterruptedException e) {
}
log.debug("Check s/c -\n s1: {} s2: {}\n c1: {} c2: {}", new Object[] { scp, conn.getScope(), ctx, conn.getScope().getContext() });
}
});
Thread s = new Thread(new Runnable() {
public void run() {
Red5.setConnectionLocal(sender);
IConnection conn = Red5.getConnectionLocal();
assertTrue(scp.connect(conn));
try {
Thread.sleep(10L);
} catch (InterruptedException e) {
}
Object[] sendobj = new Object[] { conn.getClient().getId(), message };
// get the recipient
IClientRegistry reg = ctx.getClientRegistry();
IConnection rcon = reg.lookupClient("recipient").getConnections(scp).iterator().next();
((IServiceCapableConnection) rcon).invoke("privMessage", sendobj);
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
}
log.debug("Check s/c -\n s1: {} s2: {}\n c1: {} c2: {}", new Object[] { scp, conn.getScope(), ctx, conn.getScope().getContext() });
}
});
r.start();
s.start();
r.join();
s.join();
IClientRegistry reg = ctx.getClientRegistry();
log.debug("Client registry: {}", reg.getClass().getName());
if (reg.hasClient("recipient")) {
IClient recip = reg.lookupClient("recipient");
Set<IConnection> rcons = recip.getConnections(scp);
log.debug("Recipient has {} connections", rcons.size());
} else {
fail("Recipient not found");
}