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
.jupiter
.api
.Assertions
.assertEquals
;
23 import java
.util
.Collections
;
25 import java
.util
.stream
.Collectors
;
26 import java
.util
.stream
.Stream
;
28 import org
.junit
.jupiter
.api
.Test
;
29 import org
.junit
.jupiter
.api
.extension
.ExtendWith
;
30 import org
.junit
.jupiter
.api
.AfterEach
;
31 import org
.lttng
.tools
.ILttngSession
;
32 import org
.lttng
.ust
.agent
.filter
.FilterChangeNotifier
;
33 import org
.lttng
.ust
.agent
.integration
.filter
.FilterListenerITBase
.TestFilterListener
;
34 import org
.lttng
.ust
.agent
.session
.EventRule
;
35 import org
.lttng
.ust
.agent
.utils
.EventRuleFactory
;
36 import org
.lttng
.ust
.agent
.utils
.TestPrintExtension
;
39 * For the filter change notifications to work, several setup steps are
43 * <li>Initialize the Java agent register it to the sessiond [Agent]</li>
44 * <li>Instantiate a filer change listener, and register it to the notifier
46 * <li>Apply some event rule changes in the tracing session (lttng enable-event,
47 * etc.) [Session]</li>
51 * Then on teardown, the following steps are expected:
55 * <li>Dispose the Java agent, closing the connection to the sessiond [Agent]
57 * <li>Destroy the tracing session, removing tracked events [Session]</li>
60 * (and then the filter change listener should be de-registered from the
61 * notifier. If it is deregistered earlier, then obviously no notifications
62 * would be received thereafter).
65 * Within these two sets, each step can happen in any order. This results in 6 x
66 * 2 = 12 possibilities. The goal of this test class it to test these 12
70 @ExtendWith(TestPrintExtension
.class)
71 @SuppressWarnings("javadoc")
72 public abstract class FilterListenerOrderingITBase
{
74 protected static final String EVENT_NAME_A
= "EventA";
75 private static final String EVENT_NAME_B
= "EventB";
77 protected EventRuleFactory eventRuleFactory
;
79 private ILttngSession session
;
80 private TestFilterListener listener
;
86 public void baseTeardown() {
88 * Deregister the listener (should always be done after all the other
91 FilterChangeNotifier
.getInstance().unregisterListener(listener
);
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
99 protected abstract ILttngSession
.Domain
getDomain();
101 protected abstract void registerAgent();
103 private void registerListener() {
104 listener
= new TestFilterListener();
105 FilterChangeNotifier
.getInstance().registerListener(listener
);
108 private void enableRulesInSession() {
109 session
= ILttngSession
.createCommandLineSession(null, getDomain());
110 session
.enableEvent(EVENT_NAME_A
, null, false, null);
111 session
.enableEvent(EVENT_NAME_B
, null, false, null);
114 protected abstract void deregisterAgent();
116 private void destroySession() {
121 protected EventRuleFactory
getEventRuleFactory() {
122 if (eventRuleFactory
== null) {
123 eventRuleFactory
= new EventRuleFactory(getDomain());
125 return eventRuleFactory
;
128 // ------------------------------------------------------------------------
130 // ------------------------------------------------------------------------
133 * Check that the expected event rules are present after setup but before
136 private void checkOngoingConditions() {
137 Set
<EventRule
> exptectedRules
= Stream
.of(
138 getEventRuleFactory().createRule(EVENT_NAME_A
),
139 getEventRuleFactory().createRule(EVENT_NAME_B
))
140 .collect(Collectors
.toSet());
142 assertEquals(2, listener
.getNbNotifications());
143 assertEquals(exptectedRules
, listener
.getCurrentRules());
147 * Check that the expected event rules are present after/during teardown.
149 private void checkFinalConditions() {
150 Set
<EventRule
> expectedRules
= Collections
.EMPTY_SET
;
152 assertEquals(4, listener
.getNbNotifications());
153 assertEquals(expectedRules
, listener
.getCurrentRules());
157 public void testAgentListenerSession_AgentSession() {
160 enableRulesInSession();
162 checkOngoingConditions();
167 checkFinalConditions();
171 public void testAgentSessionListener_AgentSession() {
173 enableRulesInSession();
176 checkOngoingConditions();
181 checkFinalConditions();
185 public void testListenerAgentSession_AgentSession() {
188 enableRulesInSession();
190 checkOngoingConditions();
195 checkFinalConditions();
199 public void testListenerSessionAgent_AgentSession() {
201 enableRulesInSession();
204 checkOngoingConditions();
209 checkFinalConditions();
213 public void testSessionAgentListener_AgentSession() {
214 enableRulesInSession();
218 checkOngoingConditions();
223 checkFinalConditions();
227 public void testSessionListenerAgent_AgentSession() {
228 enableRulesInSession();
232 checkOngoingConditions();
237 checkFinalConditions();
243 public void testAgentListenerSession_SessionAgent() {
246 enableRulesInSession();
248 checkOngoingConditions();
251 checkFinalConditions();
253 checkFinalConditions();
257 public void testAgentSessionListener_SessionAgent() {
259 enableRulesInSession();
262 checkOngoingConditions();
265 checkFinalConditions();
267 checkFinalConditions();
271 public void testListenerAgentSession_SessionAgent() {
274 enableRulesInSession();
276 checkOngoingConditions();
279 checkFinalConditions();
281 checkFinalConditions();
285 public void testListenerSessionAgent_SessionAgent() {
287 enableRulesInSession();
290 checkOngoingConditions();
293 checkFinalConditions();
295 checkFinalConditions();
299 public void testSessionAgentListener_SessionAgent() {
300 enableRulesInSession();
304 checkOngoingConditions();
307 checkFinalConditions();
309 checkFinalConditions();
313 public void testSessionListenerAgent_SessionAgent() {
314 enableRulesInSession();
318 checkOngoingConditions();
321 checkFinalConditions();
323 checkFinalConditions();