use of org.redisson.config.Config in project redisson by redisson.
the class JCacheTest method testClear.
@Test
public void testClear() throws Exception {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
cache.put("1", "2");
cache.clear();
assertThat(cache.get("1")).isNull();
cache.close();
runner.stop();
}
use of org.redisson.config.Config in project redisson by redisson.
the class JCacheTest method testAsync.
@Test
public void testAsync() throws Exception {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
CacheAsync<String, String> async = cache.unwrap(CacheAsync.class);
async.putAsync("1", "2").get();
assertThat(async.getAsync("1").get()).isEqualTo("2");
cache.close();
runner.stop();
}
use of org.redisson.config.Config in project redisson by redisson.
the class JCacheTest method testRemoveAll.
@Test
public void testRemoveAll() throws Exception {
RedisProcess runner = new RedisRunner().nosave().randomDir().port(6311).run();
URL configUrl = getClass().getResource("redisson-jcache.yaml");
Config cfg = Config.fromYAML(configUrl);
Configuration<String, String> config = RedissonConfiguration.fromConfig(cfg);
Cache<String, String> cache = Caching.getCachingProvider().getCacheManager().createCache("test", config);
cache.put("1", "2");
cache.put("3", "4");
cache.put("4", "4");
cache.put("5", "5");
Set<? extends String> keys = new HashSet<String>(Arrays.asList("1", "3", "4", "5"));
cache.removeAll(keys);
assertThat(cache.containsKey("1")).isFalse();
assertThat(cache.containsKey("3")).isFalse();
assertThat(cache.containsKey("4")).isFalse();
assertThat(cache.containsKey("5")).isFalse();
cache.close();
runner.stop();
}
use of org.redisson.config.Config in project redisson by redisson.
the class WeightedRoundRobinBalancerTest method testUseMasterForReadsIfNoConnectionsToSlaves.
@Test
public void testUseMasterForReadsIfNoConnectionsToSlaves() {
Assertions.assertThrows(WriteRedisConnectionException.class, () -> {
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 RedissonScheduledExecutorServiceTest method testTaskFailover.
@Test
public void testTaskFailover() throws Exception {
AtomicInteger counter = new AtomicInteger();
new MockUp<TasksRunnerService>() {
@Mock
void finish(Invocation invocation, String requestId, boolean removeTask) {
if (counter.incrementAndGet() > 1) {
invocation.proceed();
}
}
};
Config config = createConfig();
RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test2", 1));
node.shutdown();
node = RedissonNode.create(nodeConfig);
node.start();
RScheduledExecutorService executor = redisson.getExecutorService("test2", ExecutorOptions.defaults().taskRetryInterval(10, TimeUnit.SECONDS));
long start = System.currentTimeMillis();
RExecutorFuture<?> f = executor.schedule(new IncrementRunnableTask("counter"), 1, TimeUnit.SECONDS);
f.toCompletableFuture().join();
assertThat(System.currentTimeMillis() - start).isBetween(900L, 1300L);
assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(1);
Thread.sleep(2000);
node.shutdown();
node = RedissonNode.create(nodeConfig);
node.start();
Thread.sleep(8500);
assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(2);
Thread.sleep(16000);
assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(2);
redisson.getKeys().delete("counter");
assertThat(redisson.getKeys().count()).isEqualTo(1);
}
Aggregations