- private void validateMultiRouterReceived(List<Pair<ActorRef, Long>> actual, ActorRef... expected) {
- Assert.assertTrue(actual != null);
- Assert.assertTrue(actual.size() == expected.length);
- }
-
- private void validateRouterReceived(List<Pair<ActorRef, Long>> actual, ActorRef expected){
- Assert.assertTrue(actual != null);
- Assert.assertTrue(actual.size() == 1);
-
- for (Pair<ActorRef, Long> pair : actual){
- Assert.assertTrue(expected.path().uid() == pair.first().path().uid());
+ private JavaTestKit createProbeForMessage(ActorSystem node, ActorPath subjectPath, final Class<?> clazz)
+ throws Exception {
+ final JavaTestKit probe = new JavaTestKit(node);
+
+ ConditionalProbe conditionalProbe = new ConditionalProbe(probe.getRef(), new Predicate<Object>() {
+ @Override
+ public boolean apply(@Nullable Object input) {
+ if (input != null) {
+ return clazz.equals(input.getClass());
+ } else {
+ return false;
+ }
+ }
+ });
+
+ FiniteDuration duration = Duration.create(3, TimeUnit.SECONDS);
+ Timeout timeout = new Timeout(duration);
+ int maxTries = 30;
+ int i = 0;
+ while(true) {
+ ActorSelection subject = node.actorSelection(subjectPath);
+ Future<Object> future = Patterns.ask(subject, conditionalProbe, timeout);
+
+ try {
+ Await.ready(future, duration);
+ break;
+ } catch (TimeoutException | InterruptedException e) {
+ if(++i > maxTries) {
+ throw e;
+ }
+ }