+ public static <T> List<T> expectMatching(ActorRef actor, Class<T> clazz, int count) {
+ int timeout = 5000;
+ List<T> messages = Collections.emptyList();
+ for(int i = 0; i < timeout / 50; i++) {
+ try {
+ messages = getAllMatching(actor, clazz);
+ if(messages.size() >= count) {
+ return messages;
+ }
+ } catch (Exception e) {}
+
+ Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
+ }
+
+ Assert.fail(String.format("Expected %d messages of type %s. Actual received was %d: %s", count, clazz,
+ messages.size(), messages));
+ return null;
+ }
+