use of org.redisson.api.RBatchRx in project redisson by redisson.
the class RedissonBatchRxTest method testBatchList.
@ParameterizedTest
@MethodSource("data")
public void testBatchList(BatchOptions batchOptions) {
RBatchRx b = redisson.createBatch(batchOptions);
RListRx<Integer> listAsync = b.getList("list");
for (int i = 1; i < 540; i++) {
listAsync.add(i);
}
BatchResult<?> res = sync(b.execute());
Assertions.assertEquals(539, res.getResponses().size());
}
use of org.redisson.api.RBatchRx in project redisson by redisson.
the class RedissonBatchRxTest method testSyncSlaves.
@ParameterizedTest
@MethodSource("data")
public void testSyncSlaves(BatchOptions batchOptions) throws FailedToStartRedisException, IOException, InterruptedException {
RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();
ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slave1).addNode(master2, slave2).addNode(master3, slave3);
ClusterProcesses process = clusterRunner.run();
Config config = new Config();
config.useClusterServers().setTimeout(1000000).setRetryInterval(1000000).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
RedissonRxClient redisson = Redisson.create(config).rxJava();
batchOptions.syncSlaves(1, 1, TimeUnit.SECONDS);
RBatchRx batch = redisson.createBatch(batchOptions);
for (int i = 0; i < 100; i++) {
RMapRx<String, String> map = batch.getMap("test");
map.put("" + i, "" + i);
}
BatchResult<?> result = sync(batch.execute());
assertThat(result.getResponses()).hasSize(100);
assertThat(result.getSyncedSlaves()).isEqualTo(1);
process.shutdown();
redisson.shutdown();
}
use of org.redisson.api.RBatchRx in project redisson by redisson.
the class RedissonBatchRxTest method testConvertor.
@ParameterizedTest
@MethodSource("data")
public void testConvertor(BatchOptions batchOptions) {
RBatchRx batch = redisson.createBatch(batchOptions);
Single<Double> f1 = batch.getScoredSortedSet("myZKey").addScore("abc", 1d);
Completable f2 = batch.getBucket("test").set("1");
sync(batch.execute());
assertThat(sync(f1)).isEqualTo(1d);
sync(f2);
RScoredSortedSetRx<String> set = redisson.getScoredSortedSet("myZKey");
assertThat(sync(set.getScore("abc"))).isEqualTo(1d);
RBucketRx<String> bucket = redisson.getBucket("test");
assertThat(sync(bucket.get())).isEqualTo("1");
RBatchRx batch2 = redisson.createBatch(batchOptions);
Single<Double> b2f1 = batch2.getScoredSortedSet("myZKey2").addScore("abc", 1d);
Single<Double> b2f2 = batch2.getScoredSortedSet("myZKey2").addScore("abc", 1d);
sync(batch2.execute());
assertThat(sync(b2f1)).isEqualTo(1d);
assertThat(sync(b2f2)).isEqualTo(2d);
}
use of org.redisson.api.RBatchRx in project redisson by redisson.
the class RedissonBatchRxTest method test.
@ParameterizedTest
@MethodSource("data")
public void test(BatchOptions batchOptions) {
RBatchRx batch = redisson.createBatch(batchOptions);
batch.getMap("test").fastPut("1", "2");
batch.getMap("test").fastPut("2", "3");
batch.getMap("test").put("2", "5");
batch.getAtomicLong("counter").incrementAndGet();
batch.getAtomicLong("counter").incrementAndGet();
List<?> res = sync(batch.execute()).getResponses();
Assertions.assertEquals(5, res.size());
Assertions.assertTrue((Boolean) res.get(0));
Assertions.assertTrue((Boolean) res.get(1));
Assertions.assertEquals("3", res.get(2));
Assertions.assertEquals(1L, res.get(3));
Assertions.assertEquals(2L, res.get(4));
Map<String, String> map = new HashMap<String, String>();
map.put("1", "2");
map.put("2", "5");
assertThat(sync(redisson.getAtomicLong("counter").get())).isEqualTo(2);
Assertions.assertTrue(sync(redisson.getMap("test").remove("2", "5")));
Assertions.assertTrue(sync(redisson.getMap("test").remove("1", "2")));
}
use of org.redisson.api.RBatchRx in project redisson by redisson.
the class RedissonBatchRxTest method testAtomicSyncSlaves.
@ParameterizedTest
@MethodSource("data")
public void testAtomicSyncSlaves(BatchOptions batchOptions) throws FailedToStartRedisException, IOException, InterruptedException {
RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();
ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slave1).addNode(master2, slave2).addNode(master3, slave3);
ClusterProcesses process = clusterRunner.run();
Config config = new Config();
config.useClusterServers().setTimeout(123000).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
RedissonRxClient redisson = Redisson.create(config).rxJava();
batchOptions.executionMode(ExecutionMode.IN_MEMORY_ATOMIC).syncSlaves(1, 1, TimeUnit.SECONDS);
RBatchRx batch = redisson.createBatch(batchOptions);
for (int i = 0; i < 10; i++) {
batch.getAtomicLong("{test}" + i).addAndGet(i);
}
BatchResult<?> result = sync(batch.execute());
assertThat(result.getSyncedSlaves()).isEqualTo(1);
int i = 0;
for (Object res : result.getResponses()) {
assertThat((Long) res).isEqualTo(i++);
}
process.shutdown();
redisson.shutdown();
}
Aggregations