use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class TestShutdownHookHandler method testShutdownHookHandlerReject.
@Test
public void testShutdownHookHandlerReject() throws Exception {
Deencapsulation.setField(ShutdownHookHandler.INSTANCE, "shuttingDown", true);
Holder<InvocationType> typeHolder = new Holder<>(InvocationType.PRODUCER);
Invocation invocation = new MockUp<Invocation>() {
@Mock
public InvocationType getInvocationType() {
return typeHolder.value;
}
}.getMockInstance();
ShutdownHookHandler handler = ShutdownHookHandler.INSTANCE;
handler.handle(invocation, asyncResp -> {
InvocationException e = asyncResp.getResult();
Assert.assertEquals(((CommonExceptionData) e.getErrorData()).getMessage(), "shutting down in progress");
Assert.assertEquals(e.getStatusCode(), 590);
});
typeHolder.value = InvocationType.CONSUMER;
handler.handle(invocation, asyncResp -> {
InvocationException e = asyncResp.getResult();
Assert.assertEquals(((CommonExceptionData) e.getErrorData()).getMessage(), "shutting down in progress");
Assert.assertEquals(e.getStatusCode(), 490);
});
}
use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class TestInvokerUtils method testSyncInvokeInvocationWithException.
@Test
public void testSyncInvokeInvocationWithException() throws InterruptedException {
Invocation invocation = Mockito.mock(Invocation.class);
Response response = Mockito.mock(Response.class);
new MockUp<SyncResponseExecutor>() {
@Mock
public Response waitResponse() throws InterruptedException {
return Mockito.mock(Response.class);
}
};
Mockito.when(response.isSuccessed()).thenReturn(true);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
Mockito.when(operationMeta.getMicroserviceQualifiedName()).thenReturn("test");
try {
InvokerUtils.syncInvoke(invocation);
} catch (InvocationException e) {
Assert.assertEquals(490, e.getStatusCode());
}
}
use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class ConsumerQpsFlowControlHandler method handle.
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
if (!Config.INSTANCE.isConsumerEnabled()) {
invocation.next(asyncResp);
return;
}
OperationMeta operationMeta = invocation.getOperationMeta();
QpsController qpsController = qpsControllerMgr.getOrCreate(operationMeta);
if (qpsController.isLimitNewRequest()) {
// 429
CommonExceptionData errorData = new CommonExceptionData("rejected by qps flowcontrol");
asyncResp.consumerFail(new InvocationException(QpsConst.TOO_MANY_REQUESTS_STATUS, errorData));
return;
}
invocation.next(asyncResp);
}
use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class ProviderQpsFlowControlHandler method handle.
@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
if (!Config.INSTANCE.isProviderEnabled()) {
invocation.next(asyncResp);
return;
}
String microServiceName = (String) invocation.getContext(Const.SRC_MICROSERVICE);
if (microServiceName != null && !microServiceName.isEmpty()) {
QpsController qpsController = qpsControllerMgr.getOrCreate(microServiceName);
if (qpsController.isLimitNewRequest()) {
// 429
CommonExceptionData errorData = new CommonExceptionData("rejected by qps flowcontrol");
asyncResp.producerFail(new InvocationException(QpsConst.TOO_MANY_REQUESTS_STATUS, errorData));
return;
}
}
invocation.next(asyncResp);
}
use of io.servicecomb.core.exception.InvocationException in project java-chassis by ServiceComb.
the class TestBizkeeperCommand method testGetCacheKeyProvider.
@Test
public void testGetCacheKeyProvider() {
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter().withRequestCacheEnabled(true).withRequestLogEnabled(false);
BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation, HystrixObservableCommand.Setter.withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation)).andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation)).andCommandPropertiesDefaults(setter));
String str = bizkeeperCommand.getCacheKey();
Assert.assertNull(str);
Response resp = Mockito.mock(Response.class);
Mockito.when(resp.isFailed()).thenReturn(false);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.isFailed()).thenReturn(true);
InvocationException excp = Mockito.mock(InvocationException.class);
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(400);
Assert.assertEquals(false, bizkeeperCommand.isFailedResponse(resp));
Mockito.when(resp.getResult()).thenReturn(excp);
Mockito.when(excp.getStatusCode()).thenReturn(590);
Assert.assertEquals(true, bizkeeperCommand.isFailedResponse(resp));
}
Aggregations