Add some integration tests for JUL
[lttng-ust-java-tests.git] / src / org / lttng / ust / agent / benchmarks / jul / handler / lttng / old / OldLttngJulHandlerTracingEnabledBenchmark.java
CommitLineData
da8308fe 1package org.lttng.ust.agent.benchmarks.jul.handler.lttng.old;
86316987
AM
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;
da8308fe
AM
12import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark;
13import org.lttng.ust.agent.jul.LttngLogHandler;
14import org.lttng.ust.agent.utils.LttngSessionControl;
15import org.lttng.ust.agent.utils.LttngSessionControl.Domain;
86316987
AM
16
17@SuppressWarnings("deprecation")
18public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark {
19
da8308fe 20 private LttngLogHandler agentHandler;
86316987
AM
21
22 @Before
23 public void testSetup() throws IOException {
da8308fe 24 LTTngAgent agentInstance = LTTngAgent.getLTTngAgent();
86316987
AM
25
26 /*
27 * The "old API" works by attaching a handler managed by the agent to
da8308fe 28 * the root JUL logger. This causes problems here, because we use
86316987
AM
29 * logger.setUserParentHandler(false), which does not trigger the
30 * handler as would be expected.
31 *
32 * Instead we will retrieve this handler through reflection, and attach
33 * it to our own logger here for the duration of the test.
34 */
35 try {
da8308fe
AM
36 Field julHandlerField = LTTngAgent.class.getDeclaredField("julHandler");
37 julHandlerField.setAccessible(true);
38 agentHandler = (LttngLogHandler) julHandlerField.get(agentInstance);
86316987 39
da8308fe 40 logger.addHandler(agentHandler);
86316987
AM
41
42 } catch (ReflectiveOperationException e) {
43 fail();
44 }
45
da8308fe 46 assertTrue(LttngSessionControl.setupSessionAllEvents(null, Domain.JUL));
86316987
AM
47 }
48
49 @After
50 public void testTeardown() {
9368bd5e
AM
51 assertTrue(LttngSessionControl.stopSession(null));
52 assertTrue(LttngSessionControl.destroySession(null));
86316987 53
da8308fe
AM
54 logger.removeHandler(agentHandler);
55 LTTngAgent.dispose();
86316987
AM
56 }
57}
This page took 0.025378 seconds and 4 git commands to generate.