use of org.apache.dubbo.rpc.protocol.dubbo.support.DemoService in project dubbo by alibaba.
the class MultiThreadTest method testDubboMultiThreadInvoke.
@Test
public void testDubboMultiThreadInvoke() throws Exception {
ApplicationModel.getServiceRepository().registerService("TestService", DemoService.class);
int port = NetUtils.getAvailablePort();
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(new DemoServiceImpl(), DemoService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/TestService")));
final AtomicInteger counter = new AtomicInteger();
final DemoService service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/TestService")));
Assertions.assertEquals(service.getSize(new String[] { "123", "456", "789" }), 3);
final StringBuffer sb = new StringBuffer();
for (int i = 0; i < 1024 * 64 + 32; i++) sb.append('A');
Assertions.assertEquals(sb.toString(), service.echo(sb.toString()));
ExecutorService exec = Executors.newFixedThreadPool(10);
for (int i = 0; i < 10; i++) {
final int fi = i;
exec.execute(new Runnable() {
public void run() {
for (int i = 0; i < 30; i++) {
System.out.println(fi + ":" + counter.getAndIncrement());
Assertions.assertEquals(service.echo(sb.toString()), sb.toString());
}
}
});
}
exec.shutdown();
exec.awaitTermination(10, TimeUnit.SECONDS);
rpcExporter.unexport();
}
use of org.apache.dubbo.rpc.protocol.dubbo.support.DemoService in project dubbo by alibaba.
the class ServerStatusCheckerTest method testServerStatusChecker.
@Test
public void testServerStatusChecker() throws Exception {
int port = NetUtils.getAvailablePort(7000);
URL url = URL.valueOf("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName());
DemoService service = new DemoServiceImpl();
DubboProtocol.getDubboProtocol().export(proxy.getInvoker(service, DemoService.class, url));
StatusChecker server = ExtensionLoader.getExtensionLoader(StatusChecker.class).getExtension("server");
Assertions.assertEquals(ServerStatusChecker.class, server.getClass());
Status status = server.check();
Assertions.assertEquals(Status.Level.OK, status.getLevel());
ProtocolUtils.closeAll();
}
use of org.apache.dubbo.rpc.protocol.dubbo.support.DemoService in project dubbo by alibaba.
the class FutureFilterTest method testSyncCallback.
@Test
public void testSyncCallback() {
@SuppressWarnings("unchecked") Invoker<DemoService> 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(result);
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
given(invoker.getUrl()).willReturn(url);
Result filterResult = eventFilter.invoke(invoker, invocation);
assertEquals("High", filterResult.getValue());
}
use of org.apache.dubbo.rpc.protocol.dubbo.support.DemoService in project dubbo by alibaba.
the class DubboProtocolTest method testPayloadOverException.
@Test
public void testPayloadOverException() throws Exception {
DemoService service = new DemoServiceImpl();
int port = NetUtils.getAvailablePort();
protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName()).addParameter("payload", 10 * 1024)));
service = proxy.getProxy(protocol.refer(DemoService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName()).addParameter("timeout", 6000L).addParameter("payload", 160)));
try {
service.download(300);
Assertions.fail();
} catch (Exception expected) {
Assertions.assertTrue(expected.getMessage().contains("Data length too large"));
}
}
use of org.apache.dubbo.rpc.protocol.dubbo.support.DemoService in project dubbo by alibaba.
the class DubboProtocolTest method testRemoteApplicationName.
@Test
public void testRemoteApplicationName() throws Exception {
DemoService service = new DemoServiceImpl();
int port = NetUtils.getAvailablePort();
URL url = URL.valueOf("dubbo://127.0.0.1:" + port + "/" + DemoService.class.getName() + "?codec=exchange").addParameter("timeout", 3000L).addParameter("application", "consumer");
protocol.export(proxy.getInvoker(service, DemoService.class, url));
service = proxy.getProxy(protocol.refer(DemoService.class, url));
assertEquals(service.getRemoteApplicationName(), "consumer");
}
Aggregations