Simplify error checking in writeWithPendingDetection() 71/102771/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 18 Oct 2022 21:33:28 +0000 (23:33 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 20 Oct 2022 09:01:20 +0000 (11:01 +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>
(cherry picked from commit 7f08b1035520fcc0f60ab6c6ab6536366510a45f)

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 549bbe18cb96dc67e99bce2dff6134717f82601e..04f5e2fa7e1015db6e199ed67c9bc74c0024501f 100644 (file)
@@ -103,19 +103,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