Mercurial > stress-tester
changeset 1095:d729a8ca2552
MySql - bugfixes + FlowProcessor improvements
author | Devel 2 |
---|---|
date | Mon, 11 May 2020 14:19:47 +0200 |
parents | 7026f72f9bfc |
children | 73500970d137 |
files | stress-tester/src/main/java/com/passus/st/client/DbMetric.java stress-tester/src/main/java/com/passus/st/client/FlowProcessor.java stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandler.java stress-tester/src/main/java/com/passus/st/client/mysql/MySqlMetric.java |
diffstat | 4 files changed, 40 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/DbMetric.java Mon May 11 13:51:50 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/DbMetric.java Mon May 11 14:19:47 2020 +0200 @@ -11,7 +11,7 @@ private HashMap<String, MutableInt> queryTypeCount = new HashMap<>(); - private int recordsNum = 0; + private MutableInt recordsNum = new MutableInt(0); public DbMetric(String name) { super(name); @@ -33,19 +33,19 @@ } public void incRecordsNum() { - recordsNum++; + recordsNum.increment(); } @Override public void update(Metric metric) { DbMetric dbMetric = (DbMetric) metric; Metric.updateCountMap(queryTypeCount, dbMetric.queryTypeCount); - recordsNum += dbMetric.recordsNum; + recordsNum.add(dbMetric.recordsNum); } @Override public void reset() { queryTypeCount.clear(); - recordsNum = 0; + recordsNum.setValue(0); } }
--- a/stress-tester/src/main/java/com/passus/st/client/FlowProcessor.java Mon May 11 13:51:50 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/FlowProcessor.java Mon May 11 14:19:47 2020 +0200 @@ -11,6 +11,8 @@ import com.passus.st.filter.FlowFilterChain; import org.apache.logging.log4j.Logger; +import java.util.List; + import static com.passus.st.client.FlowContext.*; import static com.passus.st.client.FlowError.*; import static com.passus.st.client.FlowUtils.*; @@ -424,8 +426,8 @@ debug(logger, flowContext, "Decoder error. " + decoder.getLastError()); } + responseReceived0(flowContext, null, true); decoder.clear(flowContext); - responseReceived0(flowContext, null, false); } else if (decoder.state() == DataDecoder.STATE_FINISHED) { if (collectMetric) { synchronized (metric) { @@ -437,6 +439,10 @@ Object resp = decoder.getResult(); if (logger.isDebugEnabled()) { debug(logger, flowContext, "Response decoded. Response class " + resp.getClass().getSimpleName() + "."); + if (resp instanceof List) { + List respList = (List) resp; + debug(logger, flowContext, "Decoded " + respList.size() + " packets."); + } } Object req = null; @@ -444,9 +450,9 @@ req = flowContext.sentEvent().getRequest(); } + boolean blocked = filterChain.filterInbound(req, resp, flowContext) == Filter.DENY; + responseReceived0(flowContext, resp, blocked); decoder.clear(flowContext); - boolean blocked = filterChain.filterInbound(req, resp, flowContext) != Filter.DENY; - responseReceived0(flowContext, resp, blocked); } } catch (Exception e) { if (collectMetric) {
--- a/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandler.java Mon May 11 13:51:50 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlFlowHandler.java Mon May 11 14:19:47 2020 +0200 @@ -101,9 +101,9 @@ } } } else { - for (MySqlPacket resp : resps) { - if (resp.getPacketType() == ROW_RESPONSE) { - if (collectMetrics) { + if (collectMetrics) { + for (MySqlPacket resp : resps) { + if (resp.getPacketType() == ROW_RESPONSE) { synchronized (metric) { metric.incRecordsNum(); }
--- a/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlMetric.java Mon May 11 13:51:50 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/mysql/MySqlMetric.java Mon May 11 14:19:47 2020 +0200 @@ -2,6 +2,7 @@ import com.passus.commons.metric.Metric; import com.passus.st.client.DbMetric; +import com.passus.st.utils.DbUtils; import org.apache.commons.lang3.mutable.MutableInt; import java.util.HashMap; @@ -12,6 +13,8 @@ private final HashMap<Integer, MutableInt> errorCodesCount = new HashMap<>(); + private final StringBuilder sb = new StringBuilder(); + public MySqlMetric() { this(DEFAULT_NAME); } @@ -40,6 +43,27 @@ @Override public String extractStatementType(String query) { + sb.setLength(0); + int pos = DbUtils.extractStatementType(query, sb); + if (pos != -1) { + String stmtType = sb.toString().toUpperCase(); + switch (stmtType) { + case "ALTER": + case "CREATE": + case "DROP": + case "START": + sb.append(' '); + pos = DbUtils.extractStatementType(query, pos, sb); + if (pos != -1) { + return sb.toString().toUpperCase(); + } + + break; + default: + return stmtType; + } + } + return null; } }