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 com.google.common.base.Optional;
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());
34 @Override public Object executeOperation(ActorSelection actor,
36 return executeRemoteOperationResponse;
39 @Override public Optional<ActorSelection> findPrimaryShard(String shardName) {
40 return Optional.absent();
43 public void setExecuteShardOperationResponse(Object response){
44 executeShardOperationResponse = response;
47 public void setExecuteRemoteOperationResponse(Object response){
48 executeRemoteOperationResponse = response;
51 public void setExecuteRemoteOperationFailure(Exception executeRemoteOperationFailure) {
52 this.executeRemoteOperationFailure = executeRemoteOperationFailure;
55 public void setExecuteLocalOperationResponse(
56 Object executeLocalOperationResponse) {
57 this.executeLocalOperationResponse = executeLocalOperationResponse;
60 public void setExecuteLocalShardOperationResponse(
61 Object executeLocalShardOperationResponse) {
62 this.executeLocalShardOperationResponse = executeLocalShardOperationResponse;
65 @SuppressWarnings("unchecked")
66 public <T> T getInputMessage(Class<T> expType) throws Exception {
67 assertNotNull("Input message was null", inputMessage);
68 return (T) expType.getMethod("fromSerializable", Object.class).invoke(null, inputMessage);
72 public Object executeOperation(ActorRef actor,
74 return this.executeLocalOperationResponse;