use of org.opendaylight.controller.md.sal.dom.api.DOMRpcException in project controller by opendaylight.
the class RpcBrokerTest method testExecuteRpcFailureWithException.
@Test
public void testExecuteRpcFailureWithException() {
new TestKit(node1) {
{
when(domRpcService1.invokeRpc(eq(TEST_RPC_TYPE), Mockito.<NormalizedNode<?, ?>>any())).thenReturn(Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("NOT FOUND")));
final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
rpcInvoker1.tell(executeMsg, getRef());
final Failure rpcResponse = expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
Assert.assertTrue(rpcResponse.cause() instanceof DOMRpcException);
}
};
}
use of org.opendaylight.controller.md.sal.dom.api.DOMRpcException in project controller by opendaylight.
the class DOMRpcServiceTestBugfix560 method test.
@Test
public void test() throws ExecutionException, InterruptedException {
// FIXME: This is made to only make sure instance identifier codec for path is instantiated.
domMountPointService.createMountPoint(BI_MOUNT_ID).addService(DOMRpcService.class, new DOMRpcService() {
@Override
public <T extends DOMRpcAvailabilityListener> ListenerRegistration<T> registerRpcListener(final T arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final SchemaPath arg0, final NormalizedNode<?, ?> arg1) {
final DOMRpcResult result = new DefaultDOMRpcResult((NormalizedNode<?, ?>) null);
return Futures.immediateCheckedFuture(result);
}
}).register();
final Optional<MountPoint> mountInstance = bindingMountPointService.getMountPoint(BA_MOUNT_ID);
assertTrue(mountInstance.isPresent());
final Optional<RpcConsumerRegistry> rpcRegistry = mountInstance.get().getService(RpcConsumerRegistry.class);
assertTrue(rpcRegistry.isPresent());
final OpendaylightTestRpcServiceService rpcService = rpcRegistry.get().getRpcService(OpendaylightTestRpcServiceService.class);
assertNotNull(rpcService);
try {
final Future<RpcResult<Void>> result = rpcService.rockTheHouse(new RockTheHouseInputBuilder().build());
assertTrue(result.get().isSuccessful());
} catch (final IllegalStateException ex) {
fail("OpendaylightTestRpcServiceService class doesn't contain rockTheHouse method!");
}
}
use of org.opendaylight.controller.md.sal.dom.api.DOMRpcException in project controller by opendaylight.
the class RoutedDOMRpcRoutingTableEntry method invokeRpc.
@Override
protected CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(final NormalizedNode<?, ?> input) {
final Optional<NormalizedNode<?, ?>> maybeKey = NormalizedNodes.findNode(input, keyId);
// Routing key is present, attempt to deliver as a routed RPC
if (maybeKey.isPresent()) {
final NormalizedNode<?, ?> key = maybeKey.get();
final Object value = key.getValue();
if (value instanceof YangInstanceIdentifier) {
final YangInstanceIdentifier iid = (YangInstanceIdentifier) value;
// Find a DOMRpcImplementation for a specific iid
final List<DOMRpcImplementation> specificImpls = getImplementations(iid);
if (specificImpls != null) {
return specificImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
}
LOG.debug("No implementation for context {} found will now look for wildcard id", iid);
// Find a DOMRpcImplementation for a wild card. Usually remote-rpc-connector would register an
// implementation this way
final List<DOMRpcImplementation> mayBeRemoteImpls = getImplementations(YangInstanceIdentifier.EMPTY);
if (mayBeRemoteImpls != null) {
return mayBeRemoteImpls.get(0).invokeRpc(DOMRpcIdentifier.create(getSchemaPath(), iid), input);
}
} else {
LOG.warn("Ignoring wrong context value {}", value);
}
}
final List<DOMRpcImplementation> impls = getImplementations(null);
if (impls != null) {
return impls.get(0).invokeRpc(globalRpcId, input);
} else {
return Futures.<DOMRpcResult, DOMRpcException>immediateFailedCheckedFuture(new DOMRpcImplementationNotAvailableException("No implementation of RPC %s available", getSchemaPath()));
}
}
use of org.opendaylight.controller.md.sal.dom.api.DOMRpcException in project controller by opendaylight.
the class RemoteRpcImplementationTest method testInvokeRpcWithNullInput.
/**
* 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(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, null);
assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
assertEquals(rpcOutput, result.getResult());
}
use of org.opendaylight.controller.md.sal.dom.api.DOMRpcException in project controller by opendaylight.
the class RemoteRpcImplementationTest method testInvokeRpcWithNoOutput.
/**
* 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(Futures.<DOMRpcResult, DOMRpcException>immediateCheckedFuture(rpcResult));
final CheckedFuture<DOMRpcResult, DOMRpcException> frontEndFuture = remoteRpcImpl1.invokeRpc(TEST_RPC_ID, invokeRpcInput);
assertTrue(frontEndFuture instanceof RemoteDOMRpcFuture);
final DOMRpcResult result = frontEndFuture.checkedGet(5, TimeUnit.SECONDS);
assertNull(result.getResult());
}
Aggregations