use of com.linkedin.r2.util.finalizer.RequestFinalizer in project rest.li by linkedin.
the class TestClientRequestFinalizerFilter method testStreamRequestOrdering.
@Test
public void testStreamRequestOrdering() {
final AtomicReference<Observer> observerReference = new AtomicReference<>();
final AtomicInteger addObserverExecutionOrder = new AtomicInteger(0);
when(_streamResponse.getEntityStream()).thenReturn(_entityStream);
doAnswer(invocation -> {
addObserverExecutionOrder.set(_index.incrementAndGet());
observerReference.set((Observer) invocation.getArguments()[0]);
return null;
}).when(_entityStream).addObserver(anyObject());
_filterChain.onStreamRequest(null, _requestContext, null);
registerRequestFinalizer();
_filterChain.onStreamResponse(_streamResponse, _requestContext, null);
observerReference.get().onDone();
Assert.assertEquals(_firstFilter._onRequestExecutionOrder, 1);
Assert.assertEquals(_lastFilter._onRequestExecutionOrder, 2);
Assert.assertEquals(_lastFilter._onResponseExecutionOrder, 3);
Assert.assertEquals(addObserverExecutionOrder.get(), 4, "Expected observer with RequestFinalizer " + "to be added before calling the next filter.");
Assert.assertEquals(_firstFilter._onResponseExecutionOrder, 5);
Assert.assertEquals(_testRequestFinalizer._executionOrder, 6, "Expected request finalizer to be " + "executed last.");
}
Aggregations