2

I'm starting to use cyclops-react with async-retry. I'm still a little bit lost with it.

I'm using SimpleReact and simulating a timeout from the server but I never receive a timeout with something like this:

private List<Object> executeParallel() {
    List<Object> result = new SimpleReact(mainThreadPool)
            .of(getSupplier())
            .withRetrier(new AsyncRetryExecutor(retryThreadPool)
                    .abortIf((t) -> !TimeoutException.class.isAssignableFrom(t.getClass()))
            )
            .retry(retrySupplier())
            .block()
            .collect(Collectors.toList());
    return result;
}

private Supplier getSupplier() {
    return () -> someOperationThatTimesOut();
}

private Function<Supplier, Object> retrySupplier() {
    return supplier -> supplier.get();
}

What is missing there?

John McClean
  • 5,225
  • 1
  • 22
  • 30
Jorge
  • 184
  • 1
  • 8
  • Hey Jorge, I'll add a detailed answer to this, but the function that can timeout should be supplied to the retry operator. – John McClean Nov 17 '16 at 11:33

1 Answers1

1

This version works

 AtomicInteger count = new AtomicInteger(0);

@Test
public void executeParallel() {
    List<Object> result = new SimpleReact(Executors.newFixedThreadPool(1))
            .of(getSupplier())
            .withRetrier(new AsyncRetryExecutor(Executors.newScheduledThreadPool(1))
            .retry(Supplier::get)
            .block()
            .collect(Collectors.toList());
    System.out.println(result);
}

private Supplier<String> getSupplier() {
    return () -> {
        System.out.println("Attempt " + count.incrementAndGet());
        if(count.get()<4)
            throw ExceptionSoftener.throwSoftenedException(new TimeoutException());
        return "success";
    };
}

It will print out

Attempt 1
Attempt 2
Attempt 3
Attempt 4
[success]

I suspect you don't need the abortIf on the async-retrier, and I'm not sure what is going inside someOperationThatTimesOut() - that may be the key here.

John McClean
  • 5,225
  • 1
  • 22
  • 30
  • Thanks for the response @john-mcClean. Basically yes. Everything was correct, but the operation that should timeout was not timing out due to a missconfiguration – Jorge Nov 22 '16 at 14:01
  • Cool - if you have any more questions please do fire away! Thanks! – John McClean Nov 23 '16 at 01:49