Bug 7449: Slice ReadTransactionSuccess response
[controller.git] / opendaylight / md-sal / cds-access-client / src / test / java / org / opendaylight / controller / cluster / access / client / AccessClientUtil.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.Mockito.doReturn;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.spy;
13
14 import akka.actor.ActorRef;
15 import akka.actor.ActorSystem;
16 import java.util.function.Consumer;
17 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.Request;
19 import org.opendaylight.controller.cluster.access.concepts.Response;
20 import org.opendaylight.controller.cluster.access.concepts.ResponseEnvelope;
21
22 /**
23  * Util class to access package private members in cds-access-client for test purposes.
24  */
25 public class AccessClientUtil {
26
27     public static ClientActorContext createClientActorContext(final ActorSystem system, final ActorRef actor,
28                                                               final ClientIdentifier id, final String persistenceId) {
29
30         return spy(new ClientActorContext(actor, persistenceId, system, id, newMockClientActorConfig()));
31     }
32
33     public static ClientActorConfig newMockClientActorConfig() {
34         ClientActorConfig mockConfig = mock(ClientActorConfig.class);
35         doReturn(2_000_000).when(mockConfig).getMaximumMessageSliceSize();
36         doReturn(1_000_000_000).when(mockConfig).getFileBackedStreamingThreshold();
37         doReturn(AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS)
38                 .when(mockConfig).getBackendAlivenessTimerInterval();
39         doReturn(AbstractClientConnection.DEFAULT_REQUEST_TIMEOUT_NANOS).when(mockConfig).getRequestTimeout();
40         doReturn(AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS)
41                  .when(mockConfig).getNoProgressTimeout();
42         return mockConfig;
43     }
44
45     public static <T extends BackendInfo> ConnectedClientConnection<T> createConnectedConnection(
46             final ClientActorContext context, final Long cookie, final T backend) {
47         return new ConnectedClientConnection<>(context, cookie, backend);
48     }
49
50     public static void completeRequest(final AbstractClientConnection<? extends BackendInfo> connection,
51                                        final ResponseEnvelope<?> envelope) {
52         connection.receiveResponse(envelope);
53     }
54
55     public static ConnectionEntry createConnectionEntry(final Request<?, ?> request,
56                                                         final Consumer<Response<?, ?>> callback,
57                                                         final long now) {
58         return new ConnectionEntry(request, callback, now);
59     }
60
61 }

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