tmf: Update tests for default timestamp output format in custom parsers
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 25 Jul 2016 19:25:03 +0000 (15:25 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Wed, 27 Jul 2016 18:57:42 +0000 (14:57 -0400)
Change-Id: I188c68511a38364ba31b50645bebb125243bed22
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/77865
Reviewed-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/parsers/custom/CustomTxtTraceDataTest.java
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/parsers/custom/CustomXmlTraceDataTest.java
tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/txt/testTxtDefinition.xml
tmf/org.eclipse.tracecompass.tmf.core.tests/testfiles/xml/testDefinition.xml

index ea6b90d5147c327e7b58bf989ec62f7c035ca089..1a62b5add66843c4967f8a71a69dc81bd5d59321 100644 (file)
@@ -16,10 +16,15 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtEvent;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace;
@@ -29,6 +34,8 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
+import com.google.common.collect.Lists;
+
 /**
  * Test the events parsed by a custom txt trace
  *
@@ -60,6 +67,7 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
 
         private static final int NB_EVENTS = 10;
         private CustomTxtTraceDefinition fDefinition;
+        private ITmfEventAspect<?> fTimestampAspect;
 
         @Override
         public ITmfTrace getTrace() throws IOException, TmfTraceException {
@@ -67,7 +75,8 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
             final File file = new File(TRACE_PATH);
             try (BufferedWriter writer = new BufferedWriter(new FileWriter(file));) {
                 for (int i = 0; i < NB_EVENTS; ++i) {
-                    String eventStr = i + " hello world\n";
+                    SimpleDateFormat f = new SimpleDateFormat(TIMESTAMP_FORMAT);
+                    String eventStr = f.format(new Date(i)) + " hello world\n";
                     writer.write(eventStr);
                     int extra = i % 3;
                     for (int j = 0; j < extra; j++) {
@@ -75,7 +84,10 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
                     }
                 }
             }
-            return new CustomTxtTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+            ITmfTrace trace = new CustomTxtTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+            ArrayList<@NonNull ITmfEventAspect<?>> aspects = Lists.newArrayList(trace.getEventAspects());
+            fTimestampAspect = aspects.stream().filter(aspect -> aspect.getName().equals("Timestamp")).findFirst().get();
+            return trace;
         }
 
         @Override
@@ -84,6 +96,7 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
             String name = fDefinition.definitionName;
             assertEquals("Event name", name, event.getName());
             assertEquals("Event name and type", event.getType().getName(), event.getName());
+            assertEquals("Timestamp", Long.toString(event.getTimestamp().toNanos()), fTimestampAspect.resolve(event));
         }
 
         @Override
@@ -100,6 +113,7 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
         private static final String ODD_EVENT = "OddName";
         private static final String EVEN_EVENT = "EvenName";
         private CustomTxtTraceDefinition fDefinition;
+        private ITmfEventAspect<?> fTimestampAspect;
 
         @Override
         public ITmfTrace getTrace() throws IOException, TmfTraceException {
@@ -116,7 +130,10 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
                     }
                 }
             }
-            return new CustomTxtTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+            ITmfTrace trace = new CustomTxtTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+            ArrayList<@NonNull ITmfEventAspect<?>> aspects = Lists.newArrayList(trace.getEventAspects());
+            fTimestampAspect = aspects.stream().filter(aspect -> aspect.getName().equals("Timestamp")).findFirst().get();
+            return trace;
         }
 
         @Override
@@ -131,6 +148,7 @@ public class CustomTxtTraceDataTest extends AbstractCustomTraceDataTest {
                 assertEquals("Event name", ODD_EVENT, event.getName());
             }
             assertEquals("Event name and type", event.getType().getName(), event.getName());
+            assertEquals("Timestamp", TmfBaseAspects.getTimestampAspect().resolve(event), fTimestampAspect.resolve(event));
         }
 
         @Override
index 48b811cb81cb5c4ad423290a77618c04ceacea58..372322ed136a8f591ab4f5e3465bf7e962d872f5 100644 (file)
@@ -17,11 +17,14 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
+import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
 import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlEvent;
 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace;
@@ -31,6 +34,8 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
+import com.google.common.collect.Lists;
+
 /**
  * Test the events parsed by a custom XML trace
  *
@@ -63,6 +68,7 @@ public class CustomXmlTraceDataTest extends AbstractCustomTraceDataTest {
 
         private static final int NB_EVENTS = 10;
         private CustomXmlTraceDefinition fDefinition;
+        private ITmfEventAspect<?> fTimestampAspect;
 
         @Override
         public ITmfTrace getTrace() throws IOException, TmfTraceException {
@@ -77,7 +83,10 @@ public class CustomXmlTraceDataTest extends AbstractCustomTraceDataTest {
                 }
                 writer.write("</trace>");
             }
-            return new CustomXmlTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+            ITmfTrace trace = new CustomXmlTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+            ArrayList<@NonNull ITmfEventAspect<?>> aspects = Lists.newArrayList(trace.getEventAspects());
+            fTimestampAspect = aspects.stream().filter(aspect -> aspect.getName().equals("Timestamp")).findFirst().get();
+            return trace;
         }
 
         @Override
@@ -86,6 +95,7 @@ public class CustomXmlTraceDataTest extends AbstractCustomTraceDataTest {
             String name = fDefinition.definitionName;
             assertEquals("Event name", name, event.getName());
             assertEquals("Event name and type", event.getType().getName(), event.getName());
+            assertEquals("Timestamp", Long.toString(event.getTimestamp().toNanos()), fTimestampAspect.resolve(event));
         }
 
         @Override
@@ -102,6 +112,7 @@ public class CustomXmlTraceDataTest extends AbstractCustomTraceDataTest {
         private static final String ATTRIBUTE_EVENT = "AttributeName";
         private static final String ELEMENT_EVENT = "ElementName";
         private CustomXmlTraceDefinition fDefinition;
+        private ITmfEventAspect<?> fTimestampAspect;
 
         @Override
         public ITmfTrace getTrace() throws IOException, TmfTraceException {
@@ -117,7 +128,10 @@ public class CustomXmlTraceDataTest extends AbstractCustomTraceDataTest {
                 }
                 writer.write("</trace>");
             }
-            return new CustomXmlTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+            ITmfTrace trace = new CustomXmlTrace(null, fDefinition, file.getPath(), BLOCK_SIZE);
+            ArrayList<@NonNull ITmfEventAspect<?>> aspects = Lists.newArrayList(trace.getEventAspects());
+            fTimestampAspect = aspects.stream().filter(aspect -> aspect.getName().equals("Timestamp")).findFirst().get();
+            return trace;
         }
 
         @Override
@@ -132,6 +146,7 @@ public class CustomXmlTraceDataTest extends AbstractCustomTraceDataTest {
                 assertEquals("Event name", ELEMENT_EVENT, event.getName());
             }
             assertEquals("Event name and type", event.getType().getName(), event.getName());
+            assertEquals("Timestamp", TmfBaseAspects.getTimestampAspect().resolve(event), fTimestampAspect.resolve(event));
         }
 
         @Override
index da479bf6ee6b676cb25a25f699f12e24b911e29d..4125f676dd2082594c6fd04012989a5e857b657a 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <CustomTxtTraceDefinitionList>
 <Definition name="testtxt">
-<TimeStampOutputFormat>dd/MM/yyyy HH:mm:ss:SSS</TimeStampOutputFormat>
+<TimeStampOutputFormat>Tn</TimeStampOutputFormat>
 <InputLine>
 <Cardinality max="2147483647" min="0"/>
 <RegEx>(\S*\s\S*) (.*\S)</RegEx>
 <InputData action="2" tag="MESSAGE"/>
 </InputLine>
 </InputLine>
-<OutputColumn name="Time Stamp" tag="TIMESTAMP"/>
+<OutputColumn name="Timestamp" tag="TIMESTAMP"/>
 <OutputColumn name="Message" tag="MESSAGE"/>
 </Definition>
 <Definition name="testtxtevname">
-<TimeStampOutputFormat>dd/MM/yyyy HH:mm:ss:SSS</TimeStampOutputFormat>
 <InputLine>
 <Cardinality max="2147483647" min="0"/>
 <RegEx>(\d*) (.*\S)?</RegEx>
index ccdc4adbca59c70693b4f602470e8f074bf19632..f364d0a31c9ccf9b51999d191b02a0707b2fe74b 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <CustomXMLTraceDefinitionList>
 <Definition name="myxml">
-<TimeStampOutputFormat>HH:mm:ss:SSS</TimeStampOutputFormat>
+<TimeStampOutputFormat>Tn</TimeStampOutputFormat>
 <InputElement name="trace">
 <InputElement logentry="true" name="element">
 <InputData action="0" name="Message" tag="MESSAGE"/>
@@ -14,7 +14,6 @@
 <OutputColumn name="Message" tag="MESSAGE"/>
 </Definition>
 <Definition name="xmlevname">
-<TimeStampOutputFormat>HH:mm:ss:SSS</TimeStampOutputFormat>
 <InputElement name="trace">
 <InputElement eventtype="DefaultName" logentry="true" name="element">
 <InputData action="0" name="Ignore" tag="IGNORE"/>
This page took 0.027992 seconds and 5 git commands to generate.