changeset 1155:3eefcb0f98cf

HttpTrafficDumperFilter.append, CsvMetricsCollectionEncoderTest fixed
author Devel 2
date Mon, 15 Jun 2020 08:07:16 +0200
parents b03609639a1e
children d9dbc633012c
files stress-tester/src/main/java/com/passus/st/client/http/filter/HttpTrafficDumperFilter.java stress-tester/src/test/java/com/passus/st/metric/CsvMetricsCollectionEncoderTest.java
diffstat 2 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpTrafficDumperFilter.java	Fri Jun 12 14:50:59 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpTrafficDumperFilter.java	Mon Jun 15 08:07:16 2020 +0200
@@ -29,6 +29,7 @@
 import static com.passus.net.http.HttpUtils.intToVersionString;
 import static com.passus.st.client.http.HttpConsts.*;
 import static com.passus.st.client.http.filter.HttpFlowUtils.extractHttpContext;
+import static com.passus.st.config.CommonNodeDefs.BOOLEAN_DEF;
 import static com.passus.st.config.CommonNodeDefs.STRING_DEF;
 
 @NodeDefinitionCreate(HttpTrafficDumperFilter.HttpSessionCookieFilterNodeDefCreator.class)
@@ -51,6 +52,8 @@
 
     private final CsvHelper csvHelper = new CsvHelper();
 
+    private boolean append = false;
+
     @Override
     public FlowFilter instanceForWorker(int index) {
         return this;
@@ -59,6 +62,7 @@
     @Override
     public void configure(Configuration config, ConfigurationContext context) {
         fileName = config.getString("fileName");
+        append = config.getBoolean("append", false);
     }
 
     private void writeHeaders() throws IOException {
@@ -93,6 +97,10 @@
 
     private void createWriter(String name) throws IOException {
         file = new File(name);
+        if (file.exists() && !append) {
+            file.delete();
+        }
+
         try {
             writer = new OutputStreamWriter(new FileOutputStream(file, true), encoding);
         } catch (FileNotFoundException ex) {
@@ -228,6 +236,7 @@
 
                 csvHelper.write(context.loop(), writer);
                 csvHelper.write("\n", writer);
+                writer.flush();
             }
         } catch (Exception e) {
             LOGGER.error(e.getMessage(), e);
@@ -241,7 +250,8 @@
         @Override
         public NodeDefinition create() {
             return mapDef(
-                    tupleDef("fileName", STRING_DEF)
+                    tupleDef("fileName", STRING_DEF),
+                    tupleDef("append", BOOLEAN_DEF).setRequired(false)
             );
         }
 
--- a/stress-tester/src/test/java/com/passus/st/metric/CsvMetricsCollectionEncoderTest.java	Fri Jun 12 14:50:59 2020 +0200
+++ b/stress-tester/src/test/java/com/passus/st/metric/CsvMetricsCollectionEncoderTest.java	Mon Jun 15 08:07:16 2020 +0200
@@ -17,7 +17,7 @@
         MetricsCollection coll = new MetricsCollection(0, 1, Arrays.asList(metric));
         CsvMetricsCollectionEncoder encoder = new CsvMetricsCollectionEncoder("test");
 
-        String expected = "0,1,testString,\"{key1=1, key2=value1, key3=null}\",1";
+        String expected = "0;1;testString;{key1=1, key2=value1, key3=null};1";
         assertEquals(expected, encoder.encode(coll));
         assertEquals(expected, encoder.encode(coll));
     }
@@ -29,7 +29,7 @@
         MetricsCollection coll = new MetricsCollection(0, 1, Arrays.asList(metric));
         CsvMetricsCollectionEncoder encoder = new CsvMetricsCollectionEncoder("test");
 
-        String expected = "startTime,endTime,string,map,int";
+        String expected = "startTime;endTime;string;map;int";
         assertEquals(expected, encoder.encodeHeaders(coll));
     }