2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.access.client;
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;
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.RequestSuccess;
23 import org.opendaylight.controller.cluster.access.concepts.Response;
24 import org.opendaylight.controller.cluster.access.concepts.ResponseEnvelope;
25 import org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope;
26 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
28 public class ReconnectingClientConnectionTest
29 extends AbstractClientConnectionTest<ReconnectingClientConnection<BackendInfo>, BackendInfo> {
32 protected ReconnectingClientConnection<BackendInfo> createConnection() {
33 final BackendInfo backend = new BackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, 10);
35 final ConnectedClientConnection<BackendInfo> oldConnection =
36 new ConnectedClientConnection<>(context, 0L, backend);
37 return new ReconnectingClientConnection<>(oldConnection);
42 public void testReconnectConnection() throws Exception {
43 final ClientActorBehavior<BackendInfo> behavior = mock(ClientActorBehavior.class);
44 Assert.assertSame(behavior, connection.reconnectConnection(behavior));
49 public void testSendRequestReceiveResponse() throws Exception {
50 final Consumer<Response<?, ?>> callback = mock(Consumer.class);
51 final Request<?, ?> request = createRequest(replyToProbe.ref());
52 connection.sendRequest(request, callback);
53 backendProbe.expectNoMsg();
54 final LocalHistoryIdentifier historyId = new LocalHistoryIdentifier(CLIENT_ID, 0L);
55 final RequestSuccess<?, ?> message = new TransactionAbortSuccess(new TransactionIdentifier(historyId, 0L), 0L);
56 final ResponseEnvelope<?> envelope = new SuccessEnvelope(message, 0L, 0L, 0L);
57 connection.receiveResponse(envelope);
58 verify(callback, after(1000).never()).accept(any());