X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fshardmanager%2FShardManagerGetSnapshotReplyActorTest.java;h=76af089b4d29bd4c13c78ff9b9f42a919c7592b6;hp=d64bf60d10d73af3f586473838bb5ac3e1f200a2;hb=95c296a7c1e8e186a88a0a0dc82e080b2185db33;hpb=f86f7e8c204fb19615c45e669a764c623576e1a3 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerGetSnapshotReplyActorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerGetSnapshotReplyActorTest.java index d64bf60d10..76af089b4d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerGetSnapshotReplyActorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/shardmanager/ShardManagerGetSnapshotReplyActorTest.java @@ -7,24 +7,28 @@ */ package org.opendaylight.controller.cluster.datastore.shardmanager; -import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; + import akka.actor.ActorRef; import akka.actor.Status.Failure; import akka.actor.Terminated; import akka.testkit.JavaTestKit; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.junit.After; import org.junit.Test; +import org.opendaylight.controller.cluster.access.concepts.MemberName; import org.opendaylight.controller.cluster.datastore.AbstractActorTest; import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier; -import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot; -import org.opendaylight.controller.cluster.datastore.messages.DatastoreSnapshot.ShardSnapshot; -import org.opendaylight.controller.cluster.raft.TestActorFactory; +import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot; +import org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot.ShardSnapshot; +import org.opendaylight.controller.cluster.datastore.persisted.ShardManagerSnapshot; +import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry; import org.opendaylight.controller.cluster.raft.client.messages.GetSnapshotReply; +import org.opendaylight.controller.cluster.raft.persisted.ByteState; +import org.opendaylight.controller.cluster.raft.persisted.Snapshot; import scala.concurrent.duration.Duration; import scala.concurrent.duration.FiniteDuration; @@ -34,51 +38,53 @@ import scala.concurrent.duration.FiniteDuration; * @author Thomas Pantelis */ public class ShardManagerGetSnapshotReplyActorTest extends AbstractActorTest { - private final TestActorFactory actorFactory = new TestActorFactory(getSystem()); - - @After - public void tearDown() { - actorFactory.close(); - } + private static final MemberName MEMBER_1 = MemberName.forName("member-1"); @Test public void testSuccess() { JavaTestKit kit = new JavaTestKit(getSystem()); - byte[] shardManagerSnapshot = new byte[]{0,5,9}; - ActorRef replyActor = actorFactory.createActor(ShardManagerGetSnapshotReplyActor.props( - Arrays.asList("shard1", "shard2", "shard3"), "config", - shardManagerSnapshot, kit.getRef(), "shard-manager", Duration.create(100, TimeUnit.SECONDS)), - actorFactory.generateActorId("actor")); + List shardList = Arrays.asList("shard1", "shard2", "shard3"); + ShardManagerSnapshot shardManagerSnapshot = new ShardManagerSnapshot(shardList); + ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props( + shardList, "config", shardManagerSnapshot, kit.getRef(), + "shard-manager", Duration.create(100, TimeUnit.SECONDS)), "testSuccess"); kit.watch(replyActor); - byte[] shard1Snapshot = new byte[]{1,2,3}; - replyActor.tell(new GetSnapshotReply(ShardIdentifier.builder().memberName("member-1").type("config"). - shardName("shard1").build().toString(), shard1Snapshot), ActorRef.noSender()); + ByteState shard1SnapshotState = ByteState.of(new byte[]{1,2,3}); + replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard1", MEMBER_1, "config").toString(), + Snapshot.create(shard1SnapshotState, Collections.emptyList(), + 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender()); - byte[] shard2Snapshot = new byte[]{4,5,6}; - replyActor.tell(new GetSnapshotReply(ShardIdentifier.builder().memberName("member-1").type("config"). - shardName("shard2").build().toString(), shard2Snapshot), ActorRef.noSender()); + ByteState shard2SnapshotState = ByteState.of(new byte[]{4,5,6}); + replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard2", MEMBER_1, "config").toString(), + Snapshot.create(shard2SnapshotState, Collections.emptyList(), + 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender()); kit.expectNoMsg(FiniteDuration.create(500, TimeUnit.MILLISECONDS)); - byte[] shard3Snapshot = new byte[]{7,8,9}; - replyActor.tell(new GetSnapshotReply(ShardIdentifier.builder().memberName("member-1").type("config"). - shardName("shard3").build().toString(), shard3Snapshot), ActorRef.noSender()); + ByteState shard3SnapshotState = ByteState.of(new byte[]{7,8,9}); + replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard3", MEMBER_1, "config").toString(), + Snapshot.create(shard3SnapshotState, Collections.emptyList(), + 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender()); DatastoreSnapshot datastoreSnapshot = kit.expectMsgClass(DatastoreSnapshot.class); assertEquals("getType", "config", datastoreSnapshot.getType()); - assertArrayEquals("getShardManagerSnapshot", shardManagerSnapshot, datastoreSnapshot.getShardManagerSnapshot()); + assertEquals("getShardManagerSnapshot", shardManagerSnapshot.getShardList(), + datastoreSnapshot.getShardManagerSnapshot().getShardList()); List shardSnapshots = datastoreSnapshot.getShardSnapshots(); assertEquals("ShardSnapshot size", 3, shardSnapshots.size()); assertEquals("ShardSnapshot 1 getName", "shard1", shardSnapshots.get(0).getName()); - assertArrayEquals("ShardSnapshot 1 getSnapshot", shard1Snapshot, shardSnapshots.get(0).getSnapshot()); + assertEquals("ShardSnapshot 1 getSnapshot", shard1SnapshotState, + shardSnapshots.get(0).getSnapshot().getState()); assertEquals("ShardSnapshot 2 getName", "shard2", shardSnapshots.get(1).getName()); - assertArrayEquals("ShardSnapshot 2 getSnapshot", shard2Snapshot, shardSnapshots.get(1).getSnapshot()); + assertEquals("ShardSnapshot 2 getSnapshot", shard2SnapshotState, + shardSnapshots.get(1).getSnapshot().getState()); assertEquals("ShardSnapshot 3 getName", "shard3", shardSnapshots.get(2).getName()); - assertArrayEquals("ShardSnapshot 3 getSnapshot", shard3Snapshot, shardSnapshots.get(2).getSnapshot()); + assertEquals("ShardSnapshot 3 getSnapshot", shard3SnapshotState, + shardSnapshots.get(2).getSnapshot().getState()); kit.expectMsgClass(Terminated.class); } @@ -87,16 +93,15 @@ public class ShardManagerGetSnapshotReplyActorTest extends AbstractActorTest { public void testGetSnapshotFailureReply() { JavaTestKit kit = new JavaTestKit(getSystem()); - byte[] shardManagerSnapshot = new byte[]{0,5,9}; - ActorRef replyActor = actorFactory.createActor(ShardManagerGetSnapshotReplyActor.props( - Arrays.asList("shard1", "shard2"), "config", - shardManagerSnapshot, kit.getRef(), "shard-manager", Duration.create(100, TimeUnit.SECONDS)), - actorFactory.generateActorId("actor")); + ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props( + Arrays.asList("shard1", "shard2"), "config", null, kit.getRef(), "shard-manager", + Duration.create(100, TimeUnit.SECONDS)), "testGetSnapshotFailureReply"); kit.watch(replyActor); - replyActor.tell(new GetSnapshotReply(ShardIdentifier.builder().memberName("member-1").type("config"). - shardName("shard1").build().toString(), new byte[]{1,2,3}), ActorRef.noSender()); + replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard1", MEMBER_1, "config").toString(), + Snapshot.create(ByteState.of(new byte[]{1,2,3}), Collections.emptyList(), + 2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender()); replyActor.tell(new Failure(new RuntimeException()), ActorRef.noSender()); @@ -108,11 +113,9 @@ public class ShardManagerGetSnapshotReplyActorTest extends AbstractActorTest { public void testGetSnapshotTimeout() { JavaTestKit kit = new JavaTestKit(getSystem()); - byte[] shardManagerSnapshot = new byte[]{0,5,9}; - ActorRef replyActor = actorFactory.createActor(ShardManagerGetSnapshotReplyActor.props( - Arrays.asList("shard1"), "config", - shardManagerSnapshot, kit.getRef(), "shard-manager", Duration.create(100, TimeUnit.MILLISECONDS)), - actorFactory.generateActorId("actor")); + ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props( + Arrays.asList("shard1"), "config", null, kit.getRef(), "shard-manager", + Duration.create(100, TimeUnit.MILLISECONDS)), "testGetSnapshotTimeout"); kit.watch(replyActor);