Commit | Line | Data |
---|---|---|
2b408e85 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 | ||
4821eac9 | 19 | package org.lttng.ust.agent.utils; |
8576633f | 20 | |
eca27046 AM |
21 | import static org.junit.Assert.assertTrue; |
22 | import static org.junit.Assert.fail; | |
23 | ||
4821eac9 | 24 | import java.io.IOException; |
8576633f AM |
25 | import java.util.logging.Level; |
26 | import java.util.logging.Logger; | |
27 | ||
eca27046 AM |
28 | import org.lttng.tools.LttngToolsHelper; |
29 | import org.lttng.tools.ILttngSession.Domain; | |
4821eac9 AM |
30 | import org.lttng.ust.agent.jul.LttngLogHandler; |
31 | ||
8a0613fa AM |
32 | /** |
33 | * Utility methods for JUL tests | |
34 | */ | |
4821eac9 AM |
35 | public final class JulTestUtils { |
36 | ||
37 | private JulTestUtils() { | |
38 | } | |
8576633f | 39 | |
eca27046 AM |
40 | /** |
41 | * Setup method common to most JUL tests. To be called in a @BeforeClass. | |
42 | */ | |
43 | public static void testClassSetup() { | |
44 | /* Make sure we can find the JNI library and lttng-tools */ | |
45 | checkForJulLibrary(); | |
46 | assertTrue("lttng-tools is not working properly.", LttngUtils.checkForLttngTools(Domain.JUL)); | |
47 | ||
48 | LttngToolsHelper.destroyAllSessions(); | |
49 | } | |
50 | ||
51 | /** | |
52 | * Teardown method common to most JUL tests. To be called in a @AfterClass. | |
53 | */ | |
54 | public static void testClassCleanup() { | |
55 | LttngToolsHelper.deleteAllTraces(); | |
56 | } | |
57 | ||
4821eac9 AM |
58 | /** |
59 | * Check the the JUL native library is available, effectively allowing LTTng | |
60 | * JUL handlers to be used. | |
4821eac9 | 61 | */ |
eca27046 | 62 | private static void checkForJulLibrary() { |
4821eac9 AM |
63 | try { |
64 | LttngLogHandler testHandler = new LttngLogHandler(); | |
65 | testHandler.close(); | |
66 | } catch (SecurityException | IOException e) { | |
eca27046 | 67 | fail(e.getMessage()); |
4821eac9 | 68 | } |
8576633f AM |
69 | } |
70 | ||
4821eac9 AM |
71 | /** |
72 | * Send 10 dummy events through the provided logger | |
73 | * | |
74 | * @param logger | |
75 | * The logger to use to send events | |
76 | */ | |
77 | public static void send10EventsTo(Logger logger) { | |
8576633f AM |
78 | String a = new String("a"); |
79 | Object[] params = { a, new String("b"), new Object() }; | |
80 | ||
81 | // Levels are FINE, FINER, FINEST, INFO, SEVERE, WARNING | |
82 | logger.fine("A fine level message"); | |
83 | logger.finer("A finer level message"); | |
84 | logger.finest("A finest level message"); | |
85 | logger.info("A info level message"); | |
86 | logger.severe("A severe level message"); | |
87 | logger.warning("A warning level message"); | |
88 | logger.warning("Another warning level message"); | |
89 | logger.log(Level.WARNING, "A warning message using Logger.log()"); | |
90 | logger.log(Level.INFO, "A message with one parameter", a); | |
91 | logger.log(Level.INFO, "A message with parameters", params); | |
92 | } | |
93 | } |