From 488e20476e5cba646c01ff5aaea606981a263b70 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sun, 17 Feb 2019 21:47:16 +0100 Subject: [PATCH] Improve message of StressTestFailedException.NotAllMessagesReceivedException --- .../smack/util/BooleansUtils.java | 9 ++++ .../smack/XmppConnectionStressTest.java | 49 +++++++++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/BooleansUtils.java b/smack-core/src/main/java/org/jivesoftware/smack/util/BooleansUtils.java index 35bce33f8..a8c8afc5e 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/BooleansUtils.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/BooleansUtils.java @@ -27,4 +27,13 @@ public class BooleansUtils { return false; } + public static int numberOf(boolean[] array, boolean target) { + int res = 0; + for (boolean b : array) { + if (b == target) { + res++; + } + } + return res; + } } diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/XmppConnectionStressTest.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/XmppConnectionStressTest.java index 06d7e5a9f..8cabed30c 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/XmppConnectionStressTest.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/XmppConnectionStressTest.java @@ -216,7 +216,7 @@ public class XmppConnectionStressTest { } while (!acquired && System.currentTimeMillis() < waitStart + replyTimeoutMillis); if (!acquired && receiveExceptions.isEmpty() && sendExceptions.isEmpty()) { - throw new StressTestFailedException.NotAllMessagesReceivedException(receiveMarkers); + throw new StressTestFailedException.NotAllMessagesReceivedException(receiveMarkers, connections); } if (!receiveExceptions.isEmpty() || !sendExceptions.isEmpty()) { @@ -241,10 +241,53 @@ public class XmppConnectionStressTest { public final Map> receiveMarkers; - private NotAllMessagesReceivedException(Map> receiveMarkers) { - super("Did not receive all messages"); + private NotAllMessagesReceivedException(Map> receiveMarkers, List connections) { + super("Did not receive all messages\n" + markersToString(receiveMarkers, connections).toString()); this.receiveMarkers = receiveMarkers; } + + public static StringBuilder markersToString(Map> receiveMarkers, List connections) { + StringBuilder sb = new StringBuilder(); + final int connectionCount = connections.size(); + + Map connectionIds = new HashMap<>(connectionCount); + for (int i = 0; i < connectionCount; i++) { + XMPPConnection connection = connections.get(i); + EntityFullJid connectionAddress = connection.getUser(); + connectionIds.put(connectionAddress, i); + } + + for (Map.Entry> entry : receiveMarkers.entrySet()) { + XMPPConnection connection = entry.getKey(); + Map receiveMarkersOfThisConnection = entry.getValue(); + Integer markerToConnectionId = connectionIds.get(connection.getUser()); + + for (Map.Entry receiveMarkerOfThisConnection : receiveMarkersOfThisConnection.entrySet()) { + boolean[] marker = receiveMarkerOfThisConnection.getValue(); + int numberOfFalseMarkers = BooleansUtils.numberOf(marker, false); + if (numberOfFalseMarkers == 0) { + continue; + } + + EntityFullJid markerFromAddress = receiveMarkerOfThisConnection.getKey(); + Integer markerFromConnectionId = connectionIds.get(markerFromAddress); + sb.append(markerToConnectionId) + .append(" is missing ").append(numberOfFalseMarkers) + .append(" messages from ").append(markerFromConnectionId) + .append(" :"); + for (int i = 0; i < marker.length; i++) { + if (marker[i]) { + continue; + } + sb.append(i).append(", "); + } + sb.setLength(sb.length() - 2); + sb.append('\n'); + } + } + + return sb; + } } public static final class ErrorsWhileSendingOrReceivingException extends StressTestFailedException {