]> git.lttng.org Git - lttng-ust-java-tests.git/blob
c6cc49c5c1553994d6c267e9c6682f6cdb60fa0c
[lttng-ust-java-tests.git] /
1 package org.lttng.ust.agent.benchmarks.jul.handler.lttng.old;
2
3 import static org.junit.Assert.assertTrue;
4 import static org.junit.Assert.fail;
5
6 import java.lang.reflect.Field;
7
8 import org.junit.After;
9 import org.junit.Before;
10 import org.lttng.ust.agent.LTTngAgent;
11 import org.lttng.ust.agent.benchmarks.jul.handler.AbstractJulBenchmark;
12 import org.lttng.ust.agent.jul.LttngLogHandler;
13 import org.lttng.ust.agent.utils.LttngSession;
14 import org.lttng.ust.agent.utils.LttngSession.Domain;
15
16 @SuppressWarnings("deprecation")
17 public class OldLttngJulHandlerTracingEnabledBenchmark extends AbstractJulBenchmark {
18
19 private LttngSession session;
20 private LttngLogHandler agentHandler;
21
22 @Before
23 public void testSetup() {
24 LTTngAgent agentInstance = LTTngAgent.getLTTngAgent();
25
26 /*
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.
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 {
36 Field julHandlerField = LTTngAgent.class.getDeclaredField("julHandler");
37 julHandlerField.setAccessible(true);
38 agentHandler = (LttngLogHandler) julHandlerField.get(agentInstance);
39
40 logger.addHandler(agentHandler);
41
42 } catch (ReflectiveOperationException e) {
43 fail();
44 }
45
46 session = new LttngSession(null, Domain.JUL);
47 assertTrue(session.enableAllEvents());
48 assertTrue(session.start());
49 }
50
51 @After
52 public void testTeardown() {
53 assertTrue(session.stop());
54 session.close();
55
56 logger.removeHandler(agentHandler);
57 LTTngAgent.dispose();
58 }
59 }
This page took 0.031636 seconds and 3 git commands to generate.