use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project controller by opendaylight.
the class RemoteOpsImplementationTest method testInvokeRpcWithLookupException.
/**
* 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(QName.class), any(NormalizedNode.class));
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();
}
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project controller by opendaylight.
the class OpsInvoker method execute.
@SuppressWarnings("checkstyle:IllegalCatch")
private void execute(final ExecuteRpc msg) {
LOG.debug("Executing RPC {}", msg.getType());
final ActorRef sender = getSender();
final ListenableFuture<? extends DOMRpcResult> future;
try {
future = rpcService.invokeRpc(msg.getType(), msg.getInput());
} catch (final RuntimeException e) {
LOG.debug("Failed to invoke RPC {}", msg.getType(), e);
sender.tell(new Failure(e), self());
return;
}
Futures.addCallback(future, new AbstractCallback<QName, DOMRpcResult>(getSender(), msg.getType()) {
@Override
Object nullResponse(final QName type) {
LOG.warn("Execution of {} resulted in null result", type);
return new RpcResponse(null);
}
@Override
Object response(final QName type, final DOMRpcResult result) {
final Collection<? extends RpcError> errors = result.getErrors();
return errors.isEmpty() ? new RpcResponse(result.getResult()) : // discarding any output
new Failure(new RpcErrorsException(String.format("Execution of rpc %s failed", type), errors));
}
}, MoreExecutors.directExecutor());
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class NetconfDeviceRpcTest method testInvokeRpc.
@Test
public void testInvokeRpc() throws Exception {
ContainerNode input = createNode("urn:ietf:params:xml:ns:netconf:base:1.0", "2011-06-01", "filter");
final DOMRpcResult result = rpc.invokeRpc(type, input).get();
assertEquals(expectedReply.getResult().getIdentifier(), result.getResult().getIdentifier());
assertEquals(resolveNode(expectedReply), resolveNode(result));
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class KeepaliveSalFacadeResponseWaitingTest method testKeepaliveSalResponseWaiting.
/**
* Not sending keepalive rpc test while the repsonse is processing.
*/
@Test
public void testKeepaliveSalResponseWaiting() {
// This settable future object will be never set to any value. The test wants to simulate waiting for the result
// of the future object.
final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
doReturn(settableFuture).when(deviceRpc).invokeRpc(null, null);
// This settable future will be used to check the invokation of keepalive RPC. Should be never invoked.
final SettableFuture<DOMRpcResult> keepaliveSettableFuture = SettableFuture.create();
final DOMRpcResult keepaliveResult = new DefaultDOMRpcResult(Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME)).build());
keepaliveSettableFuture.set(keepaliveResult);
keepaliveSalFacade.onDeviceConnected(null, null, deviceRpc);
// Invoke general RPC on simulated local facade without args (or with null args). Will be returned
// settableFuture variable without any set value. WaitingShaduler in keepalive sal facade should wait for any
// result from the RPC and reset keepalive scheduler.
underlyingSalFacade.invokeNullRpc();
// Invoking of general RPC.
verify(deviceRpc, after(2000).times(1)).invokeRpc(null, null);
// verify the keepalive RPC invoke. Should be never happen.
verify(deviceRpc, after(2000).never()).invokeRpc(NETCONF_GET_CONFIG_QNAME, KEEPALIVE_PAYLOAD);
}
use of org.opendaylight.mdsal.dom.api.DOMRpcResult in project netconf by opendaylight.
the class KeepaliveSalFacadeTest method testKeepaliveSuccess.
@Test
public void testKeepaliveSuccess() throws Exception {
final DOMRpcResult result = new DefaultDOMRpcResult(Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NetconfMessageTransformUtil.NETCONF_RUNNING_QNAME)).build());
doReturn(FluentFutures.immediateFluentFuture(result)).when(deviceRpc).invokeRpc(any(QName.class), any(ContainerNode.class));
keepaliveSalFacade.onDeviceConnected(null, null, deviceRpc);
verify(underlyingSalFacade).onDeviceConnected(isNull(), isNull(), any(DOMRpcService.class), isNull());
verify(deviceRpc, timeout(15000).times(5)).invokeRpc(any(QName.class), any(ContainerNode.class));
}
Aggregations