use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class TestConsumerSchemaFactory method testGetOrCreateConsumer.
@Test
public void testGetOrCreateConsumer() {
MicroserviceMeta microserviceMeta = consumerSchemaFactory.getOrCreateConsumer("ms", "latest");
OperationMeta operationMeta = microserviceMeta.ensureFindOperation("schema.add");
Assert.assertEquals("add", operationMeta.getOperationId());
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class TestConsumer method testInvokerUtils.
@Test
public void testInvokerUtils() {
Invocation oInvocation = Mockito.mock(Invocation.class);
OperationMeta oOperationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(oOperationMeta.isSync()).thenReturn(false);
Mockito.when(oInvocation.getOperationMeta()).thenReturn(oOperationMeta);
InvokerUtils.reactiveInvoke(oInvocation, Mockito.mock(AsyncResponse.class));
boolean validReactiveInvoke = true;
try {
InvokerUtils.reactiveInvoke(null, null);
} catch (Exception e) {
Assert.assertEquals(java.lang.NullPointerException.class, e.getClass());
validReactiveInvoke = false;
}
Assert.assertFalse(validReactiveInvoke);
boolean validInvokeIsNull = true;
try {
InvokerUtils.invoke(null);
} catch (Exception e) {
Assert.assertEquals(java.lang.NullPointerException.class, e.getClass());
validInvokeIsNull = false;
}
Assert.assertFalse(validInvokeIsNull);
boolean validInvoke = true;
try {
InvokerUtils.invoke(oInvocation);
} catch (Exception e) {
Assert.assertEquals(java.lang.NullPointerException.class, e.getClass());
validInvoke = false;
}
Assert.assertFalse(validInvoke);
}
use of io.servicecomb.core.definition.OperationMeta in project java-chassis by ServiceComb.
the class TestInvokerUtils method testInvoke.
@Test
public void testInvoke() {
Object[] objectArray = new Object[2];
Invocation invocation = Mockito.mock(Invocation.class);
OperationMeta operationMeta = Mockito.mock(OperationMeta.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(operationMeta);
Mockito.when(operationMeta.isSync()).thenReturn(false);
Mockito.when(invocation.getArgs()).thenReturn(objectArray);
Object obj = InvokerUtils.invoke(invocation);
Assert.assertNull(obj);
}
use of io.servicecomb.core.definition.OperationMeta 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.definition.OperationMeta 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);
}
Aggregations