InitParams params = new InitParams();
ValueParam paramConf = new ValueParam();
paramConf.setName(RPCServiceImpl.PARAM_JGROUPS_CONFIG);
paramConf.setValue("jar:/conf/portal/udp.xml");
params.addParameter(paramConf);
RPCServiceImpl service = null;
try
{
service = new RPCServiceImpl(container.getContext(), params, configManager);
RemoteCommand getName = service.registerCommand(new SingleMethodCallCommand(myService, "getName"));
RemoteCommand add = service.registerCommand(new SingleMethodCallCommand(myService, "add", int.class));
RemoteCommand evaluate1 = service.registerCommand(new SingleMethodCallCommand(myService, "evaluate", int[].class));
RemoteCommand evaluate2 = service.registerCommand(new SingleMethodCallCommand(myService, "evaluate", List.class));
RemoteCommand total1 = service.registerCommand(new SingleMethodCallCommand(myService, "total", int.class));
RemoteCommand total2 = service.registerCommand(new SingleMethodCallCommand(myService, "total", int.class, int.class));
RemoteCommand total3 = service.registerCommand(new SingleMethodCallCommand(myService, "total", int[].class));
RemoteCommand total4 = service.registerCommand(new SingleMethodCallCommand(myService, "total", String.class, long.class, int[].class));
RemoteCommand testTypes1 = service.registerCommand(new SingleMethodCallCommand(myService, "testTypes", String[].class));
RemoteCommand testTypes2 = service.registerCommand(new SingleMethodCallCommand(myService, "testTypes", int[].class));
RemoteCommand testTypes3 = service.registerCommand(new SingleMethodCallCommand(myService, "testTypes", long[].class));
RemoteCommand testTypes4 = service.registerCommand(new SingleMethodCallCommand(myService, "testTypes", byte[].class));
RemoteCommand testTypes5 = service.registerCommand(new SingleMethodCallCommand(myService, "testTypes", short[].class));
RemoteCommand testTypes6 = service.registerCommand(new SingleMethodCallCommand(myService, "testTypes", char[].class));
RemoteCommand testTypes7 = service.registerCommand(new SingleMethodCallCommand(myService, "testTypes", double[].class));
RemoteCommand testTypes8 = service.registerCommand(new SingleMethodCallCommand(myService, "testTypes", float[].class));
RemoteCommand testTypes9 = service.registerCommand(new SingleMethodCallCommand(myService, "testTypes", boolean[].class));
service.start();
List<Object> result;
assertEquals("name", service.executeCommandOnCoordinator(getName, true));
result = service.executeCommandOnAllNodes(getName, true);
assertTrue(result != null && result.size() == 1);
assertEquals("name", result.get(0));
assertEquals(10, service.executeCommandOnCoordinator(add, true, 10));
result = service.executeCommandOnAllNodes(add, true, 10);
assertTrue(result != null && result.size() == 1);
assertEquals(20, result.get(0));
assertEquals(100, service.executeCommandOnCoordinator(evaluate1, true, new int[]{10, 10, 10, 30, 40}));
result = service.executeCommandOnAllNodes(evaluate1, true, new int[]{10, 10, 10, 30, 40});
assertTrue(result != null && result.size() == 1);
assertEquals(100, result.get(0));
List<Integer> values = new ArrayList<Integer>();
values.add(10);
values.add(10);
values.add(10);
values.add(30);
values.add(40);
assertEquals(100, service.executeCommandOnCoordinator(evaluate2, true, (Serializable)values));
result = service.executeCommandOnAllNodes(evaluate2, true, (Serializable)values);
assertTrue(result != null && result.size() == 1);
assertEquals(100, result.get(0));
assertEquals(10, service.executeCommandOnCoordinator(total1, true, 10));
result = service.executeCommandOnAllNodes(total1, true, 10);
assertTrue(result != null && result.size() == 1);
assertEquals(10, result.get(0));
assertEquals(20, service.executeCommandOnCoordinator(total2, true, 10, 10));
result = service.executeCommandOnAllNodes(total2, true, 10, 10);
assertTrue(result != null && result.size() == 1);
assertEquals(20, result.get(0));
assertEquals(100, service.executeCommandOnCoordinator(total3, true, new int[]{10, 10, 10, 30, 40}));
result = service.executeCommandOnAllNodes(total3, true, new int[]{10, 10, 10, 30, 40});
assertTrue(result != null && result.size() == 1);
assertEquals(100, result.get(0));
assertEquals(100, service.executeCommandOnCoordinator(total4, true, "foo", 50, new int[]{10, 10, 10, 30, 40}));
result = service.executeCommandOnAllNodes(total4, true, "foo", 50, new int[]{10, 10, 10, 30, 40});
assertTrue(result != null && result.size() == 1);
assertEquals(100, result.get(0));
assertEquals(0, service.executeCommandOnCoordinator(total4, true, "foo", 50, null));
result = service.executeCommandOnAllNodes(total4, true, "foo", 50, null);
assertTrue(result != null && result.size() == 1);
assertEquals(0, result.get(0));
try
{
service.executeCommandOnCoordinator(total4, true, "foo", 50);
fail("We expect a RPCException since the list of arguments mismatch with what is expected");
}
catch (RPCException e)
{
// OK
}
result = service.executeCommandOnAllNodes(total4, true, "foo", 50);
assertTrue(result != null && result.size() == 1);
assertTrue("We expect a RPCException since the list of arguments mismatch with what is expected", result.get(0) instanceof RPCException);
assertEquals("foo", service.executeCommandOnCoordinator(testTypes1, true, (Serializable)new String[]{"foo"}));
result = service.executeCommandOnAllNodes(testTypes1, true, (Serializable)new String[]{"foo"});
assertTrue(result != null && result.size() == 1);
assertEquals("foo", result.get(0));
assertEquals(10, service.executeCommandOnCoordinator(testTypes2, true, new int[]{10}));
result = service.executeCommandOnAllNodes(testTypes2, true, new int[]{10});
assertTrue(result != null && result.size() == 1);
assertEquals(10, result.get(0));
assertEquals(11L, service.executeCommandOnCoordinator(testTypes3, true, new long[]{10}));
result = service.executeCommandOnAllNodes(testTypes3, true, new long[]{10});
assertTrue(result != null && result.size() == 1);
assertEquals(11L, result.get(0));
assertEquals((byte)12, service.executeCommandOnCoordinator(testTypes4, true, new byte[]{10}));
result = service.executeCommandOnAllNodes(testTypes4, true, new byte[]{10});
assertTrue(result != null && result.size() == 1);
assertEquals((byte)12, result.get(0));
assertEquals((short)13, service.executeCommandOnCoordinator(testTypes5, true, new short[]{10}));
result = service.executeCommandOnAllNodes(testTypes5, true, new short[]{10});
assertTrue(result != null && result.size() == 1);
assertEquals((short)13, result.get(0));
assertEquals('a', service.executeCommandOnCoordinator(testTypes6, true, new char[]{'a'}));
result = service.executeCommandOnAllNodes(testTypes6, true, new char[]{'a'});
assertTrue(result != null && result.size() == 1);
assertEquals('a', result.get(0));
assertEquals(10.5, service.executeCommandOnCoordinator(testTypes7, true, new double[]{10}));
result = service.executeCommandOnAllNodes(testTypes7, true, new double[]{10});
assertTrue(result != null && result.size() == 1);
assertEquals(10.5, result.get(0));
assertEquals((float)11.5, service.executeCommandOnCoordinator(testTypes8, true, new float[]{10}));
result = service.executeCommandOnAllNodes(testTypes8, true, new float[]{10});
assertTrue(result != null && result.size() == 1);
assertEquals((float)11.5, result.get(0));
assertEquals(true, service.executeCommandOnCoordinator(testTypes9, true, new boolean[]{true}));
result = service.executeCommandOnAllNodes(testTypes9, true, new boolean[]{true});
assertTrue(result != null && result.size() == 1);
assertEquals(true, result.get(0));
}
finally
{
if (service != null)
{
service.stop();
}
}
}