1 package org.lttng.ust.agent.jul.benchmarks.handler.lttng.old;
3 import static org.junit.Assert.assertTrue;
4 import static org.junit.Assert.fail;
6 import java.io.IOException;
7 import java.lang.reflect.Field;
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;
17 @SuppressWarnings("deprecation")
18 public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark {
20 private LTTngAgent agent;
21 private LTTngLogHandler oldHandler;
24 public void testSetup() throws IOException {
25 agent = LTTngAgent.getLTTngAgent();
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.
33 * Instead we will retrieve this handler through reflection, and attach
34 * it to our own logger here for the duration of the test.
37 Field julRootField = LTTngAgent.class.getDeclaredField("julRoot");
38 julRootField.setAccessible(true);
39 LTTngJUL lf = (LTTngJUL) julRootField.get(null); // static field
41 Field handlerField = LTTngJUL.class.getDeclaredField("handler");
42 handlerField.setAccessible(true);
43 oldHandler = (LTTngLogHandler) handlerField.get(lf);
45 logger.addHandler(oldHandler);
47 } catch (ReflectiveOperationException e) {
51 assertTrue(LttngSessionControl.setupJulSessionAllEvents());
55 public void testTeardown() {
56 assertTrue(LttngSessionControl.stopSession());
57 assertTrue(LttngSessionControl.destroySession());
59 logger.removeHandler(oldHandler);