Search in sources :

Example 86 with ParameterizedTest

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

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

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

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

Example 90 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project redisson by redisson.

the class RedissonSpringCacheTest method testPutGet.

@ParameterizedTest
@MethodSource("data")
public void testPutGet(Class<?> contextClass) {
    AnnotationConfigApplicationContext context = contexts.get(contextClass);
    SampleBean bean = context.getBean(SampleBean.class);
    bean.store("object1", new SampleObject("name1", "value1"));
    SampleObject s = bean.read("object1");
    assertThat(s.getName()).isEqualTo("name1");
    assertThat(s.getValue()).isEqualTo("value1");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) 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