use of org.apache.servicecomb.demo.CodeFirstPojoIntf in project incubator-servicecomb-java-chassis by apache.
the class CodeFirstPojoClient method testCodeFirstCompletableFuture.
private void testCodeFirstCompletableFuture(CodeFirstPojoIntf codeFirst) {
if (!CodeFirstPojoClientIntf.class.isInstance(codeFirst)) {
return;
}
Vertx vertx = VertxUtils.getOrCreateVertxByName("transport", null);
CountDownLatch latch = new CountDownLatch(1);
// vertx.runOnContext in normal thread is not a good practice
// here just a test, not care for this.
vertx.runOnContext(V -> {
InvocationContext context = new InvocationContext();
context.addContext("k", "v");
ContextUtils.setInvocationContext(context);
CompletableFuture<String> future = ((CodeFirstPojoClientIntf) codeFirst).sayHiAsync("someone");
future.thenCompose(result -> {
TestMgr.check("someone sayhi, context k: v", result);
TestMgr.check(true, context == ContextUtils.getInvocationContext());
return ((CodeFirstPojoClientIntf) codeFirst).sayHiAsync("someone 1");
}).whenComplete((r, e) -> {
TestMgr.check("someone 1 sayhi, context k: v", r);
latch.countDown();
});
ContextUtils.removeInvocationContext();
});
try {
latch.await();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
Aggregations