Change-Id: I068b38bb275d23d27559aec3f336a6b9081fb732
Signed-off-by: Jakub Morvay <jmorvay@cisco.com>
.storeRoot(config.getPrefix().getRootIdentifier());
DatastoreContext shardDatastoreContext = builder.build();
.storeRoot(config.getPrefix().getRootIdentifier());
DatastoreContext shardDatastoreContext = builder.build();
- final Map<String, String> peerAddresses = Collections.emptyMap();
+ final Map<String, String> peerAddresses = getPeerAddresses(shardName);
final boolean isActiveMember = true;
LOG.debug("{} doCreatePrefixShard: shardId: {}, memberNames: {}, peerAddresses: {}, isActiveMember: {}",
final boolean isActiveMember = true;
LOG.debug("{} doCreatePrefixShard: shardId: {}, memberNames: {}, peerAddresses: {}, isActiveMember: {}",
package org.opendaylight.controller.cluster.sharding;
package org.opendaylight.controller.cluster.sharding;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.collect.Lists;
import com.typesafe.config.ConfigFactory;
import java.util.Collections;
import com.google.common.collect.Lists;
import com.typesafe.config.ConfigFactory;
import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
private static final DOMDataTreeIdentifier TEST_ID =
new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
private static final DOMDataTreeIdentifier TEST_ID =
new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
- private static final String MODULE_SHARDS_CONFIG = "module-shards-cars-member-1-and-2.conf";
+ private static final String MODULE_SHARDS_CONFIG = "module-shards-default.conf";
private ActorSystem leaderSystem;
private ActorSystem followerSystem;
private ActorSystem leaderSystem;
private ActorSystem followerSystem;
leaderTestKit.waitUntilLeader(leaderOperDatastore.getActorContext(),
ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY));
leaderTestKit.waitUntilLeader(leaderOperDatastore.getActorContext(),
ClusterUtils.getCleanShardName(YangInstanceIdentifier.EMPTY));
leaderTestKit.waitForMembersUp("member-2");
leaderTestKit.waitForMembersUp("member-2");
+ // TODO refactor shard creation and verification to own method
final DistributedShardRegistration shardRegistration =
waitOnAsyncTask(leaderShardFactory.createDistributedShard(
TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)),
final DistributedShardRegistration shardRegistration =
waitOnAsyncTask(leaderShardFactory.createDistributedShard(
TEST_ID, Lists.newArrayList(AbstractTest.MEMBER_NAME, AbstractTest.MEMBER_2_NAME)),
assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier())));
assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier())));
+ final Set<String> peers = new HashSet<>();
+ IntegrationTestKit.verifyShardState(leaderConfigDatastore,
+ ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()), onDemandShardState ->
+ peers.addAll(onDemandShardState.getPeerAddresses().values()));
+ assertEquals(peers.size(), 1);
+
final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
try {
followerShardFactory.createProducer(Collections.singleton(TEST_ID));
final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
try {
followerShardFactory.createProducer(Collections.singleton(TEST_ID));
findLocalShard(followerConfigDatastore.getActorContext(),
ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
findLocalShard(followerConfigDatastore.getActorContext(),
ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()));
+ final Set<String> peers = new HashSet<>();
+ IntegrationTestKit.verifyShardState(leaderConfigDatastore,
+ ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()), onDemandShardState ->
+ peers.addAll(onDemandShardState.getPeerAddresses().values()));
+ assertEquals(peers.size(), 1);
+
LOG.debug("Got after waiting for nonleader");
final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
LOG.debug("Got after waiting for nonleader");
final DOMDataTreeProducer producer = leaderShardFactory.createProducer(Collections.singleton(TEST_ID));
assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
ClusterUtils.getCleanShardName(TestModel.JUNK_PATH)));
assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
ClusterUtils.getCleanShardName(TestModel.JUNK_PATH)));
LOG.debug("Closing registrations");
reg1.close().toCompletableFuture().get();
LOG.debug("Closing registrations");
reg1.close().toCompletableFuture().get();
assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
assertNotNull(findLocalShard(followerConfigDatastore.getActorContext(),
ClusterUtils.getCleanShardName(TestModel.TEST_PATH)));
+
+ final Set<String> peers = new HashSet<>();
+ IntegrationTestKit.verifyShardState(leaderConfigDatastore,
+ ClusterUtils.getCleanShardName(TEST_ID.getRootIdentifier()), onDemandShardState ->
+ peers.addAll(onDemandShardState.getPeerAddresses().values()));
+ assertEquals(peers.size(), 1);
+
waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
waitUntilShardIsDown(leaderConfigDatastore.getActorContext(),
waitOnAsyncTask(reg1.close(), DistributedShardedDOMDataTree.SHARD_FUTURE_TIMEOUT_DURATION);
waitUntilShardIsDown(leaderConfigDatastore.getActorContext(),