Bug 8619: Introduce inheritance of progress trackers
[controller.git] / opendaylight / md-sal / cds-access-client / src / test / java / org / opendaylight / controller / cluster / access / client / ConnectedClientConnectionTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.access.client;
9
10 import static org.mockito.Matchers.any;
11 import static org.mockito.Matchers.same;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.verify;
14
15 import java.util.Optional;
16 import java.util.function.Consumer;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.opendaylight.controller.cluster.access.ABIVersion;
20 import org.opendaylight.controller.cluster.access.concepts.RequestException;
21 import org.opendaylight.controller.cluster.access.concepts.Response;
22
23 public class ConnectedClientConnectionTest
24         extends AbstractClientConnectionTest<ConnectedClientConnection<BackendInfo>, BackendInfo> {
25
26     @Test
27     public void testCheckTimeoutConnectionTimedout() throws Exception {
28         final Consumer<Response<?, ?>> callback = mock(Consumer.class);
29         connection.sendRequest(createRequest(replyToProbe.ref()), callback);
30         final long now = context.ticker().read() + ConnectedClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS;
31         final Optional<Long> timeout = connection.checkTimeout(now);
32         Assert.assertNull(timeout);
33     }
34
35     @Override
36     protected ConnectedClientConnection<BackendInfo> createConnection() {
37         final BackendInfo backend = new BackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, 10);
38         final ConnectingClientConnection<BackendInfo> connectingConn = new ConnectingClientConnection<>(context, 0L);
39         return  new ConnectedClientConnection<>(connectingConn, backend);
40     }
41
42     @Override
43     @Test
44     public void testReconnectConnection() throws Exception {
45         final ClientActorBehavior<BackendInfo> behavior = mock(ClientActorBehavior.class);
46         connection.lockedReconnect(behavior, mock(RequestException.class));
47         verify(behavior).reconnectConnection(same(connection), any(ReconnectingClientConnection.class));
48     }
49
50 }