From: Alexandre Montplaisir Date: Fri, 5 Feb 2016 21:16:35 +0000 (-0500) Subject: Add tests for context-related filtering X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8c202b54fabc6b8ff3b15a3f46d87426deceb953;p=lttng-ust-java-tests.git Add tests for context-related filtering Signed-off-by: Alexandre Montplaisir --- diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextITBase.java index 721b619..7cc3471 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextITBase.java @@ -474,4 +474,86 @@ public abstract class AppContextITBase { assertTrue(cim.unregisterContextInfoRetriever(RETRIEVER_NAME_1)); } + + // ------------------------------------------------------------------------ + // Tests related to filtering + // ------------------------------------------------------------------------ + + /** + * Test with a filter expression using a context, but not having the actual + * context enabled. + * + * The JNI should still send the context so UST can use it for filtering, + * but it should not be present in the resulting trace. + */ + @Test + public void testContextFilterExpressionNotEnabled() { + assertTrue(cim.registerContextInfoRetriever(RETRIEVER_NAME_1, ContextInfoRetrieverStubs.STRING_RETRIEVER)); + + assertTrue(session.enableEvent(EVENT_NAME, null, false, + "$app." + RETRIEVER_NAME_1 + '.' + CONTEXT_NAME + "==\"" + ContextInfoRetrieverStubs.STRING_VALUE + '\"')); + + assertTrue(session.start()); + sendEventsToLoggers(); + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertFalse(output.isEmpty()); + + testContextNotPresentInTrace(output, RETRIEVER_NAME_1, CONTEXT_NAME); + + assertTrue(cim.unregisterContextInfoRetriever(RETRIEVER_NAME_1)); + } + + /** + * Test with a filter expression and an enabled context. The filter however + * should *exclude* the events, so no events should be present in the + * resulting trace. + */ + @Test + public void testContextFilterExpressionEnabledNotMatching() { + assertTrue(cim.registerContextInfoRetriever(RETRIEVER_NAME_1, ContextInfoRetrieverStubs.STRING_RETRIEVER)); + + assertTrue(session.enableEvent(EVENT_NAME, null, false, + "$app." + RETRIEVER_NAME_1 + '.' + CONTEXT_NAME + "!=\"" + ContextInfoRetrieverStubs.STRING_VALUE + '\"')); + + assertTrue(session.enableAppContext(RETRIEVER_NAME_1, CONTEXT_NAME)); + assertTrue(session.start()); + sendEventsToLoggers(); + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertTrue(output.isEmpty()); + + assertTrue(cim.unregisterContextInfoRetriever(RETRIEVER_NAME_1)); + } + + /** + * Test with a filter expression and an enabled context. The filter however + * should match the events, so events with the context info should be + * present in the resulting trace. + */ + @Test + public void testContextFilterExpressionEnabledMatching() { + assertTrue(cim.registerContextInfoRetriever(RETRIEVER_NAME_1, ContextInfoRetrieverStubs.STRING_RETRIEVER)); + + assertTrue(session.enableEvent(EVENT_NAME, null, false, + "$app." + RETRIEVER_NAME_1 + '.' + CONTEXT_NAME + "==\"" + ContextInfoRetrieverStubs.STRING_VALUE + '\"')); + + assertTrue(session.enableAppContext(RETRIEVER_NAME_1, CONTEXT_NAME)); + assertTrue(session.start()); + sendEventsToLoggers(); + assertTrue(session.stop()); + + List output = session.view(); + assertNotNull(output); + assertFalse(output.isEmpty()); + + testContextPresentInTrace(output, RETRIEVER_NAME_1, CONTEXT_NAME, + "{ string = \"" + ContextInfoRetrieverStubs.STRING_VALUE + "\" } }"); + + assertTrue(cim.unregisterContextInfoRetriever(RETRIEVER_NAME_1)); + } } 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 a86a273..d89571d 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 @@ -526,4 +526,49 @@ public class TcpClientIT { 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()); + } }