+ public static <T> T expectFirstMatching(ActorRef actor, Class<T> clazz) {
+ return expectFirstMatching(actor, clazz, 5000);
+ }
+
+ public static <T> T expectFirstMatching(ActorRef actor, Class<T> clazz, long timeout) {
+ int count = (int) (timeout / 50);
+ for(int i = 0; i < count; i++) {
+ try {
+ T message = getFirstMatching(actor, clazz);
+ if(message != null) {
+ return message;
+ }
+ } catch (Exception e) {}
+
+ Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
+ }
+
+ Assert.fail("Did not receive message of type " + clazz);
+ return null;
+ }
+
+ public static <T> List<T> getAllMatching(ActorRef actor, Class<T> clazz) throws Exception {