Search in sources :

Example 1 with RedissonReactiveClient

use of org.redisson.api.RedissonReactiveClient in project redisson by redisson.

the class RedissonRemoteServiceTest method testReactive.

@Test
public void testReactive() throws InterruptedException {
    RedissonReactiveClient r1 = Redisson.create(createConfig()).reactive();
    r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
    RedissonReactiveClient r2 = Redisson.create(createConfig()).reactive();
    RemoteInterfaceReactive ri = r2.getRemoteService().get(RemoteInterfaceReactive.class);
    Mono<Void> f = ri.voidMethod("someName", 100L);
    f.block();
    Mono<Long> resFuture = ri.resultMethod(100L);
    assertThat(resFuture.block()).isEqualTo(200);
    r1.shutdown();
    r2.shutdown();
}
Also used : RedissonReactiveClient(org.redisson.api.RedissonReactiveClient) Test(org.junit.jupiter.api.Test)

Example 2 with RedissonReactiveClient

use of org.redisson.api.RedissonReactiveClient in project redisson by redisson.

the class RedissonRemoteServiceTest method testCancelReactive.

@Test
public void testCancelReactive() throws InterruptedException {
    RedissonReactiveClient r1 = Redisson.create(createConfig()).reactive();
    AtomicInteger iterations = new AtomicInteger();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    r1.getKeys().flushall();
    r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl(iterations), 1, executor);
    RedissonReactiveClient r2 = Redisson.create(createConfig()).reactive();
    RemoteInterfaceReactive ri = r2.getRemoteService().get(RemoteInterfaceReactive.class);
    Mono<Void> f = ri.cancelMethod();
    Disposable t = f.doOnSubscribe(s -> s.request(1)).subscribe();
    Thread.sleep(500);
    t.dispose();
    executor.shutdown();
    r1.shutdown();
    r2.shutdown();
    assertThat(iterations.get()).isLessThan(Integer.MAX_VALUE / 2);
    assertThat(executor.awaitTermination(2, TimeUnit.SECONDS)).isTrue();
}
Also used : Disposable(reactor.core.Disposable) RemoteServiceTimeoutException(org.redisson.remote.RemoteServiceTimeoutException) Single(io.reactivex.rxjava3.core.Single) Disposable(reactor.core.Disposable) RedissonReactiveClient(org.redisson.api.RedissonReactiveClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RRemoteService(org.redisson.api.RRemoteService) RRemoteAsync(org.redisson.api.annotation.RRemoteAsync) ArrayList(java.util.ArrayList) RFuture(org.redisson.api.RFuture) RedissonRxClient(org.redisson.api.RedissonRxClient) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RRemoteRx(org.redisson.api.annotation.RRemoteRx) RedissonClient(org.redisson.api.RedissonClient) RRemoteReactive(org.redisson.api.annotation.RRemoteReactive) ExecutorService(java.util.concurrent.ExecutorService) SerializationCodec(org.redisson.codec.SerializationCodec) IOException(java.io.IOException) Completable(io.reactivex.rxjava3.core.Completable) Mono(reactor.core.publisher.Mono) NotSerializableException(java.io.NotSerializableException) Executors(java.util.concurrent.Executors) RemoteInvocationOptions(org.redisson.api.RemoteInvocationOptions) Serializable(java.io.Serializable) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) RemoteServiceAckTimeoutException(org.redisson.remote.RemoteServiceAckTimeoutException) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) RedissonReactiveClient(org.redisson.api.RedissonReactiveClient) Test(org.junit.jupiter.api.Test)

Example 3 with RedissonReactiveClient

use of org.redisson.api.RedissonReactiveClient in project redisson by redisson.

the class RedissonReferenceReactiveTest method shouldUseDefaultCodec.

@Test
public void shouldUseDefaultCodec() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
    objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, false);
    JsonJacksonCodec codec = new JsonJacksonCodec(objectMapper);
    Config config = new Config();
    config.setCodec(codec);
    config.useSingleServer().setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
    RedissonReactiveClient reactive = Redisson.create(config).reactive();
    RBucketReactive<Object> b1 = reactive.getBucket("b1");
    sync(b1.set(new MyObject()));
    RSetReactive<Object> s1 = reactive.getSet("s1");
    Assertions.assertTrue(sync(s1.add(b1)));
    Assertions.assertTrue(codec == b1.getCodec());
    RedissonReactiveClient reactive1 = Redisson.create(config).reactive();
    RSetReactive<RBucketReactive> s2 = reactive1.getSet("s1");
    RBucketReactive<MyObject> b2 = sync(s2.iterator(1));
    Assertions.assertTrue(codec == b2.getCodec());
    Assertions.assertTrue(sync(b2.get()) instanceof MyObject);
    reactive.shutdown();
    reactive1.shutdown();
}
Also used : JsonJacksonCodec(org.redisson.codec.JsonJacksonCodec) Config(org.redisson.config.Config) RBucketReactive(org.redisson.api.RBucketReactive) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RedissonReactiveClient(org.redisson.api.RedissonReactiveClient) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 RedissonReactiveClient (org.redisson.api.RedissonReactiveClient)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Completable (io.reactivex.rxjava3.core.Completable)1 Single (io.reactivex.rxjava3.core.Single)1 IOException (java.io.IOException)1 NotSerializableException (java.io.NotSerializableException)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1