use of org.springframework.data.redis.connection.ReactiveRedisConnection in project redisson by redisson.
the class RedissonSubscribeReactiveTest method testPubSub.
@Test
public void testPubSub() {
RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
AtomicLong counter = new AtomicLong();
ReactiveStringRedisTemplate template = new ReactiveStringRedisTemplate(factory);
template.listenTo(ChannelTopic.of("test")).flatMap(message -> {
counter.incrementAndGet();
return Mono.empty();
}).subscribe();
for (int i = 0; i < 40; i++) {
ReactiveRedisConnection connection = factory.getReactiveConnection();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
}
Awaitility.await().atMost(Duration.ONE_SECOND).untilAsserted(() -> {
assertThat(counter.get()).isEqualTo(40);
});
}
use of org.springframework.data.redis.connection.ReactiveRedisConnection in project redisson by redisson.
the class RedissonSubscribeReactiveTest method testUnSubscribe.
@Test
public void testUnSubscribe() {
RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
ReactiveRedisConnection connection = factory.getReactiveConnection();
Mono<ReactiveSubscription> s = connection.pubSubCommands().createSubscription();
AtomicReference<byte[]> msg = new AtomicReference<byte[]>();
ReactiveSubscription ss = s.block();
ss.subscribe(ByteBuffer.wrap("test".getBytes())).block();
ss.receive().doOnEach(message -> {
msg.set(message.get().getMessage().array());
}).subscribe();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
Awaitility.await().atMost(Duration.ONE_SECOND).until(() -> Arrays.equals("msg".getBytes(), msg.get()));
ss.unsubscribe();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
}
use of org.springframework.data.redis.connection.ReactiveRedisConnection in project spring-boot by spring-projects.
the class RedisReactiveHealthIndicatorTests method redisCommandIsDown.
@Test
void redisCommandIsDown() {
ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
given(commands.info("server")).willReturn(Mono.error(new RedisConnectionFailureException("Connection failed")));
ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
given(redisConnection.closeLater()).willReturn(Mono.empty());
RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands);
Mono<Health> health = healthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> assertThat(h.getStatus()).isEqualTo(Status.DOWN)).verifyComplete();
then(redisConnection).should().closeLater();
}
use of org.springframework.data.redis.connection.ReactiveRedisConnection in project spring-boot by spring-projects.
the class RedisReactiveHealthIndicatorTests method redisIsUp.
@Test
void redisIsUp() {
Properties info = new Properties();
info.put("redis_version", "2.8.9");
ReactiveRedisConnection redisConnection = mock(ReactiveRedisConnection.class);
given(redisConnection.closeLater()).willReturn(Mono.empty());
ReactiveServerCommands commands = mock(ReactiveServerCommands.class);
given(commands.info("server")).willReturn(Mono.just(info));
RedisReactiveHealthIndicator healthIndicator = createHealthIndicator(redisConnection, commands);
Mono<Health> health = healthIndicator.health();
StepVerifier.create(health).consumeNextWith((h) -> {
assertThat(h.getStatus()).isEqualTo(Status.UP);
assertThat(h.getDetails()).containsOnlyKeys("version");
assertThat(h.getDetails().get("version")).isEqualTo("2.8.9");
}).verifyComplete();
then(redisConnection).should().closeLater();
}
use of org.springframework.data.redis.connection.ReactiveRedisConnection in project redisson by redisson.
the class RedissonSubscribeReactiveTest method testTemplate.
@Test
public void testTemplate() {
RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
AtomicLong counter = new AtomicLong();
ReactiveStringRedisTemplate template = new ReactiveStringRedisTemplate(factory);
template.listenTo(ChannelTopic.of("test")).flatMap(message -> {
counter.incrementAndGet();
return Mono.empty();
}).subscribe();
template.listenTo(ChannelTopic.of("test2")).flatMap(message -> {
counter.incrementAndGet();
return Mono.empty();
}).subscribe();
ReactiveRedisConnection connection = factory.getReactiveConnection();
connection.pubSubCommands().publish(ByteBuffer.wrap("test".getBytes()), ByteBuffer.wrap("msg".getBytes())).block();
Awaitility.await().atMost(Duration.ONE_SECOND).until(() -> counter.get() == 1);
}
Aggregations