Skip to content

Commit e7d23a3

Browse files
authored
Merge pull request Netflix#1406 from mattrjacobs/fix-retry-deadlock
Added unit test that demonstrates calling .retry() on an Observable produced by Hystrix does not result in deadlock
2 parents 1bf896b + b54a22b commit e7d23a3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

hystrix-core/src/test/java/com/netflix/hystrix/HystrixCommandTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.netflix.hystrix.strategy.concurrency.HystrixRequestContext;
3030
import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
3131
import com.netflix.hystrix.strategy.properties.HystrixProperty;
32+
import com.sun.javafx.collections.NonIterableChange;
3233
import org.junit.After;
3334
import org.junit.Rule;
3435
import org.junit.Test;
@@ -3940,6 +3941,43 @@ public void onNext(String s) {
39403941
System.out.println("ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
39413942
}
39423943

3944+
@Test
3945+
public void testRxRetry() throws Exception {
3946+
// see https://github.com/Netflix/Hystrix/issues/1100
3947+
// Since each command instance is single-use, the expectation is that applying the .retry() operator
3948+
// results in only a single execution and propagation out of that error
3949+
HystrixCommand<Integer> cmd = getLatentCommand(ExecutionIsolationStrategy.THREAD, AbstractTestHystrixCommand.ExecutionResult.FAILURE, 300,
3950+
AbstractTestHystrixCommand.FallbackResult.UNIMPLEMENTED, 100);
3951+
3952+
final CountDownLatch latch = new CountDownLatch(1);
3953+
3954+
System.out.println(System.currentTimeMillis() + " : Starting");
3955+
Observable<Integer> o = cmd.toObservable().retry(2);
3956+
System.out.println(System.currentTimeMillis() + " Created retried command : " + o);
3957+
3958+
o.subscribe(new Subscriber<Integer>() {
3959+
@Override
3960+
public void onCompleted() {
3961+
System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " : OnCompleted");
3962+
latch.countDown();
3963+
}
3964+
3965+
@Override
3966+
public void onError(Throwable e) {
3967+
System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " : OnError : " + e);
3968+
latch.countDown();
3969+
}
3970+
3971+
@Override
3972+
public void onNext(Integer integer) {
3973+
System.out.println(System.currentTimeMillis() + " : " + Thread.currentThread().getName() + " : OnNext : " + integer);
3974+
}
3975+
});
3976+
3977+
latch.await(1000, TimeUnit.MILLISECONDS);
3978+
System.out.println(System.currentTimeMillis() + " ReqLog : " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());
3979+
}
3980+
39433981
/**
39443982
*********************** THREAD-ISOLATED Execution Hook Tests **************************************
39453983
*/

0 commit comments

Comments
 (0)