Improve exception message of XmppConnectionStressTest

This commit is contained in:
Florian Schmaus 2019-04-24 21:25:22 +02:00
parent fc70484cf6
commit 870756997f
1 changed files with 30 additions and 11 deletions

View File

@ -151,18 +151,37 @@ public class XmppConnectionStressTest {
// Sanity check: All markers before must be true, all markers including the messageNumber marker must be false. // 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++) { for (int i = 0; i < fromMarkers.length; i++) {
if ((i < messageNumber && !fromMarkers[i]) final String inOrderViolation;
|| (i >= messageNumber && fromMarkers[i])) { if (i < messageNumber && !fromMarkers[i]) {
// TODO: Better exception. // A previous message was missing.
Exception exception = new Exception("out of order"); inOrderViolation = "not yet message #";
receiveExceptions.put(connection, exception); } else if (i >= messageNumber && fromMarkers[i]) {
// TODO: Current Smack design does not guarantee that the listener won't be invoked again. // We already received a new message.
// This is because the decission to invoke a sync listeners is done at a different place // TODO: Can it ever happen that this is taken? Wouldn't we prior run into the "a previous
// then invoking the listener. // message is missing" case?
connection.removeSyncStanzaListener(this); inOrderViolation = "we already received a later (or the same) message #";
receivedSemaphore.release(); } else {
return; 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; fromMarkers[messageNumber] = true;