Search in sources :

Example 1 with RedissonNode

use of org.redisson.RedissonNode 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();
}
Also used : Config(org.redisson.config.Config) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) ArrayList(java.util.ArrayList) RedissonNode(org.redisson.RedissonNode) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 2 with RedissonNode

use of org.redisson.RedissonNode in project redisson by redisson.

the class RedissonScheduledExecutorServiceTest method testSingleWorker.

@Test
public void testSingleWorker() throws InterruptedException {
    Config config = createConfig();
    RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
    nodeConfig.getExecutorServiceWorkers().put("JobA", 1);
    RedissonNode node = RedissonNode.create(nodeConfig);
    node.start();
    RedissonClient client = Redisson.create(config);
    RScheduledExecutorService executorService = client.getExecutorService("JobA");
    executorService.schedule(new TestTask(), CronSchedule.of("0/1 * * * * ?"));
    TimeUnit.MILLISECONDS.sleep(4900);
    assertThat(client.getAtomicLong("counter").get()).isEqualTo(4);
    client.shutdown();
    node.shutdown();
}
Also used : Config(org.redisson.config.Config) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) RedissonNode(org.redisson.RedissonNode) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 BaseTest (org.redisson.BaseTest)2 RedissonNode (org.redisson.RedissonNode)2 Config (org.redisson.config.Config)2 RedissonNodeConfig (org.redisson.config.RedissonNodeConfig)2 ArrayList (java.util.ArrayList)1