// start the eventloops
loopA.execute(NOOP);
loopB.execute(NOOP);
LocalChannel channel = new LocalChannel();
ChannelPromise registerPromise = channel.newPromise();
channel.unsafe().register(loopA, registerPromise);
registerPromise.sync();
assertThat(channel.eventLoop(), instanceOf(PausableEventExecutor.class));
assertSame(loopA, channel.eventLoop().unwrap());
ScheduledFuture<?> scheduleFuture;
if (PeriodicScheduleMethod.FIXED_RATE == method) {
scheduleFuture = channel.eventLoop().scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
assertTrue(loopB.inEventLoop());
timestamps.add(System.nanoTime());
}
}, 100, 200, TimeUnit.MILLISECONDS);
} else {
scheduleFuture = channel.eventLoop().scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
assertTrue(loopB.inEventLoop());
timestamps.add(System.nanoTime());
}
}, 100, 200, TimeUnit.MILLISECONDS);
}
assertTrue(((PausableEventExecutor) channel.eventLoop()).isAcceptingNewTasks());
ChannelFuture deregisterFuture = channel.deregister();
assertFalse(((PausableEventExecutor) channel.eventLoop()).isAcceptingNewTasks());
assertTrue(deregisterFuture.sync().isSuccess());
timestamps.clear();
Thread.sleep(1000);
// no scheduled tasks must be executed after deregistration.
String message = String.format("size: %d, expected 0", timestamps.size());
assertTrue(message, timestamps.isEmpty());
assertFalse(((PausableEventExecutor) channel.eventLoop()).isAcceptingNewTasks());
registerPromise = channel.newPromise();
channel.unsafe().register(loopB, registerPromise);
assertTrue(registerPromise.sync().isSuccess());
assertTrue(((PausableEventExecutor) channel.eventLoop()).isAcceptingNewTasks());
assertThat(channel.eventLoop(), instanceOf(PausableEventExecutor.class));
assertSame(loopB, channel.eventLoop().unwrap());
// 100ms internal delay + 1 second. Should be able to execute 5 tasks in that time.
Thread.sleep(1150);
assertTrue(scheduleFuture.cancel(true));