BUG-8494: do not attempt to reconnect ReconnectingClientConnection 88/58388/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 3 Jun 2017 02:16:00 +0000 (04:16 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 7 Jun 2017 08:20:30 +0000 (10:20 +0200)
If we are in reconnect state, we should never attempt to initiate
reconnection, as that would leave us without the timer running --
which is a problem since we need to be timing out requests which
are queued even as we are attempting to reconnect to the backend.

Change-Id: Ic955a2e5b743617c26cc72815df94d0c4584704c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 584be7bf6b41f2f8b01dd718aba8d3b6cf7426ef)

opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/AbstractClientConnection.java
opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ReconnectingClientConnection.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/AbstractClientConnectionTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/ConnectedClientConnectionTest.java
opendaylight/md-sal/cds-access-client/src/test/java/org/opendaylight/controller/cluster/access/client/ReconnectingClientConnectionTest.java

index 98442256c6ecbcc9f63f54586d05611a80797d36..abd668010a16ad09c3c0d573c0a0320cd59a9e85 100644 (file)
@@ -217,7 +217,7 @@ public abstract class AbstractClientConnection<T extends BackendInfo> {
             if (delay >= DEBUG_DELAY_NANOS) {
                 if (delay > MAX_DELAY_NANOS) {
                     LOG.info("Capping {} throttle delay from {} to {} seconds", this,
-                        TimeUnit.NANOSECONDS.toSeconds(delay), MAX_DELAY_SECONDS);
+                        TimeUnit.NANOSECONDS.toSeconds(delay), MAX_DELAY_SECONDS, new Throwable());
                     delay = MAX_DELAY_NANOS;
                 }
                 if (LOG.isDebugEnabled()) {
index b59c9e324ae96b73cf28dc568a1147c3603dc3ee..6a3ba276fbe2ac58d4df2ad0ac7b621dd8fe0122 100644 (file)
@@ -29,10 +29,16 @@ public final class ReconnectingClientConnection<T extends BackendInfo> extends A
         this.cause = Preconditions.checkNotNull(cause);
     }
 
+    @Override
+    long backendSilentTicks(final long now) {
+        // We do not want to reconnect this connection, as we need the timer to to keep running
+        return 0;
+    }
+
     @Override
     ClientActorBehavior<T> lockedReconnect(final ClientActorBehavior<T> current, final RequestException cause) {
         this.cause = Preconditions.checkNotNull(cause);
-        LOG.debug("Skipping reconnect of already-reconnecting connection {}", this);
+        LOG.warn("Skipping reconnect of already-reconnecting connection {}", this);
         return current;
     }
 
index 9fd3a21d8f7afde2def32f9b5376cbc38fcb710e..3a2abbe31cbb23493513c55aa20112989ccc8bd4 100644 (file)
@@ -117,15 +117,6 @@ public abstract class AbstractClientConnectionTest<T extends AbstractClientConne
         Assert.assertFalse(timeout.isPresent());
     }
 
-    @Test
-    public void testCheckTimeoutConnectionTimeouted() throws Exception {
-        final Consumer<Response<?, ?>> callback = mock(Consumer.class);
-        connection.sendRequest(createRequest(replyToProbe.ref()), callback);
-        final long now = context.ticker().read() + ConnectedClientConnection.BACKEND_ALIVE_TIMEOUT_NANOS;
-        final Optional<Long> timeout = connection.checkTimeout(now);
-        Assert.assertNull(timeout);
-    }
-
     @Test
     public void testCheckTimeout() throws Exception {
         final Consumer<Response<?, ?>> callback = mock(Consumer.class);
index e66512d041b3be2d8e50d5d9372bea5a04e4659e..29cac2315ebccd524f79dfbe1a99cd13990817dc 100644 (file)
@@ -12,13 +12,26 @@ import static org.mockito.Matchers.same;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
+import java.util.Optional;
+import java.util.function.Consumer;
+import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 import org.opendaylight.controller.cluster.access.concepts.RequestException;
+import org.opendaylight.controller.cluster.access.concepts.Response;
 
 public class ConnectedClientConnectionTest
         extends AbstractClientConnectionTest<ConnectedClientConnection<BackendInfo>, BackendInfo> {
 
+    @Test
+    public void testCheckTimeoutConnectionTimedout() throws Exception {
+        final Consumer<Response<?, ?>> callback = mock(Consumer.class);
+        connection.sendRequest(createRequest(replyToProbe.ref()), callback);
+        final long now = context.ticker().read() + ConnectedClientConnection.BACKEND_ALIVE_TIMEOUT_NANOS;
+        final Optional<Long> timeout = connection.checkTimeout(now);
+        Assert.assertNull(timeout);
+    }
+
     @Override
     protected ConnectedClientConnection<BackendInfo> createConnection() {
         final BackendInfo backend = new BackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, 10);
index b36dd7ccec2c39e5811aa08d82100507eb272e9e..a281b1208a3334b948fe7834fbdaeb6a5c0ce356 100644 (file)
@@ -12,6 +12,7 @@ import static org.mockito.Mockito.after;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 
+import java.util.Optional;
 import java.util.function.Consumer;
 import org.junit.Assert;
 import org.junit.Test;
@@ -29,6 +30,16 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier
 public class ReconnectingClientConnectionTest
         extends AbstractClientConnectionTest<ReconnectingClientConnection<BackendInfo>, BackendInfo> {
 
+    @Test
+    public void testCheckTimeoutConnectionTimedout() throws Exception {
+        final Consumer<Response<?, ?>> callback = mock(Consumer.class);
+        connection.sendRequest(createRequest(replyToProbe.ref()), callback);
+        final long now = context.ticker().read() + ConnectedClientConnection.BACKEND_ALIVE_TIMEOUT_NANOS;
+        final Optional<Long> timeout = connection.checkTimeout(now);
+        Assert.assertNotNull(timeout);
+        Assert.assertTrue(timeout.isPresent());
+    }
+
     @Override
     protected ReconnectingClientConnection<BackendInfo> createConnection() {
         final BackendInfo backend = new BackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, 10);