Search in sources :

Example 1 with ExtendedActorSystem

use of akka.actor.ExtendedActorSystem in project controller by opendaylight.

the class ReadyLocalTransactionSerializerTest method testToAndFromBinary.

@Test
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);
    new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
    MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
    new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
    TransactionIdentifier txId = nextTransactionId();
    ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
    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("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
    List<Modification> batchedMods = batched.getModifications();
    assertEquals("getModifications size", 2, batchedMods.size());
    Modification mod = batchedMods.get(0);
    assertEquals("Modification type", WriteModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification) mod).getPath());
    assertEquals("Modification getData", writeData, ((WriteModification) mod).getData());
    mod = batchedMods.get(1);
    assertEquals("Modification type", MergeModification.class, mod.getClass());
    assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification) mod).getPath());
    assertEquals("Modification getData", mergeData, ((MergeModification) mod).getData());
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) WriteModification(org.opendaylight.controller.cluster.datastore.modification.WriteModification) Modification(org.opendaylight.controller.cluster.datastore.modification.Modification) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory) MergeModification(org.opendaylight.controller.cluster.datastore.modification.MergeModification) ExtendedActorSystem(akka.actor.ExtendedActorSystem) DataTree(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) Test(org.junit.Test) AbstractTest(org.opendaylight.controller.cluster.datastore.AbstractTest)

Aggregations

ExtendedActorSystem (akka.actor.ExtendedActorSystem)1 Test (org.junit.Test)1 TransactionIdentifier (org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier)1 AbstractTest (org.opendaylight.controller.cluster.datastore.AbstractTest)1 MergeModification (org.opendaylight.controller.cluster.datastore.modification.MergeModification)1 Modification (org.opendaylight.controller.cluster.datastore.modification.Modification)1 WriteModification (org.opendaylight.controller.cluster.datastore.modification.WriteModification)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)1 DataTree (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree)1 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)1 InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory)1