Skip to content

Instantly share code, notes, and snippets.

@alexlehm
Last active May 25, 2017 10:38
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/a9970fe66edfd381b399b91fddf0ccad to your computer and use it in GitHub Desktop.
Save alexlehm/a9970fe66edfd381b399b91fddf0ccad to your computer and use it in GitHub Desktop.
AsyncTest.java
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");
}
}
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