Created
October 17, 2015 11:11
-
-
Save alexlehm/2b3500b90fed5c881cd7 to your computer and use it in GitHub Desktop.
TimerCancelIssue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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