Mercurial > stress-tester
changeset 1244:fe3bbcdf8a1f
NetExceptionsCategory removed, FlowError enhanced, EmitterMetric changes
author | Devel 2 |
---|---|
date | Wed, 01 Jul 2020 09:09:32 +0200 |
parents | 0dddf15429a8 |
children | a8494e56ba41 |
files | stress-tester/src/main/java/com/passus/st/client/FlowError.java stress-tester/src/main/java/com/passus/st/client/FlowProcessor.java stress-tester/src/main/java/com/passus/st/client/FlowWorkerBase.java stress-tester/src/main/java/com/passus/st/emitter/EmitterMetric.java stress-tester/src/main/java/com/passus/st/emitter/EmitterUtils.java stress-tester/src/main/java/com/passus/st/emitter/nio/NioAbstractEmitterWorker.java stress-tester/src/main/java/com/passus/st/emitter/nio/NioDatagramEmitterWorker.java stress-tester/src/main/java/com/passus/st/emitter/nio/NioEmitterWorker2.java stress-tester/src/main/java/com/passus/st/emitter/nio/NioEmitterWorkerImpl.java stress-tester/src/main/java/com/passus/st/emitter/nio/NioSocketEmitterWorker.java stress-tester/src/main/java/com/passus/st/utils/NetExceptionsCategory.java |
diffstat | 11 files changed, 133 insertions(+), 111 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/FlowError.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/FlowError.java Wed Jul 01 09:09:32 2020 +0200 @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.net.BindException; import java.net.ConnectException; import java.net.SocketException; @@ -30,9 +31,14 @@ public static final byte CODE_MAX_SEND_ERRORS_REACHED = 16; public static final byte CODE_IDE_TIMEOUT = 17; - public static final byte CODE_SSL_ERROR = 18; - public static final byte CODE_SSL_UNRECOGNIZED_MESSAGE_ERROR = 19; - public static final byte CODE_SSL_HANDSHAKE_ERROR = 20; + public static final byte BIND_ADDRESS_ALREADY_IN_USE = 18; + public static final byte BIND_CANNOT_ASSIGN_ADDRESS = 19; + public static final byte BIND_MAPPER_INVALID = 20; + public static final byte BIND_OTHER = 21; + + public static final byte CODE_SSL_ERROR = 22; + public static final byte CODE_SSL_UNRECOGNIZED_MESSAGE_ERROR = 23; + public static final byte CODE_SSL_HANDSHAKE_ERROR = 24; public static final byte CODE_INTERNAL_ERROR = (byte) 255; @@ -42,13 +48,13 @@ private final Throwable cause; - public FlowError(byte code, String message) { - this(code, message, null); + public FlowError(byte code) { + this(code, (Throwable) null); } - public FlowError(byte code, String message, Throwable cause) { + public FlowError(byte code, Throwable cause) { this.code = code; - this.message = message; + this.message = codeToString(code); this.cause = cause; } @@ -73,12 +79,65 @@ '}'; } + public static String codeToString(int code) { + switch (code) { + case BIND_ADDRESS_ALREADY_IN_USE: + return "Bind error. Address already in use."; + case BIND_CANNOT_ASSIGN_ADDRESS: + return "Bind error. Cannot assign requested address."; + case BIND_MAPPER_INVALID: + return "Session mapper. Unable to map session."; + case BIND_OTHER: + return "Bind error."; + case CODE_CONNECTION_REFUSED: + return "Connection refused."; + case CODE_CONNECTION_TIMEOUT: + return "Connection timed out."; + case CODE_READ_TIMEOUT: + return "Response read timed out."; + case CODE_INVALID_RESPONSE: + return "Invalid response."; + case CODE_UNKNOWN_HOST: + return "Unknown host. Unable to resolve host name."; + case CODE_NO_ROUTE_TO_HOST: + return "No route to host."; + case CODE_CONNECTION_ATTEMPTS_REACHED: + return "Max connection attempts reached."; + case CODE_NETWORK_UNREACHABLE: + return "Network is unreachable."; + case CODE_CONNECTION_CLOSED_UNEXPECTEDLY: + return "Connection closed unexpectedly."; + case CODE_CONNECTION_RESET_BY_PEER: + return "Connection reset by peer."; + case CODE_SSL_UNRECOGNIZED_MESSAGE_ERROR: + return "Unrecognized SSL message. Probably plaintext connection."; + case CODE_SSL_HANDSHAKE_ERROR: + return "SSL handshake error."; + case CODE_SSL_ERROR: + return "SSL error."; + case CODE_CONNECTION_ERROR: + return "Connection error."; + case CODE_SOCKET_ERROR: + return "Networking socket error."; + case CODE_IO_ERROR: + return "Networking IO error."; + case CODE_MAX_ENCODER_ERRORS_REACHED: + return "Max encoder errors reached."; + case CODE_MAX_SEND_ERRORS_REACHED: + return "Max send errors reached."; + case CODE_INTERNAL_ERROR: + return "Internal error."; + default: + return "Unknown error."; + } + } + public static FlowError unknownError() { return unknownError(null); } public static FlowError unknownError(Throwable cause) { - return new FlowError(CODE_UNKNOWN_ERROR, "Unknown error.", cause); + return new FlowError(CODE_UNKNOWN_ERROR, cause); } public static FlowError internalError() { @@ -86,43 +145,52 @@ } public static FlowError internalError(Throwable cause) { - return new FlowError(CODE_INTERNAL_ERROR, "Internal error.", cause); + return new FlowError(CODE_INTERNAL_ERROR, cause); } public static FlowError interpret(Throwable ex, String stackTrace) { - if (stackTrace.contains("Connection refused")) { - return new FlowError(CODE_CONNECTION_REFUSED, "Connection refused.", ex); + if (ex instanceof BindException) { + String msg = ex.getMessage(); + if (msg.contains("Address already in use")) { + return new FlowError(BIND_ADDRESS_ALREADY_IN_USE, ex); + } else if (msg.contains("Cannot assign requested address")) { + return new FlowError(BIND_CANNOT_ASSIGN_ADDRESS, ex); + } else { + return new FlowError(BIND_OTHER, ex); + } + } else if (stackTrace.contains("Connection refused")) { + return new FlowError(CODE_CONNECTION_REFUSED, ex); } else if (stackTrace.contains("connect timed out")) { - return new FlowError(CODE_CONNECTION_TIMEOUT, "Connection timed out.", ex); + return new FlowError(CODE_CONNECTION_TIMEOUT, ex); } else if (stackTrace.contains("Read timed out")) { - return new FlowError(CODE_READ_TIMEOUT, "Response read timed out.", ex); + return new FlowError(CODE_READ_TIMEOUT, ex); } else if (stackTrace.contains("Invalid Http response")) { - return new FlowError(CODE_INVALID_RESPONSE, "Invalid response.", ex); + return new FlowError(CODE_INVALID_RESPONSE, ex); } else if (stackTrace.contains("UnknownHostException")) { - return new FlowError(CODE_UNKNOWN_HOST, "Unknown host. Unable to resolve host name.", ex); + return new FlowError(CODE_UNKNOWN_HOST, ex); } else if (stackTrace.contains("No route to host")) { - return new FlowError(CODE_NO_ROUTE_TO_HOST, "No route to host.", ex); + return new FlowError(CODE_NO_ROUTE_TO_HOST, ex); } else if (stackTrace.contains("Network is unreachable")) { - return new FlowError(CODE_NETWORK_UNREACHABLE, "Network is unreachable.", ex); + return new FlowError(CODE_NETWORK_UNREACHABLE, ex); } else if (stackTrace.contains("Software caused connection abort")) { - return new FlowError(CODE_CONNECTION_CLOSED_UNEXPECTEDLY, "Connection closed unexpectedly.", ex); + return new FlowError(CODE_CONNECTION_CLOSED_UNEXPECTEDLY, ex); } else if (stackTrace.contains("Connection reset by peer")) { - return new FlowError(CODE_CONNECTION_RESET_BY_PEER, "Connection reset by peer.", ex); + return new FlowError(CODE_CONNECTION_RESET_BY_PEER, ex); } else if (stackTrace.contains("Unrecognized SSL message")) { - return new FlowError(CODE_SSL_UNRECOGNIZED_MESSAGE_ERROR, "Unrecognized SSL message. Probably plaintext connection.", ex); + return new FlowError(CODE_SSL_UNRECOGNIZED_MESSAGE_ERROR, ex); } else if (stackTrace.contains("SSLHandshakeException")) { - return new FlowError(CODE_SSL_HANDSHAKE_ERROR, "SSL handshake error.", ex); + return new FlowError(CODE_SSL_HANDSHAKE_ERROR, ex); } Throwable cause = ex.getCause(); if (cause instanceof SSLException) { - return new FlowError(CODE_SSL_ERROR, "SSL error.", ex); + return new FlowError(CODE_SSL_ERROR, ex); } else if (cause instanceof ConnectException) { - return new FlowError(CODE_CONNECTION_ERROR, "Connection error.", ex); + return new FlowError(CODE_CONNECTION_ERROR, ex); } else if (cause instanceof SocketException) { - return new FlowError(CODE_SOCKET_ERROR, "Networking socket error.", ex); + return new FlowError(CODE_SOCKET_ERROR, ex); } else if (cause instanceof IOException) { - return new FlowError(CODE_IO_ERROR, "Networking IO error.", ex); + return new FlowError(CODE_IO_ERROR, ex); } return unknownError(ex);
--- a/stress-tester/src/main/java/com/passus/st/client/FlowProcessor.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/FlowProcessor.java Wed Jul 01 09:09:32 2020 +0200 @@ -172,7 +172,7 @@ return; } else { flowContext.block(); - error(flowContext, new FlowError(CODE_CONNECTION_ATTEMPTS_REACHED, "Max connection attempts reached.")); + error(flowContext, new FlowError(CODE_CONNECTION_ATTEMPTS_REACHED)); if (logger.isDebugEnabled()) { logger.debug("Connection failed. No reconnection.", flowContext.connectionAttempts, maxConnectionAttempts); } @@ -360,7 +360,7 @@ } if (flowContext.encoderErrors == maxEncoderErrors) { - error(flowContext, new FlowError(CODE_MAX_ENCODER_ERRORS_REACHED, "Max encoder errors reached.")); + error(flowContext, new FlowError(CODE_MAX_ENCODER_ERRORS_REACHED)); } return; @@ -396,7 +396,7 @@ } if (flowContext.sendErrors == maxSendErrors) { - error(flowContext, new FlowError(CODE_MAX_SEND_ERRORS_REACHED, "Max send errors reached.")); + error(flowContext, new FlowError(CODE_MAX_SEND_ERRORS_REACHED)); } } finally { buffer.clear();
--- a/stress-tester/src/main/java/com/passus/st/client/FlowWorkerBase.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/FlowWorkerBase.java Wed Jul 01 09:09:32 2020 +0200 @@ -642,7 +642,7 @@ flowContext.signalAndUnlock(); } - error(flowContext, new FlowError(CODE_CONNECTION_ATTEMPTS_REACHED, "Max connection attempts reached.")); + error(flowContext, new FlowError(CODE_CONNECTION_ATTEMPTS_REACHED)); } protected void send(FlowContext flowContext, SessionPayloadEvent event, boolean wait) { @@ -667,7 +667,7 @@ } if (flowContext.encoderErrors == maxEncoderErrors) { - error(flowContext, new FlowError(CODE_MAX_ENCODER_ERRORS_REACHED, "Max encoder errors reached.")); + error(flowContext, new FlowError(CODE_MAX_ENCODER_ERRORS_REACHED)); } return; @@ -702,7 +702,7 @@ } if (flowContext.sendErrors == maxSendErrors) { - error(flowContext, new FlowError(CODE_MAX_SEND_ERRORS_REACHED, "Max send errors reached.")); + error(flowContext, new FlowError(CODE_MAX_SEND_ERRORS_REACHED)); } } }
--- a/stress-tester/src/main/java/com/passus/st/emitter/EmitterMetric.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/emitter/EmitterMetric.java Wed Jul 01 09:09:32 2020 +0200 @@ -4,7 +4,7 @@ import com.passus.commons.metric.Metric; import com.passus.net.IpAddress; import com.passus.net.SocketAddress; -import com.passus.st.utils.NetExceptionsCategory; +import com.passus.st.client.FlowError; import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.mutable.MutableLong; @@ -34,8 +34,6 @@ private final MutableInt connectionsErrors = new MutableInt(0); - private final MutableInt bindErrors = new MutableInt(0); - private final Map<SocketAddress, MutableInt> remoteSocketConnections = new HashMap<>(); private final Map<IpAddress, MutableInt> bindAddresses = new HashMap<>(); @@ -56,7 +54,6 @@ attrs.put("establishedConnections", establishedConnections); attrs.put("connectionsErrors", connectionsErrors); attrs.put("closedConnections", closedConnections); - attrs.put("bindErrors", bindErrors); attrs.put("remoteSocketConnections", (Serializable) remoteSocketConnections); attrs.put("errors", (Serializable) errors); attrs.put("dropped", dropped); @@ -112,10 +109,6 @@ return connectionsErrors.intValue(); } - public void incBindErrors() { - bindErrors.increment(); - } - public void addRemoteSocketConnection(SocketAddress address) { establishedConnections.increment(); MutableInt num = remoteSocketConnections.get(address); @@ -134,12 +127,16 @@ //bindedSockets.add(address); } - public void errorCaught(Throwable cause) { - String category = NetExceptionsCategory.errorToCategory(cause); - incErrorByCategory(category); + public void error(Throwable cause) { + FlowError flowError = FlowError.interpret(cause); + error(flowError); } - public void incErrorByCategory(String category) { + public void error(FlowError flowError) { + incErrorByCategory(flowError.message()); + } + + private void incErrorByCategory(String category) { MutableInt count = errors.get(category); if (count == null) { count = new MutableInt(1); @@ -226,7 +223,6 @@ "establishedConnections=" + establishedConnections + ", " + "closedConnections=" + closedConnections + ", " + "connectionsErrors=" + connectionsErrors + ", " + - "bindErrors=" + bindErrors + ", " + "remoteSocketConnections=" + remoteSocketConnections + "," + "bindAddresses=" + bindAddresses + "," + " active=" + active + '}';
--- a/stress-tester/src/main/java/com/passus/st/emitter/EmitterUtils.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/emitter/EmitterUtils.java Wed Jul 01 09:09:32 2020 +0200 @@ -4,6 +4,7 @@ import com.passus.net.IpAddress; import com.passus.net.IpSubnet; import com.passus.net.utils.AddressUtils; +import com.passus.st.client.FlowError; import com.passus.st.emitter.SessionMapper.ConnectionParams; import org.apache.logging.log4j.Logger; @@ -15,7 +16,7 @@ import java.util.Enumeration; import java.util.List; -import static com.passus.st.utils.NetExceptionsCategory.BIND_MAPPER_SESSION_INVALID; +import static com.passus.st.client.FlowError.BIND_MAPPER_INVALID; public class EmitterUtils { @@ -38,7 +39,7 @@ if (collectMetrics) { synchronized (metric) { - metric.incErrorByCategory(BIND_MAPPER_SESSION_INVALID); + metric.error(new FlowError(BIND_MAPPER_INVALID)); } } @@ -68,7 +69,7 @@ if (collectMetrics) { synchronized (metric) { - metric.errorCaught(cause); + metric.error(cause); } }
--- a/stress-tester/src/main/java/com/passus/st/emitter/nio/NioAbstractEmitterWorker.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/emitter/nio/NioAbstractEmitterWorker.java Wed Jul 01 09:09:32 2020 +0200 @@ -2,6 +2,7 @@ import com.passus.data.ByteBuff; import com.passus.data.HeapByteBuff; +import com.passus.st.client.FlowError; import com.passus.st.emitter.EmitterHandler; import com.passus.st.emitter.SessionInfo; import com.passus.st.emitter.SessionMapper.ConnectionParams; @@ -15,7 +16,7 @@ import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -import static com.passus.st.utils.NetExceptionsCategory.BIND_MAPPER_SESSION_INVALID; +import static com.passus.st.client.FlowError.BIND_MAPPER_INVALID; public abstract class NioAbstractEmitterWorker extends NioEmitterWorker { @@ -75,7 +76,7 @@ if (collectMetrics) { synchronized (metric) { - metric.incErrorByCategory(BIND_MAPPER_SESSION_INVALID); + metric.error(new FlowError(BIND_MAPPER_INVALID)); } } @@ -203,7 +204,7 @@ if (collectMetrics) { synchronized (metric) { - metric.errorCaught(cause); + metric.error(cause); } }
--- a/stress-tester/src/main/java/com/passus/st/emitter/nio/NioDatagramEmitterWorker.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/emitter/nio/NioDatagramEmitterWorker.java Wed Jul 01 09:09:32 2020 +0200 @@ -63,7 +63,7 @@ selector.wakeup(); } catch (Exception e) { if (collectMetrics) { - metric.errorCaught(e); + metric.error(e); } logger.error(e.getMessage(), e); }
--- a/stress-tester/src/main/java/com/passus/st/emitter/nio/NioEmitterWorker2.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/emitter/nio/NioEmitterWorker2.java Wed Jul 01 09:09:32 2020 +0200 @@ -221,7 +221,7 @@ wakeUp(); } catch (Exception e) { if (collectMetrics) { - metric.errorCaught(e); + metric.error(e); } logger.error(e.getMessage(), e); } @@ -421,7 +421,7 @@ if (collectMetrics) { synchronized (metric) { - metric.errorCaught(cause); + metric.error(cause); } }
--- a/stress-tester/src/main/java/com/passus/st/emitter/nio/NioEmitterWorkerImpl.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/emitter/nio/NioEmitterWorkerImpl.java Wed Jul 01 09:09:32 2020 +0200 @@ -47,7 +47,17 @@ SocketAddress bindAddress = connParams.getBindAddress(); if (bindAddress != null && !ANY_SOCKET.equals(bindAddress)) { - channel.bind(AddressUtils.socketAddressToJdkSocket(bindAddress)); + try { + channel.bind(AddressUtils.socketAddressToJdkSocket(bindAddress)); + } catch (IOException ex) { + if (collectMetrics) { + synchronized (metric) { + metric.error(ex); + } + } + + return; + } } SocketAddress remoteAddress = connParams.getRemoteAddress(); @@ -75,7 +85,7 @@ selector.wakeup(); } catch (Exception e) { if (collectMetrics) { - metric.errorCaught(e); + metric.error(e); } logger.error(e.getMessage(), e); } @@ -128,7 +138,7 @@ selector.wakeup(); } catch (Exception e) { if (collectMetrics) { - metric.errorCaught(e); + metric.error(e); } logger.error(e.getMessage(), e); }
--- a/stress-tester/src/main/java/com/passus/st/emitter/nio/NioSocketEmitterWorker.java Wed Jul 01 08:29:08 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/emitter/nio/NioSocketEmitterWorker.java Wed Jul 01 09:09:32 2020 +0200 @@ -62,7 +62,7 @@ selector.wakeup(); } catch (Exception e) { if (collectMetrics) { - metric.errorCaught(e); + metric.error(e); } logger.error(e.getMessage(), e); }
--- a/stress-tester/src/main/java/com/passus/st/utils/NetExceptionsCategory.java Wed Jul 01 08:29:08 2020 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -package com.passus.st.utils; - -import java.net.BindException; -import java.net.ConnectException; -import java.net.NoRouteToHostException; -import java.net.SocketException; - -/** - * @author Mirosław Hawrot - */ -public class NetExceptionsCategory { - - public static final String CONNECTION_REFUSED = "connection.refused"; - public static final String CONNECTION_TIMEOUT = "connection.timeout"; - public static final String CONNECTION_NO_ROUTE_TO_HOST = "connection.no_route_to_host"; - public static final String CONNECTION_UNKNOWN = "connection.unknown"; - - public static final String BIND_MAPPER_SESSION_INVALID = "bind.mapper_session_invalid"; - public static final String BIND_NETWORK_UNREACHABLE = "bind.network_unreachable"; - public static final String BIND_ADDRESS_ALREADY_IN_USE = "bind.address_already_in_use"; - public static final String BIND_UNKNOWN = "bind.unknown"; - - public static final String UNKNOWN_ERROR = "unknown_error"; - - private NetExceptionsCategory() { - } - - public static String errorToCategory(Throwable cause) { - if (cause instanceof NoRouteToHostException) { - return CONNECTION_NO_ROUTE_TO_HOST; - } else if (cause instanceof BindException) { - String msg = cause.getMessage(); - if (msg.contains("Address already in use")) { - return BIND_ADDRESS_ALREADY_IN_USE; - } else { - return BIND_UNKNOWN; - } - } else if (cause instanceof ConnectException) { - String msg = cause.getMessage(); - if (msg.contains("Connection refused")) { - return CONNECTION_REFUSED; - } else if (msg.contains("Connection timed out")) { - return CONNECTION_TIMEOUT; - } - } else if (cause instanceof SocketException) { - String msg = cause.getMessage(); - if (msg.contains("Network is unreachable")) { - return BIND_NETWORK_UNREACHABLE; - } - } - - return UNKNOWN_ERROR; - } -}