Slice front-end request messages
[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.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.verify;
15
16 import java.util.Optional;
17 import java.util.function.Consumer;
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.opendaylight.controller.cluster.access.ABIVersion;
21 import org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder;
22 import org.opendaylight.controller.cluster.access.commands.TransactionWrite;
23 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
24 import org.opendaylight.controller.cluster.access.concepts.Request;
25 import org.opendaylight.controller.cluster.access.concepts.RequestException;
26 import org.opendaylight.controller.cluster.access.concepts.Response;
27 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
28 import org.opendaylight.controller.cluster.messaging.MessageSlice;
29 import org.opendaylight.yangtools.yang.common.QName;
30 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
31 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
32
33 public class ConnectedClientConnectionTest
34         extends AbstractClientConnectionTest<ConnectedClientConnection<BackendInfo>, BackendInfo> {
35
36     @Test
37     public void testCheckTimeoutConnectionTimedout() throws Exception {
38         final Consumer<Response<?, ?>> callback = mock(Consumer.class);
39         connection.sendRequest(createRequest(replyToProbe.ref()), callback);
40         final long now = context.ticker().read() + ConnectedClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS;
41         final Optional<Long> timeout = connection.checkTimeout(now);
42         Assert.assertNull(timeout);
43     }
44
45     @Override
46     protected ConnectedClientConnection<BackendInfo> createConnection() {
47         final BackendInfo backend = new BackendInfo(backendProbe.ref(), 0L, ABIVersion.BORON, 10);
48         final ConnectingClientConnection<BackendInfo> connectingConn = new ConnectingClientConnection<>(context, 0L);
49         return  new ConnectedClientConnection<>(connectingConn, backend);
50     }
51
52     @Override
53     @Test
54     public void testReconnectConnection() throws Exception {
55         final ClientActorBehavior<BackendInfo> behavior = mock(ClientActorBehavior.class);
56         connection.lockedReconnect(behavior, mock(RequestException.class));
57         verify(behavior).reconnectConnection(same(connection), any(ReconnectingClientConnection.class));
58     }
59
60     @SuppressWarnings("unchecked")
61     @Test
62     public void testSendSliceableMessageRequest() {
63         final ClientActorConfig config = AccessClientUtil.newMockClientActorConfig();
64         doReturn(5).when(config).getMaximumMessageSliceSize();
65         context = new ClientActorContext(contextProbe.ref(), PERSISTENCE_ID, system, CLIENT_ID, config);
66         connection = createConnection();
67
68         final Consumer<Response<?, ?>> callback = mock(Consumer.class);
69
70         final TransactionIdentifier identifier =
71                 new TransactionIdentifier(new LocalHistoryIdentifier(CLIENT_ID, 0L), 0L);
72         ModifyTransactionRequestBuilder reqBuilder =
73                 new ModifyTransactionRequestBuilder(identifier, replyToProbe.ref());
74         reqBuilder.addModification(new TransactionWrite(YangInstanceIdentifier.EMPTY, Builders.containerBuilder()
75                 .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(
76                         QName.create("namespace", "localName"))).build()));
77         reqBuilder.setSequence(0L);
78         final Request<?, ?> request = reqBuilder.build();
79         connection.sendRequest(request, callback);
80
81         backendProbe.expectMsgClass(MessageSlice.class);
82     }
83 }

©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.