2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore.utils;
11 import static org.junit.Assert.assertNotNull;
12 import akka.actor.ActorRef;
13 import akka.actor.ActorSelection;
14 import akka.actor.ActorSystem;
15 import scala.concurrent.duration.FiniteDuration;
17 public class MockActorContext extends ActorContext {
19 private volatile Object executeShardOperationResponse;
20 private volatile Object executeRemoteOperationResponse;
21 private volatile Object executeLocalOperationResponse;
22 private volatile Object executeLocalShardOperationResponse;
23 private volatile Exception executeRemoteOperationFailure;
24 private volatile Object inputMessage;
26 public MockActorContext(ActorSystem actorSystem) {
27 super(actorSystem, null, new MockClusterWrapper(), new MockConfiguration());
30 public MockActorContext(ActorSystem actorSystem, ActorRef shardManager) {
31 super(actorSystem, shardManager, new MockClusterWrapper(), new MockConfiguration());
35 @Override public Object executeShardOperation(String shardName,
36 Object message, FiniteDuration duration) {
37 return executeShardOperationResponse;
40 @Override public Object executeRemoteOperation(ActorSelection actor,
41 Object message, FiniteDuration duration) {
42 return executeRemoteOperationResponse;
45 @Override public ActorSelection findPrimary(String shardName) {
49 public void setExecuteShardOperationResponse(Object response){
50 executeShardOperationResponse = response;
53 public void setExecuteRemoteOperationResponse(Object response){
54 executeRemoteOperationResponse = response;
57 public void setExecuteRemoteOperationFailure(Exception executeRemoteOperationFailure) {
58 this.executeRemoteOperationFailure = executeRemoteOperationFailure;
61 public void setExecuteLocalOperationResponse(
62 Object executeLocalOperationResponse) {
63 this.executeLocalOperationResponse = executeLocalOperationResponse;
66 public void setExecuteLocalShardOperationResponse(
67 Object executeLocalShardOperationResponse) {
68 this.executeLocalShardOperationResponse = executeLocalShardOperationResponse;
71 @SuppressWarnings("unchecked")
72 public <T> T getInputMessage(Class<T> expType) throws Exception {
73 assertNotNull("Input message was null", inputMessage);
74 return (T) expType.getMethod("fromSerializable", Object.class).invoke(null, inputMessage);
78 public Object executeLocalOperation(ActorRef actor,
79 Object message, FiniteDuration duration) {
80 return this.executeLocalOperationResponse;
84 public Object executeLocalShardOperation(String shardName,
85 Object message, FiniteDuration duration) {
86 return this.executeLocalShardOperationResponse;