import org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DefaultDOMRpcException;
import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<DOMRpcResult> invokeRpc(final SchemaPath type, final NormalizedNode<?, ?> input) {
final ListenableFuture<RpcResult<NetconfMessage>> delegateFuture = communicator.sendRequest(
transformer.toRpcRequest(type, input), type.getLastComponent());
Futures.addCallback(delegateFuture, new FutureCallback<RpcResult<NetconfMessage>>() {
@Override
public void onSuccess(final RpcResult<NetconfMessage> result) {
- ret.set(result.isSuccessful() ? transformer.toRpcResult(result.getResult(), type)
- : new DefaultDOMRpcResult(result.getErrors()));
+ try {
+ ret.set(result.isSuccessful() ? transformer.toRpcResult(result.getResult(), type)
+ : new DefaultDOMRpcResult(result.getErrors()));
+ } catch (Exception cause) {
+ ret.setException(new DefaultDOMRpcException(
+ "Unable to parse rpc reply. type: " + type + " input: " + input, cause));
+ }
}
@Override
package org.opendaylight.netconf.sal.connect.netconf.sal;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import com.google.common.util.concurrent.Futures;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
+import java.util.concurrent.ExecutionException;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.opendaylight.mdsal.dom.api.DOMRpcResult;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.api.xml.XmlUtil;
+import org.opendaylight.netconf.sal.connect.api.MessageTransformer;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceCommunicator;
import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil;
expectedReply = transformer.toRpcResult(reply, path);
}
+ @Test
+ public void testDeadlock() throws Exception {
+ // when rpc is successful, but transformer fails for some reason
+ final MessageTransformer<NetconfMessage> failingTransformer = mock(MessageTransformer.class);
+ final RemoteDeviceCommunicator<NetconfMessage> communicatorMock = mock(RemoteDeviceCommunicator.class);
+ final NetconfMessage msg = null;
+ final RpcResult<NetconfMessage> result = RpcResultBuilder.success(msg).build();
+ when(communicatorMock.sendRequest(any(), any())).thenReturn(Futures.immediateFuture(result));
+ when(failingTransformer.toRpcResult(any(), any())).thenThrow(new RuntimeException("FAIL"));
+ final NetconfDeviceRpc failingRpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, communicatorMock, failingTransformer);
+ assertThrows(ExecutionException.class, () -> failingRpc.invokeRpc(path, mock(ContainerNode.class)).get());
+ assertThrows(ExecutionException.class, () -> failingRpc.invokeRpc(path, null).get());
+ }
+
@Test
public void testInvokeRpc() throws Exception {
NormalizedNode<?, ?> input = createNode("urn:ietf:params:xml:ns:netconf:base:1.0", "2011-06-01", "filter");