1 package org.lttng.ust.agent.benchmarks.jul.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.benchmarks.jul.handler.AbstractJulBenchmark;
13 import org.lttng.ust.agent.jul.LttngLogHandler;
14 import org.lttng.ust.agent.utils.LttngSessionControl;
15 import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
17 @SuppressWarnings("deprecation")
18 public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark {
20 private LttngLogHandler agentHandler;
23 public void testSetup() throws IOException {
24 LTTngAgent agentInstance = LTTngAgent.getLTTngAgent();
27 * The "old API" works by attaching a handler managed by the agent to
28 * the root JUL logger. This causes problems here, because we use
29 * logger.setUserParentHandler(false), which does not trigger the
30 * handler as would be expected.
32 * Instead we will retrieve this handler through reflection, and attach
33 * it to our own logger here for the duration of the test.
36 Field julHandlerField = LTTngAgent.class.getDeclaredField("julHandler");
37 julHandlerField.setAccessible(true);
38 agentHandler = (LttngLogHandler) julHandlerField.get(agentInstance);
40 logger.addHandler(agentHandler);
42 } catch (ReflectiveOperationException e) {
46 assertTrue(LttngSessionControl.setupSessionAllEvents(null, Domain.JUL));
50 public void testTeardown() {
51 assertTrue(LttngSessionControl.stopSession(null));
52 assertTrue(LttngSessionControl.destroySession(null));
54 logger.removeHandler(agentHandler);