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=5878675fdf84fe1e122cd858d0469ad604ce1769;hb=refs%2Fchanges%2F74%2F75374%2F41;hp=ae9499744f924fd1f932565e4057c9e3519b9091;hpb=aafb8cb044e992dd784d1f4f66508599cc4cd588;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 ae9499744f..5878675fdf 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,12 +9,14 @@ 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.time.Duration; import java.util.Optional; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.AbstractActorTest; @@ -31,37 +33,34 @@ public class ShardSnapshotActorTest extends AbstractActorTest { private static void testSerializeSnapshot(final String testName, final ShardDataTreeSnapshot snapshot, final boolean withInstallSnapshot) throws Exception { - new JavaTestKit(getSystem()) { - { - final ActorRef snapshotActor = getSystem().actorOf(ShardSnapshotActor.props(), testName); - watch(snapshotActor); + final TestKit kit = new TestKit(getSystem()); + final ActorRef snapshotActor = getSystem().actorOf(ShardSnapshotActor.props(), testName); + kit.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), getRef()); + ByteArrayOutputStream installSnapshotStream = withInstallSnapshot ? new ByteArrayOutputStream() : null; + ShardSnapshotActor.requestSnapshot(snapshotActor, snapshot, + Optional.ofNullable(installSnapshotStream), kit.getRef()); - final CaptureSnapshotReply reply = expectMsgClass(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 = kit.expectMsgClass(Duration.ofSeconds(3), CaptureSnapshotReply.class); + assertNotNull("getSnapshotState is null", reply.getSnapshotState()); + assertEquals("SnapshotState type", ShardSnapshotState.class, reply.getSnapshotState().getClass()); + assertEquals("Snapshot", snapshot, ((ShardSnapshotState)reply.getSnapshotState()).getSnapshot()); - if (installSnapshotStream != null) { - final ShardDataTreeSnapshot deserialized; - try (final ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream( - installSnapshotStream.toByteArray()))) { - deserialized = ShardDataTreeSnapshot.deserialize(in); - } + if (installSnapshotStream != null) { + final ShardDataTreeSnapshot deserialized; + try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream( + installSnapshotStream.toByteArray()))) { + deserialized = ShardDataTreeSnapshot.deserialize(in); + } - assertEquals("Deserialized snapshot type", snapshot.getClass(), deserialized.getClass()); + assertEquals("Deserialized snapshot type", snapshot.getClass(), deserialized.getClass()); - final Optional> maybeNode = deserialized.getRootNode(); - assertEquals("isPresent", true, maybeNode.isPresent()); - assertEquals("Root node", expectedRoot, maybeNode.get()); - } - } - }; + final Optional> maybeNode = deserialized.getRootNode(); + assertTrue("isPresent", maybeNode.isPresent()); + assertEquals("Root node", expectedRoot, maybeNode.get()); + } } @Test