2 * Copyright (C) 2016, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 package org
.lttng
.ust
.agent
.integration
.filter
;
21 import static org
.junit
.Assert
.assertEquals
;
23 import java
.util
.Collections
;
25 import java
.util
.stream
.Collectors
;
26 import java
.util
.stream
.Stream
;
28 import org
.junit
.After
;
29 import org
.junit
.Test
;
30 import org
.lttng
.tools
.ILttngSession
;
31 import org
.lttng
.ust
.agent
.filter
.FilterChangeNotifier
;
32 import org
.lttng
.ust
.agent
.integration
.filter
.FilterListenerITBase
.TestFilterListener
;
33 import org
.lttng
.ust
.agent
.session
.EventRule
;
34 import org
.lttng
.ust
.agent
.utils
.EventRuleFactory
;
37 * For the filter change notifications to work, several setup steps are
41 * <li>Initialize the Java agent register it to the sessiond [Agent]</li>
42 * <li>Instantiate a filer change listener, and register it to the notifier
44 * <li>Apply some event rule changes in the tracing session (lttng enable-event,
45 * etc.) [Session]</li>
49 * Then on teardown, the following steps are expected:
53 * <li>Dispose the Java agent, closing the connection to the sessiond [Agent]
55 * <li>Destroy the tracing session, removing tracked events [Session]</li>
58 * (and then the filter change listener should be de-registered from the
59 * notifier. If it is deregistered earlier, then obviously no notifications
60 * would be received thereafter).
63 * Within these two sets, each step can happen in any order. This results in 6 x
64 * 2 = 12 possibilities. The goal of this test class it to test these 12
68 @SuppressWarnings("javadoc")
69 public abstract class FilterListenerOrderingITBase
{
71 protected static final String EVENT_NAME_A
= "EventA";
72 private static final String EVENT_NAME_B
= "EventB";
74 private ILttngSession session
;
75 private TestFilterListener listener
;
81 public void baseTeardown() {
83 * Deregister the listener (should always be done after all the other
86 FilterChangeNotifier
.getInstance().unregisterListener(listener
);
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
94 protected abstract ILttngSession
.Domain
getDomain();
96 protected abstract void registerAgent();
98 private void registerListener() {
99 listener
= new TestFilterListener();
100 FilterChangeNotifier
.getInstance().registerListener(listener
);
103 private void enableRulesInSession() {
104 session
= ILttngSession
.createCommandLineSession(null, getDomain());
105 session
.enableEvent(EVENT_NAME_A
, null, false, null);
106 session
.enableEvent(EVENT_NAME_B
, null, false, null);
109 protected abstract void deregisterAgent();
111 private void destroySession() {
116 // ------------------------------------------------------------------------
118 // ------------------------------------------------------------------------
121 * Check that the expected event rules are present after setup but before
124 private void checkOngoingConditions() {
125 Set
<EventRule
> exptectedRules
= Stream
.of(
126 EventRuleFactory
.createRule(EVENT_NAME_A
),
127 EventRuleFactory
.createRule(EVENT_NAME_B
))
128 .collect(Collectors
.toSet());
130 assertEquals(2, listener
.getNbNotifications());
131 assertEquals(exptectedRules
, listener
.getCurrentRules());
135 * Check that the expected event rules are present after/during teardown.
137 private void checkFinalConditions() {
138 Set
<EventRule
> expectedRules
= Collections
.EMPTY_SET
;
140 assertEquals(4, listener
.getNbNotifications());
141 assertEquals(expectedRules
, listener
.getCurrentRules());
145 public void testAgentListenerSession_AgentSession() {
148 enableRulesInSession();
150 checkOngoingConditions();
155 checkFinalConditions();
159 public void testAgentSessionListener_AgentSession() {
161 enableRulesInSession();
164 checkOngoingConditions();
169 checkFinalConditions();
173 public void testListenerAgentSession_AgentSession() {
176 enableRulesInSession();
178 checkOngoingConditions();
183 checkFinalConditions();
187 public void testListenerSessionAgent_AgentSession() {
189 enableRulesInSession();
192 checkOngoingConditions();
197 checkFinalConditions();
201 public void testSessionAgentListener_AgentSession() {
202 enableRulesInSession();
206 checkOngoingConditions();
211 checkFinalConditions();
215 public void testSessionListenerAgent_AgentSession() {
216 enableRulesInSession();
220 checkOngoingConditions();
225 checkFinalConditions();
231 public void testAgentListenerSession_SessionAgent() {
234 enableRulesInSession();
236 checkOngoingConditions();
239 checkFinalConditions();
241 checkFinalConditions();
245 public void testAgentSessionListener_SessionAgent() {
247 enableRulesInSession();
250 checkOngoingConditions();
253 checkFinalConditions();
255 checkFinalConditions();
259 public void testListenerAgentSession_SessionAgent() {
262 enableRulesInSession();
264 checkOngoingConditions();
267 checkFinalConditions();
269 checkFinalConditions();
273 public void testListenerSessionAgent_SessionAgent() {
275 enableRulesInSession();
278 checkOngoingConditions();
281 checkFinalConditions();
283 checkFinalConditions();
287 public void testSessionAgentListener_SessionAgent() {
288 enableRulesInSession();
292 checkOngoingConditions();
295 checkFinalConditions();
297 checkFinalConditions();
301 public void testSessionListenerAgent_SessionAgent() {
302 enableRulesInSession();
306 checkOngoingConditions();
309 checkFinalConditions();
311 checkFinalConditions();