@Test public void createATypedActor() { try { // #typed-actor-create1 Squarer mySquarer = TypedActor.get(system) .typedActorOf(new TypedProps<SquarerImpl>(Squarer.class, SquarerImpl.class)); // #typed-actor-create1 // #typed-actor-create2 Squarer otherSquarer = TypedActor.get(system) .typedActorOf( new TypedProps<SquarerImpl>( Squarer.class, new Creator<SquarerImpl>() { public SquarerImpl create() { return new SquarerImpl("foo"); } }), "name"); // #typed-actor-create2 // #typed-actor-calls // #typed-actor-call-oneway mySquarer.squareDontCare(10); // #typed-actor-call-oneway // #typed-actor-call-future Future<Integer> fSquare = mySquarer.square(10); // A Future[Int] // #typed-actor-call-future // #typed-actor-call-option Option<Integer> oSquare = mySquarer.squareNowPlease(10); // Option[Int] // #typed-actor-call-option // #typed-actor-call-strict int iSquare = mySquarer.squareNow(10); // Int // #typed-actor-call-strict // #typed-actor-calls assertEquals(100, Await.result(fSquare, Duration.create(3, TimeUnit.SECONDS)).intValue()); assertEquals(100, oSquare.get().intValue()); assertEquals(100, iSquare); // #typed-actor-stop TypedActor.get(system).stop(mySquarer); // #typed-actor-stop // #typed-actor-poisonpill TypedActor.get(system).poisonPill(otherSquarer); // #typed-actor-poisonpill } catch (Exception e) { // Ignore } }
@Test public void return_the_fallback_when_running_in_development_mode() throws Exception { ActorSystem system = ActorSystem.create("MySystem"); URI fallback = new URI("/fallback"); LocationCache cache = new LocationCache(); ConnectionContext cc = ConnectionContext.create(system); Timeout timeout = new Timeout(Duration.create(5, "seconds")); assertEquals( Await.result( LocationService.getInstance().lookupWithContext("/whatever", fallback, cache, cc), timeout.duration()), Option.some(fallback)); }
@Override public Option<Integer> squareNowPlease(int i) { return Option.some(cal(i)); }
public Option<Integer> squareNowPlease(int i) { return Option.some(i * i); }