Search in sources :

Example 6 with RBatchRx

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

the class RedissonBatchRxTest method testDifferentCodecs.

@ParameterizedTest
@MethodSource("data")
public void testDifferentCodecs(BatchOptions batchOptions) {
    RBatchRx b = redisson.createBatch(batchOptions);
    b.getMap("test1").put("1", "2");
    b.getMap("test2", StringCodec.INSTANCE).put("21", "3");
    Maybe<Object> val1 = b.getMap("test1").get("1");
    Maybe<Object> val2 = b.getMap("test2", StringCodec.INSTANCE).get("21");
    sync(b.execute());
    Assertions.assertEquals("2", sync(val1));
    Assertions.assertEquals("3", sync(val2));
}
Also used : RBatchRx(org.redisson.api.RBatchRx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with RBatchRx

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

the class RedissonBatchRxTest method testOrdering.

@ParameterizedTest
@MethodSource("data")
public void testOrdering(BatchOptions batchOptions) throws InterruptedException {
    ExecutorService e = Executors.newFixedThreadPool(16);
    RBatchRx batch = redisson.createBatch(batchOptions);
    AtomicLong index = new AtomicLong(-1);
    List<Single<Long>> futures = new CopyOnWriteArrayList<>();
    for (int i = 0; i < 500; i++) {
        futures.add(null);
    }
    for (int i = 0; i < 500; i++) {
        final int j = i;
        e.execute(new Runnable() {

            @Override
            public void run() {
                synchronized (RedissonBatchRxTest.this) {
                    int i = (int) index.incrementAndGet();
                    int ind = j % 3;
                    Single<Long> f1 = batch.getAtomicLong("test" + ind).addAndGet(j);
                    futures.set(i, f1);
                }
            }
        });
    }
    e.shutdown();
    Assertions.assertTrue(e.awaitTermination(30, TimeUnit.SECONDS));
    List<?> s = sync(batch.execute()).getResponses();
    int i = 0;
    for (Object element : s) {
        Single<Long> a = futures.get(i);
        Assertions.assertEquals(sync(a), element);
        i++;
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Single(io.reactivex.rxjava3.core.Single) ExecutorService(java.util.concurrent.ExecutorService) AtomicLong(java.util.concurrent.atomic.AtomicLong) RBatchRx(org.redisson.api.RBatchRx) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with RBatchRx

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

the class RedissonBatchRxTest method testAtomic.

@ParameterizedTest
@MethodSource("data")
public void testAtomic(BatchOptions batchOptions) {
    batchOptions.executionMode(ExecutionMode.IN_MEMORY_ATOMIC);
    RBatchRx batch = redisson.createBatch(batchOptions);
    Single<Long> f1 = batch.getAtomicLong("A1").addAndGet(1);
    Single<Long> f2 = batch.getAtomicLong("A2").addAndGet(2);
    Single<Long> f3 = batch.getAtomicLong("A3").addAndGet(3);
    Single<Long> d1 = batch.getKeys().delete("A1", "A2");
    BatchResult<?> f = sync(batch.execute());
    List<Object> list = (List<Object>) f.getResponses();
    assertThat(list).containsExactly(1L, 2L, 3L, 2L);
    assertThat(sync(f1)).isEqualTo(1);
    assertThat(sync(f2)).isEqualTo(2);
    assertThat(sync(f3)).isEqualTo(3);
    assertThat(sync(d1)).isEqualTo(2);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RBatchRx(org.redisson.api.RBatchRx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 9 with RBatchRx

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

the class RedissonBatchRxTest method testBigRequestAtomic.

@ParameterizedTest
@MethodSource("data")
public void testBigRequestAtomic(BatchOptions batchOptions) {
    batchOptions.executionMode(ExecutionMode.IN_MEMORY_ATOMIC).responseTimeout(15, TimeUnit.SECONDS).retryInterval(1, TimeUnit.SECONDS).retryAttempts(5);
    RBatchRx batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 100; i++) {
        batch.getBucket("" + i).set(i);
        batch.getBucket("" + i).get();
    }
    BatchResult<?> s = sync(batch.execute());
    assertThat(s.getResponses().size()).isEqualTo(200);
}
Also used : RBatchRx(org.redisson.api.RBatchRx) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with RBatchRx

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

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