Add benchmarks for old LTTng-JUL API vs. new one
[lttng-ust-java-tests.git] / src / org / lttng / ust / agent / jul / benchmarks / handler / lttng / old / OldLttngJulHandlerTracingEnabledBenchmark.java
CommitLineData
86316987
AM
1package org.lttng.ust.agent.jul.benchmarks.handler.lttng.old;
2
3import static org.junit.Assert.assertTrue;
4import static org.junit.Assert.fail;
5
6import java.io.IOException;
7import java.lang.reflect.Field;
8
9import org.junit.After;
10import org.junit.Before;
11import org.lttng.ust.agent.LTTngAgent;
12import org.lttng.ust.agent.jul.LTTngJUL;
13import org.lttng.ust.agent.jul.LTTngLogHandler;
14import org.lttng.ust.agent.jul.benchmarks.handler.AbstractJulBenchmark;
15import org.lttng.ust.agent.jul.benchmarks.utils.LttngSessionControl;
16
17@SuppressWarnings("deprecation")
18public 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}
This page took 0.02474 seconds and 4 git commands to generate.