Skip to content

Instantly share code, notes, and snippets.

@alexlehm
Created October 17, 2015 11:11
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/2b3500b90fed5c881cd7 to your computer and use it in GitHub Desktop.
Save alexlehm/2b3500b90fed5c881cd7 to your computer and use it in GitHub Desktop.
TimerCancelIssue.java
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.junit.runner.RunWith;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import io.vertx.core.net.NetClient;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import io.vertx.core.Vertx;
/**
* show timer cancel issue in HandlerRegistration (https://bugs.eclipse.org/bugs/show_bug.cgi?id=480001)
*
* @author <a href="http://oss.lehmann.cx/">Alexander Lehmann</a>
*/
@RunWith(VertxUnitRunner.class)
public class TimerCancelIssue {
private static final Logger log = LoggerFactory.getLogger(TimerCancelIssue.class);
@Test
public final void testCloseWhileMailActive(TestContext testContext) {
Async async = testContext.async();
Vertx vertx = Vertx.vertx();
NetClient netClient = vertx.createNetClient();
AtomicBoolean timerFinished = new AtomicBoolean(false);
netClient.connect(80, "www.lehmann.cx", result -> {
if (result.succeeded()) {
log.debug("socket connected");
long timerid = vertx.setTimer(1000, v1 -> {
log.debug("1000ms timer finished");
timerFinished.set(true);
});
log.info("timerid1 = " + timerid);
netClient.close();
long timerid2 = vertx.setTimer(2000, v1 -> {
log.debug("2000ms timer finished");
testContext.assertTrue(timerFinished.get(), "timer1 hasn't finished");
async.complete();
});
log.info("timerid2 = " + timerid2);
} else {
log.info("socket connect failed");
testContext.fail();
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment