X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Factors%2FShardSnapshotActorTest.java;h=30b8bab1b7bafe9887e639fe20639a931b90c016;hb=bf887b0ecebf65746684691a0cd4d448ad8606f1;hp=65a8ac9ce8605c1c19493fab000c865696ec8725;hpb=5464f50be733df1bbbe31cf05665d542d3b7c5e7;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActorTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActorTest.java index 65a8ac9ce8..30b8bab1b7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActorTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/actors/ShardSnapshotActorTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -9,16 +9,18 @@ package org.opendaylight.controller.cluster.datastore.actors; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import akka.actor.ActorRef; -import akka.testkit.JavaTestKit; +import akka.testkit.javadsl.TestKit; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; import java.util.Optional; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.AbstractActorTest; import org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot; -import org.opendaylight.controller.cluster.datastore.persisted.PreBoronShardDataTreeSnapshot; import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot; +import org.opendaylight.controller.cluster.datastore.persisted.ShardSnapshotState; import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply; import org.opendaylight.controller.md.cluster.datastore.model.TestModel; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -27,41 +29,43 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; public class ShardSnapshotActorTest extends AbstractActorTest { private static final NormalizedNode DATA = ImmutableNodes.containerNode(TestModel.TEST_QNAME); - private static void testSerializeSnapshot(final String testName, final ShardDataTreeSnapshot snapshot) - throws Exception { - new JavaTestKit(getSystem()) { - { + private static void testSerializeSnapshot(final String testName, final ShardDataTreeSnapshot snapshot, + final boolean withInstallSnapshot) throws Exception { + final TestKit kit = new TestKit(getSystem()); + final ActorRef snapshotActor = getSystem().actorOf(ShardSnapshotActor.props(), testName); + kit.watch(snapshotActor); - final ActorRef snapshotActor = getSystem().actorOf(ShardSnapshotActor.props(), testName); - watch(snapshotActor); + final NormalizedNode expectedRoot = snapshot.getRootNode().get(); - final NormalizedNode expectedRoot = snapshot.getRootNode().get(); + ByteArrayOutputStream installSnapshotStream = withInstallSnapshot ? new ByteArrayOutputStream() : null; + ShardSnapshotActor.requestSnapshot(snapshotActor, snapshot, + Optional.ofNullable(installSnapshotStream), kit.getRef()); - ShardSnapshotActor.requestSnapshot(snapshotActor, snapshot, getRef()); + final CaptureSnapshotReply reply = kit.expectMsgClass(kit.duration("3 seconds"), CaptureSnapshotReply.class); + assertNotNull("getSnapshotState is null", reply.getSnapshotState()); + assertEquals("SnapshotState type", ShardSnapshotState.class, reply.getSnapshotState().getClass()); + assertEquals("Snapshot", snapshot, ((ShardSnapshotState)reply.getSnapshotState()).getSnapshot()); - final CaptureSnapshotReply reply = expectMsgClass(duration("3 seconds"), CaptureSnapshotReply.class); - assertNotNull("getSnapshot is null", reply.getSnapshot()); - - final ShardDataTreeSnapshot actual = ShardDataTreeSnapshot.deserialize(reply.getSnapshot()); - assertNotNull(actual); - assertEquals(snapshot.getClass(), actual.getClass()); + if (installSnapshotStream != null) { + final ShardDataTreeSnapshot deserialized; + try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream( + installSnapshotStream.toByteArray()))) { + deserialized = ShardDataTreeSnapshot.deserialize(in); + } - final Optional> maybeNode = actual.getRootNode(); - assertTrue(maybeNode.isPresent()); + assertEquals("Deserialized snapshot type", snapshot.getClass(), deserialized.getClass()); - assertEquals("Root node", expectedRoot, maybeNode.get()); - } - }; + final Optional> maybeNode = deserialized.getRootNode(); + assertEquals("isPresent", true, maybeNode.isPresent()); + assertEquals("Root node", expectedRoot, maybeNode.get()); + } } @Test public void testSerializeBoronSnapshot() throws Exception { - testSerializeSnapshot("testSerializeBoronSnapshot", new MetadataShardDataTreeSnapshot(DATA)); - } - - @Deprecated - @Test - public void testSerializeLegacySnapshot() throws Exception { - testSerializeSnapshot("testSerializeLegacySnapshot", new PreBoronShardDataTreeSnapshot(DATA)); + testSerializeSnapshot("testSerializeBoronSnapshotWithInstallSnapshot", + new MetadataShardDataTreeSnapshot(DATA), true); + testSerializeSnapshot("testSerializeBoronSnapshotWithoutInstallSnapshot", + new MetadataShardDataTreeSnapshot(DATA), false); } }