From 7f08b1035520fcc0f60ab6c6ab6536366510a45f Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 18 Oct 2022 23:33:28 +0200 Subject: [PATCH] Simplify error checking in writeWithPendingDetection() 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 --- .../ssh/client/AsyncSshHandlerWriter.java | 16 ++++++++-------- .../handler/ssh/client/AsyncSshHandlerTest.java | 3 +-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java index 01284e308a..204f8e5df8 100644 --- a/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java +++ b/netconf/netconf-netty-util/src/main/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerWriter.java @@ -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 diff --git a/netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java b/netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java index b3f085b293..e504c679ba 100644 --- a/netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java +++ b/netconf/netconf-netty-util/src/test/java/org/opendaylight/netconf/nettyutil/handler/ssh/client/AsyncSshHandlerTest.java @@ -218,7 +218,6 @@ public class AsyncSshHandlerTest { Futures.addCallback(stubAddListener(ioWriteFuture), new SuccessFutureListener() { @Override public void onSuccess(final SshFutureListener 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() { @Override -- 2.36.6