use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RpcUtilsTest method testAttachInvocationIdIfAsync_forceAttache.
/**
* scenario: explicitly configure to add attachment
* verify: id attribute added in attachment
*/
@Test
public void testAttachInvocationIdIfAsync_forceAttache() {
URL url = URL.valueOf("dubbo://localhost/?" + AUTO_ATTACH_INVOCATIONID_KEY + "=true");
Invocation inv = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
assertNotNull(RpcUtils.getInvocationId(inv));
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RpcUtilsTest method testIsOneway.
@Test
public void testIsOneway() {
URL url1 = URL.valueOf("dubbo://localhost/?test.return=false");
Invocation inv1 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv1.setAttachment("test." + RETURN_KEY, Boolean.TRUE.toString());
Assertions.assertFalse(RpcUtils.isOneway(url1, inv1));
URL url2 = URL.valueOf("dubbo://localhost/?test.return=false");
Invocation inv2 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv2.setAttachment(RETURN_KEY, Boolean.TRUE.toString());
Assertions.assertFalse(RpcUtils.isOneway(url2, inv2));
URL url3 = URL.valueOf("dubbo://localhost/?test");
Invocation inv3 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv3.setAttachment(RETURN_KEY, Boolean.FALSE.toString());
Assertions.assertTrue(RpcUtils.isOneway(url3, inv3));
URL url4 = URL.valueOf("dubbo://localhost/?test.return=false");
Invocation inv4 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
Assertions.assertTrue(RpcUtils.isOneway(url4, inv4));
URL url5 = URL.valueOf("dubbo://localhost/?test");
Invocation inv5 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
Assertions.assertFalse(RpcUtils.isOneway(url5, inv5));
URL url6 = URL.valueOf("dubbo://localhost/?test");
Invocation inv6 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv6.setAttachment("test." + RETURN_KEY, Boolean.FALSE.toString());
Assertions.assertTrue(RpcUtils.isOneway(url6, inv6));
URL url7 = URL.valueOf("dubbo://localhost/?test");
Invocation inv7 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv7.setAttachment("testB." + RETURN_KEY, Boolean.FALSE.toString());
Assertions.assertFalse(RpcUtils.isOneway(url7, inv7));
URL url8 = URL.valueOf("dubbo://localhost/?test");
Invocation inv8 = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
inv8.setAttachment(RETURN_KEY, Boolean.FALSE.toString());
inv8.setAttachment("test." + RETURN_KEY, Boolean.TRUE.toString());
Assertions.assertFalse(RpcUtils.isOneway(url8, inv8));
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RpcUtilsTest method testAttachInvocationIdIfAsync_normal.
/**
* regular scenario: async invocation in URL
* verify: 1. whether invocationId is set correctly, 2. idempotent or not
*/
@Test
public void testAttachInvocationIdIfAsync_normal() {
URL url = URL.valueOf("dubbo://localhost/?test.async=true");
Map<String, Object> attachments = new HashMap<>();
attachments.put("aa", "bb");
Invocation inv = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {}, attachments);
RpcUtils.attachInvocationIdIfAsync(url, inv);
long id1 = RpcUtils.getInvocationId(inv);
RpcUtils.attachInvocationIdIfAsync(url, inv);
long id2 = RpcUtils.getInvocationId(inv);
// verify if it's idempotent
assertEquals(id1, id2);
assertTrue(id1 >= 0);
assertEquals("bb", attachments.get("aa"));
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RpcUtilsTest method testAttachInvocationIdIfAsync_forceNotAttache.
/**
* scenario: explicitly configure to not add attachment
* verify: no id attribute added in attachment
*/
@Test
public void testAttachInvocationIdIfAsync_forceNotAttache() {
URL url = URL.valueOf("dubbo://localhost/?test.async=true&" + AUTO_ATTACH_INVOCATIONID_KEY + "=false");
Invocation inv = new RpcInvocation("test", "DemoService", "", new Class[] {}, new String[] {});
RpcUtils.attachInvocationIdIfAsync(url, inv);
assertNull(RpcUtils.getInvocationId(inv));
}
use of org.apache.dubbo.rpc.RpcInvocation in project dubbo by alibaba.
the class RpcUtilsTest method testGetParameterTypes.
@Test
public void testGetParameterTypes() {
Class<?> demoServiceClass = DemoService.class;
String serviceName = demoServiceClass.getName();
Invoker invoker = mock(Invoker.class);
// void sayHello(String name);
RpcInvocation inv1 = new RpcInvocation("sayHello", serviceName, "", new Class<?>[] { String.class }, null, null, invoker, null);
Class<?>[] parameterTypes1 = RpcUtils.getParameterTypes(inv1);
Assertions.assertNotNull(parameterTypes1);
Assertions.assertEquals(1, parameterTypes1.length);
Assertions.assertEquals(String.class, parameterTypes1[0]);
// long timestamp();
RpcInvocation inv2 = new RpcInvocation("timestamp", serviceName, "", null, null, null, invoker, null);
Class<?>[] parameterTypes2 = RpcUtils.getParameterTypes(inv2);
Assertions.assertEquals(0, parameterTypes2.length);
// Type enumlength(Type... types);
RpcInvocation inv3 = new RpcInvocation("enumlength", serviceName, "", new Class<?>[] { Type.class, Type.class }, null, null, invoker, null);
Class<?>[] parameterTypes3 = RpcUtils.getParameterTypes(inv3);
Assertions.assertNotNull(parameterTypes3);
Assertions.assertEquals(2, parameterTypes3.length);
Assertions.assertEquals(Type.class, parameterTypes3[0]);
Assertions.assertEquals(Type.class, parameterTypes3[1]);
// byte getbyte(byte arg);
RpcInvocation inv4 = new RpcInvocation("getbyte", serviceName, "", new Class<?>[] { byte.class }, null, null, invoker, null);
Class<?>[] parameterTypes4 = RpcUtils.getParameterTypes(inv4);
Assertions.assertNotNull(parameterTypes4);
Assertions.assertEquals(1, parameterTypes4.length);
Assertions.assertEquals(byte.class, parameterTypes4[0]);
// void $invoke(String s1, String s2);
RpcInvocation inv5 = new RpcInvocation("$invoke", serviceName, "", new Class<?>[] { String.class, String[].class }, new Object[] { "method", new String[] { "java.lang.String", "void", "java.lang.Object" } }, null, invoker, null);
Class<?>[] parameterTypes5 = RpcUtils.getParameterTypes(inv5);
Assertions.assertNotNull(parameterTypes5);
Assertions.assertEquals(3, parameterTypes5.length);
Assertions.assertEquals(String.class, parameterTypes5[0]);
Assertions.assertEquals(String.class, parameterTypes5[1]);
Assertions.assertEquals(String.class, parameterTypes5[2]);
}
Aggregations