Free disk buffers
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / messages / ReadyLocalTransactionSerializerTest.java
index 3ff8163f7d0df512401b0347dd8d6c4d818e15a6..2abb05d360a088fe2c206d1f55f2f20d51565a7e 100644 (file)
@@ -9,8 +9,15 @@ package org.opendaylight.controller.cluster.datastore.messages;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
+import akka.actor.ExtendedActorSystem;
+import akka.testkit.javadsl.TestKit;
+import com.google.common.collect.ImmutableSortedSet;
+import java.io.NotSerializableException;
 import java.util.List;
+import java.util.Optional;
+import java.util.SortedSet;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.AbstractTest;
@@ -21,23 +28,23 @@ import org.opendaylight.controller.cluster.datastore.modification.WriteModificat
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
+import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
 
 /**
  * Unit tests for ReadyLocalTransactionSerializer.
  *
  * @author Thomas Pantelis
  */
+@Deprecated(since = "9.0.0", forRemoval = true)
 public class ReadyLocalTransactionSerializerTest extends AbstractTest {
-
     @Test
-    public void testToAndFromBinary() {
-        TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
-        dataTree.setSchemaContext(TestModel.createTestContext());
+    public void testToAndFromBinary() throws NotSerializableException {
+        DataTree dataTree = new InMemoryDataTreeFactory().create(
+            DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
         DataTreeModification modification = dataTree.takeSnapshot().newModification();
 
         ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
@@ -45,20 +52,29 @@ public class ReadyLocalTransactionSerializerTest extends AbstractTest {
         MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
         new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
 
+        final SortedSet<String> shardNames = ImmutableSortedSet.of("one", "two");
         TransactionIdentifier txId = nextTransactionId();
-        ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
-
-        ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer();
-
-        byte[] bytes = serializer.toBinary(readyMessage);
+        ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true,
+                Optional.of(shardNames));
 
-        Object deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
+        final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
+        final Object deserialized;
+        try {
+            final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
+            final byte[] bytes = serializer.toBinary(readyMessage);
+            deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
+        } finally {
+            TestKit.shutdownActorSystem(system);
+        }
 
         assertNotNull("fromBinary returned null", deserialized);
         assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
         BatchedModifications batched = (BatchedModifications)deserialized;
-        assertEquals("getTransactionID", txId, batched.getTransactionID());
+        assertEquals("getTransactionID", txId, batched.getTransactionId());
         assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
+        assertTrue("isReady", batched.isReady());
+        assertTrue("isDoCommitOnReady", batched.isDoCommitOnReady());
+        assertEquals("participatingShardNames", Optional.of(shardNames), batched.getParticipatingShardNames());
 
         List<Modification> batchedMods = batched.getModifications();
         assertEquals("getModifications size", 2, batchedMods.size());