akka.util.Timeout Java Examples
The following examples show how to use
akka.util.Timeout.
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: ArticleParseClusterClient.java From learning-akka with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { Timeout timeout = new Timeout(Duration.create(5, "seconds")); ActorSystem system = ActorSystem.create("clientSystem"); Set<ActorSelection> initialContacts = new HashSet<ActorSelection>(); initialContacts.add(system.actorSelection("akka.tcp://[email protected]:2552/user/receptionist")); initialContacts.add(system.actorSelection("akka.tcp://[email protected]:2551/user/receptionist")); ActorRef receptionist = system.actorOf(ClusterClient.defaultProps(initialContacts)); ClusterClient.Send msg = new ClusterClient.Send("/user/workers", articleToParse, false); Future f = Patterns.ask(receptionist, msg, timeout); String result = (String) Await.result(f, timeout.duration()); System.out.println("result: " + result); }
Example #2
Source File: AkkaTest.java From java-specialagent with Apache License 2.0 | 6 votes |
@Test public void testAsk(final MockTracer tracer) throws Exception { final ActorRef actorRef = system.actorOf(TestActor.props(tracer, false), "ask"); final Timeout timeout = new Timeout(getDefaultDuration()); final Future<Object> future = ask(actorRef, "ask", timeout); final Boolean isSpanNull = (Boolean)Await.result(future, getDefaultDuration()); assertFalse(isSpanNull); await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(2)); final List<MockSpan> spans = tracer.finishedSpans(); assertEquals(2, spans.size()); for (final MockSpan span : spans) assertEquals(AkkaAgentIntercept.COMPONENT_NAME, span.tags().get(Tags.COMPONENT.getKey())); }
Example #3
Source File: KafkaSagaEventConsumer.java From servicecomb-pack with Apache License 2.0 | 6 votes |
private CompletionStage<String> sendSagaActor(BaseEvent event) { try { long begin = System.currentTimeMillis(); metricsService.metrics().doActorReceived(); // Use the synchronous method call to ensure that Kafka's Offset is set after the delivery is successful. Timeout timeout = new Timeout(Duration.create(10, "seconds")); Future<Object> future = Patterns.ask(sagaShardRegionActor, event, timeout); Await.result(future, timeout.duration()); long end = System.currentTimeMillis(); metricsService.metrics().doActorAccepted(); metricsService.metrics().doActorAvgTime(end - begin); return CompletableFuture.completedFuture("OK"); } catch (Exception ex) { LOG.error(ex.getMessage(),ex); metricsService.metrics().doActorRejected(); throw new CompletionException(ex); } }
Example #4
Source File: AkkaTest.java From java-specialagent with Apache License 2.0 | 6 votes |
@Test public void testForward(final MockTracer tracer) throws Exception { final ActorRef actorRef = system.actorOf(TestActor.props(tracer, true), "forward"); final Timeout timeout = new Timeout(getDefaultDuration()); final Future<Object> future = ask(actorRef, "forward", timeout); final Boolean isSpanNull = (Boolean)Await.result(future, getDefaultDuration()); assertFalse(isSpanNull); await().atMost(15, TimeUnit.SECONDS).until(TestUtil.reportedSpansSize(tracer), equalTo(2)); final List<MockSpan> spans = tracer.finishedSpans(); assertEquals(2, spans.size()); for (final MockSpan span : spans) assertEquals(AkkaAgentIntercept.COMPONENT_NAME, span.tags().get(Tags.COMPONENT.getKey())); }
Example #5
Source File: SshClientActor.java From java-11-examples with Apache License 2.0 | 6 votes |
@Override public void onReceive(Object message) throws Throwable { if (message instanceof ReceiveTimeout) { sshClientService.onSessionCreateTimeout(clientId); self().tell(PoisonPill.getInstance(), self()); } else if (message instanceof SessionCreateResponse) { SessionCreateResponse sessionCreateResponse = (SessionCreateResponse)message; LOG.info("looking for session actor: {}", sessionCreateResponse.getSessionActorAddress()); Future<ActorRef> actorRefFuture = context().system() .actorSelection(sessionCreateResponse.getSessionActorAddress()).resolveOne(Timeout.apply(2, TimeUnit.SECONDS)); sshSessionActor = Await.result(actorRefFuture, Duration.apply(2, TimeUnit.SECONDS)); sshClientService.onSessionCreateReply(sessionCreateResponse.getClientId(), sessionCreateResponse.getSessionId(), sshSessionActor, sessionCreateResponse.getSessionActorAddress()); } else if (message instanceof SessionDataResponse) { SessionDataResponse sessionDataResponse = (SessionDataResponse)message; sshClientService.onSessionDataReceived(clientId, sessionDataResponse); } else if (message instanceof SessionCloseResponse) { SessionCloseResponse sessionCloseResponse = (SessionCloseResponse)message; sshClientService.onCloseSessionResponse(clientId, sessionCloseResponse); self().tell(PoisonPill.getInstance(), self()); } else { LOG.info("onReceive: {}", message.getClass().getName()); } }
Example #6
Source File: NoPolTask.java From nopol with GNU General Public License v2.0 | 6 votes |
@Override public void run(@NotNull ProgressIndicator progressIndicator) { if (ActorManager.runNopolLocally && !ActorManager.nopolIsRunning) { ActorManager.launchNopol(); } Timeout timeout = new Timeout(scala.concurrent.duration.Duration.fromNanos(20*1000000000));// nano = 10^9 EventSender.send(EventSender.Event.REPAIR_ATTEMPT); try { ConfigActor configActor = new ConfigActorImpl(nopolContext, Files.readAllBytes(Paths.get(outputZip))); this.future = Patterns.ask(ActorManager.remoteActor, configActor, timeout); if (Plugin.enableFancyRobot) { ApplicationManager.getApplication().invokeLater(runnerFancyRobot); } this.response = Await.result(future, timeout.duration()); } catch (Exception e) { onError(e); } }
Example #7
Source File: UdpWorkerTest.java From parallec with Apache License 2.0 | 6 votes |
@Test public void testUdpWorkerBadMsgTypeDefaultType() { logger.info("IN testUdpWorkerBadMsgTypeDefaultType"); ActorRef asyncWorker = null; try { // made a timeout int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(UdpWorker.class, actorMaxOperationTimeoutSec, getUdpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.CHECK_FUTURE_STATE, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #8
Source File: PingWorkerTest.java From parallec with Apache License 2.0 | 6 votes |
@Test public void testSlowAndPollProgress() { ActorRef asyncWorker = null; try { int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(PingWorker.class, actorMaxOperationTimeoutSec, getPingMetaSample(), "www.google.com")); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #9
Source File: UdpWorkerTest.java From parallec with Apache License 2.0 | 6 votes |
@Test public void testUdpWorkerBadMsgType() { logger.info("IN testUdpWorkerBadMsgType"); ActorRef asyncWorker = null; try { // made a timeout int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(UdpWorker.class, actorMaxOperationTimeoutSec, getUdpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, new Integer(0), new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #10
Source File: PingWorkerTest.java From parallec with Apache License 2.0 | 6 votes |
@Test public void testTcpWorkerBadMsgType() { logger.info("IN testTcpWorkerBadMsgType"); ActorRef asyncWorker = null; try { int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(PingWorker.class, actorMaxOperationTimeoutSec, getPingMetaSample(), "www.google.com")); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, new Integer(0), new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #11
Source File: TcpWorkerTest.java From parallec with Apache License 2.0 | 6 votes |
@Test public void testTcpWorkerBadMsgTypeDefaultType() { logger.info("IN testUdpWorkerBadMsgTypeDefaultType"); ActorRef asyncWorker = null; try { // made a timeout int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(TcpWorker.class, actorMaxOperationTimeoutSec, getTcpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.CHECK_FUTURE_STATE, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #12
Source File: TcpWorkerTest.java From parallec with Apache License 2.0 | 6 votes |
@Test public void testTcpWorkerBadMsgType() { logger.info("IN testTcpWorkerBadMsgType"); ActorRef asyncWorker = null; try { // made a timeout int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(TcpWorker.class, actorMaxOperationTimeoutSec, getTcpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, new Integer(0), new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #13
Source File: ExecutorTest.java From Nickle-Scheduler with Apache License 2.0 | 6 votes |
@Test public void testExecutor() { ActorRef server = system.actorOf(ServerActor.props()); Timeout t = new Timeout(Duration.create(3, TimeUnit.SECONDS)); //使用ask发送消息,actor处理完,必须有返回(超时时间5秒) try { Future<Object> ask = Patterns.ask(server, "123", t); ask.onComplete(new OnComplete<Object>() { @Override public void onComplete(Throwable throwable, Object o) throws Throwable { if (throwable != null) { System.out.println("some thing wrong.{}" + throwable); } else { System.out.println("success:" + o); } } }, system.dispatcher()); System.out.println("执行完毕"); } catch (Exception e) { e.printStackTrace(); } }
Example #14
Source File: TcpWorkerIdleTest.java From parallec with Apache License 2.0 | 5 votes |
@Test public void testTcpWorkerNormalCheckCompleteForIdle() { ActorRef asyncWorker = null; logger.info("IN testTcpWorkerNormalCheckCompleteForIdle"); try { // Start new job int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(TcpWorker.class, actorMaxOperationTimeoutSec, getTcpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #15
Source File: SshWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
@Test public void testSshWorkerDupAndCancel() { ActorRef asyncWorker = null; try { // Start new job int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(SshWorker.class, actorMaxOperationTimeoutSec, SshProviderMockTest.sshMetaPassword, hostIpSample)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); // test dup asyncWorker.tell(RequestWorkerMsgType.PROCESS_REQUEST, asyncWorker); // test cancel asyncWorker.tell(RequestWorkerMsgType.CANCEL, asyncWorker); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #16
Source File: SshWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
@Test public void testSshWorkerBadMsgType() { ActorRef asyncWorker = null; try { // made a timeout int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem() .actorOf( Props.create(SshWorker.class, actorMaxOperationTimeoutSec, SshProviderMockTest.sshMetaPassword, hostIpSample2)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); // test invalid type asyncWorker.tell(new Integer(0), asyncWorker); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #17
Source File: BootStrapIndexingServiceImpl.java From searchanalytics-bigdata with MIT License | 5 votes |
@Override public void preparingIndexes() { logger.info("Starting index preparation for {}", IndexingMessage.REBUILD_ALL_INDICES); setupIndexMasterActor.tell(IndexingMessage.REBUILD_ALL_INDICES, null); final Timeout timeout = new Timeout(Duration.create(10, "seconds")); final StopWatch stopWatch = new StopWatch(); Future<Object> future = Patterns.ask(setupIndexMasterActor, IndexingMessage.REBUILD_ALL_INDICES_DONE, timeout); try { // Allow only to run for max 5 min. and check every few sec usign // thread sleep. stopWatch.start(); while (!(Boolean) Await.result(future, timeout.duration()) && stopWatch.getTotalTimeSeconds() < 5 * 60) { future = Patterns.ask(setupIndexMasterActor, IndexingMessage.REBUILD_ALL_INDICES_DONE, timeout); logger.debug("Index setup status check, Got back " + false); // TODO: use this, based on your time taken by ur env. here, 100 // ms Thread.sleep(100); } logger.debug("Index setup status check, Got back " + true); } catch (final Exception e) { logger.debug("Index setup status check, Failed getting result: " + e.getMessage()); throw new RuntimeException( "Error occured while setting up search index!", e); } logger.debug("All indexing setup finished using Akka system, Enjoy!"); }
Example #18
Source File: ITActors.java From akka-java-springfactory with MIT License | 5 votes |
@Test public void testActor() throws Exception { ActorRef dummyActor = actorSystem.actorOf(SpringProps.create(actorSystem, TestActor.class)); dummyActor.tell(new TestActor.Increment(), null); dummyActor.tell(new TestActor.Increment(), null); dummyActor.tell(new TestActor.Increment(), null); FiniteDuration duration = FiniteDuration.create(3, TimeUnit.SECONDS); Future<Object> result = ask(dummyActor, new TestActor.Get(), Timeout.durationToTimeout(duration)); assertEquals(3, Await.result(result, duration)); }
Example #19
Source File: SpringAkkaIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void whenCallingGreetingActor_thenActorGreetsTheCaller() throws Exception { ActorRef greeter = system.actorOf(SPRING_EXTENSION_PROVIDER.get(system).props("greetingActor"), "greeter"); FiniteDuration duration = FiniteDuration.create(1, TimeUnit.SECONDS); Timeout timeout = Timeout.durationToTimeout(duration); Future<Object> result = ask(greeter, new Greet("John"), timeout); Assert.assertEquals("Hello, John", Await.result(result, duration)); }
Example #20
Source File: ActorSystemManagerImpl.java From usergrid with Apache License 2.0 | 5 votes |
private void waitForClientActor( ActorRef ra ) { logger.info( "Waiting on ClientActor [{}]...", ra.path() ); started = false; int retries = 0; int maxRetries = 60; while (retries < maxRetries) { Timeout t = new Timeout( 10, TimeUnit.SECONDS ); Future<Object> fut = Patterns.ask( ra, new ClientActor.StatusRequest(), t ); try { ClientActor.StatusMessage result = (ClientActor.StatusMessage) Await.result( fut, t.duration() ); if (result.getStatus().equals( ClientActor.StatusMessage.Status.READY )) { started = true; break; } logger.info( "Waiting for ClientActor [{}] region [{}] for [{}s]", ra.path(), currentRegion, retries ); Thread.sleep( 1000 ); } catch (Exception e) { logger.error( "Error: Timeout waiting for ClientActor [{}]", ra.path() ); } retries++; } if (started) { logger.info( "ClientActor [{}] has started", ra.path() ); } else { throw new RuntimeException( "ClientActor ["+ra.path()+"] did not start in time, validate that akka seeds are configured properly" ); } }
Example #21
Source File: SshWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
@Test public void testSshWorkerTimeoutException() { ActorRef asyncWorker = null; try { // Start new job // made a timeout int actorMaxOperationTimeoutSec = 0; asyncWorker = ActorConfig.createAndGetActorSystem() .actorOf( Props.create(SshWorker.class, actorMaxOperationTimeoutSec, SshProviderMockTest.sshMetaPassword, hostIpSample2)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #22
Source File: TcpWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
/** * fake a NPE in bootStrapTcpClient */ @Test public void testBootStrapTcpClient() { logger.info("IN testTcpWorkerException"); ActorRef asyncWorker = null; try { // Start new job TcpMeta meta = getTcpMetaSample(); meta.setChannelFactory(null); int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(TcpWorker.class, actorMaxOperationTimeoutSec, meta, LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { } }
Example #23
Source File: TcpWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
/** * fake a NPE of logger; do not forget to reset it or other tests will fail. */ @Test public void testTcpWorkerException() { logger.info("IN testTcpWorkerException"); ActorRef asyncWorker = null; try { TcpWorker.setLogger(null); // Start new job int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(TcpWorker.class, actorMaxOperationTimeoutSec, getTcpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.CANCEL, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } TcpWorker.setLogger(LoggerFactory.getLogger(TcpWorker.class)); }
Example #24
Source File: TcpWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
@Test public void testTcpWorkerDupAndCancel() { ActorRef asyncWorker = null; logger.info("IN testTcpWorkerDupAndCancel"); try { // Start new job int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(TcpWorker.class, actorMaxOperationTimeoutSec, getTcpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); // test dup asyncWorker.tell(RequestWorkerMsgType.PROCESS_REQUEST, asyncWorker); // test cancel asyncWorker.tell(RequestWorkerMsgType.CANCEL, asyncWorker); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #25
Source File: TcpWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
@Test public void testTcpWorkerNormalCheckComplete() { ActorRef asyncWorker = null; logger.info("IN testTcpWorkerNormalCheckComplete"); try { // Start new job int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(TcpWorker.class, actorMaxOperationTimeoutSec, getTcpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #26
Source File: PingWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
/** * fake a NPE of logger; do not forget to reset it or other tests will fail. */ @Test public void testException() { ActorRef asyncWorker = null; try { PingWorker.setLogger(null); int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(PingWorker.class, actorMaxOperationTimeoutSec, getPingMetaSample(), "www.google.com")); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.CANCEL, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } PingWorker.setLogger(LoggerFactory.getLogger(PingWorker.class)); }
Example #27
Source File: PingWorkerTest.java From parallec with Apache License 2.0 | 5 votes |
@Test public void testDupAndCancel() { ActorRef asyncWorker = null; logger.info("IN testTcpWorkerDupAndCancel"); try { int actorMaxOperationTimeoutSec = 15; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(PingWorker.class, actorMaxOperationTimeoutSec, getPingMetaSample(), "www.google.com")); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); // test dup asyncWorker.tell(RequestWorkerMsgType.PROCESS_REQUEST, asyncWorker); // test cancel asyncWorker.tell(RequestWorkerMsgType.CANCEL, asyncWorker); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); // Start new job } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }
Example #28
Source File: AkkaActorITest.java From java-specialagent with Apache License 2.0 | 5 votes |
private static void testAsk(final ActorSystem system) throws Exception { final ActorRef actorRef = system.actorOf(TestActor.props(false), "ask"); final CountDownLatch latch = TestUtil.initExpectedSpanLatch(2); final Future<Object> future = ask(actorRef, "ask", new Timeout(getDefaultDuration())); final Boolean isSpanNull = (Boolean)Await.result(future, getDefaultDuration()); assertFalse(isSpanNull); TestUtil.checkSpan(latch, new ComponentSpanCount("java-akka", 2, true)); }
Example #29
Source File: AkkaActorITest.java From java-specialagent with Apache License 2.0 | 5 votes |
private static void testForward(final ActorSystem system) throws Exception { final ActorRef actorRef = system.actorOf(TestActor.props(true), "forward"); final CountDownLatch latch = TestUtil.initExpectedSpanLatch(2); final Future<Object> future = ask(actorRef, "forward", new Timeout(getDefaultDuration())); final Boolean isSpanNull = (Boolean)Await.result(future, getDefaultDuration()); assertFalse(isSpanNull); TestUtil.checkSpan(latch, new ComponentSpanCount("java-akka", 2, true)); }
Example #30
Source File: TcpWorkerIdleTest.java From parallec with Apache License 2.0 | 5 votes |
/** * Timeout here: as if in the none idle one, will immediately return and not to timeout. */ @Test public void testTcpWorkerTimeoutException() { ActorRef asyncWorker = null; logger.info("IN testTcpWorkerTimeoutException in idle"); try { // Start new job // made a timeout int actorMaxOperationTimeoutSec = 0; asyncWorker = ActorConfig.createAndGetActorSystem().actorOf( Props.create(TcpWorker.class, actorMaxOperationTimeoutSec, getTcpMetaSample(), LOCALHOST)); final FiniteDuration duration = Duration.create(20, TimeUnit.SECONDS); Future<Object> future = Patterns .ask(asyncWorker, RequestWorkerMsgType.PROCESS_REQUEST, new Timeout(duration)); ResponseOnSingeRequest response = (ResponseOnSingeRequest) Await .result(future, duration); logger.info("\nWorker response:" + response.toString()); } catch (Throwable ex) { logger.error("Exception in test : " + ex); } }