use of org.redisson.config.Config in project redisson by redisson.
the class WeightedRoundRobinBalancerTest method testUseMasterForReadsIfNoConnectionsToSlaves.
@Test
public void testUseMasterForReadsIfNoConnectionsToSlaves() throws IOException, InterruptedException {
RedisProcess master = null;
RedisProcess slave = null;
RedissonClient client = null;
try {
master = redisTestInstance();
slave = redisTestInstance();
Map<String, Integer> weights = new HashMap<>();
weights.put(master.getRedisServerAddressAndPort(), 1);
weights.put(slave.getRedisServerAddressAndPort(), 2);
Config config = new Config();
config.useMasterSlaveServers().setReadMode(ReadMode.SLAVE).setMasterAddress(master.getRedisServerAddressAndPort()).addSlaveAddress(slave.getRedisServerAddressAndPort()).setLoadBalancer(new WeightedRoundRobinBalancer(weights, 1));
client = Redisson.create(config);
// To simulate network connection issues to slave, stop the slave
// after creating the client. Cannot create the client without the
// slave running. See https://github.com/mrniko/redisson/issues/580
slave.stop();
RedissonClient clientCopy = client;
assertThat(clientCopy.getBucket("key").get()).isNull();
} finally {
if (master != null) {
master.stop();
}
if (slave != null) {
slave.stop();
}
if (client != null) {
client.shutdown();
}
}
}
use of org.redisson.config.Config in project redisson by redisson.
the class RedissonExecutorServiceTest method beforeClass.
@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
BaseTest.beforeClass();
if (!RedissonRuntimeEnvironment.isTravis) {
Config config = createConfig();
RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test", 1));
node = RedissonNode.create(nodeConfig);
node.start();
}
}
use of org.redisson.config.Config in project redisson by redisson.
the class RedissonTopicTest method testReattach.
@Test
public void testReattach() 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);
final AtomicBoolean executed = new AtomicBoolean();
RTopic<Integer> topic = redisson.getTopic("topic");
topic.addListener(new MessageListener<Integer>() {
@Override
public void onMessage(String channel, Integer msg) {
if (msg == 1) {
executed.set(true);
}
}
});
runner.stop();
runner = new RedisRunner().port(runner.getRedisServerPort()).nosave().randomDir().run();
Thread.sleep(1000);
redisson.getTopic("topic").publish(1);
await().atMost(5, TimeUnit.SECONDS).untilTrue(executed);
redisson.shutdown();
runner.stop();
}
use of org.redisson.config.Config in project redisson by redisson.
the class JCachingProvider method loadConfig.
private Config loadConfig(URI uri) {
Config config = null;
try {
URL jsonUrl = null;
if (DEFAULT_URI_PATH.equals(uri.getPath())) {
jsonUrl = JCachingProvider.class.getResource("/redisson-jcache.json");
} else {
jsonUrl = uri.toURL();
}
if (jsonUrl == null) {
throw new IOException();
}
config = Config.fromJSON(jsonUrl);
} catch (IOException e) {
try {
URL yamlUrl = null;
if (DEFAULT_URI_PATH.equals(uri.getPath())) {
yamlUrl = JCachingProvider.class.getResource("/redisson-jcache.yaml");
} else {
yamlUrl = uri.toURL();
}
if (yamlUrl != null) {
config = Config.fromYAML(yamlUrl);
}
} catch (IOException e2) {
// skip
}
}
return config;
}
use of org.redisson.config.Config in project redisson by redisson.
the class JCachingProvider method getCacheManager.
@Override
public CacheManager getCacheManager(URI uri, ClassLoader classLoader, Properties properties) {
if (uri == null) {
uri = getDefaultURI();
}
if (uri == null) {
throw new CacheException("Uri is not defined. Can't load default configuration");
}
if (classLoader == null) {
classLoader = getDefaultClassLoader();
}
ConcurrentMap<URI, CacheManager> value = new ConcurrentHashMap<URI, CacheManager>();
ConcurrentMap<URI, CacheManager> oldValue = managers.putIfAbsent(classLoader, value);
if (oldValue != null) {
value = oldValue;
}
CacheManager manager = value.get(uri);
if (manager != null) {
return manager;
}
Config config = loadConfig(uri);
Redisson redisson = null;
if (config != null) {
redisson = (Redisson) Redisson.create(config);
}
manager = new JCacheManager(redisson, classLoader, this, properties, uri);
CacheManager oldManager = value.putIfAbsent(uri, manager);
if (oldManager != null) {
if (redisson != null) {
redisson.shutdown();
}
manager = oldManager;
}
return manager;
}
Aggregations