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());
}
Aggregations