use of reactor.core.publisher.BaseSubscriber in project spring-security by spring-projects.
the class SecurityReactorContextConfigurationTests method createSubscriberIfNecessaryWhenParentContextContainsSecurityContextAttributesThenUseParentContext.
@Test
public void createSubscriberIfNecessaryWhenParentContextContainsSecurityContextAttributesThenUseParentContext() {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.servletRequest, this.servletResponse));
SecurityContextHolder.getContext().setAuthentication(this.authentication);
Context parentContext = Context.of(SecurityReactorContextSubscriber.SECURITY_CONTEXT_ATTRIBUTES, new HashMap<>());
BaseSubscriber<Object> parent = new BaseSubscriber<Object>() {
@Override
public Context currentContext() {
return parentContext;
}
};
CoreSubscriber<Object> subscriber = this.subscriberRegistrar.createSubscriberIfNecessary(parent);
Context resultContext = subscriber.currentContext();
assertThat(resultContext).isSameAs(parentContext);
}
use of reactor.core.publisher.BaseSubscriber in project redisson by redisson.
the class RedissonListReactiveTest method testAdd.
@Test
public void testAdd() throws InterruptedException {
final RListReactive<Long> list = redisson.getList("list");
final CountDownLatch latch = new CountDownLatch(1);
list.add(1L).subscribe(new BaseSubscriber<Boolean>() {
@Override
public void hookOnNext(Boolean value) {
list.add(2L).subscribe(new BaseSubscriber<Boolean>() {
@Override
public void hookOnNext(Boolean value) {
latch.countDown();
}
@Override
public void hookOnError(Throwable error) {
Assertions.fail(error.getMessage());
}
});
}
@Override
public void hookOnError(Throwable error) {
Assertions.fail(error.getMessage());
}
});
latch.await();
assertThat(sync(list)).containsExactly(1L, 2L);
}
use of reactor.core.publisher.BaseSubscriber in project redisson by redisson.
the class PublisherAdder method addAll.
public Publisher<Boolean> addAll(Publisher<? extends V> c) {
CompletableFuture<Boolean> promise = new CompletableFuture<>();
c.subscribe(new BaseSubscriber<V>() {
volatile boolean completed;
AtomicLong values = new AtomicLong();
Subscription s;
Boolean lastSize = false;
@Override
protected void hookOnSubscribe(Subscription s) {
this.s = s;
s.request(1);
}
@Override
protected void hookOnNext(V o) {
values.getAndIncrement();
add(o).whenComplete((res, e) -> {
if (e != null) {
promise.completeExceptionally(e);
return;
}
if (res) {
lastSize = true;
}
s.request(1);
if (values.decrementAndGet() == 0 && completed) {
promise.complete(lastSize);
}
});
}
@Override
protected void hookOnComplete() {
completed = true;
if (values.get() == 0) {
promise.complete(lastSize);
}
}
});
return Mono.fromCompletionStage(promise);
}
Aggregations