Search in sources :

Example 46 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource 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 47 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project redisson by redisson.

the class RedissonTwoLockedThread method testCountDown.

@ParameterizedTest
@MethodSource("data")
public void testCountDown(Codec codec) throws InterruptedException {
    Config config = BaseTest.createConfig();
    config.setCodec(codec);
    RedissonClient redisson = Redisson.create(config);
    Assertions.assertTimeout(Duration.ofSeconds(3), () -> {
        final String countDownName = getClass().getName() + ":countDown#1";
        final CountDownLatch startSignal = new CountDownLatch(1);
        final CountDownLatch testSignal = new CountDownLatch(1);
        final CountDownLatch completeSignal = new CountDownLatch(2);
        System.out.println("configure");
        final long millis = System.currentTimeMillis();
        new Thread() {

            @Override
            public void run() {
                try {
                    startSignal.await();
                    RCountDownLatch countDownLatch = redisson.getCountDownLatch(countDownName);
                    System.out.println("1. getCountDownLatch " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    countDownLatch.trySetCount(1);
                    System.out.println("1. trySetCount " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    Thread.sleep(500);
                    testSignal.countDown();
                    Thread.sleep(500);
                    System.out.println("1. sleep " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    countDownLatch.countDown();
                    System.out.println("1. countDown " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                completeSignal.countDown();
            }
        }.start();
        new Thread() {

            @Override
            public void run() {
                try {
                    testSignal.await();
                    RCountDownLatch countDownLatch = redisson.getCountDownLatch(countDownName);
                    System.out.println("2. getCountDownLatch " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    countDownLatch.await();
                    System.out.println("2. await " + countDownLatch.getName() + " - " + Thread.currentThread().getId());
                    long current = System.currentTimeMillis();
                    Assertions.assertTrue((current - millis) >= 1000, "current=" + current + ", millis=" + millis);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                completeSignal.countDown();
            }
        }.start();
        System.out.println("start");
        startSignal.countDown();
        completeSignal.await();
        System.out.println("complete");
    });
}
Also used : RCountDownLatch(org.redisson.api.RCountDownLatch) RedissonClient(org.redisson.api.RedissonClient) Config(org.redisson.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) RCountDownLatch(org.redisson.api.RCountDownLatch) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 48 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project redisson by redisson.

the class RedissonSpringCacheShortTTLTest method testPutGetSync.

@ParameterizedTest
@MethodSource("data")
public void testPutGetSync(Class<?> contextClass) throws InterruptedException {
    AnnotationConfigApplicationContext context = contexts.get(contextClass);
    SampleBean bean = context.getBean(SampleBean.class);
    bean.readNullSync("object1");
    assertThat(bean.read("object1")).isNull();
    Thread.sleep(1100);
    Assertions.assertThrows(IllegalStateException.class, () -> {
        bean.read("object1");
    });
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 49 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project redisson by redisson.

the class RedissonSpringCacheTest method testNull.

@ParameterizedTest
@MethodSource("data")
public void testNull(Class<?> contextClass) {
    AnnotationConfigApplicationContext context = contexts.get(contextClass);
    SampleBean bean = context.getBean(SampleBean.class);
    bean.store("object1", null);
    assertThat(bean.readNull("object1")).isNull();
    bean.remove("object1");
    assertThat(bean.readNull("object1")).isNull();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 50 with MethodSource

use of org.junit.jupiter.params.provider.MethodSource in project redisson by redisson.

the class RedissonSpringCacheTest method testRemove.

@ParameterizedTest
@MethodSource("data")
public void testRemove(Class<?> contextClass) {
    AnnotationConfigApplicationContext context = contexts.get(contextClass);
    SampleBean bean = context.getBean(SampleBean.class);
    bean.store("object1", new SampleObject("name1", "value1"));
    assertThat(bean.read("object1")).isNotNull();
    bean.remove("object1");
    assertThat(bean.readNull("object1")).isNull();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

MethodSource (org.junit.jupiter.params.provider.MethodSource)1199 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1184 Transaction (org.neo4j.graphdb.Transaction)103 Stream (java.util.stream.Stream)70 Test (org.junit.jupiter.api.Test)67 ArrayList (java.util.ArrayList)63 InterruptAfter (io.aeron.test.InterruptAfter)60 List (java.util.List)60 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)58 TimeUnit (java.util.concurrent.TimeUnit)54 IOException (java.io.IOException)52 CountDownLatch (java.util.concurrent.CountDownLatch)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)52 lombok.val (lombok.val)52 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)51 Arguments (org.junit.jupiter.params.provider.Arguments)47 AfterEach (org.junit.jupiter.api.AfterEach)46 SSLEngine (javax.net.ssl.SSLEngine)44 AtomicReference (java.util.concurrent.atomic.AtomicReference)43 Path (java.nio.file.Path)42