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