Commit | Line | Data |
---|---|---|
86316987 AM |
1 | package org.lttng.ust.agent.jul.benchmarks.handler.lttng.old; |
2 | ||
3 | import static org.junit.Assert.assertTrue; | |
4 | import static org.junit.Assert.fail; | |
5 | ||
6 | import java.io.IOException; | |
7 | import java.lang.reflect.Field; | |
8 | ||
9 | import org.junit.After; | |
10 | import org.junit.Before; | |
11 | import org.lttng.ust.agent.LTTngAgent; | |
12 | import org.lttng.ust.agent.jul.LTTngJUL; | |
13 | import org.lttng.ust.agent.jul.LTTngLogHandler; | |
14 | import org.lttng.ust.agent.jul.benchmarks.handler.AbstractJulBenchmark; | |
15 | import org.lttng.ust.agent.jul.benchmarks.utils.LttngSessionControl; | |
16 | ||
17 | @SuppressWarnings("deprecation") | |
18 | public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark { | |
19 | ||
20 | private LTTngAgent agent; | |
21 | private LTTngLogHandler oldHandler; | |
22 | ||
23 | @Before | |
24 | public void testSetup() throws IOException { | |
25 | agent = LTTngAgent.getLTTngAgent(); | |
26 | ||
27 | /* | |
28 | * The "old API" works by attaching a handler managed by the agent to | |
29 | * the root JUL logger. This causes problem here, because we use | |
30 | * logger.setUserParentHandler(false), which does not trigger the | |
31 | * handler as would be expected. | |
32 | * | |
33 | * Instead we will retrieve this handler through reflection, and attach | |
34 | * it to our own logger here for the duration of the test. | |
35 | */ | |
36 | try { | |
37 | Field julRootField = LTTngAgent.class.getDeclaredField("julRoot"); | |
38 | julRootField.setAccessible(true); | |
39 | LTTngJUL lf = (LTTngJUL) julRootField.get(null); // static field | |
40 | ||
41 | Field handlerField = LTTngJUL.class.getDeclaredField("handler"); | |
42 | handlerField.setAccessible(true); | |
43 | oldHandler = (LTTngLogHandler) handlerField.get(lf); | |
44 | ||
45 | logger.addHandler(oldHandler); | |
46 | ||
47 | } catch (ReflectiveOperationException e) { | |
48 | fail(); | |
49 | } | |
50 | ||
51 | assertTrue(LttngSessionControl.setupJulSessionAllEvents()); | |
52 | } | |
53 | ||
54 | @After | |
55 | public void testTeardown() { | |
56 | assertTrue(LttngSessionControl.stopSession()); | |
57 | assertTrue(LttngSessionControl.destroySession()); | |
58 | ||
59 | logger.removeHandler(oldHandler); | |
60 | agent.dispose(); | |
61 | } | |
62 | } |