Search in sources :

Example 1 with CodeFirstPojoIntf

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);
    }
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) CodeFirstPojoIntf(org.apache.servicecomb.demo.CodeFirstPojoIntf) Vertx(io.vertx.core.Vertx) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) DemoConst(org.apache.servicecomb.demo.DemoConst) ContextUtils(org.apache.servicecomb.swagger.invocation.context.ContextUtils) RpcReference(org.apache.servicecomb.provider.pojo.RpcReference) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext) Inject(javax.inject.Inject) CountDownLatch(java.util.concurrent.CountDownLatch) Person(org.apache.servicecomb.demo.compute.Person) List(java.util.List) User(org.apache.servicecomb.demo.server.User) VertxUtils(org.apache.servicecomb.foundation.vertx.VertxUtils) Map(java.util.Map) CseContext(org.apache.servicecomb.core.CseContext) TestMgr(org.apache.servicecomb.demo.TestMgr) Vertx(io.vertx.core.Vertx) CountDownLatch(java.util.concurrent.CountDownLatch) InvocationContext(org.apache.servicecomb.swagger.invocation.context.InvocationContext)

Aggregations

Vertx (io.vertx.core.Vertx)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Inject (javax.inject.Inject)1 CseContext (org.apache.servicecomb.core.CseContext)1 CodeFirstPojoIntf (org.apache.servicecomb.demo.CodeFirstPojoIntf)1 DemoConst (org.apache.servicecomb.demo.DemoConst)1 TestMgr (org.apache.servicecomb.demo.TestMgr)1 Person (org.apache.servicecomb.demo.compute.Person)1 User (org.apache.servicecomb.demo.server.User)1 VertxUtils (org.apache.servicecomb.foundation.vertx.VertxUtils)1 RpcReference (org.apache.servicecomb.provider.pojo.RpcReference)1 ContextUtils (org.apache.servicecomb.swagger.invocation.context.ContextUtils)1 InvocationContext (org.apache.servicecomb.swagger.invocation.context.InvocationContext)1