linkedin/parseq

onFailure didn't trigger when throwing exception

haiweiwang73 opened this issue · 1 comments

I am testing the onFailure method and not sure my use case will fit in this scenario. I am trying to test when exception thrown in one of the task, and in the consumer of the onFailure, it will re throw it into another exception. But it seems the consumer never gets triggered.

    @Override
    public Task<OrderDatagram> getTask() {
        return null;
    }

    @Override
    public Consumer1<OrderDatagram> consumer() {
        Consumer1<OrderDatagram> myConsumer = (y) ->
        {
            Optional<Integer> version = Optional.of(1);
            y.setVersion(version);
            System.out.println(y);
            throw new NullPointerException(); // Got error in null pointer
        };
        return myConsumer;
    }

    public Consumer1<Throwable> failConsumer() {
        Consumer1<Throwable> myFailConsumer = (y) ->
        {
            System.out.println("The failure consumer has been called"+ y); // Never print out
            throw new Exception(); // never thrown
        };
        return myFailConsumer;
    }

    public Task<OrderDatagram> handle(Task<OrderDatagram> prevTask){
        Task<OrderDatagram> task = prevTask.andThen("next", consumer());
        task.onFailure("print stack trace", failConsumer());
        return task;
    }
}

Let me make it clear. So you said that the consumer is triggered and do throw the NPE, but the failConsumer didn't throw the pure exception but still throw NPE? Or you mean both the consumer and failConsumer were never triggered?