use of org.redisson.api.RedissonRxClient 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.RedissonRxClient 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();
}
use of org.redisson.api.RedissonRxClient 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.redisson.api.RedissonRxClient in project redisson by redisson.
the class RedissonRemoteServiceTest method testRx.
@Test
public void testRx() {
RedissonRxClient r1 = Redisson.create(createConfig()).rxJava();
r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl());
RedissonRxClient r2 = Redisson.create(createConfig()).rxJava();
RemoteInterfaceRx ri = r2.getRemoteService().get(RemoteInterfaceRx.class);
Completable f = ri.voidMethod("someName", 100L);
f.blockingAwait();
Single<Long> resFuture = ri.resultMethod(100L);
assertThat(resFuture.blockingGet()).isEqualTo(200);
r1.shutdown();
r2.shutdown();
}
use of org.redisson.api.RedissonRxClient in project redisson by redisson.
the class RedissonBatchRxTest method testConnectionLeakAfterError.
@Test
public void testConnectionLeakAfterError() {
Config config = BaseTest.createConfig();
config.useSingleServer().setRetryInterval(100).setTimeout(200).setConnectionMinimumIdleSize(1).setConnectionPoolSize(1);
RedissonRxClient redisson = Redisson.create(config).rxJava();
BatchOptions batchOptions = BatchOptions.defaults().executionMode(ExecutionMode.REDIS_WRITE_ATOMIC);
RBatchRx batch = redisson.createBatch(batchOptions);
for (int i = 0; i < 25000; i++) {
batch.getBucket("test").set(123);
}
try {
sync(batch.execute());
Assertions.fail();
} catch (Exception e) {
// skip
}
sync(redisson.getBucket("test3").set(4));
assertThat(sync(redisson.getBucket("test3").get())).isEqualTo(4);
batch = redisson.createBatch(batchOptions);
batch.getBucket("test1").set(1);
batch.getBucket("test2").set(2);
sync(batch.execute());
assertThat(sync(redisson.getBucket("test1").get())).isEqualTo(1);
assertThat(sync(redisson.getBucket("test2").get())).isEqualTo(2);
redisson.shutdown();
}
Aggregations