private Observable<Integer> waitForExit() { return rxVertx.timerStream(POLLING_INTERVAL_IN_MS).toObservable() .flatMap(x -> { if (process.isAlive()) { return waitForExit(); } else { if (process.exitValue() != expectedResultCode) { printStream(process.getInputStream(), false); throw new IllegalStateException(printStream(process.getErrorStream(), true)); } else { printStream(process.getInputStream(), false); } return just(process.exitValue()); } }); }
private Observable<DeployRequest> doPoll(DeployRequest request) { return rxVertx.timerStream(POLLING_INTERVAL_IN_MS).toObservable() .flatMap(x -> awsAsUtil.pollForInstanceState()) .flatMap(awsState -> { if (LocalDateTime.now().isAfter(timeout)) { LOG.error("[{} - {}]: Timeout while waiting for instance to reach {} ", LogConstants.AWS_AS_REQUEST, request.getId(), awsState.name()); throw new IllegalStateException(); } LOG.info("[{} - {}]: Instance {} in auto scaling group {} in state {}", LogConstants.AWS_AS_REQUEST, request.getId(), awsAsUtil.getInstanceId(), request.getAutoScalingGroup(), awsState.name()); if (acceptedStates.contains(awsState)) { return Observable.just(request); } else { return doPoll(request); } } ); }
private Observable<DeployRequest> doPoll(DeployRequest request, String elb) { return rxVertx.timerStream(POLLING_INTERVAL_IN_MS).toObservable() .flatMap(x -> awsElbUtil.pollForInstanceState(elb)) .flatMap(awsState -> { if (!requestStillActive.apply(deployId)) { LOG.error("[{} - {}]: Request canceled, stopping poller {} ", LogConstants.AWS_ELB_REQUEST, request.getId(), awsState.name()); throw new IllegalStateException(); } if (LocalDateTime.now().isAfter(timeout)) { LOG.error("[{} - {}]: Timeout while waiting for instance to reach {} ", LogConstants.AWS_ELB_REQUEST, request.getId(), awsState.name()); throw new IllegalStateException(); } LOG.info("[{} - {}]: Instance {} on elb {} in state {}", LogConstants.AWS_ELB_REQUEST, request.getId(), awsElbUtil.getInstanceId(), elb, awsState.name()); if (acceptedStates.contains(awsState)) { return Observable.just(request); } else { return doPoll(request, elb); } } ); }
private Observable<DeployApplicationRequest> doPoll(DeployApplicationRequest request) { return rxVertx.timerStream(POLLING_INTERVAL_IN_MS).toObservable() .flatMap(x -> processUtils.checkModuleRunning(request)) .flatMap(result -> { if (LocalDateTime.now().isAfter(timeout)) { LOG.error("[{} - {}]: Timeout while waiting for application to stop. ", LogConstants.DEPLOY_REQUEST, request.getId()); throw new IllegalStateException(); } if (!request.isRunning()) { LOG.info("[{} - {}]: Application {} stopped.", LogConstants.DEPLOY_REQUEST, request.getId(), request.getMavenArtifactId()); return just(request); } else { LOG.trace("[{} - {}]: Application {} still running.", LogConstants.DEPLOY_REQUEST, request.getId(), request.getMavenArtifactId()); return doPoll(request); } } ) .doOnError(t -> LOG.info("[{} - {}]: Error while Waiting for module '{}' with applicationId '{}' to stop -> '{}'.", LogConstants.DEPLOY_REQUEST, request.getId(), request.getModuleId(), t)); } }
@Test public void testConcatOperator() { Observable<Long> o1 = vertx.timerStream(100).toObservable(); Observable<Long> o2 = vertx.timerStream(100).toObservable(); Observable<Long> obs = Observable.concat(o1, o2); AtomicInteger count = new AtomicInteger(); obs.subscribe(msg -> count.incrementAndGet(), err -> fail(), () -> { assertEquals(2, count.get()); testComplete(); }); await(); }