Search in sources :

Example 1 with RedissonNodeConfig

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();
    }
}
Also used : Config(org.redisson.config.Config) BaseTest.createConfig(org.redisson.BaseTest.createConfig) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) BeforeClass(org.junit.BeforeClass)

Example 2 with RedissonNodeConfig

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);
}
Also used : Invocation(mockit.Invocation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Config(org.redisson.config.Config) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) MockUp(mockit.MockUp) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 3 with RedissonNodeConfig

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();
}
Also used : Config(org.redisson.config.Config) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with RedissonNodeConfig

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);
    });
}
Also used : RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) BaseTest(org.redisson.BaseTest) Test(org.junit.jupiter.api.Test)

Example 5 with RedissonNodeConfig

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();
}
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)

Aggregations

RedissonNodeConfig (org.redisson.config.RedissonNodeConfig)11 Config (org.redisson.config.Config)10 Test (org.junit.jupiter.api.Test)6 BaseTest (org.redisson.BaseTest)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Invocation (mockit.Invocation)3 MockUp (mockit.MockUp)3 BeforeClass (org.junit.BeforeClass)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 RedissonNode (org.redisson.RedissonNode)2 ArrayList (java.util.ArrayList)1 BaseTest.createConfig (org.redisson.BaseTest.createConfig)1 RandomLoadBalancer (org.redisson.connection.balancer.RandomLoadBalancer)1