use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.
the class ConnectionFactoryFilterTest method testAppend.
@Test
void testAppend() throws Exception {
Deque<Integer> createOrder = new ArrayDeque<>();
Deque<Integer> connectOrder = new ArrayDeque<>();
class FactoryOrder implements ConnectionFactory<InetSocketAddress, ListenableAsyncCloseable> {
final int order;
ConnectionFactory<InetSocketAddress, ListenableAsyncCloseable> original;
FactoryOrder(int order, ConnectionFactory<InetSocketAddress, ListenableAsyncCloseable> original) {
this.order = order;
this.original = original;
}
@Override
public Single<ListenableAsyncCloseable> newConnection(final InetSocketAddress unused, @Nullable final ContextMap context, @Nullable final TransportObserver observer) {
connectOrder.add(order);
return original.newConnection(unused, context, observer);
}
@Override
public Completable closeAsync() {
return Completable.completed();
}
@Override
public Completable onClose() {
return Completable.completed();
}
}
class FilterOrder implements ConnectionFactoryFilter<InetSocketAddress, ListenableAsyncCloseable> {
final int order;
FilterOrder(int order) {
this.order = order;
}
@Override
public ConnectionFactory<InetSocketAddress, ListenableAsyncCloseable> create(final ConnectionFactory<InetSocketAddress, ListenableAsyncCloseable> original) {
createOrder.add(order);
return new FactoryOrder(order, original);
}
}
FilterOrder first = new FilterOrder(1);
FilterOrder second = new FilterOrder(2);
ConnectionFactoryFilter<InetSocketAddress, ListenableAsyncCloseable> combined = first.append(second);
ConnectionFactory<InetSocketAddress, ListenableAsyncCloseable> root = new FactoryOrder(999, new ConnectionFactory<InetSocketAddress, ListenableAsyncCloseable>() {
@Override
public Single<ListenableAsyncCloseable> newConnection(final InetSocketAddress unused, @Nullable final ContextMap context, @Nullable final TransportObserver observer) {
return Single.succeeded(DUMMY_CLOSABLE);
}
@Override
public Completable onClose() {
return Completable.completed();
}
@Override
public Completable closeAsync() {
return Completable.completed();
}
});
ConnectionFactory<InetSocketAddress, ListenableAsyncCloseable> factory = combined.create(root);
ListenableAsyncCloseable connection = factory.newConnection(mock(InetSocketAddress.class), null, null).toFuture().get();
assertThat(connection, is(sameInstance(DUMMY_CLOSABLE)));
assertThat(createOrder, is(hasSize(2)));
assertThat(createOrder, is(containsInRelativeOrder(2, 1)));
assertThat(connectOrder, is(hasSize(3)));
assertThat(connectOrder, is(containsInRelativeOrder(1, 2, 999)));
}
use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.
the class ContextPreservingBiConsumer method slowPath.
private void slowPath(T t, U u) {
ContextMap prev = CONTEXT_THREAD_LOCAL.get();
try {
CONTEXT_THREAD_LOCAL.set(saved);
delegate.accept(t, u);
} finally {
CONTEXT_THREAD_LOCAL.set(prev);
}
}
use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.
the class ContextPreservingCancellable method slowPath.
private void slowPath() {
ContextMap prev = CONTEXT_THREAD_LOCAL.get();
try {
CONTEXT_THREAD_LOCAL.set(saved);
delegate.cancel();
} finally {
CONTEXT_THREAD_LOCAL.set(prev);
}
}
use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.
the class ContextPreservingCompletableSubscriber method onSubscribeSlowPath.
private void onSubscribeSlowPath(Cancellable cancellable) {
ContextMap prev = CONTEXT_THREAD_LOCAL.get();
try {
CONTEXT_THREAD_LOCAL.set(saved);
invokeOnSubscribe(cancellable);
} finally {
CONTEXT_THREAD_LOCAL.set(prev);
}
}
use of io.servicetalk.context.api.ContextMap in project servicetalk by apple.
the class ContextPreservingConsumer method slowPath.
private void slowPath(T t) {
ContextMap prev = CONTEXT_THREAD_LOCAL.get();
try {
CONTEXT_THREAD_LOCAL.set(saved);
delegate.accept(t);
} finally {
CONTEXT_THREAD_LOCAL.set(prev);
}
}
Aggregations