X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=lttng-ust-java-tests-common%2Fsrc%2Ftest%2Fjava%2Forg%2Flttng%2Fust%2Fagent%2Fintegration%2Fclient%2FTcpClientIT.java;h=69ef96f61f793bbb9a1ac48d597be01717e32566;hb=65a36bff2c5a362152e6448d7891e94f008e4a8b;hp=2794dfa58411f96afcc98496756b1c9d6f82230e;hpb=4821eac962d2f707558b6d9a5b66af9dbe89b933;p=lttng-ust-java-tests.git diff --git a/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/integration/client/TcpClientIT.java b/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/integration/client/TcpClientIT.java index 2794dfa..69ef96f 100644 --- a/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/integration/client/TcpClientIT.java +++ b/lttng-ust-java-tests-common/src/test/java/org/lttng/ust/agent/integration/client/TcpClientIT.java @@ -20,7 +20,6 @@ package org.lttng.ust.agent.integration.client; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; import java.util.ArrayList; import java.util.Arrays; @@ -64,6 +63,11 @@ public class TcpClientIT { private static final String EVENT_NAME_B = "eventB"; private static final String EVENT_NAME_C = "eventC"; + private static final String CONTEXT_RETRIEVER_NAME_A = "retrieverA"; + private static final String CONTEXT_RETRIEVER_NAME_B = "retrieverB"; + private static final String CONTEXT_NAME_A = "contextA"; + private static final String CONTEXT_NAME_B = "contextB"; + /* Test configuration */ private static final int DOMAIN_VALUE = ILttngAgent.Domain.JUL.value(); private static final ILttngSession.Domain SESSION_DOMAIN = ILttngSession.Domain.JUL; @@ -92,7 +96,7 @@ public class TcpClientIT { clientThread = new Thread(client); clientThread.start(); - assumeTrue("Timed out waiting for root sessiond", client.waitForConnection(5)); + assertTrue("Timed out waiting for root sessiond", client.waitForConnection(5)); } /** @@ -147,7 +151,7 @@ public class TcpClientIT { } // ------------------------------------------------------------------------ - // Test cases + // Event enabling/disabling test cases // ------------------------------------------------------------------------ /** @@ -234,6 +238,25 @@ public class TcpClientIT { assertTrue(containSameElements(expectedDisableCommands, clientListener.getDisabledEventCommands())); } + /** + * Test enabling then destroying the session (should send corresponding + * disable event messages). + */ + @SuppressWarnings("static-method") + @Test + public void testEnableEventThenDestroy() { + try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { + session2.enableEvent(EVENT_NAME_A, null, false, null); + session2.enableEvent(EVENT_NAME_B, null, false, null); + } // close(), aka destroy the session, sending "disable event" messages + + List expectedEnabledCommands = Arrays.asList(EventRuleFactory.createRule(EVENT_NAME_A), EventRuleFactory.createRule(EVENT_NAME_B)); + List expectedDisabledCommands = Arrays.asList(EVENT_NAME_A, EVENT_NAME_B); + + assertEquals(expectedEnabledCommands, clientListener.getEnabledEventCommands()); + assertTrue(clientListener.getDisabledEventCommands().containsAll(expectedDisabledCommands)); + } + /** * Test specifying an event with a --loglevel option. */ @@ -373,4 +396,178 @@ public class TcpClientIT { assertEquals(expectedCommands, actualCommands); } + + // ------------------------------------------------------------------------ + // Application context enabling/disabling test cases + // ------------------------------------------------------------------------ + + /** + * Test enabling one application context. + */ + @Test + public void testEnableAppContext() { + session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); + + List expectedCommands = Collections.singletonList( + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); + + List actualCommands = clientListener.getEnabledAppContextCommands(); + assertEquals(expectedCommands, actualCommands); + } + + /** + * Test enabling two application contexts sharing the same retriever name. + */ + @Test + public void testEnableAppContextsSameRetriever() { + session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); + session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_B); + + List expectedCommands = Arrays.asList( + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A, + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_B); + + List actualCommands = clientListener.getEnabledAppContextCommands(); + assertEquals(expectedCommands, actualCommands); + } + + /** + * Test enabling two application contexts sharing the same context name, but + * with different retrievers. Unusual, but they should still be recognized + * separately. + */ + @Test + public void testEnableAppContextsSameContext() { + session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); + session.enableAppContext(CONTEXT_RETRIEVER_NAME_B, CONTEXT_NAME_A); + + List expectedCommands = Arrays.asList( + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A, + CONTEXT_RETRIEVER_NAME_B + ':' + CONTEXT_NAME_A); + + List actualCommands = clientListener.getEnabledAppContextCommands(); + assertEquals(expectedCommands, actualCommands); + } + + /** + * Test enabling one application context, then destroying the session. We + * should receive the corresponding "context removed" message. + */ + @Test + @SuppressWarnings("static-method") + public void testEnableAppContextThenDestroy() { + try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { + session2.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); + } // close(), aka destroy the session, sending "disable context" messages + + List expectedEnabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); + List expectedDisabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); + List actualEnabledCommands = clientListener.getEnabledAppContextCommands(); + List actualDisabledCommands = clientListener.getDisabledAppContextCommands(); + + assertEquals(expectedEnabledCommands, actualEnabledCommands); + assertEquals(expectedDisabledCommands, actualDisabledCommands); + } + + /** + * Test enabling the same application context in two different sessions. + * Upon destroying one, we should only receive one "destroyed" message. + */ + @Test + public void testEnableSameAppContextTwoSessions() { + List expectedEnabledCommands = Arrays.asList( + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A, + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); + List actualEnabledCommands; + + try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { + session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); + session2.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); + + actualEnabledCommands = clientListener.getEnabledAppContextCommands(); + assertEquals(expectedEnabledCommands, actualEnabledCommands); + } // close/destroy session2 + + actualEnabledCommands = clientListener.getEnabledAppContextCommands(); + assertEquals(expectedEnabledCommands, actualEnabledCommands); + + List expectedDisabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); + List actualDisabledCommands = clientListener.getDisabledAppContextCommands(); + + assertEquals(expectedDisabledCommands, actualDisabledCommands); + } + + /** + * Test enabling two different application context in two different + * sessions. Upon destroying one, we should receive the correct "destroyed" + * message. + */ + @Test + public void testEnableDiffAppContextTwoSessions() { + List expectedEnabledCommands = Arrays.asList( + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A, + CONTEXT_RETRIEVER_NAME_B + ':' + CONTEXT_NAME_B); + List actualEnabledCommands; + + try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { + session.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); + session2.enableAppContext(CONTEXT_RETRIEVER_NAME_B, CONTEXT_NAME_B); + + actualEnabledCommands = clientListener.getEnabledAppContextCommands(); + assertEquals(expectedEnabledCommands, actualEnabledCommands); + } // close/destroy session2 + + actualEnabledCommands = clientListener.getEnabledAppContextCommands(); + assertEquals(expectedEnabledCommands, actualEnabledCommands); + + List expectedDisabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_B + ':' + CONTEXT_NAME_B); + List actualDisabledCommands = clientListener.getDisabledAppContextCommands(); + + assertEquals(expectedDisabledCommands, actualDisabledCommands); + } + + // ------------------------------------------------------------------------ + // Application context filtering + // ------------------------------------------------------------------------ + + /** + * Test that enabling an event with a filter string referring to a context + * should send an agent message about this context now being "enabled". + * + * This is because we will pass the context information to UST for the + * filtering step, even if the actual context won't be present in the trace. + */ + @SuppressWarnings("static-method") + @Test + public void testContextInFilterString() { + try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { + session2.enableEvent(EVENT_NAME_A, null, false, "$app." + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A + "==\"bozo\""); + + List expectedEnabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); + assertEquals(expectedEnabledCommands, clientListener.getEnabledAppContextCommands()); + } // close(), aka destroy the session, sending "disable context" messages + + List expectedDisabledCommands = Collections.singletonList(CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); + assertEquals(expectedDisabledCommands, clientListener.getDisabledAppContextCommands()); + } + + /** + * Test that if we the context is both referred to by a filter string *and* + * enabled directly, we receive *2* messages about this context being + * enabled (and disabled on session teardown). + */ + @SuppressWarnings("static-method") + @Test + public void testContextEnabledAndInFilterString() { + try (ILttngSession session2 = ILttngSession.createSession(null, SESSION_DOMAIN);) { + session2.enableEvent(EVENT_NAME_A, null, false, "$app." + CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A + "==\"bozo\""); + session2.enableAppContext(CONTEXT_RETRIEVER_NAME_A, CONTEXT_NAME_A); + + List expectedEnabledCommands = Collections.nCopies(2, CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); + assertEquals(expectedEnabledCommands, clientListener.getEnabledAppContextCommands()); + } // close(), aka destroy the session, sending "disable context" messages + + List expectedDisabledCommands = Collections.nCopies(2, CONTEXT_RETRIEVER_NAME_A + ':' + CONTEXT_NAME_A); + assertEquals(expectedDisabledCommands, clientListener.getDisabledAppContextCommands()); + } }