Search in sources :

Example 6 with RedissonNodeConfig

use of org.redisson.config.RedissonNodeConfig 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);
}
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) Test(org.junit.jupiter.api.Test)

Example 7 with RedissonNodeConfig

use of org.redisson.config.RedissonNodeConfig 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();
}
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)

Example 8 with RedissonNodeConfig

use of org.redisson.config.RedissonNodeConfig in project redisson by redisson.

the class RedissonScheduledExecutorServiceTest method beforeClass.

@BeforeClass
public static void beforeClass() throws IOException, InterruptedException {
    if (!RedissonRuntimeEnvironment.isTravis) {
        BaseTest.beforeClass();
        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) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) RedissonNodeConfig(org.redisson.config.RedissonNodeConfig) BeforeClass(org.junit.BeforeClass)

Example 9 with RedissonNodeConfig

use of org.redisson.config.RedissonNodeConfig in project redisson by redisson.

the class RedissonExecutorServiceTest 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", 1));
    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 10 with RedissonNodeConfig

use of org.redisson.config.RedissonNodeConfig 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

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