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));
}
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());
}
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();
}
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);
}
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);
}
Aggregations