Search in sources :

Example 26 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class ExpiringCacheFactoryTest method constructCache.

@Override
protected Cache constructCache() {
    URL url = URL.valueOf(EXPIRING_CACHE_URL);
    Invocation invocation = new RpcInvocation();
    return getCacheFactory().getCache(url, invocation);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) URL(org.apache.dubbo.common.URL)

Example 27 with Invocation

use of org.apache.dubbo.rpc.Invocation in project dubbo by alibaba.

the class AbstractCacheFactoryTest method constructCache.

protected Cache constructCache() {
    URL url = URL.valueOf("test://test:11/test?cache=lru");
    Invocation invocation = new RpcInvocation();
    return getCacheFactory().getCache(url, invocation);
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) URL(org.apache.dubbo.common.URL)

Example 28 with Invocation

use of org.apache.dubbo.rpc.Invocation 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 29 with Invocation

use of org.apache.dubbo.rpc.Invocation 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 30 with Invocation

use of org.apache.dubbo.rpc.Invocation 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)

Aggregations

Invocation (org.apache.dubbo.rpc.Invocation)98 Test (org.junit.jupiter.api.Test)78 URL (org.apache.dubbo.common.URL)77 Invoker (org.apache.dubbo.rpc.Invoker)44 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)44 Result (org.apache.dubbo.rpc.Result)33 AppResponse (org.apache.dubbo.rpc.AppResponse)29 RpcException (org.apache.dubbo.rpc.RpcException)18 MockInvocation (org.apache.dubbo.rpc.support.MockInvocation)17 HashMap (java.util.HashMap)16 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)13 BlockMyInvoker (org.apache.dubbo.rpc.support.BlockMyInvoker)11 MyInvoker (org.apache.dubbo.rpc.support.MyInvoker)10 ArrayList (java.util.ArrayList)8 Person (org.apache.dubbo.rpc.support.Person)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 IMetricManager (com.alibaba.metrics.IMetricManager)5 Method (java.lang.reflect.Method)5 DemoService (org.apache.dubbo.monitor.dubbo.service.DemoService)5 FastCompass (com.alibaba.metrics.FastCompass)4