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