From 5ab95f21ee83d790871f64a501d0af4072329bc1 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Thu, 19 May 2016 18:18:49 -0400 Subject: [PATCH] Test with context and retriever names with . and _ Note that LTTng will print periods as underscores in the trace, which is known and fine, we just have to take it into consideration. Signed-off-by: Alexandre Montplaisir --- .../integration/context/AppContextITBase.java | 20 ++++++++++++++++--- .../context/AppContextOrderingITBase.java | 5 ++++- .../context/ContextInfoRetrieverStubs.java | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) 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 695dd04..0ecc0c8 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 @@ -46,7 +46,7 @@ public abstract class AppContextITBase { protected static final String EVENT_NAME = "EventName"; protected static final String RETRIEVER_NAME_1 = "Retriever1"; - protected static final String RETRIEVER_NAME_2 = "Retriever2"; + protected static final String RETRIEVER_NAME_2 = "some.retriever_2"; private static final String CONTEXT_NAME = ContextInfoRetrieverStubs.CONTEXT_NAME; @@ -98,7 +98,10 @@ public abstract class AppContextITBase { * trace output. */ private static void testContextPresentInTrace(List traceOutput, String retrieverName, String contextName, String contextValue) { - String fullString = "_app_" + retrieverName + "_" + contextName + " = " + contextValue; + String traceRetrieverName = convertToNameInTrace(retrieverName); + String traceContextName = convertToNameInTrace(contextName); + + String fullString = "_app_" + traceRetrieverName + "_" + traceContextName + " = " + contextValue; traceOutput.forEach(line -> assertTrue(line.contains(fullString))); } @@ -107,10 +110,21 @@ public abstract class AppContextITBase { * trace output */ private static void testContextNotPresentInTrace(List traceOutput, String retrieverName, String contextName) { - String fullString = "_app_" + retrieverName + "_" + contextName; + String traceRetrieverName = convertToNameInTrace(retrieverName); + String traceContextName = convertToNameInTrace(contextName); + + String fullString = "_app_" + traceRetrieverName + "_" + traceContextName; traceOutput.forEach(line -> assertFalse(line.contains(fullString))); } + /** + * LTTng accepts periods in context names, but ends up printing them as + * underscores in the trace, so the metadata grammar remains valid. + */ + private static String convertToNameInTrace(String name) { + return name.replace('.', '_'); + } + /** * Test that if no retrievers are declared, no context info is passed at * all. diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextOrderingITBase.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextOrderingITBase.java index 2a2da8e..a2a038c 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextOrderingITBase.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextOrderingITBase.java @@ -144,7 +144,10 @@ public abstract class AppContextOrderingITBase { assertNotNull(output); assertFalse(output.isEmpty()); - String expectedString = "_app_" + RETRIEVER_NAME + "_" + CONTEXT_NAME + " = { string = \"" + CONTEXT_VALUE + "\" } }"; + String traceRetriverName = RETRIEVER_NAME.replace('.', '_'); + String traceContextName = CONTEXT_NAME.replace('.', '_'); + + String expectedString = "_app_" + traceRetriverName + "_" + traceContextName + " = { string = \"" + CONTEXT_VALUE + "\" } }"; output.forEach(line -> assertTrue(line.contains(expectedString))); } diff --git a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/ContextInfoRetrieverStubs.java b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/ContextInfoRetrieverStubs.java index 0981f77..8845ef9 100644 --- a/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/ContextInfoRetrieverStubs.java +++ b/lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/ContextInfoRetrieverStubs.java @@ -22,7 +22,7 @@ import org.lttng.ust.agent.context.IContextInfoRetriever; interface ContextInfoRetrieverStubs { - String CONTEXT_NAME = "ContextName"; + String CONTEXT_NAME = "some.context_name"; Integer INTEGER_VALUE = Integer.valueOf(42); Long LONG_VALUE = Long.valueOf(9001); -- 2.34.1