use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.
the class TestSpringMVCCommonSchemaInterface method testInvocationAlreadyTimeoutInClient.
private void testInvocationAlreadyTimeoutInClient() {
try {
InvocationContext context = new InvocationContext();
context.addLocalContext(ProcessingTimeStrategy.CHAIN_START_TIME, System.nanoTime());
context.addLocalContext(ProcessingTimeStrategy.CHAIN_PROCESSING, TimeUnit.SECONDS.toNanos(1));
client.testInvocationTimeout(context, 1, "hello");
TestMgr.fail("should timeout");
} catch (InvocationException e) {
TestMgr.check(408, e.getStatusCode());
TestMgr.check("Invocation Timeout.", ((CommonExceptionData) e.getErrorData()).getMessage());
}
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.
the class PojoClient method testTraceIdOnContextContainsTraceId.
private static void testTraceIdOnContextContainsTraceId() {
InvocationContext context = new InvocationContext();
context.addContext(Const.TRACE_ID_NAME, String.valueOf(Long.MIN_VALUE));
ContextUtils.setInvocationContext(context);
String traceId = test.testTraceId();
TestMgr.check(String.valueOf(Long.MIN_VALUE), traceId);
ContextUtils.removeInvocationContext();
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.
the class CodeFirstJaxrs method cseResponse.
@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@Path("/cseResponse")
@GET
public Response cseResponse(InvocationContext c1) {
Response response = Response.createSuccess(Status.ACCEPTED, new User());
response.setHeader("h1", "h1v " + c1.getContext().get(Const.SRC_MICROSERVICE));
InvocationContext c2 = ContextUtils.getInvocationContext();
response.setHeader("h2", "h2v " + c2.getContext().get(Const.SRC_MICROSERVICE));
return response;
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.
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);
((CodeFirstPojoClientIntf) codeFirst).sayHiAsync("someone").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);
}
}
use of org.apache.servicecomb.swagger.invocation.context.InvocationContext in project java-chassis by ServiceComb.
the class CodeFirstJaxrs method response.
@ApiResponse(code = 200, response = User.class, message = "")
@ResponseHeaders({ @ResponseHeader(name = "h1", response = String.class), @ResponseHeader(name = "h2", response = String.class) })
@Path("/response")
@GET
public Response response(InvocationContext c1) {
Response response = Response.createSuccess(Status.ACCEPTED, new User());
response.addHeader("h1", "h1v " + c1.getContext().toString());
InvocationContext c2 = ContextUtils.getInvocationContext();
response.addHeader("h2", "h2v " + c2.getContext().toString());
return response;
}
Aggregations