mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 05:22:06 +01:00
Merge pull request #599 from guusdk/sint_assertresult-multisync
[sinttest] Improving assertions for MultiResultSyncPoint
This commit is contained in:
commit
68fa90435e
3 changed files with 24 additions and 4 deletions
|
@ -20,6 +20,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
@ -33,6 +34,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
import org.jivesoftware.smack.filter.StanzaFilter;
|
import org.jivesoftware.smack.filter.StanzaFilter;
|
||||||
|
|
||||||
|
import org.igniterealtime.smack.inttest.util.MultiResultSyncPoint;
|
||||||
import org.igniterealtime.smack.inttest.util.ResultSyncPoint;
|
import org.igniterealtime.smack.inttest.util.ResultSyncPoint;
|
||||||
|
|
||||||
import org.opentest4j.AssertionFailedError;
|
import org.opentest4j.AssertionFailedError;
|
||||||
|
@ -108,4 +110,18 @@ public abstract class AbstractSmackIntTest {
|
||||||
throw new AssertionFailedError(message, e);
|
throw new AssertionFailedError(message, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <R> List<R> assertResult(MultiResultSyncPoint<R, ?> syncPoint, String message) throws InterruptedException, TimeoutException, AssertionFailedError {
|
||||||
|
return assertResult(syncPoint, timeout, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <R> List<R> assertResult(MultiResultSyncPoint<R, ?> syncPoint, long timeout, String message) throws InterruptedException, TimeoutException, AssertionFailedError {
|
||||||
|
try {
|
||||||
|
return syncPoint.waitForResults(timeout, message);
|
||||||
|
} catch (InterruptedException | TimeoutException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new AssertionFailedError(message, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2021 Guus der Kinderen
|
* Copyright 2021-2024 Guus der Kinderen
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -34,13 +34,17 @@ public class MultiResultSyncPoint<R, E extends Exception> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized List<R> waitForResults(long timeout) throws E, InterruptedException, TimeoutException {
|
public synchronized List<R> waitForResults(long timeout) throws E, InterruptedException, TimeoutException {
|
||||||
|
return waitForResults(timeout, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized List<R> waitForResults(long timeout, String timeoutMessage) throws E, InterruptedException, TimeoutException {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
final long deadline = now + timeout;
|
final long deadline = now + timeout;
|
||||||
while (results.size() < expectedResultCount && exception == null && now < deadline) {
|
while (results.size() < expectedResultCount && exception == null && now < deadline) {
|
||||||
wait(deadline - now);
|
wait(deadline - now);
|
||||||
now = System.currentTimeMillis();
|
now = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
if (now >= deadline) throw new TimeoutException("MultiResultSyncPoint timeout waiting " + timeout + " millis. Got " + results.size() + " results of " + expectedResultCount + " results");
|
if (now >= deadline) throw new TimeoutException((timeoutMessage != null ? timeoutMessage + " " : "") + "MultiResultSyncPoint timeout waiting " + timeout + " millis. Got " + results.size() + " results of " + expectedResultCount + " results");
|
||||||
if (exception != null) throw exception;
|
if (exception != null) throw exception;
|
||||||
return new ArrayList<>(results);
|
return new ArrayList<>(results);
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,10 +292,10 @@ public class MultiUserChatOccupantIntegrationTest extends AbstractMultiUserChatI
|
||||||
try {
|
try {
|
||||||
mucAsSeenByThree.join(nicknameThree);
|
mucAsSeenByThree.join(nicknameThree);
|
||||||
|
|
||||||
List<Presence> results = syncPoint.waitForResults(timeout);
|
List<Presence> results = assertResult(syncPoint, "Expected all occupants of room '" + mucAddress + "' to be notified of '" + conThree.getUser() + "' using nickname '" + nicknameThree + "' joining the room (but one or more did not get notified).");
|
||||||
assertTrue(results.stream().allMatch(
|
assertTrue(results.stream().allMatch(
|
||||||
result -> JidCreate.fullFrom(mucAddress, nicknameThree).equals(result.getFrom())),
|
result -> JidCreate.fullFrom(mucAddress, nicknameThree).equals(result.getFrom())),
|
||||||
"Expected all occupants of room '" + mucAddress + "' to be notified of '" + conThree.getUser() + "' using nickname '" + nicknameThree + "' joining the room (but one or more got notified ).");
|
"Expected all occupants of room '" + mucAddress + "' to be notified of '" + conThree.getUser() + "' using nickname '" + nicknameThree + "' joining the room (but one or more got notified for a different user).");
|
||||||
assertTrue(results.stream().anyMatch(
|
assertTrue(results.stream().anyMatch(
|
||||||
result -> result.getTo().equals(conOne.getUser().asEntityFullJidIfPossible())),
|
result -> result.getTo().equals(conOne.getUser().asEntityFullJidIfPossible())),
|
||||||
"Expected '" + conOne.getUser().asEntityFullJidIfPossible() + "' to be notified of '" + conThree.getUser() + "' joining room '" + mucAddress + "' (but did not)");
|
"Expected '" + conOne.getUser().asEntityFullJidIfPossible() + "' to be notified of '" + conThree.getUser() + "' joining room '" + mucAddress + "' (but did not)");
|
||||||
|
|
Loading…
Reference in a new issue