use of org.redisson.config.RedissonNodeConfig 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.RedissonNodeConfig 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);
}
use of org.redisson.config.RedissonNodeConfig 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.RedissonNodeConfig in project redisson by redisson.
the class RedissonScheduledExecutorServiceTest method testTaskResume.
@Test
public void testTaskResume() {
Assertions.assertTimeout(Duration.ofSeconds(7), () -> {
RScheduledExecutorService executor = redisson.getExecutorService("test");
ScheduledFuture<Long> future1 = executor.schedule(new ScheduledCallableTask(), 5, TimeUnit.SECONDS);
ScheduledFuture<Long> future2 = executor.schedule(new ScheduledCallableTask(), 5, TimeUnit.SECONDS);
ScheduledFuture<Long> future3 = executor.schedule(new ScheduledCallableTask(), 5, TimeUnit.SECONDS);
node.shutdown();
RedissonNodeConfig nodeConfig = new RedissonNodeConfig(redisson.getConfig());
nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("test", 1));
node = RedissonNode.create(nodeConfig);
node.start();
assertThat(future1.get()).isEqualTo(100);
assertThat(future2.get()).isEqualTo(100);
assertThat(future3.get()).isEqualTo(100);
});
}
use of org.redisson.config.RedissonNodeConfig 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();
}
Aggregations