Search in sources :

Example 1 with MyInvoker

use of org.apache.dubbo.rpc.support.MyInvoker in project dubbo by alibaba.

the class AccessLogFilterTest method testInvokeException.

// Test filter won't throw an exception
@Test
public void testInvokeException() {
    Invoker<AccessLogFilterTest> invoker = new MyInvoker<AccessLogFilterTest>(null);
    Invocation invocation = new MockInvocation();
    LogUtil.start();
    accessLogFilter.invoke(invoker, invocation);
    assertEquals(1, LogUtil.findMessage("Exception in AccessLogFilter of service"));
    LogUtil.stop();
    DubboAppender.clear();
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) Test(org.junit.jupiter.api.Test)

Example 2 with MyInvoker

use of org.apache.dubbo.rpc.support.MyInvoker in project dubbo by alibaba.

the class AccessLogFilterTest method testDefault.

// TODO how to assert thread action
@Test
@SuppressWarnings("unchecked")
public void testDefault() throws NoSuchFieldException, IllegalAccessException {
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1");
    Invoker<AccessLogFilterTest> invoker = new MyInvoker<AccessLogFilterTest>(url);
    Invocation invocation = new MockInvocation();
    Field field = AccessLogFilter.class.getDeclaredField("LOG_ENTRIES");
    ReflectUtils.makeAccessible(field);
    assertTrue(((Map) field.get(AccessLogFilter.class)).isEmpty());
    accessLogFilter.invoke(invoker, invocation);
    Map<String, Queue<AccessLogData>> logs = (Map<String, Queue<AccessLogData>>) field.get(AccessLogFilter.class);
    assertFalse(logs.isEmpty());
    assertFalse(logs.get("true").isEmpty());
    AccessLogData log = logs.get("true").iterator().next();
    assertEquals("org.apache.dubbo.rpc.support.DemoService", log.getServiceName());
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) URL(org.apache.dubbo.common.URL) Field(java.lang.reflect.Field) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) AccessLogData(org.apache.dubbo.rpc.support.AccessLogData) Queue(java.util.Queue) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with MyInvoker

use of org.apache.dubbo.rpc.support.MyInvoker in project dubbo by alibaba.

the class ClassLoaderFilterTest method testInvoke.

@Test
public void testInvoke() throws Exception {
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1");
    String path = DemoService.class.getResource("/").getPath();
    final URLClassLoader cl = new URLClassLoader(new java.net.URL[] { new java.net.URL("file:" + path) }) {

        @Override
        public Class<?> loadClass(String name) throws ClassNotFoundException {
            try {
                return findClass(name);
            } catch (ClassNotFoundException e) {
                return super.loadClass(name);
            }
        }
    };
    final Class<?> clazz = cl.loadClass(DemoService.class.getCanonicalName());
    Invoker invoker = new MyInvoker(url) {

        @Override
        public Class getInterface() {
            return clazz;
        }

        @Override
        public Result invoke(Invocation invocation) throws RpcException {
            Assertions.assertEquals(cl, Thread.currentThread().getContextClassLoader());
            return null;
        }
    };
    Invocation invocation = Mockito.mock(Invocation.class);
    classLoaderFilter.invoke(invoker, invocation);
}
Also used : MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) URLClassLoader(java.net.URLClassLoader) DemoService(org.apache.dubbo.rpc.support.DemoService) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 4 with MyInvoker

use of org.apache.dubbo.rpc.support.MyInvoker in project dubbo by alibaba.

the class ActiveLimitFilterTest method testInvokeLessActives.

@Test
public void testInvokeLessActives() {
    URL url = URL.valueOf("test://test:11/test?accesslog=true&group=dubbo&version=1.1&actives=10");
    Invoker<ActiveLimitFilterTest> invoker = new MyInvoker<ActiveLimitFilterTest>(url);
    Invocation invocation = new MockInvocation();
    activeLimitFilter.invoke(invoker, invocation);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) BlockMyInvoker(org.apache.dubbo.rpc.support.BlockMyInvoker) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 5 with MyInvoker

use of org.apache.dubbo.rpc.support.MyInvoker in project dubbo by alibaba.

the class TpsLimitFilterTest method testFail.

@Test
public void testFail() throws Exception {
    Assertions.assertThrows(RpcException.class, () -> {
        URL url = URL.valueOf("test://test");
        url = url.addParameter(INTERFACE_KEY, "org.apache.dubbo.rpc.file.TpsService");
        url = url.addParameter(TPS_LIMIT_RATE_KEY, 5);
        Invoker<TpsLimitFilterTest> invoker = new MyInvoker<TpsLimitFilterTest>(url);
        Invocation invocation = new MockInvocation();
        for (int i = 0; i < 10; i++) {
            try {
                filter.invoke(invoker, invocation);
            } catch (Exception e) {
                assertTrue(i >= 5);
                throw e;
            }
        }
    });
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MockInvocation(org.apache.dubbo.rpc.support.MockInvocation) MyInvoker(org.apache.dubbo.rpc.support.MyInvoker) URL(org.apache.dubbo.common.URL) RpcException(org.apache.dubbo.rpc.RpcException) Test(org.junit.jupiter.api.Test)

Aggregations

MyInvoker (org.apache.dubbo.rpc.support.MyInvoker)10 Test (org.junit.jupiter.api.Test)10 URL (org.apache.dubbo.common.URL)9 Invocation (org.apache.dubbo.rpc.Invocation)9 MockInvocation (org.apache.dubbo.rpc.support.MockInvocation)8 DemoService (org.apache.dubbo.rpc.support.DemoService)3 BlockMyInvoker (org.apache.dubbo.rpc.support.BlockMyInvoker)2 Field (java.lang.reflect.Field)1 URLClassLoader (java.net.URLClassLoader)1 Map (java.util.Map)1 Queue (java.util.Queue)1 Invoker (org.apache.dubbo.rpc.Invoker)1 Result (org.apache.dubbo.rpc.Result)1 RpcException (org.apache.dubbo.rpc.RpcException)1 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)1 AccessLogData (org.apache.dubbo.rpc.support.AccessLogData)1