Skip to content

Commit

Permalink
Added unit test that demonstrates calling .retry() on an Observable p…
Browse files Browse the repository at this point in the history
…roduced by Hystrix does not result in deadlock
  • Loading branch information
Matt Jacobs committed Oct 26, 2016
1 parent 1bf896b commit b54a22b
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
import com.netflix.hystrix.strategy.properties.HystrixProperty;
import com.sun.javafx.collections.NonIterableChange;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -3940,6 +3941,43 @@ public void onNext(String s) {
System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
}

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

/**
*********************** THREAD-ISOLATED Execution Hook Tests **************************************
*/
Expand Down

0 comments on commit b54a22b

Please sign in to comment.