BUG-8452: make NoShardLeaderException retriable
[controller.git] / opendaylight / md-sal / cds-access-client / src / test / java / org / opendaylight / controller / cluster / access / client / ReconnectingClientConnectionTest.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.Mockito.after;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.verify;
14
15 import java.util.function.Consumer;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.controller.cluster.access.ABIVersion;
19 import org.opendaylight.controller.cluster.access.commands.TransactionAbortSuccess;
20 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
21 import org.opendaylight.controller.cluster.access.concepts.Request;
22 import org.opendaylight.controller.cluster.access.concepts.RequestException;
23 import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
24 import org.opendaylight.controller.cluster.access.concepts.Response;
25 import org.opendaylight.controller.cluster.access.concepts.ResponseEnvelope;
26 import org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope;
27 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
28
29 public class ReconnectingClientConnectionTest
30         extends AbstractClientConnectionTest<ReconnectingClientConnection<BackendInfo>, BackendInfo> {
31
32     @Override
33     protected ReconnectingClientConnection<BackendInfo> createConnection() {
34         final BackendInfo backend = new BackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, 10);
35
36         final ConnectedClientConnection<BackendInfo> oldConnection =
37                 new ConnectedClientConnection<>(context, 0L, backend);
38         return new ReconnectingClientConnection<>(oldConnection, mock(RequestException.class));
39     }
40
41     @Override
42     @Test
43     public void testReconnectConnection() throws Exception {
44         final ClientActorBehavior<BackendInfo> behavior = mock(ClientActorBehavior.class);
45         Assert.assertSame(behavior, connection.lockedReconnect(behavior, mock(RequestException.class)));
46     }
47
48     @Override
49     @Test
50     public void testSendRequestReceiveResponse() throws Exception {
51         final Consumer<Response<?, ?>> callback = mock(Consumer.class);
52         final Request<?, ?> request = createRequest(replyToProbe.ref());
53         connection.sendRequest(request, callback);
54         backendProbe.expectNoMsg();
55         final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(CLIENT_ID, 0L);
56         final RequestSuccess<?, ?> message = new TransactionAbortSuccess(new TransactionIdentifier(historyId, 0L), 0L);
57         final ResponseEnvelope<?> envelope = new SuccessEnvelope(message, 0L, 0L, 0L);
58         connection.receiveResponse(envelope);
59         verify(callback, after(1000).never()).accept(any());
60     }
61 }