import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+
+import akka.actor.ExtendedActorSystem;
+import akka.testkit.JavaTestKit;
+import java.io.NotSerializableException;
import java.util.List;
import org.junit.Test;
+import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
+import org.opendaylight.controller.cluster.datastore.AbstractTest;
import org.opendaylight.controller.cluster.datastore.DataStoreVersions;
import org.opendaylight.controller.cluster.datastore.modification.MergeModification;
import org.opendaylight.controller.cluster.datastore.modification.Modification;
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.DataTree;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
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.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
*
* @author Thomas Pantelis
*/
-public class ReadyLocalTransactionSerializerTest {
+public class ReadyLocalTransactionSerializerTest extends AbstractTest {
@Test
- public void testToAndFromBinary() {
- TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create();
- 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);
MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
- String txId = "tx-id";
+ TransactionIdentifier txId = nextTransactionId();
ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
- ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer();
-
- byte[] bytes = serializer.toBinary(readyMessage);
-
- 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 {
+ JavaTestKit.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());
List<Modification> batchedMods = batched.getModifications();