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