*/
@Test
public void testScopeMissingHandler() throws Throwable {
log.debug("-----------------------------------------------------------------testScopeMissingHandler");
// create app
MultiThreadedApplicationAdapter app = new MultiThreadedApplicationAdapter();
// change the handler
appScope.setHandler(app);
// start
app.start(appScope);
// create our additional scopes
assertTrue(appScope.hasHandler());
IScope top = ScopeUtils.resolveScope(appScope, "/junit");
assertTrue(top.hasHandler());
IScope room = ScopeUtils.resolveScope(appScope, "/junit/room13");
if (room == null) {
assertTrue(top.createChildScope("room13"));
room = ScopeUtils.resolveScope(appScope, "/junit/room13");
assertNotNull(room);
}
assertTrue(room.hasHandler());
// get rooms
IScope room1 = ScopeUtils.resolveScope(appScope, "/junit/room13/subroomA");
if (room1 == null) {
assertTrue(room.createChildScope("subroomA"));
room1 = ScopeUtils.resolveScope(appScope, "/junit/room13/subroomA");
assertNotNull(room1);
}
Thread.sleep(10);
IScope room2 = ScopeUtils.resolveScope(appScope, "/junit/room13/subroomB");
if (room2 == null) {
assertTrue(room.createChildScope("subroomB"));
room2 = ScopeUtils.resolveScope(appScope, "/junit/room13/subroomB");
assertNotNull(room2);
}
// let it settle for a moment
Thread.sleep(50L);
// create the SOs
String soName = "messager";
if (!app.hasSharedObject(room1, soName)) {
app.createSharedObject(room1, soName, false);
}
assertNotNull(app.getSharedObject(room1, soName, false));
if (!app.hasSharedObject(room2, soName)) {
app.createSharedObject(room2, soName, false);
}
assertNotNull(app.getSharedObject(room2, soName, false));
// test runnables represent clients
trs = new TestRunnable[2];
trs[0] = new ScopeClientWorkerA(0, app, room1);
trs[1] = new ScopeClientWorkerB(1, app, room2);
MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(trs);
// fires off threads
long start = System.nanoTime();
mttr.runTestRunnables();
System.out.println("Runtime: " + (System.nanoTime() - start) + "ns");
ScopeClientWorkerA soa = (ScopeClientWorkerA) trs[0];
log.debug("Worker: {} shared object: {}", soa.getId(), soa.getSharedObject().getAttributes());
ScopeClientWorkerB sob = (ScopeClientWorkerB) trs[1];
log.debug("Worker: {} shared object: {}", sob.getId(), sob.getSharedObject().getAttributes());
Thread.sleep(300L);
// clean up / stop
app.stop(appScope);
}