2 * Copyright (c) 2015 Brocade Communications 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.compat;
10 import static org.junit.Assert.assertEquals;
11 import akka.actor.ActorRef;
12 import akka.actor.PoisonPill;
13 import akka.testkit.TestActorRef;
14 import java.util.Collections;
15 import org.junit.Test;
16 import org.opendaylight.controller.cluster.datastore.AbstractShardTest;
17 import org.opendaylight.controller.cluster.datastore.Shard;
18 import org.opendaylight.controller.cluster.datastore.node.NormalizedNodeToNodeCodec;
19 import org.opendaylight.controller.cluster.raft.ReplicatedLogEntry;
20 import org.opendaylight.controller.cluster.raft.Snapshot;
21 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
22 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
26 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
27 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
28 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
31 * Unit tests for backwards compatibility with pre-Lithium versions.
33 * @author Thomas Pantelis
35 public class PreLithiumShardTest extends AbstractShardTest {
37 public void testApplyHelium2VersionSnapshot() throws Exception {
38 TestActorRef<Shard> shard = TestActorRef.create(getSystem(), newShardProps(),
39 "testApplyHelium2VersionSnapshot");
41 NormalizedNodeToNodeCodec codec = new NormalizedNodeToNodeCodec(SCHEMA_CONTEXT);
43 DataTree store = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
44 store.setSchemaContext(SCHEMA_CONTEXT);
46 writeToStore(store, TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
48 YangInstanceIdentifier root = YangInstanceIdentifier.EMPTY;
49 NormalizedNode<?,?> expected = readStore(store, root);
51 NormalizedNodeMessages.Container encode = codec.encode(expected);
53 Snapshot snapshot = Snapshot.create(encode.getNormalizedNode().toByteString().toByteArray(),
54 Collections.<ReplicatedLogEntry>emptyList(), 1, 2, 3, 4);
56 shard.underlyingActor().getRaftActorSnapshotCohort().applySnapshot(snapshot.getState());
58 NormalizedNode<?,?> actual = readStore(shard, root);
60 assertEquals("Root node", expected, actual);
62 shard.tell(PoisonPill.getInstance(), ActorRef.noSender());