Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / persisted / ShardSnapshotStateTest.java
1 /*
2  * Copyright (c) 2017 Brocade Communications 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.persisted;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.util.Optional;
14 import org.apache.commons.lang3.SerializationUtils;
15 import org.junit.Test;
16 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
18 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
19 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
20 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
21
22 /**
23  * Unit tests for ShardSnapshotState.
24  *
25  * @author Thomas Pantelis
26  */
27 public class ShardSnapshotStateTest {
28     @Test
29     public void testSerialization() {
30         ContainerNode expectedNode = Builders.containerBuilder()
31             .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
32             .withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo"))
33             .build();
34
35         ShardSnapshotState expected = new ShardSnapshotState(new MetadataShardDataTreeSnapshot(expectedNode));
36         ShardSnapshotState cloned = SerializationUtils.clone(expected);
37
38         assertNotNull("getSnapshot is null", cloned.getSnapshot());
39         assertEquals("getSnapshot type", MetadataShardDataTreeSnapshot.class, cloned.getSnapshot().getClass());
40         assertEquals("getRootNode", Optional.of(expectedNode),
41                 ((MetadataShardDataTreeSnapshot)cloned.getSnapshot()).getRootNode());
42     }
43 }