Search in sources :

Example 31 with ActorSystem

use of akka.actor.ActorSystem in project kontraktor by RuedigerMoeller.

the class AkkaInterop method akkaConsumes.

@Test
public void akkaConsumes() throws InterruptedException {
    final int NUM_MSG = 20_000_000;
    final ActorSystem system = ActorSystem.create("reactive-interop");
    // Attention: buffer + batchsizes of Akka need increase in order to get performance
    final ActorMaterializer mat = ActorMaterializer.create(ActorMaterializerSettings.create(system).withInputBuffer(4096, 4096), system);
    KxReactiveStreams kxStreams = KxReactiveStreams.get();
    RateMeasure rm = new RateMeasure("rate");
    CountDownLatch count = new CountDownLatch(NUM_MSG);
    Source.from(kxStreams.produce(IntStream.range(0, NUM_MSG))).runWith(Sink.foreach(elem -> {
        rm.count();
        count.countDown();
    }), mat);
    int secondsWait = 50;
    while (count.getCount() > 0 && secondsWait-- > 0) {
        System.out.println("count:" + count.getCount());
        Thread.sleep(1000);
    }
    system.shutdown();
    Assert.assertTrue(count.getCount() == 0);
    // give time closing stuff
    Thread.sleep(1000);
}
Also used : ActorSystem(akka.actor.ActorSystem) IntStream(java.util.stream.IntStream) ActorMaterializerSettings(akka.stream.ActorMaterializerSettings) PublisherSink(akka.stream.impl.PublisherSink) Publisher(org.reactivestreams.Publisher) Source(akka.stream.javadsl.Source) Sink(akka.stream.javadsl.Sink) Materializer(akka.stream.Materializer) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) SubscriberSink(akka.stream.impl.SubscriberSink) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) RxReactiveStreams(rx.RxReactiveStreams) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActorSystem(akka.actor.ActorSystem) Log(org.nustaq.kontraktor.util.Log) Actors(org.nustaq.kontraktor.Actors) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Assert(org.junit.Assert) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) Test(org.junit.Test)

Example 32 with ActorSystem

use of akka.actor.ActorSystem in project kontraktor by RuedigerMoeller.

the class AkkaInterop method akkaAkka.

@Test
public void akkaAkka() throws InterruptedException {
    final int NUM_MSG = 10_000_000;
    final ActorSystem system = ActorSystem.create("reactive-interop");
    // Attention: buffer + batchsizes of Akka need increase in order to get performance
    final ActorMaterializer mat = ActorMaterializer.create(ActorMaterializerSettings.create(system).withInputBuffer(4096, 4096), system);
    RateMeasure rm = new RateMeasure("rate");
    CountDownLatch count = new CountDownLatch(NUM_MSG);
    Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
    Source.from(it).runWith(Sink.foreach(elem -> {
        rm.count();
        count.countDown();
    }), mat);
    int secondsWait = 50;
    while (count.getCount() > 0 && secondsWait-- > 0) {
        System.out.println("count:" + count.getCount());
        Thread.sleep(1000);
    }
    system.shutdown();
    Assert.assertTrue(count.getCount() == 0);
    // give time closing stuff
    Thread.sleep(1000);
}
Also used : ActorSystem(akka.actor.ActorSystem) IntStream(java.util.stream.IntStream) ActorMaterializerSettings(akka.stream.ActorMaterializerSettings) PublisherSink(akka.stream.impl.PublisherSink) Publisher(org.reactivestreams.Publisher) Source(akka.stream.javadsl.Source) Sink(akka.stream.javadsl.Sink) Materializer(akka.stream.Materializer) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) SubscriberSink(akka.stream.impl.SubscriberSink) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) RxReactiveStreams(rx.RxReactiveStreams) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActorSystem(akka.actor.ActorSystem) Log(org.nustaq.kontraktor.util.Log) Actors(org.nustaq.kontraktor.Actors) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Assert(org.junit.Assert) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) Test(org.junit.Test)

Example 33 with ActorSystem

use of akka.actor.ActorSystem in project kontraktor by RuedigerMoeller.

the class AkkaInterop method serveAkka_RemoteToKontraktor.

@Test
public void serveAkka_RemoteToKontraktor() throws InterruptedException {
    final int NUM_MSG = 50_000_000;
    final ActorSystem system = ActorSystem.create("reactive-interop");
    final Materializer mat = ActorMaterializer.create(system);
    KxReactiveStreams kxStreams = KxReactiveStreams.get();
    RateMeasure rm = new RateMeasure("rate");
    CountDownLatch count = new CountDownLatch(NUM_MSG);
    Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
    Publisher<Integer> pub = (Publisher<Integer>) Source.from(it).runWith(Sink.publisher(), mat);
    kxStreams.asKxPublisher(pub).serve(new WebSocketPublisher().hostName("localhost").port(6790).urlPath("akka"));
    // subscribe with kontraktor client
    new KxReactiveStreams(true).connect(Integer.class, new WebSocketConnectable().url("ws://localhost:6790/akka")).subscribe((res, err) -> {
        if (Actors.isResult(err)) {
            rm.count();
            count.countDown();
        }
    });
    int secondsWait = 50;
    while (count.getCount() > 0 && secondsWait-- > 0) {
        System.out.println("count:" + count.getCount());
        Thread.sleep(1000);
    }
    system.shutdown();
    Assert.assertTrue(count.getCount() == 0);
    // give time closing stuff
    Thread.sleep(1000);
}
Also used : ActorSystem(akka.actor.ActorSystem) IntStream(java.util.stream.IntStream) ActorMaterializerSettings(akka.stream.ActorMaterializerSettings) PublisherSink(akka.stream.impl.PublisherSink) Publisher(org.reactivestreams.Publisher) Source(akka.stream.javadsl.Source) Sink(akka.stream.javadsl.Sink) Materializer(akka.stream.Materializer) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) SubscriberSink(akka.stream.impl.SubscriberSink) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) RxReactiveStreams(rx.RxReactiveStreams) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActorSystem(akka.actor.ActorSystem) Log(org.nustaq.kontraktor.util.Log) Actors(org.nustaq.kontraktor.Actors) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Assert(org.junit.Assert) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) Publisher(org.reactivestreams.Publisher) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) CountDownLatch(java.util.concurrent.CountDownLatch) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) Materializer(akka.stream.Materializer) ActorMaterializer(akka.stream.ActorMaterializer) Test(org.junit.Test)

Example 34 with ActorSystem

use of akka.actor.ActorSystem in project kontraktor by RuedigerMoeller.

the class AkkaInterop method same_as_serveAkkaKontraktorAsBridge_use_RxJavaAtReceiverSide.

@Test
public void same_as_serveAkkaKontraktorAsBridge_use_RxJavaAtReceiverSide() throws InterruptedException {
    Log.setLevel(Log.DEBUG);
    final int NUM_MSG = 20_000_000;
    final ActorSystem system = ActorSystem.create("reactive-interop");
    // Attention: buffer + batchsizes of Akka need increase in order to get performance
    final ActorMaterializer mat = ActorMaterializer.create(ActorMaterializerSettings.create(system).withInputBuffer(8192, 8192), system);
    KxReactiveStreams kxStreams = KxReactiveStreams.get();
    RateMeasure rm = new RateMeasure("rate");
    CountDownLatch count = new CountDownLatch(NUM_MSG);
    Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
    Publisher<Integer> pub = (Publisher<Integer>) Source.from(it).runWith(Sink.publisher(), mat);
    kxStreams.asKxPublisher(pub).serve(new WebSocketPublisher().hostName("localhost").port(6789).urlPath("akka"));
    AtomicInteger kontraktorCount = new AtomicInteger(0);
    // subscribe with akka client
    KxPublisher<Integer> remotedPublisher = new KxReactiveStreams(true).connect(Integer.class, new WebSocketConnectable().url("ws://localhost:6789/akka")).map(x -> {
        // (*)
        kontraktorCount.incrementAndGet();
        return x;
    });
    RxReactiveStreams.toObservable(remotedPublisher).forEach(i -> {
        rm.count();
        count.countDown();
    });
    int secondsWait = 50;
    while (count.getCount() > 0 && secondsWait-- > 0) {
        System.out.println("count:" + (NUM_MSG - count.getCount()) + " kontraktor count:" + kontraktorCount.get());
        Thread.sleep(1000);
    }
    system.shutdown();
    Assert.assertTrue(count.getCount() == 0);
    // give time closing stuff
    Thread.sleep(1000);
}
Also used : ActorSystem(akka.actor.ActorSystem) IntStream(java.util.stream.IntStream) ActorMaterializerSettings(akka.stream.ActorMaterializerSettings) PublisherSink(akka.stream.impl.PublisherSink) Publisher(org.reactivestreams.Publisher) Source(akka.stream.javadsl.Source) Sink(akka.stream.javadsl.Sink) Materializer(akka.stream.Materializer) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) SubscriberSink(akka.stream.impl.SubscriberSink) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) RxReactiveStreams(rx.RxReactiveStreams) Ignore(org.junit.Ignore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActorSystem(akka.actor.ActorSystem) Log(org.nustaq.kontraktor.util.Log) Actors(org.nustaq.kontraktor.Actors) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Assert(org.junit.Assert) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) Publisher(org.reactivestreams.Publisher) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) CountDownLatch(java.util.concurrent.CountDownLatch) ActorMaterializer(akka.stream.ActorMaterializer) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) Test(org.junit.Test)

Example 35 with ActorSystem

use of akka.actor.ActorSystem in project flink by apache.

the class AkkaRpcActorTest method testActorTerminationWhenServiceShutdown.

/**
 * Tests that actors are properly terminated when the AkkaRpcService is shut down.
 */
@Test
public void testActorTerminationWhenServiceShutdown() throws Exception {
    final ActorSystem rpcActorSystem = AkkaUtils.createDefaultActorSystem();
    final RpcService rpcService = new AkkaRpcService(rpcActorSystem, AkkaRpcServiceConfiguration.defaultConfiguration());
    try {
        SimpleRpcEndpoint rpcEndpoint = new SimpleRpcEndpoint(rpcService, SimpleRpcEndpoint.class.getSimpleName());
        rpcEndpoint.start();
        CompletableFuture<Void> terminationFuture = rpcEndpoint.getTerminationFuture();
        rpcService.stopService();
        terminationFuture.get(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
    } finally {
        rpcActorSystem.terminate();
        AkkaFutureUtils.toJava(rpcActorSystem.whenTerminated()).get(timeout.getSize(), timeout.getUnit());
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) RpcService(org.apache.flink.runtime.rpc.RpcService) Test(org.junit.Test)

Aggregations

ActorSystem (akka.actor.ActorSystem)91 ActorRef (akka.actor.ActorRef)54 Test (org.junit.Test)51 Configuration (org.apache.flink.configuration.Configuration)27 FiniteDuration (scala.concurrent.duration.FiniteDuration)12 File (java.io.File)11 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)11 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)11 Props (akka.actor.Props)10 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)10 TestActorRef (akka.testkit.TestActorRef)8 IOException (java.io.IOException)8 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)8 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)8 Deadline (scala.concurrent.duration.Deadline)8 AddressFromURIString (akka.actor.AddressFromURIString)7 ActorMaterializer (akka.stream.ActorMaterializer)7 Materializer (akka.stream.Materializer)7 Sink (akka.stream.javadsl.Sink)7 Source (akka.stream.javadsl.Source)7