Java Code Examples for akka.actor.ActorSystem#terminate()
The following examples show how to use
akka.actor.ActorSystem#terminate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AkkaRpcActorTest.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * 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(); Await.ready(rpcActorSystem.whenTerminated(), FutureUtils.toFiniteDuration(timeout)); } }
Example 2
Source File: TransactionInterceptionTest.java From txle with Apache License 2.0 | 6 votes |
@Test public void passesOmegaContextAmongActors() throws Exception { ActorSystem actorSystem = ActorSystem.create(); ActorRef actorRef = actorSystem.actorOf(UserServiceActor.props(userService)); actorRef.tell(user, noSender()); waitTillSavedUser(username); assertArrayEquals( new String[] { new TxStartedEvent(globalTxId, newLocalTxId, globalTxId, compensationMethod, 0, "", 0, user).toString(), new TxEndedEvent(globalTxId, newLocalTxId, globalTxId, compensationMethod).toString()}, toArray(messages) ); actorSystem.terminate(); }
Example 3
Source File: AkkaRpcActorTest.java From flink with Apache License 2.0 | 6 votes |
/** * 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(); Await.ready(rpcActorSystem.whenTerminated(), FutureUtils.toFiniteDuration(timeout)); } }
Example 4
Source File: PlayWSITest.java From java-specialagent with Apache License 2.0 | 6 votes |
public static void main(final String[] args) throws Exception { final ActorSystem system = ActorSystem.create(); final Materializer materializer = ActorMaterializer.create(system); final AsyncHttpClientConfig asyncHttpClientConfig = new DefaultAsyncHttpClientConfig.Builder() .setMaxRequestRetry(0) .setShutdownQuietPeriod(0) .setShutdownTimeout(0) .build(); final AsyncHttpClient asyncHttpClient = new DefaultAsyncHttpClient(asyncHttpClientConfig); try (final StandaloneAhcWSClient wsClient = new StandaloneAhcWSClient(asyncHttpClient, materializer)) { final int status = wsClient.url("http://www.google.com").get() .whenComplete((response, throwable) -> TestUtil.checkActiveSpan()) .toCompletableFuture().get(15, TimeUnit.SECONDS) .getStatus(); if (200 != status) throw new AssertionError("Response: " + status); } finally { system.terminate(); TestUtil.checkSpan(new ComponentSpanCount("play-ws", 1)); } }
Example 5
Source File: UnitTest.java From deployment-examples with MIT License | 6 votes |
@Test public void testAsync() { final ActorSystem actorSystem = ActorSystem.create("test"); try { final ExecutionContextExecutor ec = actorSystem.dispatcher(); final AsyncController controller = new AsyncController(actorSystem, ec); final CompletionStage<Result> future = controller.message(); // Block until the result is completed await().until(() -> { assertThat(future.toCompletableFuture()).isCompletedWithValueMatching(result -> { return contentAsString(result).equals("Hi!"); }); }); } finally { actorSystem.terminate(); } }
Example 6
Source File: TransactionInterceptionTest.java From servicecomb-pack with Apache License 2.0 | 6 votes |
@Test public void passesOmegaContextAmongActors() throws Exception { ActorSystem actorSystem = ActorSystem.create(); ActorRef actorRef = actorSystem.actorOf(UserServiceActor.props(userService)); actorRef.tell(user, noSender()); waitTillSavedUser(username); assertArrayEquals( new String[] { new TxStartedEvent(globalTxId, newLocalTxId, globalTxId, compensationMethod, 0, "", 0, 0, 0, 0, 0, user).toString(), new TxEndedEvent(globalTxId, newLocalTxId, globalTxId, compensationMethod).toString()}, toArray(messages) ); actorSystem.terminate(); }
Example 7
Source File: Kata3SearchAkkaStream.java From ditto-examples with Eclipse Public License 2.0 | 6 votes |
@Test public void part1CreateAkkaSearchQuery() { final ActorSystem system = ActorSystem.create("thing-search"); try { final String filter = "or(eq(attributes/counter,1), eq(attributes/counter,2))"; // TODO create Akka source of publisher with above filter final Source<List<Thing>, NotUsed> things = null; // Verify Results things.flatMapConcat(Source::from) .toMat(Sink.seq(), Keep.right()) .run(ActorMaterializer.create(system)) .thenAccept(t -> Assertions.assertThat(t).containsAnyOf(thing1, thing2).doesNotContain(thing3)) .toCompletableFuture() .join(); } finally { system.terminate(); } }
Example 8
Source File: AkkaRpcActorTest.java From flink with Apache License 2.0 | 6 votes |
/** * 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(); FutureUtils.toJava(rpcActorSystem.whenTerminated()).get(timeout.getSize(), timeout.getUnit()); } }
Example 9
Source File: HelloActorMain.java From chuidiang-ejemplos with GNU Lesser General Public License v3.0 | 6 votes |
public static void main( String[] args ) { // an actor needs an ActorSystem ActorSystem system = ActorSystem.create("HelloWorldSystem"); // create and start the actor Props actor = Props.create(HelloActor.class); ActorRef helloActor = system.actorOf(actor, "HelloActor"); // send the actor two messages helloActor.tell("hello 1",helloActor); helloActor.tell("hello 2",helloActor); helloActor.tell("hello 3",helloActor); // shut down the system system.terminate(); }
Example 10
Source File: DefaultQuarantineHandler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void shutdownActorSystem(ActorSystem actorSystem) { // shut the actor system down actorSystem.terminate(); try { // give it some time to complete the shutdown Await.ready(actorSystem.whenTerminated(), timeout); } catch (InterruptedException | TimeoutException e) { log.error("Exception thrown when terminating the actor system", e); } finally { // now let's crash the JVM System.exit(exitCode); } }
Example 11
Source File: MetricQueryServiceTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testCreateDump() throws Exception { ActorSystem s = AkkaUtils.createLocalActorSystem(new Configuration()); try { ActorRef serviceActor = MetricQueryService.startMetricQueryService(s, null, Long.MAX_VALUE); TestActorRef testActorRef = TestActorRef.create(s, Props.create(TestActor.class)); TestActor testActor = (TestActor) testActorRef.underlyingActor(); final Counter c = new SimpleCounter(); final Gauge<String> g = () -> "Hello"; final Histogram h = new TestHistogram(); final Meter m = new TestMeter(); final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(); MetricQueryService.notifyOfAddedMetric(serviceActor, c, "counter", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, g, "gauge", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, h, "histogram", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, m, "meter", tm); serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef); testActor.waitForResult(); MetricDumpSerialization.MetricSerializationResult dump = testActor.getSerializationResult(); assertTrue(dump.serializedCounters.length > 0); assertTrue(dump.serializedGauges.length > 0); assertTrue(dump.serializedHistograms.length > 0); assertTrue(dump.serializedMeters.length > 0); MetricQueryService.notifyOfRemovedMetric(serviceActor, c); MetricQueryService.notifyOfRemovedMetric(serviceActor, g); MetricQueryService.notifyOfRemovedMetric(serviceActor, h); MetricQueryService.notifyOfRemovedMetric(serviceActor, m); serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef); testActor.waitForResult(); MetricDumpSerialization.MetricSerializationResult emptyDump = testActor.getSerializationResult(); assertEquals(0, emptyDump.serializedCounters.length); assertEquals(0, emptyDump.serializedGauges.length); assertEquals(0, emptyDump.serializedHistograms.length); assertEquals(0, emptyDump.serializedMeters.length); } finally { s.terminate(); } }
Example 12
Source File: MetricQueryServiceTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testHandleOversizedMetricMessage() throws Exception { ActorSystem s = AkkaUtils.createLocalActorSystem(new Configuration()); try { final long sizeLimit = 200L; ActorRef serviceActor = MetricQueryService.startMetricQueryService(s, null, sizeLimit); TestActorRef testActorRef = TestActorRef.create(s, Props.create(TestActor.class)); TestActor testActor = (TestActor) testActorRef.underlyingActor(); final TaskManagerMetricGroup tm = UnregisteredMetricGroups.createUnregisteredTaskManagerMetricGroup(); final String gaugeValue = "Hello"; final long requiredGaugesToExceedLimit = sizeLimit / gaugeValue.length() + 1; List<Tuple2<String, Gauge<String>>> gauges = LongStream.range(0, requiredGaugesToExceedLimit) .mapToObj(x -> Tuple2.of("gauge" + x, (Gauge<String>) () -> "Hello" + x)) .collect(Collectors.toList()); gauges.forEach(gauge -> MetricQueryService.notifyOfAddedMetric(serviceActor, gauge.f1, gauge.f0, tm)); MetricQueryService.notifyOfAddedMetric(serviceActor, new SimpleCounter(), "counter", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, new TestHistogram(), "histogram", tm); MetricQueryService.notifyOfAddedMetric(serviceActor, new TestMeter(), "meter", tm); serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef); testActor.waitForResult(); MetricDumpSerialization.MetricSerializationResult dump = testActor.getSerializationResult(); assertTrue(dump.serializedCounters.length > 0); assertEquals(1, dump.numCounters); assertTrue(dump.serializedMeters.length > 0); assertEquals(1, dump.numMeters); // gauges exceeded the size limit and will be excluded assertEquals(0, dump.serializedGauges.length); assertEquals(0, dump.numGauges); assertTrue(dump.serializedHistograms.length > 0); assertEquals(1, dump.numHistograms); // unregister all but one gauge to ensure gauges are reported again if the remaining fit for (int x = 1; x < gauges.size(); x++) { MetricQueryService.notifyOfRemovedMetric(serviceActor, gauges.get(x).f1); } serviceActor.tell(MetricQueryService.getCreateDump(), testActorRef); testActor.waitForResult(); MetricDumpSerialization.MetricSerializationResult recoveredDump = testActor.getSerializationResult(); assertTrue(recoveredDump.serializedCounters.length > 0); assertEquals(1, recoveredDump.numCounters); assertTrue(recoveredDump.serializedMeters.length > 0); assertEquals(1, recoveredDump.numMeters); assertTrue(recoveredDump.serializedGauges.length > 0); assertEquals(1, recoveredDump.numGauges); assertTrue(recoveredDump.serializedHistograms.length > 0); assertEquals(1, recoveredDump.numHistograms); } finally { s.terminate(); } }
Example 13
Source File: AkkaRange.java From akarnokd-misc with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Config cfg = ConfigFactory.parseResources(AkkaRange.class, "/akka-streams.conf").resolve(); ActorSystem actorSystem = ActorSystem.create("sys", cfg); ActorMaterializer materializer = ActorMaterializer.create(actorSystem); Source<Integer, NotUsed> source = Source.repeat(1) .map(v -> v + 1); Publisher<Integer> p = source.runWith(Sink.asPublisher(AsPublisher.WITH_FANOUT), materializer); p.subscribe(println()); Thread.sleep(1000); actorSystem.terminate(); }
Example 14
Source File: Akka.java From requirementsascode with Apache License 2.0 | 3 votes |
public static void main(String[] args) { ActorSystem actorSystem = ActorSystem.create("modelBasedActorSystem"); ActorRef sayHelloActor = spawn("sayHelloActor", actorSystem, SayHelloActor.class); sayHelloActor.tell(new AsksForHelloWorld(), ActorRef.noSender()); sayHelloActor.tell(new AsksForHelloToUser("Sandra"), ActorRef.noSender()); waitForReturnKeyPressed(); actorSystem.terminate(); }