Bug 7449: Introduce ClientActorConfig in cds-access-client
[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, system.scheduler(), system.dispatcher(), persistenceId, id,
31                 newMockClientActorConfig()));
32     }
33
34     public static ClientActorConfig newMockClientActorConfig() {
35         ClientActorConfig mockConfig = mock(ClientActorConfig.class);
36         doReturn(2_000_000).when(mockConfig).getMaximumMessageSliceSize();
37         doReturn(1_000_000_000).when(mockConfig).getFileBackedStreamingThreshold();
38         return mockConfig;
39     }
40
41     public static <T extends BackendInfo> ConnectedClientConnection<T> createConnectedConnection(
42             final ClientActorContext context, final Long cookie, final T backend) {
43         return new ConnectedClientConnection<>(context, cookie, backend);
44     }
45
46     public static void completeRequest(final AbstractClientConnection<? extends BackendInfo> connection,
47                                        final ResponseEnvelope<?> envelope) {
48         connection.receiveResponse(envelope);
49     }
50
51     public static ConnectionEntry createConnectionEntry(final Request<?, ?> request,
52                                                         final Consumer<Response<?, ?>> callback,
53                                                         final long now) {
54         return new ConnectionEntry(request, callback, now);
55     }
56
57 }