use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class ValidationFilterTest method testItWithNotExistClass.
@Test
public void testItWithNotExistClass() throws Exception {
URL url = URL.valueOf("test://test:11/test?validation=true");
given(validation.getValidator(url)).willThrow(new IllegalStateException("Not found class test, cause: test"));
given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
given(invoker.getUrl()).willReturn(url);
given(invocation.getMethodName()).willReturn("echo1");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
validationFilter.setValidation(validation);
Result result = validationFilter.invoke(invoker, invocation);
assertThat(result.getException().getMessage(), is("Not found class test, cause: test"));
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class ValidationFilterTest method testItWithoutUrlParameters.
@Test
public void testItWithoutUrlParameters() throws Exception {
URL url = URL.valueOf("test://test:11/test");
given(validation.getValidator(url)).willReturn(validator);
given(invoker.invoke(invocation)).willReturn(new AppResponse("success"));
given(invoker.getUrl()).willReturn(url);
given(invocation.getMethodName()).willReturn("echo1");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
given(invocation.getArguments()).willReturn(new Object[] { "arg1" });
validationFilter.setValidation(validation);
Result result = validationFilter.invoke(invoker, invocation);
assertThat(String.valueOf(result.getValue()), is("success"));
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class ActiveLimitFilterTest method testInvokeNotTimeOut.
@Test
public void testInvokeNotTimeOut() throws Exception {
int totalThread = 100;
int maxActives = 10;
long timeout = 1000;
long blockTime = 0;
AtomicInteger count = new AtomicInteger(0);
final CountDownLatch latch = new CountDownLatch(1);
final CountDownLatch latchBlocking = new CountDownLatch(totalThread);
URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&actives=" + maxActives + "&timeout=" + timeout);
final Invoker<ActiveLimitFilterTest> invoker = new BlockMyInvoker<ActiveLimitFilterTest>(url, blockTime);
final Invocation invocation = new MockInvocation();
for (int i = 0; i < totalThread; i++) {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
Result asyncResult = activeLimitFilter.invoke(invoker, invocation);
Result result = asyncResult.get();
activeLimitFilter.onResponse(result, invoker, invocation);
} catch (RpcException expected) {
count.incrementAndGet();
activeLimitFilter.onError(expected, invoker, invocation);
} catch (Exception e) {
fail();
}
} finally {
latchBlocking.countDown();
}
}
});
thread.start();
}
latch.countDown();
try {
latchBlocking.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
assertEquals(0, count.intValue());
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class CompatibleFilterFilterTest method testInvokerNonJsonEnumSerialization.
@Test
public void testInvokerNonJsonEnumSerialization() throws Exception {
invocation = mock(Invocation.class);
given(invocation.getMethodName()).willReturn("enumlength");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { Type[].class });
given(invocation.getArguments()).willReturn(new Object[] { "hello" });
invoker = mock(Invoker.class);
given(invoker.isAvailable()).willReturn(true);
given(invoker.getInterface()).willReturn(DemoService.class);
AppResponse result = new AppResponse();
result.setValue("High");
given(invoker.invoke(invocation)).willReturn(AsyncRpcResult.newDefaultAsyncResult(result, invocation));
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
given(invoker.getUrl()).willReturn(url);
Result asyncResult = compatibleFilter.invoke(invoker, invocation);
AppResponse appResponse = (AppResponse) asyncResult.get();
compatibleFilter.onResponse(appResponse, invoker, invocation);
assertEquals(Type.High, appResponse.getValue());
}
use of org.apache.dubbo.rpc.Result in project dubbo by alibaba.
the class CompatibleFilterFilterTest method testInvokerNonJsonNonPojoSerialization.
@Test
public void testInvokerNonJsonNonPojoSerialization() {
invocation = mock(Invocation.class);
given(invocation.getMethodName()).willReturn("echo");
given(invocation.getParameterTypes()).willReturn(new Class<?>[] { String.class });
given(invocation.getArguments()).willReturn(new Object[] { "hello" });
invoker = mock(Invoker.class);
given(invoker.isAvailable()).willReturn(true);
given(invoker.getInterface()).willReturn(DemoService.class);
AppResponse result = new AppResponse();
result.setValue(new String[] { "High" });
given(invoker.invoke(invocation)).willReturn(result);
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
given(invoker.getUrl()).willReturn(url);
Result filterResult = compatibleFilter.invoke(invoker, invocation);
assertArrayEquals(new String[] { "High" }, (String[]) filterResult.getValue());
}
Aggregations