Search in sources :

Example 1 with RBatchRx

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

the class RedissonBatchRxTest method testBatchList.

@ParameterizedTest
@MethodSource("data")
public void testBatchList(BatchOptions batchOptions) {
    RBatchRx b = redisson.createBatch(batchOptions);
    RListRx<Integer> listAsync = b.getList("list");
    for (int i = 1; i < 540; i++) {
        listAsync.add(i);
    }
    BatchResult<?> res = sync(b.execute());
    Assertions.assertEquals(539, res.getResponses().size());
}
Also used : RBatchRx(org.redisson.api.RBatchRx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with RBatchRx

use of org.redisson.api.RBatchRx 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 3 with RBatchRx

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

the class RedissonBatchRxTest method testConvertor.

@ParameterizedTest
@MethodSource("data")
public void testConvertor(BatchOptions batchOptions) {
    RBatchRx batch = redisson.createBatch(batchOptions);
    Single<Double> f1 = batch.getScoredSortedSet("myZKey").addScore("abc", 1d);
    Completable f2 = batch.getBucket("test").set("1");
    sync(batch.execute());
    assertThat(sync(f1)).isEqualTo(1d);
    sync(f2);
    RScoredSortedSetRx<String> set = redisson.getScoredSortedSet("myZKey");
    assertThat(sync(set.getScore("abc"))).isEqualTo(1d);
    RBucketRx<String> bucket = redisson.getBucket("test");
    assertThat(sync(bucket.get())).isEqualTo("1");
    RBatchRx batch2 = redisson.createBatch(batchOptions);
    Single<Double> b2f1 = batch2.getScoredSortedSet("myZKey2").addScore("abc", 1d);
    Single<Double> b2f2 = batch2.getScoredSortedSet("myZKey2").addScore("abc", 1d);
    sync(batch2.execute());
    assertThat(sync(b2f1)).isEqualTo(1d);
    assertThat(sync(b2f2)).isEqualTo(2d);
}
Also used : Completable(io.reactivex.rxjava3.core.Completable) RBatchRx(org.redisson.api.RBatchRx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with RBatchRx

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

the class RedissonBatchRxTest method test.

@ParameterizedTest
@MethodSource("data")
public void test(BatchOptions batchOptions) {
    RBatchRx batch = redisson.createBatch(batchOptions);
    batch.getMap("test").fastPut("1", "2");
    batch.getMap("test").fastPut("2", "3");
    batch.getMap("test").put("2", "5");
    batch.getAtomicLong("counter").incrementAndGet();
    batch.getAtomicLong("counter").incrementAndGet();
    List<?> res = sync(batch.execute()).getResponses();
    Assertions.assertEquals(5, res.size());
    Assertions.assertTrue((Boolean) res.get(0));
    Assertions.assertTrue((Boolean) res.get(1));
    Assertions.assertEquals("3", res.get(2));
    Assertions.assertEquals(1L, res.get(3));
    Assertions.assertEquals(2L, res.get(4));
    Map<String, String> map = new HashMap<String, String>();
    map.put("1", "2");
    map.put("2", "5");
    assertThat(sync(redisson.getAtomicLong("counter").get())).isEqualTo(2);
    Assertions.assertTrue(sync(redisson.getMap("test").remove("2", "5")));
    Assertions.assertTrue(sync(redisson.getMap("test").remove("1", "2")));
}
Also used : HashMap(java.util.HashMap) RBatchRx(org.redisson.api.RBatchRx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with RBatchRx

use of org.redisson.api.RBatchRx 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)

Aggregations

RBatchRx (org.redisson.api.RBatchRx)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)19 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 RedissonRxClient (org.redisson.api.RedissonRxClient)5 Config (org.redisson.config.Config)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 HashMap (java.util.HashMap)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ClusterRunner (org.redisson.ClusterRunner)2 ClusterProcesses (org.redisson.ClusterRunner.ClusterProcesses)2 RedisRunner (org.redisson.RedisRunner)2 Completable (io.reactivex.rxjava3.core.Completable)1 Single (io.reactivex.rxjava3.core.Single)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Test (org.junit.jupiter.api.Test)1 BaseTest (org.redisson.BaseTest)1