+ /**
+ * This test method invokes and executes the remote rpc.
+ */
+ @Test
+ public void testInvokeRpc() throws Exception {
+ final ContainerNode rpcOutput = makeRPCOutput("bar");
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
+
+ final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
+ (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
+
+ when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(
+ FluentFutures.immediateFluentFuture(rpcResult));
+
+ final ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
+ assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
+
+ final DOMRpcResult result = frontEndFuture.get(5, TimeUnit.SECONDS);
+ assertEquals(rpcOutput, result.getResult());
+ }
+
+ /**
+ * This test method invokes and executes the remote rpc.
+ */
+ @Test
+ public void testInvokeRpcWithNullInput() throws Exception {
+ final ContainerNode rpcOutput = makeRPCOutput("bar");
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
+
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
+ (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
+
+ when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(
+ FluentFutures.immediateFluentFuture(rpcResult));
+
+ ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, null);
+ assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
+
+ final DOMRpcResult result = frontEndFuture.get(5, TimeUnit.SECONDS);
+ assertEquals(rpcOutput, result.getResult());
+ }
+
+ /**
+ * This test method invokes and executes the remote rpc.
+ */
+ @Test
+ public void testInvokeRpcWithNoOutput() throws Exception {
+ final ContainerNode rpcOutput = null;
+ final DOMRpcResult rpcResult = new DefaultDOMRpcResult(rpcOutput);
+
+ final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
+ (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
+
+ when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(
+ FluentFutures.immediateFluentFuture(rpcResult));
+
+ final ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
+ assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
+
+ final DOMRpcResult result = frontEndFuture.get(5, TimeUnit.SECONDS);
+ assertNull(result.getResult());
+ }
+
+ /**
+ * This test method invokes and executes the remote rpc.
+ */
+ @SuppressWarnings({"checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows"})
+ @Test(expected = DOMRpcException.class)
+ public void testInvokeRpcWithRemoteFailedFuture() throws Throwable {
+ final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ final ArgumentCaptor<NormalizedNode<?, ?>> inputCaptor =
+ (ArgumentCaptor) ArgumentCaptor.forClass(NormalizedNode.class);
+
+ when(domRpcService2.invokeRpc(eq(TEST_RPC_TYPE), inputCaptor.capture())).thenReturn(
+ FluentFutures.immediateFailedFluentFuture(new RemoteDOMRpcException("Test Exception", null)));
+
+ final ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
+ assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
+
+ try {
+ frontEndFuture.get(5, TimeUnit.SECONDS);
+ } catch (ExecutionException e) {
+ throw e.getCause();
+ }
+ }
+
+ /**
+ * This test method invokes and tests exceptions when akka timeout occured
+ * Currently ignored since this test with current config takes around 15 seconds to complete.
+ */
+ @Ignore
+ @Test(expected = RemoteDOMRpcException.class)
+ public void testInvokeRpcWithAkkaTimeoutException() throws Exception {
+ final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
+ final ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
+ assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
+
+ frontEndFuture.get(20, TimeUnit.SECONDS);
+ }
+
+ /**
+ * This test method invokes remote rpc and lookup failed
+ * with runtime exception.
+ */
+ @Test(expected = DOMRpcException.class)
+ @SuppressWarnings({"checkstyle:AvoidHidingCauseException", "checkstyle:IllegalThrows"})
+ public void testInvokeRpcWithLookupException() throws Throwable {
+ final NormalizedNode<?, ?> invokeRpcInput = makeRPCInput("foo");
+
+ doThrow(new RuntimeException("test")).when(domRpcService2).invokeRpc(any(SchemaPath.class),
+ any(NormalizedNode.class));
+
+ final ListenableFuture<DOMRpcResult> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
+ assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);