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