use of org.redisson.config.Config in project redisson by redisson.
the class RedissonScheduledExecutorServiceTest method before.
@BeforeEach
@Override
public void before() throws IOException, InterruptedException {
super.before();
Config config = createConfig();
RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test", 5));
node = RedissonNode.create(nodeConfig);
node.start();
}
use of org.redisson.config.Config in project redisson by redisson.
the class RedissonScheduledExecutorServiceTest method testLoad.
@Test
public void testLoad() throws InterruptedException {
Config config = createConfig();
RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test2", Runtime.getRuntime().availableProcessors() * 2));
RedissonNode node = RedissonNode.create(nodeConfig);
node.start();
List<RScheduledFuture<?>> futures = new ArrayList<>();
for (int i = 0; i < 10000; i++) {
RScheduledFuture<?> future = redisson.getExecutorService("test2").scheduleAsync(new RunnableTask(), 5, TimeUnit.SECONDS);
futures.add(future);
}
for (RScheduledFuture<?> future : futures) {
try {
future.toCompletableFuture().get(5100, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
Assertions.fail(e);
} catch (ExecutionException e) {
// skip
}
}
node.shutdown();
}
use of org.redisson.config.Config in project redisson by redisson.
the class RedissonExecutorServiceTest method testNodeFailover.
@Test
public void testNodeFailover() throws Exception {
AtomicInteger counter = new AtomicInteger();
new MockUp<TasksRunnerService>() {
@Mock
void finish(Invocation invocation, String requestId, boolean removeTask) {
if (counter.incrementAndGet() > 1) {
invocation.proceed();
} else {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
Config config = createConfig();
RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test2", 1));
node.shutdown();
node = RedissonNode.create(nodeConfig);
node.start();
RExecutorService executor = redisson.getExecutorService("test2", ExecutorOptions.defaults().taskRetryInterval(10, TimeUnit.SECONDS));
RExecutorFuture<?> f = executor.submit(new IncrementRunnableTask("counter"));
assertThat(executor.getTaskCount()).isEqualTo(1);
Thread.sleep(1000);
assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(1);
Thread.sleep(1000);
System.out.println("shutdown");
node.shutdown();
assertThat(executor.getTaskCount()).isEqualTo(1);
node = RedissonNode.create(nodeConfig);
node.start();
assertThat(executor.getTaskCount()).isEqualTo(1);
Thread.sleep(8500);
assertThat(executor.getTaskCount()).isEqualTo(0);
assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(2);
Thread.sleep(16000);
assertThat(executor.getTaskCount()).isEqualTo(0);
assertThat(redisson.getAtomicLong("counter").get()).isEqualTo(2);
redisson.getKeys().delete("counter");
f.get();
assertThat(redisson.getKeys().count()).isEqualTo(1);
}
use of org.redisson.config.Config in project redisson by redisson.
the class RedissonExecutorServiceTest method testTaskFinishing.
// @Test
public void testTaskFinishing() throws Exception {
AtomicInteger counter = new AtomicInteger();
new MockUp<TasksRunnerService>() {
@Mock
private void finish(Invocation invocation, String requestId) {
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();
RExecutorService executor = redisson.getExecutorService("test2");
RExecutorFuture<?> f = executor.submit(new FailoverTask("finished"));
Thread.sleep(2000);
node.shutdown();
f.get();
assertThat(redisson.<Boolean>getBucket("finished").get()).isTrue();
}
use of org.redisson.config.Config in project redisson by redisson.
the class RedissonClientProducer method create.
@Produces
@Singleton
@DefaultBean
public RedissonClient create() throws IOException {
InputStream configStream;
Optional<String> configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class);
if (configFile.isPresent()) {
configStream = getClass().getResourceAsStream(configFile.get());
} else {
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("redisson.yaml");
}
String config;
if (configStream != null) {
byte[] array = new byte[configStream.available()];
configStream.read(array);
config = new String(array, StandardCharsets.UTF_8);
} else {
String yaml = PropertiesConvertor.toYaml("quarkus.redisson.", ConfigProvider.getConfig().getPropertyNames(), prop -> {
return ConfigProvider.getConfig().getValue(prop, String.class);
});
config = yaml;
}
ConfigSupport support = new ConfigSupport() {
{
yamlMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
}
};
Config c = support.fromYAML(config, Config.class);
redisson = Redisson.create(c);
return redisson;
}
Aggregations