Mercurial > stress-tester
changeset 544:3a7100c0273b
refactoring
author | Devel 1 |
---|---|
date | Wed, 13 Sep 2017 15:46:35 +0200 |
parents | 85a2cf51b9da |
children | 17a5815215fd |
files | stress-tester-reporter/src/main/java/com/passus/st/reporter/server/ReporterImpl.java |
diffstat | 1 files changed, 36 insertions(+), 34 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester-reporter/src/main/java/com/passus/st/reporter/server/ReporterImpl.java Thu Sep 14 10:37:08 2017 +0200 +++ b/stress-tester-reporter/src/main/java/com/passus/st/reporter/server/ReporterImpl.java Wed Sep 13 15:46:35 2017 +0200 @@ -46,8 +46,8 @@ builder.append(';'); } - private static String getMapValue(Map<CharSequence, CharSequence> map, String header) { - CharSequence result = null; + private static String getValue(Map<CharSequence, ? extends Object> map, String header) { + Object result = null; if (map != null) { result = map.get(new Utf8(header)); } @@ -56,51 +56,52 @@ @Override public CharSequence handleMetric(MetricRecord metric) throws AvroRemoteException { - StringBuilder builder = new StringBuilder(); + if (verbose) { + System.out.println(metric); + } - System.out.println(metric); Map<CharSequence, Object> fields = metric.getFields(); String code = metric.getCode().toString(); + StringBuilder builder = new StringBuilder(); if (code.equalsIgnoreCase("httpRequest")) { - addValue(builder, fields.get(new Utf8("reqId"))); - addValue(builder, fields.get(new Utf8("reqMethod"))); - addValue(builder, fields.get(new Utf8("version"))); - addValue(builder, fields.get(new Utf8("url"))); - addValue(builder, fields.get(new Utf8("timeStart"))); - addValue(builder, fields.get(new Utf8("timeStop"))); - addValue(builder, fields.get(new Utf8("serverIp"))); - addValue(builder, fields.get(new Utf8("serverPort"))); - addValue(builder, fields.get(new Utf8("clientIp"))); - addValue(builder, fields.get(new Utf8("clientPort"))); - addValue(builder, fields.get(new Utf8("messageHeaderSize"))); - addValue(builder, fields.get(new Utf8("messageContentSize"))); + addValue(builder, getValue(fields, "reqId")); + addValue(builder, getValue(fields, "reqMethod")); + addValue(builder, getValue(fields, "version")); + addValue(builder, getValue(fields, "url")); + addValue(builder, getValue(fields, "timeStart")); + addValue(builder, getValue(fields, "timeStop")); + addValue(builder, getValue(fields, "serverIp")); + addValue(builder, getValue(fields, "serverPort")); + addValue(builder, getValue(fields, "clientIp")); + addValue(builder, getValue(fields, "clientPort")); + addValue(builder, getValue(fields, "messageHeaderSize")); + addValue(builder, getValue(fields, "messageContentSize")); Map<CharSequence, CharSequence> heads = (Map<CharSequence, CharSequence>) fields.get(new Utf8("headers")); - addValue(builder, getMapValue(heads, "User-Agent")); + addValue(builder, getValue(heads, "User-Agent")); Map<CharSequence, CharSequence> misc = (Map<CharSequence, CharSequence>) fields.get(new Utf8("misc")); - addValue(builder, getMapValue(misc, "sessionId")); - addValue(builder, getMapValue(misc, "username")); + addValue(builder, getValue(misc, "sessionId")); + addValue(builder, getValue(misc, "username")); reqFile.println(builder.toString()); reqFile.flush(); -// System.out.println(builder.toString()); } + if (code.equalsIgnoreCase("httpResponse")) { - addValue(builder, fields.get(new Utf8("reqId"))); - addValue(builder, fields.get(new Utf8("reason"))); - addValue(builder, fields.get(new Utf8("statusCode"))); - addValue(builder, fields.get(new Utf8("timeStart"))); - addValue(builder, fields.get(new Utf8("timeStop"))); + addValue(builder, getValue(fields, "reqId")); + addValue(builder, getValue(fields, "reason")); + addValue(builder, getValue(fields, "statusCode")); + addValue(builder, getValue(fields, "timeStart")); + addValue(builder, getValue(fields, "timeStop")); Map<CharSequence, CharSequence> heads = (Map<CharSequence, CharSequence>) fields.get(new Utf8("headers")); - addValue(builder, getMapValue(heads, "Content-Type")); + addValue(builder, getValue(heads, "Content-Type")); // addValue(builder, fields.get(new Utf8("clientIp"))); // addValue(builder, fields.get(new Utf8("clientPort"))); // addValue(builder, fields.get(new Utf8("serverIp"))); // addValue(builder, fields.get(new Utf8("serverPort"))); - addValue(builder, fields.get(new Utf8("messageHeaderSize"))); - addValue(builder, fields.get(new Utf8("messageContentSize"))); + addValue(builder, getValue(fields, "messageHeaderSize")); + addValue(builder, getValue(fields, "messageContentSize")); respFile.println(builder.toString()); respFile.flush(); -// System.out.println(builder.toString()); } if (verbose) { @@ -116,7 +117,9 @@ @Override public CharSequence handleMetricsCollection(MetricsCollectionRecord collection) throws AvroRemoteException { - System.out.println(collection); + if (verbose) { + System.out.println(collection); + } StringBuilder builder = new StringBuilder(); addValue(builder, collection.getStartTimestamp()); @@ -130,11 +133,11 @@ addValue(builder, emitterFields.get(new Utf8("establishedConnections"))); addValue(builder, emitterFields.get(new Utf8("closedConnections"))); addValue(builder, emitterFields.get(new Utf8("bindErrors"))); - + } else { builder.append(";;;;;"); } - + emitterMetric = findMetric(collection, "pcapSource"); if (emitterMetric != null) { Map<CharSequence, Object> emitterFields = emitterMetric.getFields(); @@ -143,8 +146,7 @@ } else { builder.append(";;"); } - - + emitterFile.println(builder.toString()); emitterFile.flush();