2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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
8 package org.opendaylight.controller.cluster.datastore.shardmanager;
10 import akka.actor.ActorRef;
11 import akka.actor.Props;
13 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
14 import org.opendaylight.controller.cluster.datastore.TestShard;
15 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
16 import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot;
18 public class TestShardManager extends ShardManager {
19 TestShardManager(AbstractShardManagerCreator<?> builder) {
24 * Plug into shard actor creation to replace info with our testing one.
25 * @param info shard info.
26 * @return actor for replaced shard info.
29 protected ActorRef newShardActor(ShardInformation info) {
30 ShardInformation newInfo = new ShardInformation(info.getShardName(),
31 info.getShardId(), getPeerAddresses(info.getShardName()),
32 info.getDatastoreContext(),
33 TestShard.builder().restoreFromSnapshot(info.getBuilder().getRestoreFromSnapshot()),
35 newInfo.setSchemaContext(info.getSchemaContext());
36 newInfo.setActiveMember(info.isActiveMember());
39 localShards.put(info.getShardName(), info);
40 return getContext().actorOf(newInfo.newProps().withDispatcher(shardDispatcherPath),
41 info.getShardId().toString());
45 ShardInformation createShardInfoFor(String shardName, ShardIdentifier shardId,
46 Map<String, String> peerAddresses,
47 DatastoreContext datastoreContext,
48 Map<String, DatastoreSnapshot.ShardSnapshot> shardSnapshots) {
49 return new ShardInformation(shardName, shardId, peerAddresses,
50 datastoreContext, TestShard.builder().restoreFromSnapshot(shardSnapshots.get(shardName)),
54 public static class TestShardManagerCreator extends AbstractShardManagerCreator<TestShardManagerCreator> {
56 public Props props() {
58 return Props.create(TestShardManager.class, this);