1 package org.opendaylight.controller.cluster.datastore.modification;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import com.google.common.base.Optional;
6 import com.google.common.base.Stopwatch;
7 import org.apache.commons.lang.SerializationUtils;
8 import org.junit.Ignore;
10 import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
11 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
12 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
18 public class MutableCompositeModificationTest extends AbstractModificationTest {
21 public void testApply() throws Exception {
23 MutableCompositeModification compositeModification = new MutableCompositeModification();
24 compositeModification.addModification(new WriteModification(TestModel.TEST_PATH,
25 ImmutableNodes.containerNode(TestModel.TEST_QNAME)));
27 DOMStoreReadWriteTransaction transaction = store.newReadWriteTransaction();
28 compositeModification.apply(transaction);
29 commitTransaction(transaction);
31 Optional<NormalizedNode<?, ?>> data = readData(TestModel.TEST_PATH);
33 assertNotNull(data.get());
34 assertEquals(TestModel.TEST_QNAME, data.get().getNodeType());
38 public void testSerialization() {
39 YangInstanceIdentifier writePath = TestModel.TEST_PATH;
40 NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
41 new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
42 withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
44 YangInstanceIdentifier mergePath = TestModel.OUTER_LIST_PATH;
45 NormalizedNode<?, ?> mergeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
46 new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).build();
48 YangInstanceIdentifier deletePath = TestModel.TEST_PATH;
50 MutableCompositeModification compositeModification = new MutableCompositeModification();
51 compositeModification.addModification(new WriteModification(writePath, writeData));
52 compositeModification.addModification(new MergeModification(mergePath, mergeData));
53 compositeModification.addModification(new DeleteModification(deletePath));
55 MutableCompositeModification clone = (MutableCompositeModification) SerializationUtils.clone(compositeModification);
57 assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, clone.getVersion());
59 assertEquals("getModifications size", 3, clone.getModifications().size());
61 WriteModification write = (WriteModification)clone.getModifications().get(0);
62 assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, write.getVersion());
63 assertEquals("getPath", writePath, write.getPath());
64 assertEquals("getData", writeData, write.getData());
66 MergeModification merge = (MergeModification)clone.getModifications().get(1);
67 assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, merge.getVersion());
68 assertEquals("getPath", mergePath, merge.getPath());
69 assertEquals("getData", mergeData, merge.getData());
71 DeleteModification delete = (DeleteModification)clone.getModifications().get(2);
72 assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, delete.getVersion());
73 assertEquals("getPath", deletePath, delete.getPath());
78 public void testSerializationScale() throws Exception {
79 YangInstanceIdentifier writePath = TestModel.TEST_PATH;
80 NormalizedNode<?, ?> writeData = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
81 new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).
82 withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, "foo")).build();
84 MutableCompositeModification compositeModification = new MutableCompositeModification();
85 for(int i = 0; i < 1000; i++) {
86 compositeModification.addModification(new WriteModification(writePath, writeData));
89 Stopwatch sw = Stopwatch.createStarted();
90 for(int i = 0; i < 1000; i++) {
91 new ModificationPayload(compositeModification);
95 System.out.println("Elapsed: "+sw);
97 ModificationPayload p = new ModificationPayload(compositeModification);
99 for(int i = 0; i < 1000; i++) {
104 System.out.println("Elapsed: "+sw);