Simplify error checking in writeWithPendingDetection() 55/102755/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 21:33:28 +0000 (23:33 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 19 Oct 2022 07:28:38 +0000 (09:28 +0200)
We are only interested in seeing the failure, as we are guarateed to see
a completed future.

JIRA: NETCONF-905
Change-Id: I3fa0236592ff785be49e0cb69a20d7c08b9432e9
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java
netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java

index 01284e308a8e2b3636af9915b90e57cb02387da3..204f8e5df8a9156a715fb8372bed3752316c997a 100644 (file)
@@ -98,19 +98,19 @@ public final class AsyncSshHandlerWriter implements AutoCloseable {
                 // window resize write would try to write the message on an already locked channelSession,
                 // while the pending write was in progress from the write callback
                 synchronized (asyncInLock) {
+                    final var cause = future.getException();
                     if (LOG.isTraceEnabled()) {
-                        LOG.trace(
-                            "Ssh write request finished on channel: {} with result: {}: and ex:{}, message: {}",
-                            ctx.channel(), future.isWritten(), future.getException(), byteBufToString(byteBufMsg));
+                        LOG.trace("Ssh write request finished on channel: {} with ex: {}, message: {}", ctx.channel(),
+                            cause, byteBufToString(byteBufMsg));
                     }
 
                     // Notify success or failure
-                    if (future.isWritten()) {
-                        promise.setSuccess();
-                    } else {
+                    if (cause != null) {
                         LOG.warn("Ssh write request failed on channel: {} for message: {}", ctx.channel(),
-                                byteBufToString(byteBufMsg), future.getException());
-                        promise.setFailure(future.getException());
+                            byteBufToString(byteBufMsg), cause);
+                        promise.setFailure(cause);
+                    } else {
+                        promise.setSuccess();
                     }
 
                     //rescheduling message from queue after successfully sent
index b3f085b2930d83507eebddde3e26e877400c964d..e504c679ba5b3d0e04eba433f193f89208b1a91b 100644 (file)
@@ -218,7 +218,6 @@ public class AsyncSshHandlerTest {
         Futures.addCallback(stubAddListener(ioWriteFuture), new SuccessFutureListener<IoWriteFuture>() {
             @Override
             public void onSuccess(final SshFutureListener<IoWriteFuture> result) {
-                doReturn(false).when(ioWriteFuture).isWritten();
                 doReturn(new IllegalStateException()).when(ioWriteFuture).getException();
                 result.operationComplete(ioWriteFuture);
             }
@@ -407,7 +406,7 @@ public class AsyncSshHandlerTest {
     private static IoOutputStream getMockedIoOutputStream() throws IOException {
         final IoOutputStream mock = mock(IoOutputStream.class);
         final IoWriteFuture ioWriteFuture = mock(IoWriteFuture.class);
-        doReturn(true).when(ioWriteFuture).isWritten();
+        doReturn(null).when(ioWriteFuture).getException();
 
         Futures.addCallback(stubAddListener(ioWriteFuture), new SuccessFutureListener<IoWriteFuture>() {
             @Override