Add unit test for FrontedMetadata memory leaks
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / shardmanager / TestShardManager.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.shardmanager;
9
10 import akka.actor.ActorRef;
11 import akka.actor.Props;
12 import java.util.Map;
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;
17
18 public class TestShardManager extends ShardManager {
19     TestShardManager(AbstractShardManagerCreator<?> builder) {
20         super(builder);
21     }
22
23     /**
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.
27      */
28     @Override
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()),
34                 peerAddressResolver);
35         newInfo.setSchemaContext(info.getSchemaContext());
36         newInfo.setActiveMember(info.isActiveMember());
37
38
39         localShards.put(info.getShardName(), info);
40         return getContext().actorOf(newInfo.newProps().withDispatcher(shardDispatcherPath),
41                 info.getShardId().toString());
42     }
43
44     @Override
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)),
51                 peerAddressResolver);
52     }
53
54     public static class TestShardManagerCreator extends AbstractShardManagerCreator<TestShardManagerCreator> {
55         @Override
56         public Props props() {
57             verify();
58             return Props.create(TestShardManager.class, this);
59         }
60     }
61 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.