Fix AtomixDocumentTree event notifications
Change-Id: Id79ba675dfc83fbe6c04a7789842a4e65050c046
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CatalystSerializers.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CatalystSerializers.java
index 7159f06..3252f61 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CatalystSerializers.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CatalystSerializers.java
@@ -108,6 +108,8 @@
serializer.register(DocumentTreeEvent.class, factory);
serializer.register(Maps.immutableEntry("a", "b").getClass(), factory);
serializer.register(ImmutableList.of().getClass(), factory);
+ serializer.register(ImmutableList.of("a").getClass(), factory);
+ serializer.register(Arrays.asList().getClass(), factory);
serializer.resolve(new LongCommands.TypeResolver());
serializer.resolve(new AtomixConsistentMapCommands.TypeResolver());
diff --git a/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixDocumentTreeTest.java b/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixDocumentTreeTest.java
index dbaabd8..0759e43 100644
--- a/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixDocumentTreeTest.java
+++ b/core/store/primitives/src/test/java/org/onosproject/store/primitives/resources/impl/AtomixDocumentTreeTest.java
@@ -19,7 +19,6 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -32,7 +31,6 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.onosproject.store.service.DocumentPath;
import org.onosproject.store.service.DocumentTreeEvent;
@@ -311,7 +309,6 @@
* Tests listeners.
*/
@Test
- @Ignore
public void testNotifications() throws Exception {
AtomixDocumentTree tree = createAtomixClient().getResource(UUID.randomUUID().toString(),
AtomixDocumentTree.class).join();
@@ -320,9 +317,30 @@
// add listener; create a node in the tree and verify an CREATED event is received.
tree.addListener(listener).thenCompose(v -> tree.set(DocumentPath.from("root.a"), "a".getBytes())).join();
DocumentTreeEvent<byte[]> event = listener.event();
- assertNotNull(event);
assertEquals(DocumentTreeEvent.Type.CREATED, event.type());
+ assertFalse(event.oldValue().isPresent());
assertArrayEquals("a".getBytes(), event.newValue().get().value());
+ // update a node in the tree and verify an UPDATED event is received.
+ tree.set(DocumentPath.from("root.a"), "newA".getBytes()).join();
+ event = listener.event();
+ assertEquals(DocumentTreeEvent.Type.UPDATED, event.type());
+ assertArrayEquals("newA".getBytes(), event.newValue().get().value());
+ assertArrayEquals("a".getBytes(), event.oldValue().get().value());
+ // remove a node in the tree and verify an REMOVED event is received.
+ tree.removeNode(DocumentPath.from("root.a")).join();
+ event = listener.event();
+ assertEquals(DocumentTreeEvent.Type.DELETED, event.type());
+ assertFalse(event.newValue().isPresent());
+ assertArrayEquals("newA".getBytes(), event.oldValue().get().value());
+ // recursively create a node and verify CREATED events for all intermediate nodes.
+ tree.createRecursive(DocumentPath.from("root.x.y"), "xy".getBytes()).join();
+ event = listener.event();
+ assertEquals(DocumentTreeEvent.Type.CREATED, event.type());
+ assertEquals(DocumentPath.from("root.x"), event.path());
+ event = listener.event();
+ assertEquals(DocumentTreeEvent.Type.CREATED, event.type());
+ assertEquals(DocumentPath.from("root.x.y"), event.path());
+ assertArrayEquals("xy".getBytes(), event.newValue().get().value());
}
private static class TestEventListener implements DocumentTreeListener<byte[]> {