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