use of org.apache.servicecomb.core.Handler in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method doInvoke.
@Test
public void doInvoke(@Mocked Endpoint endpoint, @Mocked OperationMeta operationMeta, @Mocked Object[] swaggerArguments, @Mocked SchemaMeta schemaMeta) throws Throwable {
Response response = Response.ok("ok");
Handler handler = (invocation, asyncResp) -> asyncResp.complete(response);
List<Handler> handlerChain = Arrays.asList(handler);
Deencapsulation.setField(invocation, "handlerList", handlerChain);
Holder<Response> result = new Holder<>();
restInvocation = new AbstractRestInvocationForTest() {
@Override
protected void sendResponse(Response response) {
result.value = response;
}
};
restInvocation.invocation = invocation;
restInvocation.doInvoke();
Assert.assertSame(response, result.value);
assertEquals(nanoTime, invocation.getInvocationStageTrace().getStartHandlersRequest());
assertEquals(nanoTime, invocation.getInvocationStageTrace().getFinishHandlersResponse());
}
use of org.apache.servicecomb.core.Handler in project java-chassis by ServiceComb.
the class TestAbstractRestInvocation method scheduleInvocation_flowControlReject.
@SuppressWarnings("deprecation")
@Test
public void scheduleInvocation_flowControlReject() {
new Expectations(operationMeta) {
{
operationMeta.getProviderQpsFlowControlHandler();
result = (Handler) (invocation, asyncResp) -> asyncResp.producerFail(new InvocationException(new HttpStatus(429, "Too Many Requests"), new CommonExceptionData("rejected by qps flowcontrol")));
}
};
Holder<Integer> status = new Holder<>();
Holder<String> reasonPhrase = new Holder<>();
Holder<Integer> endCount = new Holder<>(0);
Holder<String> responseBody = new Holder<>();
responseEx = new AbstractHttpServletResponse() {
@SuppressWarnings("deprecation")
@Override
public void setStatus(int sc, String sm) {
status.value = sc;
reasonPhrase.value = sm;
}
@Override
public void flushBuffer() {
endCount.value = endCount.value + 1;
}
@Override
public void setContentType(String type) {
assertEquals("application/json; charset=utf-8", type);
}
@Override
public void setBodyBuffer(Buffer bodyBuffer) {
responseBody.value = bodyBuffer.toString();
}
};
initRestInvocation();
restInvocation.scheduleInvocation();
assertEquals(Integer.valueOf(429), status.value);
assertEquals("Too Many Requests", reasonPhrase.value);
assertEquals("{\"message\":\"rejected by qps flowcontrol\"}", responseBody.value);
assertEquals(Integer.valueOf(1), endCount.value);
}
Aggregations