Fix unit test CS warnings in sal-distributed-datastore
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / actors / ShardSnapshotActorTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.actors;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13
14 import akka.actor.ActorRef;
15 import akka.testkit.JavaTestKit;
16 import java.util.Optional;
17 import org.junit.Test;
18 import org.opendaylight.controller.cluster.datastore.AbstractActorTest;
19 import org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot;
20 import org.opendaylight.controller.cluster.datastore.persisted.PreBoronShardDataTreeSnapshot;
21 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
22 import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply;
23 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
24 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
25 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
26
27 public class ShardSnapshotActorTest extends AbstractActorTest {
28     private static final NormalizedNode<?, ?> DATA = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
29
30     private static void testSerializeSnapshot(final String testName, final ShardDataTreeSnapshot snapshot)
31             throws Exception {
32         new JavaTestKit(getSystem()) {
33             {
34
35                 final ActorRef snapshotActor = getSystem().actorOf(ShardSnapshotActor.props(), testName);
36                 watch(snapshotActor);
37
38                 final NormalizedNode<?, ?> expectedRoot = snapshot.getRootNode().get();
39
40                 ShardSnapshotActor.requestSnapshot(snapshotActor, snapshot, getRef());
41
42                 final CaptureSnapshotReply reply = expectMsgClass(duration("3 seconds"), CaptureSnapshotReply.class);
43                 assertNotNull("getSnapshot is null", reply.getSnapshot());
44
45                 final ShardDataTreeSnapshot actual = ShardDataTreeSnapshot.deserialize(reply.getSnapshot());
46                 assertNotNull(actual);
47                 assertEquals(snapshot.getClass(), actual.getClass());
48
49                 final Optional<NormalizedNode<?, ?>> maybeNode = actual.getRootNode();
50                 assertTrue(maybeNode.isPresent());
51
52                 assertEquals("Root node", expectedRoot, maybeNode.get());
53             }
54         };
55     }
56
57     @Test
58     public void testSerializeBoronSnapshot() throws Exception {
59         testSerializeSnapshot("testSerializeBoronSnapshot", new MetadataShardDataTreeSnapshot(DATA));
60     }
61
62     @Deprecated
63     @Test
64     public void testSerializeLegacySnapshot() throws Exception {
65         testSerializeSnapshot("testSerializeLegacySnapshot", new PreBoronShardDataTreeSnapshot(DATA));
66     }
67 }