Commit | Line | Data |
---|---|---|
b34f80ae AM |
1 | /* |
2 | * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> | |
3 | * | |
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. | |
8 | * | |
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. | |
13 | * | |
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. | |
17 | */ | |
18 | ||
19 | package org.lttng.ust.agent.integration.events; | |
20 | ||
7a4f0255 MJ |
21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
22 | import static org.junit.jupiter.api.Assertions.assertTrue; | |
b34f80ae AM |
23 | |
24 | import java.util.Arrays; | |
8f21b7d2 AM |
25 | import java.util.Collections; |
26 | import java.util.List; | |
b34f80ae | 27 | |
7a4f0255 MJ |
28 | import org.junit.jupiter.api.AfterEach; |
29 | import org.junit.jupiter.api.BeforeEach; | |
30 | import org.junit.jupiter.api.Test; | |
31 | import org.junit.jupiter.api.extension.ExtendWith; | |
b34f80ae | 32 | import org.lttng.tools.ILttngSession; |
7a4f0255 | 33 | import org.lttng.ust.agent.utils.TestPrintExtension; |
b34f80ae AM |
34 | |
35 | /** | |
36 | * Base class for the list events command tests | |
37 | */ | |
7a4f0255 | 38 | @ExtendWith(TestPrintExtension.class) |
b34f80ae AM |
39 | public abstract class ListEventsITBase { |
40 | ||
0fcd7d54 | 41 | protected static final String LOGGER_NAME_1 = "org.lttng.somecomponent"; |
b34f80ae | 42 | protected static final String LOGGER_NAME_2 = "org.lttng.mycomponent"; |
6c2b24d5 | 43 | protected static final String LOGGER_NAME_3 = "org.lttng.myothercomponent-àéç"; |
b34f80ae AM |
44 | |
45 | private ILttngSession session; | |
46 | ||
47 | /** | |
48 | * Common test setup | |
49 | */ | |
7a4f0255 | 50 | @BeforeEach |
b34f80ae AM |
51 | public void testSetup() { |
52 | session = ILttngSession.createSession(null, getDomain()); | |
53 | } | |
54 | ||
55 | /** | |
56 | * Common test teardown | |
57 | */ | |
7a4f0255 | 58 | @AfterEach |
b34f80ae AM |
59 | public void testTeardown() { |
60 | session.close(); | |
61 | } | |
62 | ||
63 | protected abstract ILttngSession.Domain getDomain(); | |
64 | ||
65 | protected abstract void attachHandlerToLogger(int handlerIndex, int loggerIndex); | |
66 | ||
67 | protected abstract void detachHandlerFromLogger(int handlerIndex, int loggerIndex); | |
68 | ||
69 | /** | |
70 | * Test with many loggers existing, but none of them having a LTTng handler | |
71 | * attached. | |
72 | */ | |
73 | @Test | |
74 | public void testManyLoggersNoneAttached() { | |
75 | /* Don't attach anything */ | |
8f21b7d2 | 76 | List<String> actualEvents = session.listEvents(); |
b34f80ae AM |
77 | assertTrue(actualEvents.isEmpty()); |
78 | } | |
79 | ||
80 | /** | |
81 | * Test with many loggers existing, but only a subset of them has a LTTng | |
82 | * handler attached. | |
83 | */ | |
84 | @Test | |
85 | public void testManyLoggersSomeAttached() { | |
86 | attachHandlerToLogger(1, 1); | |
87 | ||
8f21b7d2 AM |
88 | List<String> expectedEvents = Arrays.asList(LOGGER_NAME_1); |
89 | List<String> actualEvents = session.listEvents(); | |
90 | ||
91 | Collections.sort(expectedEvents); | |
92 | Collections.sort(actualEvents); | |
b34f80ae AM |
93 | |
94 | assertEquals(expectedEvents, actualEvents); | |
95 | } | |
96 | ||
97 | /** | |
98 | * Test with many loggers existing, and all of them having a LTTng handler | |
99 | * attached. | |
100 | */ | |
101 | @Test | |
102 | public void testManyLoggersAllAttached() { | |
103 | attachHandlerToLogger(1, 1); | |
104 | attachHandlerToLogger(2, 2); | |
105 | attachHandlerToLogger(2, 3); | |
106 | ||
8f21b7d2 AM |
107 | List<String> expectedEvents = Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2, LOGGER_NAME_3); |
108 | List<String> actualEvents = session.listEvents(); | |
109 | ||
110 | Collections.sort(expectedEvents); | |
111 | Collections.sort(actualEvents); | |
b34f80ae AM |
112 | |
113 | assertEquals(expectedEvents, actualEvents); | |
114 | } | |
115 | ||
116 | /** | |
117 | * Test with some loggers having had handlers attached but then detached. | |
118 | */ | |
119 | @Test | |
120 | public void testLoggersSomeDetached() { | |
121 | attachHandlerToLogger(1, 1); | |
122 | attachHandlerToLogger(2, 2); | |
123 | ||
124 | attachHandlerToLogger(2, 3); | |
125 | detachHandlerFromLogger(2, 3); | |
126 | /* Only loggers 1 and 2 will be attached */ | |
127 | ||
8f21b7d2 AM |
128 | List<String> expectedEvents = Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2); |
129 | List<String> actualEvents = session.listEvents(); | |
130 | ||
131 | Collections.sort(expectedEvents); | |
132 | Collections.sort(actualEvents); | |
b34f80ae AM |
133 | |
134 | assertEquals(expectedEvents, actualEvents); | |
135 | } | |
136 | ||
137 | /** | |
138 | * Test with all loggers having had handlers attached and then detached. | |
139 | */ | |
140 | @Test | |
141 | public void testLoggersAllDetached() { | |
142 | attachHandlerToLogger(1, 1); | |
143 | attachHandlerToLogger(2, 2); | |
144 | attachHandlerToLogger(2, 3); | |
145 | detachHandlerFromLogger(1, 1); | |
146 | detachHandlerFromLogger(2, 2); | |
147 | detachHandlerFromLogger(2, 3); | |
148 | ||
8f21b7d2 | 149 | List<String> actualEvents = session.listEvents(); |
b34f80ae AM |
150 | assertTrue(actualEvents.isEmpty()); |
151 | } | |
152 | } |