Search in sources :

Example 81 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest 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 82 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest 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 83 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest 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 84 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest 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 85 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest 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

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2045 MethodSource (org.junit.jupiter.params.provider.MethodSource)1116 EnumSource (org.junit.jupiter.params.provider.EnumSource)325 ValueSource (org.junit.jupiter.params.provider.ValueSource)302 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)181 Transaction (org.neo4j.graphdb.Transaction)117 CsvSource (org.junit.jupiter.params.provider.CsvSource)113 ArrayList (java.util.ArrayList)112 ByteBuffer (java.nio.ByteBuffer)81 List (java.util.List)81 Path (java.nio.file.Path)75 Test (org.junit.jupiter.api.Test)74 InterruptAfter (io.aeron.test.InterruptAfter)72 IOException (java.io.IOException)72 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)67 TimeUnit (java.util.concurrent.TimeUnit)65 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)62 CountDownLatch (java.util.concurrent.CountDownLatch)61 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)60 Stream (java.util.stream.Stream)59