Fix AtomixDocumentTree event notifications
Change-Id: Id79ba675dfc83fbe6c04a7789842a4e65050c046
Showing
2 changed files
with
24 additions
and
4 deletions
| ... | @@ -108,6 +108,8 @@ public final class CatalystSerializers { | ... | @@ -108,6 +108,8 @@ public final class CatalystSerializers { |
| 108 | serializer.register(DocumentTreeEvent.class, factory); | 108 | serializer.register(DocumentTreeEvent.class, factory); |
| 109 | serializer.register(Maps.immutableEntry("a", "b").getClass(), factory); | 109 | serializer.register(Maps.immutableEntry("a", "b").getClass(), factory); |
| 110 | serializer.register(ImmutableList.of().getClass(), factory); | 110 | serializer.register(ImmutableList.of().getClass(), factory); |
| 111 | + serializer.register(ImmutableList.of("a").getClass(), factory); | ||
| 112 | + serializer.register(Arrays.asList().getClass(), factory); | ||
| 111 | 113 | ||
| 112 | serializer.resolve(new LongCommands.TypeResolver()); | 114 | serializer.resolve(new LongCommands.TypeResolver()); |
| 113 | serializer.resolve(new AtomixConsistentMapCommands.TypeResolver()); | 115 | serializer.resolve(new AtomixConsistentMapCommands.TypeResolver()); | ... | ... |
| ... | @@ -19,7 +19,6 @@ package org.onosproject.store.primitives.resources.impl; | ... | @@ -19,7 +19,6 @@ package org.onosproject.store.primitives.resources.impl; |
| 19 | import static org.junit.Assert.assertArrayEquals; | 19 | import static org.junit.Assert.assertArrayEquals; |
| 20 | import static org.junit.Assert.assertEquals; | 20 | import static org.junit.Assert.assertEquals; |
| 21 | import static org.junit.Assert.assertFalse; | 21 | import static org.junit.Assert.assertFalse; |
| 22 | -import static org.junit.Assert.assertNotNull; | ||
| 23 | import static org.junit.Assert.assertNull; | 22 | import static org.junit.Assert.assertNull; |
| 24 | import static org.junit.Assert.assertTrue; | 23 | import static org.junit.Assert.assertTrue; |
| 25 | import static org.junit.Assert.fail; | 24 | import static org.junit.Assert.fail; |
| ... | @@ -32,7 +31,6 @@ import java.util.concurrent.BlockingQueue; | ... | @@ -32,7 +31,6 @@ import java.util.concurrent.BlockingQueue; |
| 32 | 31 | ||
| 33 | import org.junit.AfterClass; | 32 | import org.junit.AfterClass; |
| 34 | import org.junit.BeforeClass; | 33 | import org.junit.BeforeClass; |
| 35 | -import org.junit.Ignore; | ||
| 36 | import org.junit.Test; | 34 | import org.junit.Test; |
| 37 | import org.onosproject.store.service.DocumentPath; | 35 | import org.onosproject.store.service.DocumentPath; |
| 38 | import org.onosproject.store.service.DocumentTreeEvent; | 36 | import org.onosproject.store.service.DocumentTreeEvent; |
| ... | @@ -311,7 +309,6 @@ public class AtomixDocumentTreeTest extends AtomixTestBase { | ... | @@ -311,7 +309,6 @@ public class AtomixDocumentTreeTest extends AtomixTestBase { |
| 311 | * Tests listeners. | 309 | * Tests listeners. |
| 312 | */ | 310 | */ |
| 313 | @Test | 311 | @Test |
| 314 | - @Ignore | ||
| 315 | public void testNotifications() throws Exception { | 312 | public void testNotifications() throws Exception { |
| 316 | AtomixDocumentTree tree = createAtomixClient().getResource(UUID.randomUUID().toString(), | 313 | AtomixDocumentTree tree = createAtomixClient().getResource(UUID.randomUUID().toString(), |
| 317 | AtomixDocumentTree.class).join(); | 314 | AtomixDocumentTree.class).join(); |
| ... | @@ -320,9 +317,30 @@ public class AtomixDocumentTreeTest extends AtomixTestBase { | ... | @@ -320,9 +317,30 @@ public class AtomixDocumentTreeTest extends AtomixTestBase { |
| 320 | // add listener; create a node in the tree and verify an CREATED event is received. | 317 | // add listener; create a node in the tree and verify an CREATED event is received. |
| 321 | tree.addListener(listener).thenCompose(v -> tree.set(DocumentPath.from("root.a"), "a".getBytes())).join(); | 318 | tree.addListener(listener).thenCompose(v -> tree.set(DocumentPath.from("root.a"), "a".getBytes())).join(); |
| 322 | DocumentTreeEvent<byte[]> event = listener.event(); | 319 | DocumentTreeEvent<byte[]> event = listener.event(); |
| 323 | - assertNotNull(event); | ||
| 324 | assertEquals(DocumentTreeEvent.Type.CREATED, event.type()); | 320 | assertEquals(DocumentTreeEvent.Type.CREATED, event.type()); |
| 321 | + assertFalse(event.oldValue().isPresent()); | ||
| 325 | assertArrayEquals("a".getBytes(), event.newValue().get().value()); | 322 | assertArrayEquals("a".getBytes(), event.newValue().get().value()); |
| 323 | + // update a node in the tree and verify an UPDATED event is received. | ||
| 324 | + tree.set(DocumentPath.from("root.a"), "newA".getBytes()).join(); | ||
| 325 | + event = listener.event(); | ||
| 326 | + assertEquals(DocumentTreeEvent.Type.UPDATED, event.type()); | ||
| 327 | + assertArrayEquals("newA".getBytes(), event.newValue().get().value()); | ||
| 328 | + assertArrayEquals("a".getBytes(), event.oldValue().get().value()); | ||
| 329 | + // remove a node in the tree and verify an REMOVED event is received. | ||
| 330 | + tree.removeNode(DocumentPath.from("root.a")).join(); | ||
| 331 | + event = listener.event(); | ||
| 332 | + assertEquals(DocumentTreeEvent.Type.DELETED, event.type()); | ||
| 333 | + assertFalse(event.newValue().isPresent()); | ||
| 334 | + assertArrayEquals("newA".getBytes(), event.oldValue().get().value()); | ||
| 335 | + // recursively create a node and verify CREATED events for all intermediate nodes. | ||
| 336 | + tree.createRecursive(DocumentPath.from("root.x.y"), "xy".getBytes()).join(); | ||
| 337 | + event = listener.event(); | ||
| 338 | + assertEquals(DocumentTreeEvent.Type.CREATED, event.type()); | ||
| 339 | + assertEquals(DocumentPath.from("root.x"), event.path()); | ||
| 340 | + event = listener.event(); | ||
| 341 | + assertEquals(DocumentTreeEvent.Type.CREATED, event.type()); | ||
| 342 | + assertEquals(DocumentPath.from("root.x.y"), event.path()); | ||
| 343 | + assertArrayEquals("xy".getBytes(), event.newValue().get().value()); | ||
| 326 | } | 344 | } |
| 327 | 345 | ||
| 328 | private static class TestEventListener implements DocumentTreeListener<byte[]> { | 346 | private static class TestEventListener implements DocumentTreeListener<byte[]> { | ... | ... |
-
Please register or login to post a comment