2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.actors;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import akka.actor.ActorRef;
14 import akka.testkit.JavaTestKit;
15 import java.util.Optional;
16 import org.junit.Test;
17 import org.opendaylight.controller.cluster.datastore.AbstractActorTest;
18 import org.opendaylight.controller.cluster.datastore.persisted.ShardDataTreeSnapshot;
19 import org.opendaylight.controller.cluster.datastore.persisted.MetadataShardDataTreeSnapshot;
20 import org.opendaylight.controller.cluster.datastore.persisted.PreBoronShardDataTreeSnapshot;
21 import org.opendaylight.controller.cluster.raft.base.messages.CaptureSnapshotReply;
22 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
26 public class ShardSnapshotActorTest extends AbstractActorTest {
27 private static final NormalizedNode<?, ?> DATA = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
29 private static void testSerializeSnapshot(final String testName, final ShardDataTreeSnapshot snapshot)
31 new JavaTestKit(getSystem()) {{
33 final ActorRef snapshotActor = getSystem().actorOf(ShardSnapshotActor.props(), testName);
36 final NormalizedNode<?, ?> expectedRoot = snapshot.getRootNode().get();
38 ShardSnapshotActor.requestSnapshot(snapshotActor, snapshot, getRef());
40 final CaptureSnapshotReply reply = expectMsgClass(duration("3 seconds"), CaptureSnapshotReply.class);
41 assertNotNull("getSnapshot is null", reply.getSnapshot());
43 final ShardDataTreeSnapshot actual = ShardDataTreeSnapshot.deserialize(reply.getSnapshot());
44 assertNotNull(actual);
45 assertEquals(snapshot.getClass(), actual.getClass());
47 final Optional<NormalizedNode<?, ?>> maybeNode = actual.getRootNode();
48 assertTrue(maybeNode.isPresent());
50 assertEquals("Root node", expectedRoot, maybeNode.get());
55 public void testSerializeBoronSnapshot() throws Exception {
56 testSerializeSnapshot("testSerializeBoronSnapshot", new MetadataShardDataTreeSnapshot(DATA));
61 public void testSerializeLegacySnapshot() throws Exception {
62 testSerializeSnapshot("testSerializeLegacySnapshot", new PreBoronShardDataTreeSnapshot(DATA));