Re: [akka-user] JavaTestkit question

2015-05-31 Thread Konrad Malawski
Hi TS,
there's a number of ways you can achieve this,
one is: expectMsgAnyOf(...) and then another expectMsgAnyOff with one
message (the received one) less from the expected collection,
another one is fishForMessage() where you implement a partial function
which can fish for the message you want to get - it you could return true
for any of the 2 messages for example.



On Sat, May 23, 2015 at 1:49 AM, TS test.tester1...@gmail.com wrote:

 Let's take this code..


 public void testIt() throws IOException {

 new JavaTestKit(system) {{

 final Props props = Props.create(MyActor.class);

 final ActorRef subject = system.actorOf(props);

ByteString someBytes =
 ByteString.fromArray(abcd.getBytes())

subject.tell(someBytes, getSelf());

//await response

   Actor1 actor1 = expectMsgClass(Actor1.class);

  Actor2 actor2 = expectMsgClass(Actor2.class);

   }};

 }


 in myActor.java

 actor1Ref and actor2Ref are ActorRef of Actor1 and Actor2 actors.

   

@Override

public void onReceive(Object message) {

   if(message instanceof ByteString) {

   // do something

   getSender().tell(actor1Ref, getSelf());

  // some more things

 getSender().tell(actor2Ref, getSelf());

}

...

 }

 The order

 Actor1 actor1 = expectMsgClass(Actor1.class);

 Actor2 actor2 = expectMsgClass(Actor2.class);

 seems to work and test passes. if actor1 message arrives late, the test
 would fail I think.

 Is there a way to say expectMsgClassesInNoParticularOrder(Actor1.class,
 Actor2.class) ?

 --
  Read the docs: http://akka.io/docs/
  Check the FAQ:
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
 ---
 You received this message because you are subscribed to the Google Groups
 Akka User List group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to akka-user+unsubscr...@googlegroups.com.
 To post to this group, send email to akka-user@googlegroups.com.
 Visit this group at http://groups.google.com/group/akka-user.
 For more options, visit https://groups.google.com/d/optout.




-- 
Cheers,
Konrad 'ktoso' Malawski
Akka http://akka.io/ @ Typesafe http://typesafe.com/

-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] JavaTestkit question

2015-05-22 Thread TS
Let's take this code..


public void testIt() throws IOException {

new JavaTestKit(system) {{

final Props props = Props.create(MyActor.class);

final ActorRef subject = system.actorOf(props);

   ByteString someBytes = 
ByteString.fromArray(abcd.getBytes())

   subject.tell(someBytes, getSelf());

   //await response

  Actor1 actor1 = expectMsgClass(Actor1.class);

 Actor2 actor2 = expectMsgClass(Actor2.class);

  }};

}


in myActor.java

actor1Ref and actor2Ref are ActorRef of Actor1 and Actor2 actors.

  

   @Override

   public void onReceive(Object message) {

  if(message instanceof ByteString) {

  // do something

  getSender().tell(actor1Ref, getSelf());

 // some more things

getSender().tell(actor2Ref, getSelf());

   }

   ...

}

The order 

Actor1 actor1 = expectMsgClass(Actor1.class);

Actor2 actor2 = expectMsgClass(Actor2.class);

seems to work and test passes. if actor1 message arrives late, the test 
would fail I think. 

Is there a way to say expectMsgClassesInNoParticularOrder(Actor1.class, 
Actor2.class) ?

-- 
  Read the docs: http://akka.io/docs/
  Check the FAQ: 
 http://doc.akka.io/docs/akka/current/additional/faq.html
  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups Akka 
User List group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.