use of reactor.core.publisher.BaseSubscriber in project redisson by redisson.
the class RedissonListReactiveTest method testAddAllWithIndex.
@Test
public void testAddAllWithIndex() throws InterruptedException {
final RListReactive<Long> list = redisson.getList("list");
final CountDownLatch latch = new CountDownLatch(1);
list.addAll(Arrays.asList(1L, 2L, 3L)).subscribe(new BaseSubscriber<Boolean>() {
@Override
public void hookOnNext(Boolean element) {
list.addAll(Arrays.asList(1L, 24L, 3L)).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, 3L, 1L, 24L, 3L);
}
use of reactor.core.publisher.BaseSubscriber in project spring-security by spring-projects.
the class SecurityReactorContextConfigurationTests method createSubscriberIfNecessaryWhenWebSecurityContextAvailableThenCreateWithParentContext.
@Test
public void createSubscriberIfNecessaryWhenWebSecurityContextAvailableThenCreateWithParentContext() {
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(this.servletRequest, this.servletResponse));
SecurityContextHolder.getContext().setAuthentication(this.authentication);
String testKey = "test_key";
String testValue = "test_value";
BaseSubscriber<Object> parent = new BaseSubscriber<Object>() {
@Override
public Context currentContext() {
return Context.of(testKey, testValue);
}
};
CoreSubscriber<Object> subscriber = this.subscriberRegistrar.createSubscriberIfNecessary(parent);
Context resultContext = subscriber.currentContext();
assertThat(resultContext.getOrEmpty(testKey)).hasValue(testValue);
Map<Object, Object> securityContextAttributes = resultContext.getOrDefault(SecurityReactorContextSubscriber.SECURITY_CONTEXT_ATTRIBUTES, null);
assertThat(securityContextAttributes).hasSize(3);
assertThat(securityContextAttributes).contains(entry(HttpServletRequest.class, this.servletRequest), entry(HttpServletResponse.class, this.servletResponse), entry(Authentication.class, this.authentication));
}
use of reactor.core.publisher.BaseSubscriber in project spring-security by spring-projects.
the class SecurityReactorContextConfigurationTests method createSubscriberIfNecessaryWhenSubscriberContextContainsSecurityContextAttributesThenReturnOriginalSubscriber.
@Test
public void createSubscriberIfNecessaryWhenSubscriberContextContainsSecurityContextAttributesThenReturnOriginalSubscriber() {
Context context = Context.of(SecurityReactorContextSubscriber.SECURITY_CONTEXT_ATTRIBUTES, new HashMap<>());
BaseSubscriber<Object> originalSubscriber = new BaseSubscriber<Object>() {
@Override
public Context currentContext() {
return context;
}
};
CoreSubscriber<Object> resultSubscriber = this.subscriberRegistrar.createSubscriberIfNecessary(originalSubscriber);
assertThat(resultSubscriber).isSameAs(originalSubscriber);
}
use of reactor.core.publisher.BaseSubscriber in project spring-framework by spring-projects.
the class ChannelSendOperatorTests method cancelWhileItemCached.
// gh-22720
@Test
public void cancelWhileItemCached() {
LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
ChannelSendOperator<DataBuffer> operator = new ChannelSendOperator<>(Mono.fromCallable(() -> {
DataBuffer dataBuffer = bufferFactory.allocateBuffer();
dataBuffer.write("foo", StandardCharsets.UTF_8);
return dataBuffer;
}), publisher -> {
ZeroDemandSubscriber subscriber = new ZeroDemandSubscriber();
publisher.subscribe(subscriber);
return Mono.never();
});
BaseSubscriber<Void> subscriber = new BaseSubscriber<>() {
};
operator.subscribe(subscriber);
subscriber.cancel();
bufferFactory.checkForLeaks();
}
use of reactor.core.publisher.BaseSubscriber in project spring-framework by spring-projects.
the class ChannelSendOperatorTests method errorFromWriteSourceWhileItemCached.
// gh-22720
@Test
public void errorFromWriteSourceWhileItemCached() {
// 1. First item received
// 2. writeFunction applied and writeCompletionBarrier subscribed to it
// 3. Write Publisher fails right after that and before request(n) from server
LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
ZeroDemandSubscriber writeSubscriber = new ZeroDemandSubscriber();
ChannelSendOperator<DataBuffer> operator = new ChannelSendOperator<>(Flux.create(sink -> {
DataBuffer dataBuffer = bufferFactory.allocateBuffer();
dataBuffer.write("foo", StandardCharsets.UTF_8);
sink.next(dataBuffer);
sink.error(new IllegalStateException("err"));
}), publisher -> {
publisher.subscribe(writeSubscriber);
return Mono.never();
});
operator.subscribe(new BaseSubscriber<Void>() {
});
try {
// Let cached signals ("foo" and error) be published..
writeSubscriber.signalDemand(1);
} catch (Throwable ex) {
assertThat(ex.getCause()).isNotNull();
assertThat(ex.getCause().getMessage()).isEqualTo("err");
}
bufferFactory.checkForLeaks();
}
Aggregations