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");
});
}
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");
});
}
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();
}
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();
}
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");
}
Aggregations