Search in sources :

Example 1 with RedissonRxClient

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

the class RedissonBatchRxTest method testSyncSlaves.

@ParameterizedTest
@MethodSource("data")
public void testSyncSlaves(BatchOptions batchOptions) throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();
    ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slave1).addNode(master2, slave2).addNode(master3, slave3);
    ClusterProcesses process = clusterRunner.run();
    Config config = new Config();
    config.useClusterServers().setTimeout(1000000).setRetryInterval(1000000).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonRxClient redisson = Redisson.create(config).rxJava();
    batchOptions.syncSlaves(1, 1, TimeUnit.SECONDS);
    RBatchRx batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 100; i++) {
        RMapRx<String, String> map = batch.getMap("test");
        map.put("" + i, "" + i);
    }
    BatchResult<?> result = sync(batch.execute());
    assertThat(result.getResponses()).hasSize(100);
    assertThat(result.getSyncedSlaves()).isEqualTo(1);
    process.shutdown();
    redisson.shutdown();
}
Also used : ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) Config(org.redisson.config.Config) RedisRunner(org.redisson.RedisRunner) ClusterRunner(org.redisson.ClusterRunner) RBatchRx(org.redisson.api.RBatchRx) RedissonRxClient(org.redisson.api.RedissonRxClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with RedissonRxClient

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

the class RedissonBatchRxTest method testAtomicSyncSlaves.

@ParameterizedTest
@MethodSource("data")
public void testAtomicSyncSlaves(BatchOptions batchOptions) throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();
    ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slave1).addNode(master2, slave2).addNode(master3, slave3);
    ClusterProcesses process = clusterRunner.run();
    Config config = new Config();
    config.useClusterServers().setTimeout(123000).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonRxClient redisson = Redisson.create(config).rxJava();
    batchOptions.executionMode(ExecutionMode.IN_MEMORY_ATOMIC).syncSlaves(1, 1, TimeUnit.SECONDS);
    RBatchRx batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 10; i++) {
        batch.getAtomicLong("{test}" + i).addAndGet(i);
    }
    BatchResult<?> result = sync(batch.execute());
    assertThat(result.getSyncedSlaves()).isEqualTo(1);
    int i = 0;
    for (Object res : result.getResponses()) {
        assertThat((Long) res).isEqualTo(i++);
    }
    process.shutdown();
    redisson.shutdown();
}
Also used : ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) Config(org.redisson.config.Config) AtomicLong(java.util.concurrent.atomic.AtomicLong) RedisRunner(org.redisson.RedisRunner) ClusterRunner(org.redisson.ClusterRunner) RBatchRx(org.redisson.api.RBatchRx) RedissonRxClient(org.redisson.api.RedissonRxClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with RedissonRxClient

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

the class RedissonBatchRxTest method testWriteTimeout.

@ParameterizedTest
@MethodSource("data")
public void testWriteTimeout(BatchOptions batchOptions) throws InterruptedException {
    Config config = BaseTest.createConfig();
    config.useSingleServer().setRetryInterval(700).setTimeout(1500);
    RedissonRxClient redisson = Redisson.create(config).rxJava();
    RBatchRx batch = redisson.createBatch(batchOptions);
    RMapCacheRx<String, String> map = batch.getMapCache("test");
    int total = 10000;
    for (int i = 0; i < total; i++) {
        map.put("" + i, "" + i, 5, TimeUnit.MINUTES);
        if (batchOptions.getExecutionMode() == ExecutionMode.REDIS_WRITE_ATOMIC) {
            if (i % 100 == 0) {
                Thread.sleep(10);
            }
        }
    }
    long s = System.currentTimeMillis();
    sync(batch.execute());
    long executionTime = System.currentTimeMillis() - s;
    if (batchOptions.getExecutionMode() == ExecutionMode.IN_MEMORY) {
        assertThat(executionTime).isLessThan(1000);
    } else {
        assertThat(executionTime).isLessThan(300);
    }
    assertThat(sync(redisson.getMapCache("test").size())).isEqualTo(total);
    redisson.shutdown();
}
Also used : Config(org.redisson.config.Config) RBatchRx(org.redisson.api.RBatchRx) RedissonRxClient(org.redisson.api.RedissonRxClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with RedissonRxClient

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

the class RedissonRemoteServiceTest method testRx.

@Test
public void testRx() {
    RedissonRxClient r1 = Redisson.create(createConfig()).rxJava();
    r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
    RedissonRxClient r2 = Redisson.create(createConfig()).rxJava();
    RemoteInterfaceRx ri = r2.getRemoteService().get(RemoteInterfaceRx.class);
    Completable f = ri.voidMethod("someName", 100L);
    f.blockingAwait();
    Single<Long> resFuture = ri.resultMethod(100L);
    assertThat(resFuture.blockingGet()).isEqualTo(200);
    r1.shutdown();
    r2.shutdown();
}
Also used : Completable(io.reactivex.rxjava3.core.Completable) RedissonRxClient(org.redisson.api.RedissonRxClient) Test(org.junit.jupiter.api.Test)

Example 5 with RedissonRxClient

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

the class RedissonBatchRxTest method testConnectionLeakAfterError.

@Test
public void testConnectionLeakAfterError() {
    Config config = BaseTest.createConfig();
    config.useSingleServer().setRetryInterval(100).setTimeout(200).setConnectionMinimumIdleSize(1).setConnectionPoolSize(1);
    RedissonRxClient redisson = Redisson.create(config).rxJava();
    BatchOptions batchOptions = BatchOptions.defaults().executionMode(ExecutionMode.REDIS_WRITE_ATOMIC);
    RBatchRx batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 25000; i++) {
        batch.getBucket("test").set(123);
    }
    try {
        sync(batch.execute());
        Assertions.fail();
    } catch (Exception e) {
    // skip
    }
    sync(redisson.getBucket("test3").set(4));
    assertThat(sync(redisson.getBucket("test3").get())).isEqualTo(4);
    batch = redisson.createBatch(batchOptions);
    batch.getBucket("test1").set(1);
    batch.getBucket("test2").set(2);
    sync(batch.execute());
    assertThat(sync(redisson.getBucket("test1").get())).isEqualTo(1);
    assertThat(sync(redisson.getBucket("test2").get())).isEqualTo(2);
    redisson.shutdown();
}
Also used : Config(org.redisson.config.Config) RBatchRx(org.redisson.api.RBatchRx) RedisException(org.redisson.client.RedisException) FailedToStartRedisException(org.redisson.RedisRunner.FailedToStartRedisException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RedissonRxClient(org.redisson.api.RedissonRxClient) BatchOptions(org.redisson.api.BatchOptions) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RedissonRxClient (org.redisson.api.RedissonRxClient)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 RBatchRx (org.redisson.api.RBatchRx)5 Config (org.redisson.config.Config)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 Test (org.junit.jupiter.api.Test)2 ClusterRunner (org.redisson.ClusterRunner)2 ClusterProcesses (org.redisson.ClusterRunner.ClusterProcesses)2 RedisRunner (org.redisson.RedisRunner)2 Completable (io.reactivex.rxjava3.core.Completable)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BaseTest (org.redisson.BaseTest)1 FailedToStartRedisException (org.redisson.RedisRunner.FailedToStartRedisException)1 BatchOptions (org.redisson.api.BatchOptions)1 RedisException (org.redisson.client.RedisException)1