Search in sources :

Example 6 with DemoService

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();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) DemoService(org.apache.dubbo.rpc.protocol.dubbo.support.DemoService) DemoServiceImpl(org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 7 with DemoService

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();
}
Also used : Status(org.apache.dubbo.common.status.Status) DemoService(org.apache.dubbo.rpc.protocol.dubbo.support.DemoService) StatusChecker(org.apache.dubbo.common.status.StatusChecker) URL(org.apache.dubbo.common.URL) DemoServiceImpl(org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 8 with DemoService

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());
}
Also used : AppResponse(org.apache.dubbo.rpc.AppResponse) DemoService(org.apache.dubbo.rpc.protocol.dubbo.support.DemoService) URL(org.apache.dubbo.common.URL) Result(org.apache.dubbo.rpc.Result) Test(org.junit.jupiter.api.Test)

Example 9 with DemoService

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"));
    }
}
Also used : DemoService(org.apache.dubbo.rpc.protocol.dubbo.support.DemoService) RpcException(org.apache.dubbo.rpc.RpcException) DemoServiceImpl(org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Example 10 with DemoService

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");
}
Also used : DemoService(org.apache.dubbo.rpc.protocol.dubbo.support.DemoService) URL(org.apache.dubbo.common.URL) DemoServiceImpl(org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl) Test(org.junit.jupiter.api.Test)

Aggregations

DemoService (org.apache.dubbo.rpc.protocol.dubbo.support.DemoService)15 Test (org.junit.jupiter.api.Test)15 DemoServiceImpl (org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl)12 URL (org.apache.dubbo.common.URL)5 RpcException (org.apache.dubbo.rpc.RpcException)3 EchoService (org.apache.dubbo.rpc.service.EchoService)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AppResponse (org.apache.dubbo.rpc.AppResponse)2 Result (org.apache.dubbo.rpc.Result)2 Type (org.apache.dubbo.rpc.protocol.dubbo.support.Type)2 Field (java.lang.reflect.Field)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Status (org.apache.dubbo.common.status.Status)1 StatusChecker (org.apache.dubbo.common.status.StatusChecker)1 Channel (org.apache.dubbo.remoting.Channel)1 Invocation (org.apache.dubbo.rpc.Invocation)1 NonSerialized (org.apache.dubbo.rpc.protocol.dubbo.support.NonSerialized)1