use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.
the class TestInvokerUtils method testReactiveInvoke.
@Test
public void testReactiveInvoke() {
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
boolean validAssert;
try {
InvokerUtils.reactiveInvoke(invocation, asyncResp);
validAssert = true;
} catch (Exception e) {
validAssert = false;
}
Assert.assertTrue(validAssert);
}
use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.
the class VertxHttpMethod method handleResponse.
protected void handleResponse(Invocation invocation, HttpClientResponse httpResponse, RestOperationMeta restOperation, AsyncResponse asyncResp) {
ProduceProcessor produceProcessor = null;
String contentType = httpResponse.getHeader("Content-Type");
if (contentType != null) {
String contentTypeForFind = contentType;
int idx = contentType.indexOf(';');
if (idx != -1) {
contentTypeForFind = contentType.substring(0, idx);
}
produceProcessor = restOperation.findProduceProcessor(contentTypeForFind);
}
if (produceProcessor == null) {
String msg = String.format("path %s, statusCode %d, reasonPhrase %s, response content-type %s is not supported", restOperation.getAbsolutePath(), httpResponse.statusCode(), httpResponse.statusMessage(), contentType);
Exception exception = ExceptionFactory.createConsumerException(new CommonExceptionData(msg));
asyncResp.fail(invocation.getInvocationType(), exception);
return;
}
ProduceProcessor finalProduceProcessor = produceProcessor;
httpResponse.bodyHandler(responseBuf -> {
invocation.getResponseExecutor().execute(() -> {
try {
ResponseMeta responseMeta = restOperation.getOperationMeta().findResponseMeta(httpResponse.statusCode());
Object result = finalProduceProcessor.decodeResponse(responseBuf, responseMeta.getJavaType());
Response response = Response.create(httpResponse.statusCode(), httpResponse.statusMessage(), result);
for (String headerName : responseMeta.getHeaders().keySet()) {
List<String> headerValues = httpResponse.headers().getAll(headerName);
for (String headerValue : headerValues) {
response.getHeaders().addHeader(headerName, headerValue);
}
}
asyncResp.complete(response);
} catch (Throwable e) {
asyncResp.fail(invocation.getInvocationType(), e);
}
});
});
}
use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.
the class TestVertxGetMethod method testVertxGetMethod.
@Test
public void testVertxGetMethod() {
HttpClient client = Mockito.mock(HttpClient.class);
Invocation invocation = Mockito.mock(Invocation.class);
IpPort ipPort = Mockito.mock(IpPort.class);
Mockito.when(ipPort.getPort()).thenReturn(10);
assertEquals(10, ipPort.getPort());
Mockito.when(ipPort.getHostOrIp()).thenReturn("ever");
assertEquals("ever", ipPort.getHostOrIp());
RestOperationMeta operation = Mockito.mock(RestOperationMeta.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
HttpClientRequest obj = VertxGetMethod.INSTANCE.createRequest(client, invocation, ipPort, "good", operation, asyncResp);
Assert.assertNull(obj);
}
use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.
the class TestHighwayTransport method testSendException.
@Test
public void testSendException() throws Exception {
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
commonHighwayMock(invocation);
Holder<Boolean> sended = new Holder<Boolean>(false);
new MockUp<HighwayClient>() {
@Mock
public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
sended.value = true;
}
};
transport.send(invocation, asyncResp);
Assert.assertTrue(sended.value);
}
use of io.servicecomb.core.AsyncResponse in project java-chassis by ServiceComb.
the class TestVertxHttpMethod method testHandleResponse.
@Test
public void testHandleResponse() {
boolean status = false;
try {
Invocation invocation = Mockito.mock(Invocation.class);
AsyncResponse asyncResp = Mockito.mock(AsyncResponse.class);
HttpClientResponse httpResponse = Mockito.mock(HttpClientResponse.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
RestOperationMeta swaggerRestOperation = Mockito.mock(RestOperationMeta.class);
Endpoint endpoint = Mockito.mock(Endpoint.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
URLPathBuilder urlPathBuilder = Mockito.mock(URLPathBuilder.class);
Mockito.when(swaggerRestOperation.getPathBuilder()).thenReturn(urlPathBuilder);
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
Mockito.when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
Mockito.when(invocation.getEndpoint()).thenReturn(endpoint);
String contentType = httpResponse.getHeader("Content-Type");
ProduceProcessor produceProcessor = Mockito.mock(ProduceProcessor.class);
Mockito.when(swaggerRestOperation.findProduceProcessor(contentType)).thenReturn(produceProcessor);
this.handleResponse(invocation, httpResponse, swaggerRestOperation, asyncResp);
} catch (Exception ex) {
status = true;
}
Assert.assertFalse(status);
}
Aggregations