Search in sources :

Example 1 with ReactiveStringRedisTemplate

use of org.springframework.data.redis.core.ReactiveStringRedisTemplate 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);
    });
}
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) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) ReactiveStringRedisTemplate(org.springframework.data.redis.core.ReactiveStringRedisTemplate) Test(org.junit.Test)

Example 2 with ReactiveStringRedisTemplate

use of org.springframework.data.redis.core.ReactiveStringRedisTemplate in project redisson by redisson.

the class RedissonReactiveTest method testGetSet.

@Test
public void testGetSet() {
    RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
    ReactiveStringRedisTemplate template = new ReactiveStringRedisTemplate(factory);
    Assertions.assertThat(template.opsForValue().get("123").block()).isNull();
    template.opsForValue().set("123", "444").block();
    Assertions.assertThat(template.opsForValue().get("123").block()).isEqualTo("444");
}
Also used : ReactiveStringRedisTemplate(org.springframework.data.redis.core.ReactiveStringRedisTemplate) Test(org.junit.Test)

Example 3 with ReactiveStringRedisTemplate

use of org.springframework.data.redis.core.ReactiveStringRedisTemplate 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);
}
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) AtomicLong(java.util.concurrent.atomic.AtomicLong) ReactiveRedisConnection(org.springframework.data.redis.connection.ReactiveRedisConnection) ReactiveStringRedisTemplate(org.springframework.data.redis.core.ReactiveStringRedisTemplate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ReactiveStringRedisTemplate (org.springframework.data.redis.core.ReactiveStringRedisTemplate)3 ByteBuffer (java.nio.ByteBuffer)2 Arrays (java.util.Arrays)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Awaitility (org.awaitility.Awaitility)2 Duration (org.awaitility.Duration)2 ReactiveRedisConnection (org.springframework.data.redis.connection.ReactiveRedisConnection)2 ReactiveSubscription (org.springframework.data.redis.connection.ReactiveSubscription)2 ChannelTopic (org.springframework.data.redis.listener.ChannelTopic)2 Mono (reactor.core.publisher.Mono)2