2 * Copyright (c) 2016 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;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.MockitoAnnotations.initMocks;
14 import akka.actor.ActorRef;
15 import akka.actor.PoisonPill;
16 import akka.actor.Props;
17 import akka.testkit.TestActorRef;
18 import java.util.concurrent.CountDownLatch;
19 import java.util.concurrent.TimeUnit;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.mockito.Mock;
23 import org.opendaylight.controller.cluster.access.concepts.MemberName;
24 import org.opendaylight.controller.cluster.datastore.config.Configuration;
25 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
26 import org.opendaylight.controller.cluster.datastore.shardmanager.ShardManagerTest.TestShardManager;
27 import org.opendaylight.controller.cluster.raft.TestActorFactory;
28 import org.opendaylight.controller.cluster.raft.utils.InMemoryJournal;
29 import org.opendaylight.controller.cluster.raft.utils.InMemorySnapshotStore;
30 import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
32 public class AbstractShardManagerTest extends AbstractClusterRefActorTest {
34 protected static final MemberName MEMBER_1 = MemberName.forName("member-1");
36 protected static int ID_COUNTER = 1;
37 protected static TestActorRef<MessageCollectorActor> mockShardActor;
38 protected static ShardIdentifier mockShardName;
40 protected final String shardMrgIDSuffix = "config" + ID_COUNTER++;
41 protected final TestActorFactory actorFactory = new TestActorFactory(getSystem());
42 protected final DatastoreContext.Builder datastoreContextBuilder = DatastoreContext.newBuilder()
43 .dataStoreName(shardMrgIDSuffix).shardInitializationTimeout(600, TimeUnit.MILLISECONDS)
44 .shardHeartbeatIntervalInMillis(100).shardElectionTimeoutFactor(6);
47 protected static CountDownLatch ready;
49 protected TestShardManager.Builder newTestShardMgrBuilder() {
50 return TestShardManager.builder(datastoreContextBuilder).distributedDataStore(mock(DistributedDataStore.class));
53 protected TestShardManager.Builder newTestShardMgrBuilder(final Configuration config) {
54 return TestShardManager.builder(datastoreContextBuilder).configuration(config)
55 .distributedDataStore(mock(DistributedDataStore.class));
58 protected Props newShardMgrProps(final Configuration config) {
59 return newTestShardMgrBuilder(config).waitTillReadyCountDownLatch(ready).props();
63 public void setUp() throws Exception {
66 InMemoryJournal.clear();
67 InMemorySnapshotStore.clear();
69 if (mockShardActor == null) {
70 mockShardName = ShardIdentifier.create(Shard.DEFAULT_NAME, MEMBER_1, "config");
71 mockShardActor = TestActorRef.create(getSystem(), Props.create(MessageCollectorActor.class),
72 mockShardName.toString());
75 mockShardActor.underlyingActor().clear();
79 public void tearDown() {
80 InMemoryJournal.clear();
81 InMemorySnapshotStore.clear();
83 mockShardActor.tell(PoisonPill.getInstance(), ActorRef.noSender());
84 mockShardActor = null;