+ @SuppressWarnings("checkstyle:IllegalCatch")
+ public static <T> List<T> expectMatching(final ActorRef actor, final Class<T> clazz, final int count) {
+ return expectMatching(actor, clazz, count, msg -> true);
+ }
+
+ @SuppressWarnings("checkstyle:IllegalCatch")
+ public static <T> List<T> expectMatching(final ActorRef actor, final Class<T> clazz, final int count,
+ final Predicate<T> matcher) {
+ int timeout = 5000;
+ Exception lastEx = null;
+ List<T> messages = Collections.emptyList();
+ for (int i = 0; i < timeout / 50; i++) {
+ try {
+ messages = getAllMatching(actor, clazz);
+ Iterables.removeIf(messages, Predicates.not(matcher));
+ if (messages.size() >= count) {
+ return messages;
+ }
+
+ lastEx = null;
+ } catch (Exception e) {
+ lastEx = e;
+ }
+
+ Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
+ }
+
+ throw new AssertionError(String.format("Expected %d messages of type %s. Actual received was %d: %s", count,
+ clazz, messages.size(), messages), lastEx);
+ }
+
+ public static <T> T expectFirstMatching(final ActorRef actor, final Class<T> clazz) {