import org.opendaylight.controller.cluster.datastore.utils.MessageCollectorActor;
import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper;
import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration;
+import org.opendaylight.controller.cluster.datastore.utils.PrimaryShardInfoFutureCache;
import org.opendaylight.controller.cluster.notifications.LeaderStateChanged;
import org.opendaylight.controller.cluster.notifications.RegisterRoleChangeListener;
import org.opendaylight.controller.cluster.notifications.RoleChangeNotification;
return TestActorRef.create(system, Props.create(MessageCollectorActor.class), name);
}
+ private final PrimaryShardInfoFutureCache primaryShardInfoCache = new PrimaryShardInfoFutureCache();
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
InMemoryJournal.clear();
}
- private Props newShardMgrProps() {
+ private Props newShardMgrProps(boolean persistent) {
return ShardManager.props(new MockClusterWrapper(), new MockConfiguration(),
- datastoreContextBuilder.build(), ready);
+ datastoreContextBuilder.persistent(persistent).build(), ready, primaryShardInfoCache);
}
private Props newPropsShardMgrWithMockShardActor() {
@Override
public ShardManager create() throws Exception {
return new ForwardingShardManager(clusterWrapper, config, datastoreContextBuilder.build(),
- ready, name, shardActor);
+ ready, name, shardActor, primaryShardInfoCache);
}
};
throws Exception {
new JavaTestKit(getSystem()) {{
final TestActorRef<ShardManager> shardManager =
- TestActorRef.create(getSystem(), newShardMgrProps());
+ TestActorRef.create(getSystem(), newShardMgrProps(true));
assertEquals("getKnownModules size", 0, shardManager.underlyingActor().getKnownModules().size());
throws Exception {
new JavaTestKit(getSystem()) {{
final TestActorRef<ShardManager> shardManager =
- TestActorRef.create(getSystem(), newShardMgrProps());
+ TestActorRef.create(getSystem(), newShardMgrProps(true));
SchemaContext schemaContext = mock(SchemaContext.class);
Set<ModuleIdentifier> moduleIdentifierSet = new HashSet<>();
public void testRecoveryApplicable(){
new JavaTestKit(getSystem()) {
{
- final Props persistentProps = ShardManager.props(
- new MockClusterWrapper(),
- new MockConfiguration(),
- DatastoreContext.newBuilder().persistent(true).build(), ready);
+ final Props persistentProps = newShardMgrProps(true);
final TestActorRef<ShardManager> persistentShardManager =
TestActorRef.create(getSystem(), persistentProps);
assertTrue("Recovery Applicable", dataPersistenceProvider1.isRecoveryApplicable());
- final Props nonPersistentProps = ShardManager.props(
- new MockClusterWrapper(),
- new MockConfiguration(),
- DatastoreContext.newBuilder().persistent(false).build(), ready);
+ final Props nonPersistentProps = newShardMgrProps(false);
final TestActorRef<ShardManager> nonPersistentShardManager =
TestActorRef.create(getSystem(), nonPersistentProps);
private static final long serialVersionUID = 1L;
@Override
public ShardManager create() throws Exception {
- return new ShardManager(new MockClusterWrapper(), new MockConfiguration(), DatastoreContext.newBuilder().build(), ready) {
+ return new ShardManager(new MockClusterWrapper(), new MockConfiguration(), DatastoreContext.newBuilder().build(),
+ ready, new PrimaryShardInfoFutureCache()) {
@Override
protected DataPersistenceProvider createDataPersistenceProvider(boolean persistent) {
DataPersistenceProviderMonitor dataPersistenceProviderMonitor
public void testRoleChangeNotificationAndShardLeaderStateChangedReleaseReady() throws Exception {
new JavaTestKit(getSystem()) {
{
- TestActorRef<ShardManager> shardManager = TestActorRef.create(getSystem(), newShardMgrProps());
+ TestActorRef<ShardManager> shardManager = TestActorRef.create(getSystem(), newShardMgrProps(true));
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.underlyingActor().onReceiveCommand(new RoleChangeNotification(
public void testRoleChangeNotificationToFollowerWithShardLeaderStateChangedReleaseReady() throws Exception {
new JavaTestKit(getSystem()) {
{
- TestActorRef<ShardManager> shardManager = TestActorRef.create(getSystem(), newShardMgrProps());
+ TestActorRef<ShardManager> shardManager = TestActorRef.create(getSystem(), newShardMgrProps(true));
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.underlyingActor().onReceiveCommand(new RoleChangeNotification(
public void testReadyCountDownForMemberUpAfterLeaderStateChanged() throws Exception {
new JavaTestKit(getSystem()) {
{
- TestActorRef<ShardManager> shardManager = TestActorRef.create(getSystem(), newShardMgrProps());
+ TestActorRef<ShardManager> shardManager = TestActorRef.create(getSystem(), newShardMgrProps(true));
String memberId = "member-1-shard-default-" + shardMrgIDSuffix;
shardManager.underlyingActor().onReceiveCommand(new RoleChangeNotification(
public void testRoleChangeNotificationDoNothingForUnknownShard() throws Exception {
new JavaTestKit(getSystem()) {
{
- TestActorRef<ShardManager> shardManager = TestActorRef.create(getSystem(), newShardMgrProps());
+ TestActorRef<ShardManager> shardManager = TestActorRef.create(getSystem(), newShardMgrProps(true));
shardManager.underlyingActor().onReceiveCommand(new RoleChangeNotification(
"unknown", RaftState.Candidate.name(), RaftState.Leader.name()));
@Test
public void testByDefaultSyncStatusIsFalse() throws Exception{
- final Props persistentProps = ShardManager.props(
- new MockClusterWrapper(),
- new MockConfiguration(),
- DatastoreContext.newBuilder().persistent(true).build(), ready);
+ final Props persistentProps = newShardMgrProps(true);
final TestActorRef<ShardManager> shardManager =
TestActorRef.create(getSystem(), persistentProps);
final Props persistentProps = ShardManager.props(
new MockClusterWrapper(),
new MockConfiguration(),
- DatastoreContext.newBuilder().persistent(true).build(), ready);
+ DatastoreContext.newBuilder().persistent(true).build(), ready, primaryShardInfoCache);
final TestActorRef<ShardManager> shardManager =
TestActorRef.create(getSystem(), persistentProps);
@Test
public void testWhenShardIsCandidateSyncStatusIsFalse() throws Exception{
- final Props persistentProps = ShardManager.props(
- new MockClusterWrapper(),
- new MockConfiguration(),
- DatastoreContext.newBuilder().persistent(true).build(), ready);
+ final Props persistentProps = newShardMgrProps(true);
final TestActorRef<ShardManager> shardManager =
TestActorRef.create(getSystem(), persistentProps);
final Props persistentProps = ShardManager.props(
new MockClusterWrapper(),
new MockConfiguration(),
- DatastoreContext.newBuilder().persistent(true).build(), ready);
+ DatastoreContext.newBuilder().persistent(true).build(), ready, primaryShardInfoCache);
final TestActorRef<ShardManager> shardManager =
TestActorRef.create(getSystem(), persistentProps);
return Arrays.asList("default", "astronauts");
}
},
- DatastoreContext.newBuilder().persistent(true).build(), ready);
+ DatastoreContext.newBuilder().persistent(true).build(), ready, primaryShardInfoCache);
final TestActorRef<ShardManager> shardManager =
TestActorRef.create(getSystem(), persistentProps);
TestShardManager(String shardMrgIDSuffix) {
super(new MockClusterWrapper(), new MockConfiguration(),
- DatastoreContext.newBuilder().dataStoreType(shardMrgIDSuffix).build(), ready);
+ DatastoreContext.newBuilder().dataStoreType(shardMrgIDSuffix).build(), ready,
+ new PrimaryShardInfoFutureCache());
}
@Override
protected ForwardingShardManager(ClusterWrapper cluster, Configuration configuration,
DatastoreContext datastoreContext, CountDownLatch waitTillReadyCountdownLatch, String name,
- ActorRef shardActor) {
- super(cluster, configuration, datastoreContext, waitTillReadyCountdownLatch);
+ ActorRef shardActor, PrimaryShardInfoFutureCache primaryShardInfoCache) {
+ super(cluster, configuration, datastoreContext, waitTillReadyCountdownLatch, primaryShardInfoCache);
this.shardActor = shardActor;
this.name = name;
}