From 870756997faec1e1bfabfac0cd6c2395b04da873 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Wed, 24 Apr 2019 21:25:22 +0200 Subject: [PATCH] Improve exception message of XmppConnectionStressTest --- .../smack/XmppConnectionStressTest.java | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) 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 acb62b869..aa0965306 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 @@ -151,18 +151,37 @@ public class XmppConnectionStressTest { // Sanity check: All markers before must be true, all markers including the messageNumber marker must be false. for (int i = 0; i < fromMarkers.length; i++) { - if ((i < messageNumber && !fromMarkers[i]) - || (i >= messageNumber && fromMarkers[i])) { - // TODO: Better exception. - Exception exception = new Exception("out of order"); - receiveExceptions.put(connection, exception); - // TODO: Current Smack design does not guarantee that the listener won't be invoked again. - // This is because the decission to invoke a sync listeners is done at a different place - // then invoking the listener. - connection.removeSyncStanzaListener(this); - receivedSemaphore.release(); - return; + final String inOrderViolation; + if (i < messageNumber && !fromMarkers[i]) { + // A previous message was missing. + inOrderViolation = "not yet message #"; + } else if (i >= messageNumber && fromMarkers[i]) { + // We already received a new message. + // TODO: Can it ever happen that this is taken? Wouldn't we prior run into the "a previous + // message is missing" case? + inOrderViolation = "we already received a later (or the same) message #"; + } else { + continue; } + + + StringBuilder exceptionMessage = new StringBuilder(); + exceptionMessage.append("We received message #").append(messageNumber).append(" but "); + exceptionMessage.append(inOrderViolation); + exceptionMessage.append(i); + exceptionMessage.append("\nMessage with id ").append(stanza.getStanzaId()) + .append(" from ").append(from) + .append(" to ").append(stanza.getTo()); + + Exception exception = new Exception(exceptionMessage.toString()); + receiveExceptions.put(connection, exception); + // TODO: Current Smack design does not guarantee that the listener won't be invoked again. + // This is because the decission to invoke a sync listeners is done at a different place + // then invoking the listener. + connection.removeSyncStanzaListener(this); + receivedSemaphore.release(); + // TODO: Do not return here? + return; } fromMarkers[messageNumber] = true;