Search in sources :

Example 6 with ReactiveRedisConnection

use of org.springframework.data.redis.connection.ReactiveRedisConnection in project redisson by redisson.

the class RedissonSubscribeReactiveTest method testSubscribe.

@Test
public void testSubscribe() {
    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();
}
Also used : Arrays(java.util.Arrays) Duration(org.awaitility.Duration) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) Mono(reactor.core.publisher.Mono) AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteBuffer(java.nio.ByteBuffer) ReactiveStringRedisTemplate(org.springframework.data.redis.core.ReactiveStringRedisTemplate) AtomicLong(java.util.concurrent.atomic.AtomicLong) ChannelTopic(org.springframework.data.redis.listener.ChannelTopic) ReactiveSubscription(org.springframework.data.redis.connection.ReactiveSubscription) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) Awaitility(org.awaitility.Awaitility) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) ReactiveSubscription(org.springframework.data.redis.connection.ReactiveSubscription) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 ReactiveRedisConnection (org.springframework.data.redis.connection.ReactiveRedisConnection)6 Mono (reactor.core.publisher.Mono)6 ByteBuffer (java.nio.ByteBuffer)4 Arrays (java.util.Arrays)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Awaitility (org.awaitility.Awaitility)4 Duration (org.awaitility.Duration)4 Test (org.junit.Test)4 ReactiveSubscription (org.springframework.data.redis.connection.ReactiveSubscription)4 ReactiveStringRedisTemplate (org.springframework.data.redis.core.ReactiveStringRedisTemplate)4 ChannelTopic (org.springframework.data.redis.listener.ChannelTopic)4 RedisConnectionException (io.lettuce.core.RedisConnectionException)2 Properties (java.util.Properties)2 Test (org.junit.jupiter.api.Test)2 BDDMockito.given (org.mockito.BDDMockito.given)2 BDDMockito.then (org.mockito.BDDMockito.then)2 Mockito.mock (org.mockito.Mockito.mock)2 Health (org.springframework.boot.actuate.health.Health)2