2 * Copyright (C) 2015, 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.events;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertTrue;
24 import java.util.Arrays;
25 import java.util.HashSet;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.lttng.tools.ILttngSession;
34 * Base class for the list events command tests
36 public abstract class ListEventsITBase {
38 protected static final String LOGGER_NAME_1 = "org.lttng";
39 protected static final String LOGGER_NAME_2 = "org.lttng.mycomponent";
40 protected static final String LOGGER_NAME_3 = "org.lttng.myothercomponent-àéç";
42 private ILttngSession session;
48 public void testSetup() {
49 session = ILttngSession.createSession(null, getDomain());
53 * Common test teardown
56 public void testTeardown() {
60 protected abstract ILttngSession.Domain getDomain();
62 protected abstract void attachHandlerToLogger(int handlerIndex, int loggerIndex);
64 protected abstract void detachHandlerFromLogger(int handlerIndex, int loggerIndex);
67 * Test with many loggers existing, but none of them having a LTTng handler
71 public void testManyLoggersNoneAttached() {
72 /* Don't attach anything */
73 Set<String> actualEvents = session.listEvents();
74 assertTrue(actualEvents.isEmpty());
78 * Test with many loggers existing, but only a subset of them has a LTTng
82 public void testManyLoggersSomeAttached() {
83 attachHandlerToLogger(1, 1);
85 Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1));
86 Set<String> actualEvents = session.listEvents();
88 assertEquals(expectedEvents, actualEvents);
92 * Test with many loggers existing, and all of them having a LTTng handler
96 public void testManyLoggersAllAttached() {
97 attachHandlerToLogger(1, 1);
98 attachHandlerToLogger(2, 2);
99 attachHandlerToLogger(2, 3);
101 Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2, LOGGER_NAME_3));
102 Set<String> actualEvents = session.listEvents();
104 assertEquals(expectedEvents, actualEvents);
108 * Test with some loggers having had handlers attached but then detached.
111 public void testLoggersSomeDetached() {
112 attachHandlerToLogger(1, 1);
113 attachHandlerToLogger(2, 2);
115 attachHandlerToLogger(2, 3);
116 detachHandlerFromLogger(2, 3);
117 /* Only loggers 1 and 2 will be attached */
119 Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2));
120 Set<String> actualEvents = session.listEvents();
122 assertEquals(expectedEvents, actualEvents);
126 * Test with all loggers having had handlers attached and then detached.
129 public void testLoggersAllDetached() {
130 attachHandlerToLogger(1, 1);
131 attachHandlerToLogger(2, 2);
132 attachHandlerToLogger(2, 3);
133 detachHandlerFromLogger(1, 1);
134 detachHandlerFromLogger(2, 2);
135 detachHandlerFromLogger(2, 3);
137 Set<String> actualEvents = session.listEvents();
138 assertTrue(actualEvents.isEmpty());