Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HystrixContextScheduler and observe() #202

Closed
vadims opened this issue Jan 22, 2014 · 1 comment
Closed

HystrixContextScheduler and observe() #202

vadims opened this issue Jan 22, 2014 · 1 comment

Comments

@vadims
Copy link

vadims commented Jan 22, 2014

HystrixContextScheduler wraps the first schedule call, however it sends the raw scheduler (in HystrixContextFunc2) when calling the action.

If that action needs to schedule something, it will lose the context.

Here's a small demo:

public class Test {

  public static class DummyCommand extends HystrixCommand<Void> {

    public DummyCommand() {
      super(HystrixCommandGroupKey.Factory.asKey("Dummy"));
    }

    @Override
    protected Void run() throws Exception {
      Thread.sleep(10);
      return null;
    }
  }

  public static void main(String[] args) {
    HystrixRequestContext context = HystrixRequestContext.initializeContext();

    new DummyCommand().observe().flatMap(new Func1<Void, Observable<Void>>() {
      @Override
      public Observable<Void> call(Void result) {
        return Observable.zip(new DummyCommand().observe(), new DummyCommand().observe(), new Func2<Void, Void, Void>() {
          @Override
          public Void call(Void a, Void b) {
            return null;
          }
        }).synchronize();
      }
    }).toBlockingObservable().single();

    System.out.println("context = " + HystrixRequestLog.getCurrentRequest().getExecutedCommandsAsString());

    context.shutdown();
    Hystrix.reset();
  }
}

if you comment out Thread.sleep(10), then on my machine the commands execute fast enough that they can be observed on the main thread and then the context is preserved.

Expected output:

context = DummyCommand[SUCCESS][XXX ms]x3

Actual output:

context = DummyCommand[SUCCESS][XXX ms]
@vadims
Copy link
Author

vadims commented Feb 20, 2014

#210 fixed this issue

@vadims vadims closed this as completed Feb 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant