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());
33 @Override public Object executeOperation(ActorSelection actor,
35 return executeRemoteOperationResponse;
38 public void setExecuteShardOperationResponse(Object response){
39 executeShardOperationResponse = response;
42 public void setExecuteRemoteOperationResponse(Object response){
43 executeRemoteOperationResponse = response;
46 public void setExecuteRemoteOperationFailure(Exception executeRemoteOperationFailure) {
47 this.executeRemoteOperationFailure = executeRemoteOperationFailure;
50 public void setExecuteLocalOperationResponse(
51 Object executeLocalOperationResponse) {
52 this.executeLocalOperationResponse = executeLocalOperationResponse;
55 public void setExecuteLocalShardOperationResponse(
56 Object executeLocalShardOperationResponse) {
57 this.executeLocalShardOperationResponse = executeLocalShardOperationResponse;
60 @SuppressWarnings("unchecked")
61 public <T> T getInputMessage(Class<T> expType) throws Exception {
62 assertNotNull("Input message was null", inputMessage);
63 return (T) expType.getMethod("fromSerializable", Object.class).invoke(null, inputMessage);
67 public Object executeOperation(ActorRef actor,
69 return this.executeLocalOperationResponse;