Search in sources :

Example 11 with Invocation

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

the class AccessKeyAuthenticatorTest method testAuthenticateRequestNoSignature.

@Test
void testAuthenticateRequestNoSignature() {
    URL url = URL.valueOf("dubbo://10.10.10.10:2181").addParameter(Constants.ACCESS_KEY_ID_KEY, "ak").addParameter(CommonConstants.APPLICATION_KEY, "test").addParameter(Constants.SECRET_ACCESS_KEY_KEY, "sk");
    Invocation invocation = new RpcInvocation();
    AccessKeyAuthenticator helper = new AccessKeyAuthenticator();
    assertThrows(RpcAuthenticationException.class, () -> helper.authenticate(invocation, url));
}
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) Test(org.junit.jupiter.api.Test)

Example 12 with Invocation

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

the class AccessKeyAuthenticatorTest method testGetSignatureNoParameter.

@Test
void testGetSignatureNoParameter() {
    URL url = mock(URL.class);
    Invocation invocation = mock(Invocation.class);
    String secretKey = "123456";
    AccessKeyAuthenticator helper = new AccessKeyAuthenticator();
    String signature = helper.getSignature(url, invocation, secretKey, String.valueOf(System.currentTimeMillis()));
    assertNotNull(signature);
}
Also used : Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 13 with Invocation

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

the class ConsumerSignFilterTest method testAuthDisabled.

@Test
void testAuthDisabled() {
    URL url = mock(URL.class);
    Invoker invoker = mock(Invoker.class);
    Invocation invocation = mock(Invocation.class);
    when(invoker.getUrl()).thenReturn(url);
    ConsumerSignFilter consumerSignFilter = new ConsumerSignFilter();
    consumerSignFilter.invoke(invoker, invocation);
    verify(invocation, never()).setAttachment(eq(Constants.REQUEST_SIGNATURE_KEY), anyString());
}
Also used : Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test)

Example 14 with Invocation

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

the class DubboCodecSupport method getResponseSerialization.

public static Serialization getResponseSerialization(URL url, AppResponse appResponse) {
    Object invocationObj = appResponse.getAttribute(INVOCATION_KEY);
    if (invocationObj != null) {
        Invocation invocation = (Invocation) invocationObj;
        Object serializationTypeObj = invocation.get(SERIALIZATION_ID_KEY);
        if (serializationTypeObj != null) {
            return CodecSupport.getSerializationById((byte) serializationTypeObj);
        }
    }
    return ExtensionLoader.getExtensionLoader(Serialization.class).getExtension(url.getParameter(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION));
}
Also used : Serialization(org.apache.dubbo.common.serialize.Serialization) Invocation(org.apache.dubbo.rpc.Invocation)

Example 15 with Invocation

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

the class RpcUtilsTest method testIsAsync.

@Test
public void testIsAsync() {
    Object[] args = new Object[] { "hello", "dubbo", 520 };
    Class<?> demoServiceClass = DemoService.class;
    String serviceName = demoServiceClass.getName();
    Invoker invoker = mock(Invoker.class);
    URL url = URL.valueOf("test://127.0.0.1:1/org.apache.dubbo.rpc.support.DemoService?interface=org.apache.dubbo.rpc.support.DemoService");
    RpcInvocation inv = new RpcInvocation("test", serviceName, "", new Class<?>[] { String.class, String[].class, Object[].class }, new Object[] { "method", new String[] {}, args }, null, invoker, null);
    Assertions.assertFalse(RpcUtils.isAsync(url, inv));
    inv.setInvokeMode(InvokeMode.ASYNC);
    Assertions.assertTrue(RpcUtils.isAsync(url, inv));
    URL url1 = URL.valueOf("dubbo://localhost/?test.async=true");
    Invocation inv1 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    inv1.setAttachment("test." + ASYNC_KEY, Boolean.FALSE.toString());
    Assertions.assertFalse(RpcUtils.isAsync(url1, inv1));
    URL url2 = URL.valueOf("dubbo://localhost/?test.async=true");
    Invocation inv2 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    inv2.setAttachment(ASYNC_KEY, Boolean.FALSE.toString());
    Assertions.assertFalse(RpcUtils.isAsync(url2, inv2));
    URL url3 = URL.valueOf("dubbo://localhost/?test");
    Invocation inv3 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    inv3.setAttachment(ASYNC_KEY, Boolean.TRUE.toString());
    Assertions.assertTrue(RpcUtils.isAsync(url3, inv3));
    URL url4 = URL.valueOf("dubbo://localhost/?test.async=true");
    Invocation inv4 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    Assertions.assertTrue(RpcUtils.isAsync(url4, inv4));
    URL url5 = URL.valueOf("dubbo://localhost/?test");
    Invocation inv5 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    Assertions.assertFalse(RpcUtils.isAsync(url5, inv5));
    URL url6 = URL.valueOf("dubbo://localhost/?test");
    Invocation inv6 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    inv6.setAttachment("test." + ASYNC_KEY, Boolean.TRUE.toString());
    Assertions.assertTrue(RpcUtils.isAsync(url6, inv6));
    URL url7 = URL.valueOf("dubbo://localhost/?test.async=true&async=false");
    Invocation inv7 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    Assertions.assertTrue(RpcUtils.isAsync(url7, inv7));
    URL url8 = URL.valueOf("dubbo://localhost/?test.async=false&async=true");
    Invocation inv8 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    Assertions.assertFalse(RpcUtils.isAsync(url8, inv8));
    URL url9 = URL.valueOf("dubbo://localhost/?test.async=true");
    Invocation inv9 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    inv9.setAttachment("testB." + ASYNC_KEY, Boolean.FALSE.toString());
    Assertions.assertTrue(RpcUtils.isAsync(url9, inv9));
    URL url10 = URL.valueOf("dubbo://localhost/?test.async=true");
    Invocation inv10 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
    ((RpcInvocation) inv10).setInvokeMode(InvokeMode.ASYNC);
    Assertions.assertTrue(RpcUtils.isAsync(url10, inv9));
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) Invoker(org.apache.dubbo.rpc.Invoker) Invocation(org.apache.dubbo.rpc.Invocation) RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) URL(org.apache.dubbo.common.URL) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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