From b21572e7fcdc926c7839f2b936eb3f623304fd6c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 25 Jun 2020 18:57:34 +0200 Subject: [PATCH] Enable overwrite test suite With data being split up correctly between shards, we can re-enable the test suite for snapshot triggers. JIRA: CONTROLLER-1913 JIRA: CONTROLLER-1950 Change-Id: Ibda02648682aee03cf4c5a0275f705d79dbe6b1c Signed-off-by: Robert Varga --- ...ctDistributedDataStoreIntegrationTest.java | 16 ++++---- ...butedDataStoreRemotingIntegrationTest.java | 40 +++++++++---------- ...ule-shards-default-cars-member1-and-2.conf | 26 ++++++++++++ 3 files changed, 54 insertions(+), 28 deletions(-) create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/test/resources/module-shards-default-cars-member1-and-2.conf diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractDistributedDataStoreIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractDistributedDataStoreIntegrationTest.java index f530d673a2..cbe494f06c 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractDistributedDataStoreIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractDistributedDataStoreIntegrationTest.java @@ -911,7 +911,6 @@ public abstract class AbstractDistributedDataStoreIntegrationTest { } @Test - @Ignore("Writes to root node are not split into shards") public void testSnapshotOnRootOverwrite() throws Exception { if (!DistributedDataStore.class.isAssignableFrom(testParameter)) { // FIXME: ClientBackedDatastore does not have stable indexes/term, the snapshot index seems to fluctuate @@ -931,10 +930,10 @@ public abstract class AbstractDistributedDataStoreIntegrationTest { testKit.testWriteTransaction(dataStore, YangInstanceIdentifier.empty(), rootNode); IntegrationTestKit.verifyShardState(dataStore, "cars", - state -> assertEquals(0, state.getSnapshotIndex())); + state -> assertEquals(1, state.getSnapshotIndex())); // root has been written expect snapshot at index 0 - verifySnapshot("member-1-shard-cars-testRootOverwrite", 0, 1); + verifySnapshot("member-1-shard-cars-testRootOverwrite", 1, 1); for (int i = 0; i < 10; i++) { testKit.testWriteTransaction(dataStore, CarsModel.newCarPath("car " + i), @@ -943,23 +942,24 @@ public abstract class AbstractDistributedDataStoreIntegrationTest { // fake snapshot causes the snapshotIndex to move IntegrationTestKit.verifyShardState(dataStore, "cars", - state -> assertEquals(9, state.getSnapshotIndex())); + state -> assertEquals(10, state.getSnapshotIndex())); // however the real snapshot still has not changed and was taken at index 0 - verifySnapshot("member-1-shard-cars-testRootOverwrite", 0, 1); + verifySnapshot("member-1-shard-cars-testRootOverwrite", 1, 1); // root overwrite so expect a snapshot testKit.testWriteTransaction(dataStore, YangInstanceIdentifier.empty(), rootNode); // this was a real snapshot so everything should be in it(1 + 10 + 1) IntegrationTestKit.verifyShardState(dataStore, "cars", - state -> assertEquals(11, state.getSnapshotIndex())); + state -> assertEquals(12, state.getSnapshotIndex())); - verifySnapshot("member-1-shard-cars-testRootOverwrite", 11, 1); + verifySnapshot("member-1-shard-cars-testRootOverwrite", 12, 1); } } - private void verifySnapshot(String persistenceId, long lastAppliedIndex, long lastAppliedTerm) { + private static void verifySnapshot(final String persistenceId, final long lastAppliedIndex, + final long lastAppliedTerm) { await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> { List snap = InMemorySnapshotStore.getSnapshots(persistenceId, Snapshot.class); assertEquals(1, snap.size()); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java index 8637a5f17d..fbc7fa2ae8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DistributedDataStoreRemotingIntegrationTest.java @@ -227,7 +227,8 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest { } private void initDatastores(final String type, final String moduleShardsConfig, final String[] shards, - DatastoreContext.Builder leaderBuilder, DatastoreContext.Builder followerBuilder) throws Exception { + final DatastoreContext.Builder leaderBuilder, final DatastoreContext.Builder followerBuilder) + throws Exception { leaderTestKit = new IntegrationTestKit(leaderSystem, leaderBuilder, commitTimeout); leaderDistributedDataStore = leaderTestKit.setupAbstractDataStore( @@ -1443,7 +1444,6 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest { } @Test - @Ignore("Writes to root node are not split into shards") public void testSnapshotOnRootOverwrite() throws Exception { if (!DistributedDataStore.class.isAssignableFrom(testParameter)) { // FIXME: ClientBackedDatastore does not have stable indexes/term, the snapshot index seems to fluctuate @@ -1451,13 +1451,13 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest { } final String testName = "testSnapshotOnRootOverwrite"; - String[] shards = {"cars", "default"}; - initDatastores(testName, "module-shards-default-cars-member1.conf", shards, + final String[] shards = {"cars", "default"}; + initDatastores(testName, "module-shards-default-cars-member1-and-2.conf", shards, leaderDatastoreContextBuilder.snapshotOnRootOverwrite(true), followerDatastoreContextBuilder.snapshotOnRootOverwrite(true)); leaderTestKit.waitForMembersUp("member-2"); - ContainerNode rootNode = ImmutableContainerNodeBuilder.create() + final ContainerNode rootNode = ImmutableContainerNodeBuilder.create() .withNodeIdentifier(YangInstanceIdentifier.NodeIdentifier.create(SchemaContext.NAME)) .withChild((ContainerNode) CarsModel.create()) .build(); @@ -1465,13 +1465,13 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest { leaderTestKit.testWriteTransaction(leaderDistributedDataStore, YangInstanceIdentifier.empty(), rootNode); IntegrationTestKit.verifyShardState(leaderDistributedDataStore, "cars", - state -> assertEquals(0, state.getSnapshotIndex())); + state -> assertEquals(1, state.getSnapshotIndex())); IntegrationTestKit.verifyShardState(followerDistributedDataStore, "cars", - state -> assertEquals(0, state.getSnapshotIndex())); + state -> assertEquals(1, state.getSnapshotIndex())); - verifySnapshot("member-1-shard-cars-testSnapshotOnRootOverwrite", 0); - verifySnapshot("member-2-shard-cars-testSnapshotOnRootOverwrite", 0); + verifySnapshot("member-1-shard-cars-testSnapshotOnRootOverwrite", 1); + verifySnapshot("member-2-shard-cars-testSnapshotOnRootOverwrite", 1); for (int i = 0; i < 10; i++) { leaderTestKit.testWriteTransaction(leaderDistributedDataStore, CarsModel.newCarPath("car " + i), @@ -1480,28 +1480,28 @@ public class DistributedDataStoreRemotingIntegrationTest extends AbstractTest { // fake snapshot causes the snapshotIndex to move IntegrationTestKit.verifyShardState(leaderDistributedDataStore, "cars", - state -> assertEquals(9, state.getSnapshotIndex())); + state -> assertEquals(10, state.getSnapshotIndex())); IntegrationTestKit.verifyShardState(followerDistributedDataStore, "cars", - state -> assertEquals(9, state.getSnapshotIndex())); + state -> assertEquals(10, state.getSnapshotIndex())); - // however the real snapshot still has not changed and was taken at index 0 - verifySnapshot("member-1-shard-cars-testSnapshotOnRootOverwrite", 0); - verifySnapshot("member-2-shard-cars-testSnapshotOnRootOverwrite", 0); + // however the real snapshot still has not changed and was taken at index 1 + verifySnapshot("member-1-shard-cars-testSnapshotOnRootOverwrite", 1); + verifySnapshot("member-2-shard-cars-testSnapshotOnRootOverwrite", 1); // root overwrite so expect a snapshot leaderTestKit.testWriteTransaction(leaderDistributedDataStore, YangInstanceIdentifier.empty(), rootNode); - // this was a real snapshot so everything should be in it(1 + 10 + 1) + // this was a real snapshot so everything should be in it(1(DisableTrackingPayload) + 1 + 10 + 1) IntegrationTestKit.verifyShardState(leaderDistributedDataStore, "cars", - state -> assertEquals(11, state.getSnapshotIndex())); + state -> assertEquals(12, state.getSnapshotIndex())); IntegrationTestKit.verifyShardState(followerDistributedDataStore, "cars", - state -> assertEquals(11, state.getSnapshotIndex())); + state -> assertEquals(12, state.getSnapshotIndex())); - verifySnapshot("member-1-shard-cars-testSnapshotOnRootOverwrite", 11); - verifySnapshot("member-2-shard-cars-testSnapshotOnRootOverwrite", 11); + verifySnapshot("member-1-shard-cars-testSnapshotOnRootOverwrite", 12); + verifySnapshot("member-2-shard-cars-testSnapshotOnRootOverwrite", 12); } - private void verifySnapshot(String persistenceId, long lastAppliedIndex) { + private void verifySnapshot(final String persistenceId, final long lastAppliedIndex) { await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> { List snap = InMemorySnapshotStore.getSnapshots(persistenceId, Snapshot.class); assertEquals(1, snap.size()); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/module-shards-default-cars-member1-and-2.conf b/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/module-shards-default-cars-member1-and-2.conf new file mode 100644 index 0000000000..efc3dd470a --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/resources/module-shards-default-cars-member1-and-2.conf @@ -0,0 +1,26 @@ +module-shards = [ + { + name = "default" + shards = [ + { + name="default", + replicas = [ + "member-1", + "member-2" + ] + } + ] + }, + { + name = "cars" + shards = [ + { + name="cars" + replicas = [ + "member-1", + "member-2" + ] + } + ] + } +] \ No newline at end of file -- 2.36.6