a43dc55fdcd532beca3f2d1e51d2de70ce4e6e9f
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / 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.spy;
11
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSystem;
14 import java.util.function.Consumer;
15 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
16 import org.opendaylight.controller.cluster.access.concepts.Request;
17 import org.opendaylight.controller.cluster.access.concepts.Response;
18 import org.opendaylight.controller.cluster.access.concepts.ResponseEnvelope;
19
20 /**
21  * Util class to access package private members in cds-access-client for test purposes.
22  */
23 public class AccessClientUtil {
24
25     public static ClientActorContext createClientActorContext(final ActorSystem system, final ActorRef actor,
26                                                               final ClientIdentifier id, final String persistenceId) {
27         return spy(new ClientActorContext(actor, system.scheduler(), system.dispatcher(), persistenceId, id));
28     }
29
30     public static <T extends BackendInfo> ConnectedClientConnection<T> createConnectedConnection(
31             final ClientActorContext context, final Long cookie, final T backend) {
32         return new ConnectedClientConnection<>(context, cookie, backend);
33     }
34
35     public static void completeRequest(final AbstractClientConnection<? extends BackendInfo> connection,
36                                        final ResponseEnvelope<?> envelope) {
37         connection.receiveResponse(envelope);
38     }
39
40     public static ConnectionEntry createConnectionEntry(final Request<?, ?> request,
41                                                         final Consumer<Response<?, ?>> callback,
42                                                         final long now) {
43         return new ConnectionEntry(request, callback, now);
44     }
45
46 }