use of org.redisson.config.Config in project redisson by redisson.
the class RedissonTest method testMasterSlaveConnectionFail.
@Test(expected = RedisConnectionException.class)
public void testMasterSlaveConnectionFail() throws InterruptedException {
Config config = new Config();
config.useMasterSlaveServers().setMasterAddress("127.99.0.1:1111");
Redisson.create(config);
Thread.sleep(1500);
}
use of org.redisson.config.Config in project redisson by redisson.
the class RedissonTest method testSer.
@Test(expected = RedisException.class)
public void testSer() {
Config config = new Config();
config.useSingleServer().setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());
config.setCodec(new SerializationCodec());
RedissonClient r = Redisson.create(config);
r.getMap("test").put("1", new Dummy());
}
use of org.redisson.config.Config in project redisson by redisson.
the class RedissonTest method testConnectionListener.
@Test
public void testConnectionListener() throws IOException, InterruptedException, TimeoutException {
final RedisProcess p = redisTestConnection();
final AtomicInteger connectCounter = new AtomicInteger();
final AtomicInteger disconnectCounter = new AtomicInteger();
Config config = new Config();
config.useSingleServer().setAddress(p.getRedisServerAddressAndPort());
RedissonClient r = Redisson.create(config);
int id = r.getNodesGroup().addConnectionListener(new ConnectionListener() {
@Override
public void onDisconnect(InetSocketAddress addr) {
assertThat(addr).isEqualTo(new InetSocketAddress(p.getRedisServerBindAddress(), p.getRedisServerPort()));
disconnectCounter.incrementAndGet();
}
@Override
public void onConnect(InetSocketAddress addr) {
assertThat(addr).isEqualTo(new InetSocketAddress(p.getRedisServerBindAddress(), p.getRedisServerPort()));
connectCounter.incrementAndGet();
}
});
assertThat(id).isNotZero();
r.getBucket("1").get();
Assert.assertEquals(0, p.stop());
try {
r.getBucket("1").get();
} catch (Exception e) {
}
RedisProcess pp = new RedisRunner().nosave().port(p.getRedisServerPort()).randomDir().run();
r.getBucket("1").get();
r.shutdown();
Assert.assertEquals(0, pp.stop());
await().atMost(1, TimeUnit.SECONDS).until(() -> assertThat(connectCounter.get()).isEqualTo(1));
await().until(() -> assertThat(disconnectCounter.get()).isEqualTo(1));
}
use of org.redisson.config.Config in project redisson by redisson.
the class CommandHandlersTest method testEncoder.
@Test(expected = RedisException.class)
public void testEncoder() throws InterruptedException {
Config config = createConfig();
config.setCodec(new ErrorsCodec());
RedissonClient redisson = Redisson.create(config);
redisson.getBucket("1234").set("1234");
}
use of org.redisson.config.Config in project redisson by redisson.
the class RedissonBlockingQueueTest method testPollAsyncReattach.
@Test
public void testPollAsyncReattach() throws InterruptedException, IOException, ExecutionException, TimeoutException {
RedisProcess runner = new RedisRunner().nosave().randomDir().randomPort().run();
Config config = new Config();
config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
RedissonClient redisson = Redisson.create(config);
RBlockingQueue<Integer> queue1 = redisson.getBlockingQueue("queue:pollany");
RFuture<Integer> f = queue1.pollAsync(10, TimeUnit.SECONDS);
f.await(1, TimeUnit.SECONDS);
runner.stop();
runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
queue1.put(123);
// check connection rotation
for (int i = 0; i < 10; i++) {
queue1.put(i);
}
assertThat(queue1.size()).isEqualTo(10);
Integer result = f.get(1, TimeUnit.SECONDS);
assertThat(result).isEqualTo(123);
redisson.shutdown();
runner.stop();
}
Aggregations