Remove unused exceptions
[controller.git] / opendaylight / md-sal / cds-access-client / src / test / java / org / opendaylight / controller / cluster / access / client / ConnectingClientConnectionTest.java
index 2d5b696..911f349 100644 (file)
@@ -16,12 +16,14 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 
 import akka.actor.ActorRef;
 import akka.actor.ActorSystem;
 import akka.testkit.TestProbe;
+import com.google.common.testing.FakeTicker;
 import java.util.Optional;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.TimeUnit;
@@ -43,7 +45,7 @@ import org.opendaylight.controller.cluster.access.concepts.RequestEnvelope;
 import org.opendaylight.controller.cluster.access.concepts.RequestException;
 import org.opendaylight.controller.cluster.access.concepts.RequestFailure;
 import org.opendaylight.controller.cluster.access.concepts.Response;
-import org.opendaylight.controller.cluster.common.actor.TestTicker;
+import org.opendaylight.controller.cluster.messaging.MessageSlicer;
 import org.opendaylight.yangtools.concepts.WritableIdentifier;
 import scala.concurrent.duration.FiniteDuration;
 
@@ -109,7 +111,7 @@ public class ConnectingClientConnectionTest {
     @Mock
     private ClientActorContext mockContext;
 
-    private TestTicker ticker;
+    private FakeTicker ticker;
     private BackendInfo mockBackendInfo;
     private MockRequest mockRequest;
     private MockRequest mockRequest2;
@@ -138,10 +140,15 @@ public class ConnectingClientConnectionTest {
 
         doNothing().when(mockCallback).accept(any(MockFailure.class));
 
-        ticker = new TestTicker();
-        ticker.increment(ThreadLocalRandom.current().nextLong());
+        ticker = new FakeTicker();
+        ticker.advance(ThreadLocalRandom.current().nextLong());
         doReturn(ticker).when(mockContext).ticker();
 
+        final ClientActorConfig mockConfig = AccessClientUtil.newMockClientActorConfig();
+        doReturn(mockConfig).when(mockContext).config();
+
+        doReturn(mock(MessageSlicer.class)).when(mockContext).messageSlicer();
+
         mockActor = TestProbe.apply(actorSystem);
         mockBackendInfo = new BackendInfo(mockActor.ref(), 0, ABIVersion.current(), 5);
         mockRequest = new MockRequest(mockIdentifier, mockReplyTo);
@@ -191,7 +198,7 @@ public class ConnectingClientConnectionTest {
     @Test
     public void testSendRequestNeedsBackend() {
         queue.sendRequest(mockRequest, mockCallback);
-        final Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+        final Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertTrue(ret.isPresent());
     }
@@ -207,67 +214,67 @@ public class ConnectingClientConnectionTest {
         setupBackend();
 
         queue.sendRequest(mockRequest, mockCallback);
-        final Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+        final Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertTrue(ret.isPresent());
         assertTransmit(mockRequest, 0);
     }
 
     @Test
-    public void testRunTimeoutEmpty() throws NoProgressException {
-        Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+    public void testRunTimeoutEmpty() {
+        Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertFalse(ret.isPresent());
     }
 
     @Test
-    public void testRunTimeoutWithoutShift() throws NoProgressException {
+    public void testRunTimeoutWithoutShift() {
         queue.sendRequest(mockRequest, mockCallback);
-        Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+        Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertTrue(ret.isPresent());
     }
 
     @Test
-    public void testRunTimeoutWithTimeoutLess() throws NoProgressException {
+    public void testRunTimeoutWithTimeoutLess() {
         queue.sendRequest(mockRequest, mockCallback);
 
-        ticker.increment(AbstractClientConnection.REQUEST_TIMEOUT_NANOS - 1);
+        ticker.advance(AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS - 1);
 
-        Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+        Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertTrue(ret.isPresent());
     }
 
     @Test
-    public void testRunTimeoutWithTimeoutExact() throws NoProgressException {
+    public void testRunTimeoutWithTimeoutExact() {
         setupBackend();
 
         queue.sendRequest(mockRequest, mockCallback);
 
-        ticker.increment(AbstractClientConnection.REQUEST_TIMEOUT_NANOS);
+        ticker.advance(AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS);
 
-        Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+        Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNull(ret);
     }
 
     @Test
-    public void testRunTimeoutWithTimeoutMore() throws NoProgressException {
+    public void testRunTimeoutWithTimeoutMore() {
         setupBackend();
 
         queue.sendRequest(mockRequest, mockCallback);
 
-        ticker.increment(AbstractClientConnection.REQUEST_TIMEOUT_NANOS + 1);
+        ticker.advance(AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS + 1);
 
-        Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+        Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNull(ret);
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    public void testRunTimeoutWithoutProgressExact() throws NoProgressException {
+    public void testRunTimeoutWithoutProgressExact() {
         queue.sendRequest(mockRequest, mockCallback);
 
-        ticker.increment(AbstractClientConnection.NO_PROGRESS_TIMEOUT_NANOS);
+        ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS);
 
         // Kaboom
         queue.runTimer((ClientActorBehavior) mockBehavior);
@@ -275,10 +282,10 @@ public class ConnectingClientConnectionTest {
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    public void testRunTimeoutWithoutProgressMore() throws NoProgressException {
+    public void testRunTimeoutWithoutProgressMore() {
         queue.sendRequest(mockRequest, mockCallback);
 
-        ticker.increment(AbstractClientConnection.NO_PROGRESS_TIMEOUT_NANOS + 1);
+        ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS + 1);
 
         // Kaboom
         queue.runTimer((ClientActorBehavior) mockBehavior);
@@ -286,21 +293,21 @@ public class ConnectingClientConnectionTest {
     }
 
     @Test
-    public void testRunTimeoutEmptyWithoutProgressExact() throws NoProgressException {
-        ticker.increment(AbstractClientConnection.NO_PROGRESS_TIMEOUT_NANOS);
+    public void testRunTimeoutEmptyWithoutProgressExact() {
+        ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS);
 
         // No problem
-        Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+        Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertFalse(ret.isPresent());
     }
 
     @Test
-    public void testRunTimeoutEmptyWithoutProgressMore() throws NoProgressException {
-        ticker.increment(AbstractClientConnection.NO_PROGRESS_TIMEOUT_NANOS + 1);
+    public void testRunTimeoutEmptyWithoutProgressMore() {
+        ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS + 1);
 
         // No problem
-        Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+        Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNotNull(ret);
         assertFalse(ret.isPresent());
     }
@@ -337,26 +344,28 @@ public class ConnectingClientConnectionTest {
     }
 
     @Test
-    public void testProgressRecord() throws NoProgressException {
+    public void testProgressRecord() {
         setupBackend();
 
         queue.sendRequest(mockRequest, mockCallback);
 
-        ticker.increment(10);
+        ticker.advance(10);
         queue.sendRequest(mockRequest2, mockCallback);
         queue.receiveResponse(mockResponseEnvelope);
 
-        ticker.increment(AbstractClientConnection.NO_PROGRESS_TIMEOUT_NANOS - 11);
+        ticker.advance(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS - 11);
 
-        Optional<FiniteDuration> ret = queue.checkTimeout(ticker.read());
+        Optional<Long> ret = queue.checkTimeout(ticker.read());
         assertNull(ret);
     }
 
     private void setupBackend() {
-        final ConnectedClientConnection<?> newConn = new ConnectedClientConnection<>(mockContext, mockCookie,
-                mockBackendInfo);
-        queue.setForwarder(new SimpleReconnectForwarder(newConn));
-        queue = newConn;
+        final ConnectingClientConnection<BackendInfo> connectingConn =
+                new ConnectingClientConnection<>(mockContext, mockCookie);
+        final ConnectedClientConnection<BackendInfo> connectedConn =
+                new ConnectedClientConnection<>(connectingConn, mockBackendInfo);
+        queue.setForwarder(new SimpleReconnectForwarder(connectedConn));
+        queue = connectedConn;
     }
 
     private void assertTransmit(final Request<?, ?> expected, final long sequence) {

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.