fiber.join();
}
@Test
public void testDumpStackWaitingFiberWhenCalledFromFiber() throws Exception {
final Condition cond = new SimpleConditionSynchronizer(null);
final AtomicBoolean flag = new AtomicBoolean(false);
final Fiber fiber = new Fiber(scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
foo();
}
private void foo() throws InterruptedException, SuspendExecution {
Object token = cond.register();
try {
for (int i = 0; !flag.get(); i++)
cond.await(i);
} finally {
cond.unregister(token);
}
}
}).start();
Thread.sleep(200);
Fiber fiber2 = new Fiber(scheduler, new SuspendableRunnable() {
@Override
public void run() throws SuspendExecution, InterruptedException {
StackTraceElement[] st = fiber.getStackTrace();
// Strand.printStackTrace(st, System.err);
assertThat(st[0].getMethodName(), equalTo("park"));
boolean found = false;
for (StackTraceElement ste : st) {
if (ste.getMethodName().equals("foo")) {
found = true;
break;
}
}
assertThat(found, is(true));
assertThat(st[st.length - 1].getMethodName(), equalTo("run"));
assertThat(st[st.length - 1].getClassName(), equalTo(Fiber.class.getName()));
}
}).start();
fiber2.join();
flag.set(true);
cond.signalAll();
fiber.join();
}