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;
16 public class MockActorContext extends ActorContext {
18 private volatile Object executeShardOperationResponse;
19 private volatile Object executeRemoteOperationResponse;
20 private volatile Object executeLocalOperationResponse;
21 private volatile Object executeLocalShardOperationResponse;
22 private volatile Exception executeRemoteOperationFailure;
23 private volatile Object inputMessage;
25 public MockActorContext(ActorSystem actorSystem) {
26 super(actorSystem, null, new MockClusterWrapper(), new MockConfiguration());
29 public MockActorContext(ActorSystem actorSystem, ActorRef shardManager) {
30 super(actorSystem, shardManager, new MockClusterWrapper(), new MockConfiguration());
34 @Override public Object executeShardOperation(String shardName,
36 return executeShardOperationResponse;
39 @Override public Object executeRemoteOperation(ActorSelection actor,
41 return executeRemoteOperationResponse;
44 @Override public ActorSelection findPrimary(String shardName) {
48 public void setExecuteShardOperationResponse(Object response){
49 executeShardOperationResponse = response;
52 public void setExecuteRemoteOperationResponse(Object response){
53 executeRemoteOperationResponse = response;
56 public void setExecuteRemoteOperationFailure(Exception executeRemoteOperationFailure) {
57 this.executeRemoteOperationFailure = executeRemoteOperationFailure;
60 public void setExecuteLocalOperationResponse(
61 Object executeLocalOperationResponse) {
62 this.executeLocalOperationResponse = executeLocalOperationResponse;
65 public void setExecuteLocalShardOperationResponse(
66 Object executeLocalShardOperationResponse) {
67 this.executeLocalShardOperationResponse = executeLocalShardOperationResponse;
70 @SuppressWarnings("unchecked")
71 public <T> T getInputMessage(Class<T> expType) throws Exception {
72 assertNotNull("Input message was null", inputMessage);
73 return (T) expType.getMethod("fromSerializable", Object.class).invoke(null, inputMessage);
77 public Object executeLocalOperation(ActorRef actor,
79 return this.executeLocalOperationResponse;
83 public Object executeLocalShardOperation(String shardName,
85 return this.executeLocalShardOperationResponse;