@Override public Observable<BatchReturnType> createObservableCommand(Collection<CollapsedRequest<ResponseType, RequestArgumentType>> requests) { final HystrixCommand<BatchReturnType> command = self.createCommand(requests); command.markAsCollapsedCommand(this.getCollapserKey(), requests.size()); self.metrics.markBatch(requests.size()); return command.toObservable(); }
final Future<R> delegate = toObservable().toBlocking().toFuture();
@Test public void testRxRetry() throws Exception { // see https://github.com/Netflix/Hystrix/issues/1100 // Since each command instance is single-use, the expectation is that applying the .retry() operator // results in only a single execution and propagation out of that error HystrixCommand<Integer> cmd = getLatentCommand(ExecutionIsolationStrategy.THREAD, AbstractTestHystrixCommand.ExecutionResult.FAILURE, 300, AbstractTestHystrixCommand.FallbackResult.UNIMPLEMENTED, 100); final CountDownLatch latch = new CountDownLatch(1); System.out.println(System.currentTimeMillis() + " : Starting"); Observable<Integer> o = cmd.toObservable().retry(2); System.out.println(System.currentTimeMillis() + " Created retried command : " + o); o.subscribe(new Subscriber<Integer>() { @Override public void onCompleted() { System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " : OnCompleted"); latch.countDown(); } @Override public void onError(Throwable e) { System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " : OnError : " + e); latch.countDown(); } @Override public void onNext(Integer integer) { System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " : OnNext : " + integer); } }); latch.await(1000, TimeUnit.MILLISECONDS); System.out.println(System.currentTimeMillis() + " ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString()); }
Observable<Boolean> o = cmd.toObservable(); Subscription s = o. doOnUnsubscribe(new Action0() {
HystrixCommand<Integer> cmd = getCommand(ExecutionIsolationStrategy.THREAD, AbstractTestHystrixCommand.ExecutionResult.SUCCESS, 100, AbstractTestHystrixCommand.FallbackResult.UNIMPLEMENTED); Observable<Integer> o = cmd.toObservable() .doOnNext(new Action1<Integer>() { @Override
Observable<Integer> cmdResult = cmd.toObservable() .doOnNext(new Action1<Integer>() { @Override
Observable<Boolean> o = cmd.toObservable(); Subscription s = o. doOnUnsubscribe(new Action0() {
@Test public void testInsideHystrixSemaphoreObserve() throws Exception { HystrixCommand<Boolean> command = new HystrixCommand<Boolean>(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("TestUtil")) .andCommandKey(HystrixCommandKey.Factory.asKey("SemaphoreIsolatedCommandName")) .andCommandPropertiesDefaults(HystrixCommandProperties.Setter().withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE))) { @Override protected Boolean run() { assertEquals("SemaphoreIsolatedCommandName", Hystrix.getCurrentThreadExecutingCommand().name()); System.out.println("Semaphore Thread : " + Thread.currentThread().getName()); //should be a single execution on the caller thread (since it's busy here) assertEquals(1, Hystrix.getCommandCount()); return Hystrix.getCurrentThreadExecutingCommand() != null; } }; // it should be true for semaphore isolation as well assertTrue(command.toObservable().toBlocking().single()); // and then be null again once done assertNull(Hystrix.getCurrentThreadExecutingCommand()); }
@Override public Observable<BatchReturnType> createObservableCommand(Collection<CollapsedRequest<ResponseType, RequestArgumentType>> requests) { final HystrixCommand<BatchReturnType> command = self.createCommand(requests); command.markAsCollapsedCommand(this.getCollapserKey(), requests.size()); self.metrics.markBatch(requests.size()); return command.toObservable(); }
.toObservable() .retry(3) .map(foo -> confirmableDeliveryEvent)
} else if (isReturnsObservable(method)) { return hystrixCommand.toObservable(); } else if (isReturnsSingle(method)) { return hystrixCommand.toObservable().toSingle(); } else if (isReturnsCompletable(method)) { return hystrixCommand.toObservable().toCompletable();
final Future<R> delegate = toObservable().toBlocking().toFuture();