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; | |
25 | import java.util.HashSet; | |
26 | import java.util.Set; | |
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 | ||
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"; | |
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 */ | |
73 | Set<String> actualEvents = session.listEvents(); | |
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 | ||
85 | Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1)); | |
86 | Set<String> actualEvents = session.listEvents(); | |
87 | ||
88 | assertEquals(expectedEvents, actualEvents); | |
89 | } | |
90 | ||
91 | /** | |
92 | * Test with many loggers existing, and all of them having a LTTng handler | |
93 | * attached. | |
94 | */ | |
95 | @Test | |
96 | public void testManyLoggersAllAttached() { | |
97 | attachHandlerToLogger(1, 1); | |
98 | attachHandlerToLogger(2, 2); | |
99 | attachHandlerToLogger(2, 3); | |
100 | ||
101 | Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2, LOGGER_NAME_3)); | |
102 | Set<String> actualEvents = session.listEvents(); | |
103 | ||
104 | assertEquals(expectedEvents, actualEvents); | |
105 | } | |
106 | ||
107 | /** | |
108 | * Test with some loggers having had handlers attached but then detached. | |
109 | */ | |
110 | @Test | |
111 | public void testLoggersSomeDetached() { | |
112 | attachHandlerToLogger(1, 1); | |
113 | attachHandlerToLogger(2, 2); | |
114 | ||
115 | attachHandlerToLogger(2, 3); | |
116 | detachHandlerFromLogger(2, 3); | |
117 | /* Only loggers 1 and 2 will be attached */ | |
118 | ||
119 | Set<String> expectedEvents = new HashSet<>(Arrays.asList(LOGGER_NAME_1, LOGGER_NAME_2)); | |
120 | Set<String> actualEvents = session.listEvents(); | |
121 | ||
122 | assertEquals(expectedEvents, actualEvents); | |
123 | } | |
124 | ||
125 | /** | |
126 | * Test with all loggers having had handlers attached and then detached. | |
127 | */ | |
128 | @Test | |
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); | |
136 | ||
137 | Set<String> actualEvents = session.listEvents(); | |
138 | assertTrue(actualEvents.isEmpty()); | |
139 | } | |
140 | } |