Advertisement
Guest User

Untitled

a guest
May 15th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import akka.actor.ActorIdentity;
  2. import akka.actor.ActorRef;
  3. import akka.actor.ActorSystem;
  4. import akka.event.Logging;
  5. import akka.testkit.JavaTestKit;
  6. import akka.testkit.TestProbe;
  7. import com.typesafe.training.coffeehouse.CoffeeHouse;
  8. import org.junit.AfterClass;
  9. import org.junit.BeforeClass;
  10. import org.junit.Test;
  11. import org.junit.runner.RunWith;
  12. import org.junit.runners.JUnit4;
  13. import scala.concurrent.duration.Duration;
  14. import static org.junit.Assert.*;
  15.  
  16. @RunWith(JUnit4.class)
  17. public class CoffeeHouseTest {
  18.  
  19. static ActorSystem system;
  20.  
  21. @BeforeClass
  22. public static void setup() {
  23. system = ActorSystem.create();
  24. }
  25.  
  26. @AfterClass
  27. public static void teardown() {
  28. JavaTestKit.shutdownActorSystem(system);
  29. system = null;
  30. }
  31.  
  32. @Test
  33. public void creatingCoffeeHouseDebug() {
  34. new JavaTestKit(system) {{
  35. new EventFilter<Void>(Logging.Debug.class) {
  36. protected Void run() {
  37. system.actorOf(CoffeeHouse.props());
  38. return null;
  39. }
  40. }.matches(".*[Oo]pen.*").occurrences(1).exec();
  41. }};
  42. }
  43.  
  44. @Test
  45. public void creatingNewGuestActors() {
  46. new JavaTestKit(system) {{
  47. ActorRef coffeeHouse = system.actorOf(CoffeeHouse.props(), "create-guest");
  48. final String guestPath = "/user/create-guest/$*";
  49. coffeeHouse.tell(CoffeeHouse.CreateGuest.Instance, null);
  50. new AwaitAssert(duration("1 minute"), duration("200 millis")) {
  51. @Override
  52. protected void check() {
  53. system.actorSelection(guestPath)
  54. .tell(new akka.actor.Identify(101), getRef());
  55. ActorIdentity i =
  56. expectMsgClass(duration("100 millis"), ActorIdentity.class);
  57. assertEquals(i.correlationId(), 101);
  58. assertNotNull(i.getRef());
  59.  
  60. }
  61. };
  62. }};
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement