Search in sources :

Example 81 with ActorSystem

use of akka.actor.ActorSystem in project controller by opendaylight.

the class TransactionProxyTest method setUpReadData.

private void setUpReadData(final String shardName, final NormalizedNode<?, ?> expectedNode) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = getSystem().actorOf(Props.create(DoNothingActor.class));
    doReturn(getSystem().actorSelection(shardActorRef.path())).when(mockActorContext).actorSelection(shardActorRef.path().toString());
    doReturn(primaryShardInfoReply(getSystem(), shardActorRef)).when(mockActorContext).findPrimaryShardAsync(eq(shardName));
    ActorRef txActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
    doReturn(actorSystem.actorSelection(txActorRef.path())).when(mockActorContext).actorSelection(txActorRef.path().toString());
    doReturn(Futures.successful(createTransactionReply(txActorRef, DataStoreVersions.CURRENT_VERSION))).when(mockActorContext).executeOperationAsync(eq(actorSystem.actorSelection(shardActorRef.path())), eqCreateTransaction(memberName, TransactionType.READ_ONLY), any(Timeout.class));
    doReturn(readDataReply(expectedNode)).when(mockActorContext).executeOperationAsync(eq(actorSelection(txActorRef)), eqReadData(YangInstanceIdentifier.EMPTY), any(Timeout.class));
}
Also used : ActorSystem(akka.actor.ActorSystem) DoNothingActor(org.opendaylight.controller.cluster.raft.utils.DoNothingActor) ActorRef(akka.actor.ActorRef) Timeout(akka.util.Timeout)

Example 82 with ActorSystem

use of akka.actor.ActorSystem in project controller by opendaylight.

the class RemoteRpcProviderConfigTest method testConfigCustomizations.

@Test
public void testConfigCustomizations() {
    AkkaConfigurationReader reader = new TestConfigReader();
    final int expectedCapacity = 100;
    String timeOutVal = "10ms";
    FiniteDuration expectedTimeout = FiniteDuration.create(10, TimeUnit.MILLISECONDS);
    RemoteRpcProviderConfig config = new RemoteRpcProviderConfig.Builder("unit-test").metricCaptureEnabled(// enable metric capture
    true).mailboxCapacity(expectedCapacity).mailboxPushTimeout(timeOutVal).withConfigReader(reader).build();
    Assert.assertTrue(config.isMetricCaptureEnabled());
    Assert.assertEquals(expectedCapacity, config.getMailBoxCapacity().intValue());
    Assert.assertEquals(expectedTimeout.toMillis(), config.getMailBoxPushTimeout().toMillis());
    // Now check this config inside an actor
    ActorSystem system = ActorSystem.create("unit-test", config.get());
    TestActorRef<ConfigTestActor> configTestActorTestActorRef = TestActorRef.create(system, Props.create(ConfigTestActor.class));
    ConfigTestActor actor = configTestActorTestActorRef.underlyingActor();
    Config actorConfig = actor.getConfig();
    config = new RemoteRpcProviderConfig(actorConfig);
    Assert.assertTrue(config.isMetricCaptureEnabled());
    Assert.assertEquals(expectedCapacity, config.getMailBoxCapacity().intValue());
    Assert.assertEquals(expectedTimeout.toMillis(), config.getMailBoxPushTimeout().toMillis());
}
Also used : ActorSystem(akka.actor.ActorSystem) Config(com.typesafe.config.Config) FiniteDuration(scala.concurrent.duration.FiniteDuration) AkkaConfigurationReader(org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader) Test(org.junit.Test)

Example 83 with ActorSystem

use of akka.actor.ActorSystem in project jaqy by Teradata.

the class S3PathTest method test1.

@Test
public void test1() throws Exception {
    /*
		 * A workaround for S3Mock generating an output to stdout.
		 *     https://github.com/findify/s3mock/issues/67
		 * It generates an output in Eclipse, but not so when running
		 * mvn clean test.
		 */
    InMemoryProvider provider = new InMemoryProvider();
    ActorSystem actor = S3Mock.$lessinit$greater$default$3(8001, provider);
    S3Mock api = new S3Mock(8001, provider, actor);
    api.start();
    // setup
    Globals globals = new Globals();
    JaqyInterpreter interpreter = new JaqyInterpreter(globals, null, null);
    AmazonS3ClientBuilder builder = S3Utils.getS3Builder(interpreter);
    builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8001", "us-west-2"));
    // setup some files in the bucket
    AmazonS3 s3client = builder.build();
    s3client.createBucket("tests");
    File dir = new File("../tests/unittests/csv/lib");
    s3client.putObject("tests", "unittests/csv/lib/sin.csv", new File(dir, "sin.csv"));
    s3client.putObject("tests", "unittests/csv/lib/sin2.csv", new File(dir, "sin2.csv"));
    s3client.shutdown();
    S3PathHandler handler = new S3PathHandler();
    String url = "s3://tests/unittests/csv/lib/sin.csv";
    String parent = "s3://tests/unittests/csv/lib";
    S3Path path = (S3Path) handler.getPath(url, interpreter);
    Assert.assertNotNull(path);
    Assert.assertEquals("tests", path.getBucket());
    Assert.assertEquals("unittests/csv/lib/sin.csv", path.getFile());
    Assert.assertEquals(url, path.getPath());
    Assert.assertEquals(url, path.getCanonicalPath());
    Assert.assertTrue(path.exists());
    Assert.assertEquals(31443, path.length());
    Assert.assertEquals(31443, path.length());
    Assert.assertTrue(path.isFile());
    Assert.assertEquals(0, FileUtils.compare(path.getInputStream(), new FileInputStream(new File(dir, "sin.csv"))));
    path = (S3Path) path.getParent();
    Assert.assertEquals(parent, path.getPath());
    path = (S3Path) path.getRelativePath("sin2.csv");
    Assert.assertEquals("s3://tests/unittests/csv/lib/sin2.csv", path.getPath());
    Assert.assertTrue(path.isFile());
    path = (S3Path) path.getParent();
    path = (S3Path) path.getRelativePath("/unittests/csv/lib/import1.csv");
    Assert.assertEquals("s3://tests/unittests/csv/lib/import1.csv", path.getPath());
    FileUtils.copy(path.getOutputStream(), new FileInputStream(new File(dir, "import1.csv")), new byte[4096]);
    Assert.assertEquals(25, path.length());
    Assert.assertEquals(25, path.length());
    Assert.assertEquals(0, FileUtils.compare(path.getInputStream(), new FileInputStream(new File(dir, "import1.csv"))));
    path = (S3Path) path.getParent();
    path = (S3Path) path.getRelativePath("../../csv/lib/sin.csv");
    Assert.assertEquals(url, path.getPath());
    path = (S3Path) path.getParent();
    path = (S3Path) path.getRelativePath("../test/abc.csv");
    Assert.assertEquals(0, path.length());
    Assert.assertEquals(0, path.length());
    Assert.assertFalse(path.exists());
    Assert.assertFalse(path.exists());
    s3client = S3Utils.getS3Client(interpreter);
    if (s3client != null)
        s3client.shutdown();
    CoordinatedShutdown.get(actor).runAll();
    api.stop();
}
Also used : ActorSystem(akka.actor.ActorSystem) Globals(com.teradata.jaqy.Globals) AmazonS3(com.amazonaws.services.s3.AmazonS3) JaqyInterpreter(com.teradata.jaqy.JaqyInterpreter) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) InMemoryProvider(io.findify.s3mock.provider.InMemoryProvider) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) FileInputStream(java.io.FileInputStream) File(java.io.File) S3Mock(io.findify.s3mock.S3Mock) Test(org.junit.Test)

Example 84 with ActorSystem

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

the class AkkaInterop method serveAkkaKontraktorAsBridge.

@Test
@Ignore
public void serveAkkaKontraktorAsBridge() 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;
    });
    // for unknown reasons, this loses messages .. kontraktor receiver (*) above gets them all.
    // when trying to reproduce this locally the message loss seems not to occur.
    // as one can see from the counters the message loss is linear (not related to stream completion)
    // I think its an Akka issue as same test works if consuming from RxJava (see below)
    Source.from(remotedPublisher).runWith(Sink.foreach(elem -> {
        rm.count();
        count.countDown();
    }), mat);
    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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 85 with ActorSystem

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

the class AkkaInterop method kontraktorConsumes.

@Test
public void kontraktorConsumes() 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).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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) 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) Materializer(akka.stream.Materializer) ActorMaterializer(akka.stream.ActorMaterializer) 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