Last active
May 25, 2017 10:38
-
-
Save alexlehm/a9970fe66edfd381b399b91fddf0ccad to your computer and use it in GitHub Desktop.
AsyncTest.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
package cx.lehmann.vertx; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import io.vertx.core.logging.Logger; | |
import io.vertx.core.logging.LoggerFactory; | |
import io.vertx.ext.unit.Async; | |
import io.vertx.ext.unit.TestContext; | |
import io.vertx.ext.unit.junit.VertxUnitRunner; | |
@RunWith(VertxUnitRunner.class) | |
public class AsyncTest { | |
private static final Logger log = LoggerFactory.getLogger(AsyncTest.class); | |
private TestClient client = new TestClient(); | |
@Test | |
public void asyncTest(TestContext theContext) { | |
Async submit = theContext.async(9); | |
String submission = ""; | |
for (int i = 0; i < 9; i++) { | |
final int fi = i; | |
client.submitJob(submission, theContext.asyncAssertSuccess(job -> { | |
log.info("success " + fi); | |
submit.countDown(); | |
})); | |
} | |
log.info("await"); | |
submit.await(); | |
log.info("finished"); | |
} | |
} |
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
package cx.lehmann.vertx; | |
import io.vertx.core.AsyncResult; | |
import io.vertx.core.Future; | |
import io.vertx.core.Handler; | |
import io.vertx.core.Vertx; | |
/** | |
* @author <a href="https://oss.lehmann.cx/">Alexander Lehmann</a> | |
* | |
*/ | |
public class TestClient { | |
public void submitJob(String submission, Handler<AsyncResult<String>> asyncAssertSuccess) { | |
Vertx.vertx().setTimer(1000, t -> { | |
asyncAssertSuccess.handle(Future.succeededFuture("success")); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment