Test with context and retriever names with . and _
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 19 May 2016 22:18:49 +0000 (18:18 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Thu, 19 May 2016 22:28:59 +0000 (18:28 -0400)
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 <alexmonthy@voxpopuli.im>
lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextITBase.java
lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/AppContextOrderingITBase.java
lttng-ust-java-tests-common/src/main/java/org/lttng/ust/agent/integration/context/ContextInfoRetrieverStubs.java

index 695dd040e71e5682c25ee46b99c5ac420b1bde33..0ecc0c82677cec5807e3d089b031e7718e1f9b05 100644 (file)
@@ -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<String> 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<String> 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.
index 2a2da8e7a4bfe2995fbdfe88c6f8edbd31beec87..a2a038c7206d433445ae7fe3c80753d69bd4f1a7 100644 (file)
@@ -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)));
     }
 
index 0981f775b3d17a95f8a99e300d545c9f9ed1239f..8845ef9948ab0c391c6a7b5c3fef0b3544d339ad 100644 (file)
@@ -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);
This page took 0.025262 seconds and 4 git commands to generate.