Skip to content

Instantly share code, notes, and snippets.

@alexlehm
Created October 22, 2015 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexlehm/1f274afe2409aab3e2de to your computer and use it in GitHub Desktop.
Save alexlehm/1f274afe2409aab3e2de to your computer and use it in GitHub Desktop.
TimerCancelTest.java
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.impl.HandlerRegistration;
import io.vertx.test.core.VertxTestBase;
/**
* @author <a href="http://oss.lehmann.cx/">Alexander Lehmann</a>
*
*/
public class TimerCancelTest extends VertxTestBase {
@Test
public void testTimerCancel() {
Vertx vertx = Vertx.vertx();
HandlerRegistration<String> handlerRegistration = new HandlerRegistration<String>(vertx, null, null, null, false,
false, null, -1);
AtomicBoolean timerFinished = new AtomicBoolean(false);
long tid1 = vertx.setTimer(1000, id -> {
timerFinished.set(true);
});
if (tid1 != 0) {
fail("timer id is not 0, the issue will not show");
}
handlerRegistration.unregister();
vertx.setTimer(2000, id2 -> {
assertTrue("timer did not finish", timerFinished.get());
testComplete();
});
await();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment