Add a couple filter listener reg/dereg tests
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 1 Sep 2015 20:09:26 +0000 (16:09 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Tue, 1 Sep 2015 20:09:26 +0000 (16:09 -0400)
Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
lttng-ust-java-tests/src/test/java/org/lttng/ust/agent/integration/filter/FilterListenerITBase.java

index e7c537ce5cd8bfb0b5f98836c6f33a166c631817..efacc245434387a714313424445e47a5276b20fd 100644 (file)
@@ -233,6 +233,99 @@ public abstract class FilterListenerITBase {
         assertTrue(listener.checkRules());
     }
 
+    /**
+     * Test sending some notifications then detaching a listener. Subsequent
+     * notifications should not be sent.
+     */
+    @Test
+    public void testDetachingListener() {
+        Set<EventRule> rules = Stream.of(
+                        new EventRule(EVENT_NAME_A, LOG_LEVEL_UNSPECIFIED, null),
+                        new EventRule(EVENT_NAME_B, LOG_LEVEL_UNSPECIFIED, null))
+                .collect(Collectors.toSet());
+
+        listener.setParameters(2, rules);
+
+        session.enableEvent(EVENT_NAME_A, null, false, null);
+        session.enableEvent(EVENT_NAME_B, null, false, null);
+        FilterNotificationManager.getInstance().unregisterListener(listener);
+        session.enableEvent(EVENT_NAME_C, null, false, null);
+
+        assertTrue(listener.waitForAllNotifications());
+        assertTrue(listener.checkRules());
+    }
+
+    /**
+     * Run a test with multiple listeners attached to the manager. All listeners
+     * should receive all the data.
+     */
+    @Test
+    public void testMultipleListeners() {
+        FilterNotificationManager fnm = FilterNotificationManager.getInstance();
+        TestFilterListener listener2 = new TestFilterListener();
+        TestFilterListener listener3 = new TestFilterListener();
+        fnm.registerListener(listener2);
+        fnm.registerListener(listener3);
+
+        Set<EventRule> rules = Stream.of(
+                new EventRule(EVENT_NAME_A, LOG_LEVEL_UNSPECIFIED, null),
+                new EventRule(EVENT_NAME_B, LOG_LEVEL_UNSPECIFIED, null))
+            .collect(Collectors.toSet());
+
+        listener.setParameters(4, rules);
+        listener2.setParameters(4, rules);
+        listener3.setParameters(4, rules);
+
+        session.enableEvent(EVENT_NAME_A, null, false, null);
+        session.enableEvent(EVENT_NAME_B, null, false, null);
+        session.enableEvent(EVENT_NAME_C, null, false, null);
+        session.disableEvents(EVENT_NAME_C);
+
+        assertTrue(listener.waitForAllNotifications());
+        assertTrue(listener2.waitForAllNotifications());
+        assertTrue(listener3.waitForAllNotifications());
+        assertTrue(listener.checkRules());
+        assertTrue(listener2.checkRules());
+        assertTrue(listener3.checkRules());
+
+        fnm.unregisterListener(listener2);
+        fnm.unregisterListener(listener3);
+    }
+
+    /**
+     * Test with both attached and unattached listeners. The unattached ones
+     * should not receive anything, but should not interfere with the other
+     * ones.
+     */
+    @Test
+    public void testUnattachedListeners() {
+        FilterNotificationManager fnm = FilterNotificationManager.getInstance();
+        TestFilterListener listener2 = new TestFilterListener();
+        TestFilterListener listener3 = new TestFilterListener();
+        /* We attach then detach listener2. We never attach listener3 */
+        fnm.registerListener(listener2);
+        fnm.unregisterListener(listener2);
+
+        Set<EventRule> rules = Stream.of(
+                new EventRule(EVENT_NAME_A, LOG_LEVEL_UNSPECIFIED, null),
+                new EventRule(EVENT_NAME_B, LOG_LEVEL_UNSPECIFIED, null))
+            .collect(Collectors.toSet());
+
+        listener.setParameters(2, rules);
+        listener2.setParameters(0, Collections.EMPTY_SET);
+        listener3.setParameters(0, Collections.EMPTY_SET);
+
+        session.enableEvent(EVENT_NAME_A, null, false, null);
+        session.enableEvent(EVENT_NAME_B, null, false, null);
+
+        assertTrue(listener.waitForAllNotifications());
+        assertTrue(listener2.waitForAllNotifications());
+        assertTrue(listener3.waitForAllNotifications());
+        assertTrue(listener.checkRules());
+        assertTrue(listener2.checkRules());
+        assertTrue(listener3.checkRules());
+    }
+
     /**
      * The filter listener used for tests.
      *
This page took 0.023899 seconds and 4 git commands to generate.