You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/07/10 11:34:50 UTC
[shardingsphere-elasticjob-lite] branch master updated: Use java 8
style for elasticjob cloud (#1022)
This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob-lite.git
The following commit(s) were added to refs/heads/master by this push:
new e9f048c Use java 8 style for elasticjob cloud (#1022)
e9f048c is described below
commit e9f048c59a57f64db08151566a208de95a6d5f7a
Author: Liang Zhang <te...@163.com>
AuthorDate: Fri Jul 10 19:34:44 2020 +0800
Use java 8 style for elasticjob cloud (#1022)
---
.../elasticjob/cloud/context/TaskContext.java | 13 +---
.../reg/zookeeper/ZookeeperRegistryCenter.java | 12 +---
.../statistics/rdb/StatisticRdbRepository.java | 15 ++--
.../cloud/fixture/EmbedTestingServer.java | 16 ++---
.../statistics/rdb/StatisticRdbRepositoryTest.java | 83 ++++++++++++----------
.../elasticjob/cloud/executor/TaskExecutor.java | 4 +-
.../executor/local/fixture/TestDataflowJob.java | 14 ++--
.../elasticjob/cloud/restful/RestfulServer.java | 13 ++--
.../config/app/CloudAppConfigurationService.java | 10 ++-
.../config/job/CloudJobConfigurationService.java | 11 ++-
.../cloud/scheduler/env/BootstrapEnvironment.java | 6 +-
.../cloud/scheduler/ha/FrameworkIDService.java | 15 ++--
.../scheduler/mesos/AppConstraintEvaluator.java | 8 +--
.../cloud/scheduler/mesos/FacadeService.java | 29 +++-----
.../cloud/scheduler/mesos/MesosStateService.java | 24 +++----
.../cloud/scheduler/mesos/ReconcileService.java | 27 +++----
.../cloud/scheduler/mesos/SchedulerService.java | 15 ++--
.../mesos/TaskLaunchScheduledService.java | 8 +--
.../cloud/scheduler/producer/ProducerManager.java | 35 +++++----
.../scheduler/restful/CloudAppRestfulApi.java | 24 +++----
.../scheduler/restful/CloudJobRestfulApi.java | 40 +++++------
.../cloud/scheduler/restful/RestfulService.java | 7 +-
.../scheduler/state/failover/FailoverService.java | 26 +++----
.../cloud/scheduler/state/ready/ReadyService.java | 21 ++----
.../scheduler/state/running/RunningService.java | 34 +++------
.../scheduler/statistics/StatisticManager.java | 26 +++----
.../statistics/job/JobRunningStatisticJob.java | 21 +++---
.../statistics/job/RegisteredJobStatisticJob.java | 17 ++---
.../statistics/job/TaskResultStatisticJob.java | 17 ++---
.../cloud/restful/RestfulServerTest.java | 9 ++-
.../cloud/restful/fixture/TestRestfulApi.java | 8 +--
.../app/CloudAppConfigurationServiceTest.java | 4 +-
.../job/CloudJobConfigurationServiceTest.java | 4 +-
.../scheduler/env/BootstrapEnvironmentTest.java | 6 +-
.../scheduler/fixture/EmbedTestingServer.java | 16 ++---
.../cloud/scheduler/ha/FrameworkIDServiceTest.java | 7 +-
.../mesos/AppConstraintEvaluatorTest.java | 50 +++++--------
.../cloud/scheduler/mesos/FacadeServiceTest.java | 35 +++++----
.../cloud/scheduler/mesos/SchedulerEngineTest.java | 2 +-
.../mesos/TaskLaunchScheduledServiceTest.java | 2 +-
.../scheduler/producer/ProducerManagerTest.java | 30 ++++----
.../restful/AbstractCloudRestfulApiTest.java | 23 +++---
.../state/failover/FailoverServiceTest.java | 23 +++---
.../scheduler/state/ready/ReadyServiceTest.java | 49 ++++++-------
.../scheduler/statistics/StatisticManagerTest.java | 32 ++++-----
.../statistics/job/JobRunningStatisticJobTest.java | 31 ++++----
.../job/RegisteredJobStatisticJobTest.java | 17 ++---
.../statistics/job/TaskResultStatisticJobTest.java | 30 ++++----
.../lite/example/EmbedZookeeperServer.java | 16 ++---
49 files changed, 424 insertions(+), 561 deletions(-)
diff --git a/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/context/TaskContext.java b/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/context/TaskContext.java
index 55403ca..966c664 100755
--- a/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/context/TaskContext.java
+++ b/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/context/TaskContext.java
@@ -17,11 +17,9 @@
package org.apache.shardingsphere.elasticjob.cloud.context;
-import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
-import com.google.common.collect.Lists;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@@ -31,6 +29,7 @@ import lombok.ToString;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
+import java.util.stream.Collectors;
/**
* Task runtime context.
@@ -145,14 +144,8 @@ public final class TaskContext {
public static MetaInfo from(final String value) {
String[] result = value.split(DELIMITER);
Preconditions.checkState(1 == result.length || 2 == result.length || 5 == result.length);
- return new MetaInfo(result[0], 1 == result.length || "".equals(result[1]) ? Collections.<Integer>emptyList() : Lists.transform(Splitter.on(",").splitToList(result[1]),
- new Function<String, Integer>() {
-
- @Override
- public Integer apply(final String input) {
- return Integer.parseInt(input);
- }
- }));
+ return new MetaInfo(result[0], 1 == result.length || "".equals(result[1])
+ ? Collections.emptyList() : Splitter.on(",").splitToList(result[1]).stream().map(Integer::parseInt).collect(Collectors.toList()));
}
@Override
diff --git a/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/reg/zookeeper/ZookeeperRegistryCenter.java b/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/reg/zookeeper/ZookeeperRegistryCenter.java
index 2a3caaf..7c61803 100755
--- a/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/reg/zookeeper/ZookeeperRegistryCenter.java
+++ b/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/reg/zookeeper/ZookeeperRegistryCenter.java
@@ -20,8 +20,6 @@ package org.apache.shardingsphere.elasticjob.cloud.reg.zookeeper;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import org.apache.shardingsphere.elasticjob.cloud.reg.exception.RegExceptionHandler;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@@ -32,6 +30,8 @@ import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.TreeCache;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.utils.CloseableUtils;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.reg.exception.RegExceptionHandler;
import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs;
@@ -166,13 +166,7 @@ public final class ZookeeperRegistryCenter implements CoordinatorRegistryCenter
public List<String> getChildrenKeys(final String key) {
try {
List<String> result = client.getChildren().forPath(key);
- Collections.sort(result, new Comparator<String>() {
-
- @Override
- public int compare(final String o1, final String o2) {
- return o2.compareTo(o1);
- }
- });
+ result.sort(Comparator.reverseOrder());
return result;
//CHECKSTYLE:OFF
} catch (final Exception ex) {
diff --git a/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/statistics/rdb/StatisticRdbRepository.java b/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/statistics/rdb/StatisticRdbRepository.java
index 46833a1..c08c583 100755
--- a/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/statistics/rdb/StatisticRdbRepository.java
+++ b/elasticjob-cloud/elasticjob-cloud-common/src/main/java/org/apache/shardingsphere/elasticjob/cloud/statistics/rdb/StatisticRdbRepository.java
@@ -17,13 +17,12 @@
package org.apache.shardingsphere.elasticjob.cloud.statistics.rdb;
-import com.google.common.base.Optional;
+import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRegisterStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRunningStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskResultStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskRunningStatistics;
-import lombok.extern.slf4j.Slf4j;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -36,6 +35,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
+import java.util.Optional;
/**
* Statistic RDB repository.
@@ -331,7 +331,7 @@ public class StatisticRdbRepository {
// TODO log failure directly to output log, consider to be configurable in the future
log.error("Fetch latest taskResultStatistics from DB error:", ex);
}
- return Optional.fromNullable(result);
+ return Optional.ofNullable(result);
}
/**
@@ -412,7 +412,7 @@ public class StatisticRdbRepository {
// TODO log failure directly to output log, consider to be configurable in the future
log.error("Fetch latest taskRunningStatistics from DB error:", ex);
}
- return Optional.fromNullable(result);
+ return Optional.ofNullable(result);
}
/**
@@ -422,8 +422,7 @@ public class StatisticRdbRepository {
*/
public Optional<JobRunningStatistics> findLatestJobRunningStatistics() {
JobRunningStatistics result = null;
- String sql = String.format("SELECT id, running_count, statistics_time, creation_time FROM %s order by id DESC LIMIT 1",
- TABLE_JOB_RUNNING_STATISTICS);
+ String sql = String.format("SELECT id, running_count, statistics_time, creation_time FROM %s order by id DESC LIMIT 1", TABLE_JOB_RUNNING_STATISTICS);
try (
Connection conn = dataSource.getConnection();
PreparedStatement preparedStatement = conn.prepareStatement(sql);
@@ -437,7 +436,7 @@ public class StatisticRdbRepository {
// TODO log failure directly to output log, consider to be configurable in the future
log.error("Fetch latest jobRunningStatistics from DB error:", ex);
}
- return Optional.fromNullable(result);
+ return Optional.ofNullable(result);
}
/**
@@ -490,6 +489,6 @@ public class StatisticRdbRepository {
// TODO log failure directly to output log, consider to be configurable in the future
log.error("Fetch latest jobRegisterStatistics from DB error:", ex);
}
- return Optional.fromNullable(result);
+ return Optional.ofNullable(result);
}
}
diff --git a/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/fixture/EmbedTestingServer.java b/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/fixture/EmbedTestingServer.java
index 8ed71f1..56819a0 100755
--- a/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/fixture/EmbedTestingServer.java
+++ b/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/fixture/EmbedTestingServer.java
@@ -55,17 +55,13 @@ public final class EmbedTestingServer {
// CHECKSTYLE:ON
RegExceptionHandler.handleException(ex);
} finally {
- Runtime.getRuntime().addShutdownHook(new Thread() {
-
- @Override
- public void run() {
- try {
- testingServer.close();
- } catch (final IOException ex) {
- RegExceptionHandler.handleException(ex);
- }
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try {
+ testingServer.close();
+ } catch (final IOException ex) {
+ RegExceptionHandler.handleException(ex);
}
- });
+ }));
}
}
}
diff --git a/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/statistics/rdb/StatisticRdbRepositoryTest.java b/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/statistics/rdb/StatisticRdbRepositoryTest.java
index 720a17b..dfd2b78 100755
--- a/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/statistics/rdb/StatisticRdbRepositoryTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-common/src/test/java/org/apache/shardingsphere/elasticjob/cloud/statistics/rdb/StatisticRdbRepositoryTest.java
@@ -17,20 +17,23 @@
package org.apache.shardingsphere.elasticjob.cloud.statistics.rdb;
-import com.google.common.base.Optional;
+import org.apache.commons.dbcp.BasicDataSource;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRegisterStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRunningStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskResultStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskRunningStatistics;
-import org.apache.commons.dbcp.BasicDataSource;
-import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.sql.SQLException;
import java.util.Date;
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
public class StatisticRdbRepositoryTest {
@@ -49,30 +52,30 @@ public class StatisticRdbRepositoryTest {
@Test
public void assertAddTaskResultStatistics() {
for (StatisticInterval each : StatisticInterval.values()) {
- Assert.assertTrue(repository.add(new TaskResultStatistics(100, 0, each, new Date())));
+ assertTrue(repository.add(new TaskResultStatistics(100, 0, each, new Date())));
}
}
@Test
public void assertAddTaskRunningStatistics() {
- Assert.assertTrue(repository.add(new TaskRunningStatistics(100, new Date())));
+ assertTrue(repository.add(new TaskRunningStatistics(100, new Date())));
}
@Test
public void assertAddJobRunningStatistics() {
- Assert.assertTrue(repository.add(new TaskRunningStatistics(100, new Date())));
+ assertTrue(repository.add(new TaskRunningStatistics(100, new Date())));
}
@Test
public void assertAddJobRegisterStatistics() {
- Assert.assertTrue(repository.add(new JobRegisterStatistics(100, new Date())));
+ assertTrue(repository.add(new JobRegisterStatistics(100, new Date())));
}
@Test
public void assertFindTaskResultStatisticsWhenTableIsEmpty() {
- Assert.assertThat(repository.findTaskResultStatistics(new Date(), StatisticInterval.MINUTE).size(), Is.is(0));
- Assert.assertThat(repository.findTaskResultStatistics(new Date(), StatisticInterval.HOUR).size(), Is.is(0));
- Assert.assertThat(repository.findTaskResultStatistics(new Date(), StatisticInterval.DAY).size(), Is.is(0));
+ assertThat(repository.findTaskResultStatistics(new Date(), StatisticInterval.MINUTE).size(), is(0));
+ assertThat(repository.findTaskResultStatistics(new Date(), StatisticInterval.HOUR).size(), is(0));
+ assertThat(repository.findTaskResultStatistics(new Date(), StatisticInterval.DAY).size(), is(0));
}
@Test
@@ -80,10 +83,10 @@ public class StatisticRdbRepositoryTest {
Date now = new Date();
Date yesterday = getYesterday();
for (StatisticInterval each : StatisticInterval.values()) {
- Assert.assertTrue(repository.add(new TaskResultStatistics(100, 0, each, yesterday)));
- Assert.assertTrue(repository.add(new TaskResultStatistics(100, 0, each, now)));
- Assert.assertThat(repository.findTaskResultStatistics(yesterday, each).size(), Is.is(2));
- Assert.assertThat(repository.findTaskResultStatistics(now, each).size(), Is.is(1));
+ assertTrue(repository.add(new TaskResultStatistics(100, 0, each, yesterday)));
+ assertTrue(repository.add(new TaskResultStatistics(100, 0, each, now)));
+ assertThat(repository.findTaskResultStatistics(yesterday, each).size(), is(2));
+ assertThat(repository.findTaskResultStatistics(now, each).size(), is(1));
}
}
@@ -91,8 +94,8 @@ public class StatisticRdbRepositoryTest {
public void assertGetSummedTaskResultStatisticsWhenTableIsEmpty() {
for (StatisticInterval each : StatisticInterval.values()) {
TaskResultStatistics po = repository.getSummedTaskResultStatistics(new Date(), each);
- Assert.assertThat(po.getSuccessCount(), Is.is(0));
- Assert.assertThat(po.getFailedCount(), Is.is(0));
+ assertThat(po.getSuccessCount(), is(0));
+ assertThat(po.getFailedCount(), is(0));
}
}
@@ -103,8 +106,8 @@ public class StatisticRdbRepositoryTest {
repository.add(new TaskResultStatistics(100, 2, each, date));
repository.add(new TaskResultStatistics(200, 5, each, date));
TaskResultStatistics po = repository.getSummedTaskResultStatistics(date, each);
- Assert.assertThat(po.getSuccessCount(), Is.is(300));
- Assert.assertThat(po.getFailedCount(), Is.is(7));
+ assertThat(po.getSuccessCount(), is(300));
+ assertThat(po.getFailedCount(), is(7));
}
}
@@ -121,24 +124,25 @@ public class StatisticRdbRepositoryTest {
repository.add(new TaskResultStatistics(100, 2, each, new Date()));
repository.add(new TaskResultStatistics(200, 5, each, new Date()));
Optional<TaskResultStatistics> po = repository.findLatestTaskResultStatistics(each);
- Assert.assertThat(po.get().getSuccessCount(), Is.is(200));
- Assert.assertThat(po.get().getFailedCount(), Is.is(5));
+ assertTrue(po.isPresent());
+ assertThat(po.get().getSuccessCount(), is(200));
+ assertThat(po.get().getFailedCount(), is(5));
}
}
@Test
public void assertFindTaskRunningStatisticsWhenTableIsEmpty() {
- Assert.assertThat(repository.findTaskRunningStatistics(new Date()).size(), Is.is(0));
+ assertThat(repository.findTaskRunningStatistics(new Date()).size(), is(0));
}
@Test
public void assertFindTaskRunningStatisticsWithDifferentFromDate() {
Date now = new Date();
Date yesterday = getYesterday();
- Assert.assertTrue(repository.add(new TaskRunningStatistics(100, yesterday)));
- Assert.assertTrue(repository.add(new TaskRunningStatistics(100, now)));
- Assert.assertThat(repository.findTaskRunningStatistics(yesterday).size(), Is.is(2));
- Assert.assertThat(repository.findTaskRunningStatistics(now).size(), Is.is(1));
+ assertTrue(repository.add(new TaskRunningStatistics(100, yesterday)));
+ assertTrue(repository.add(new TaskRunningStatistics(100, now)));
+ assertThat(repository.findTaskRunningStatistics(yesterday).size(), is(2));
+ assertThat(repository.findTaskRunningStatistics(now).size(), is(1));
}
@Test
@@ -151,22 +155,23 @@ public class StatisticRdbRepositoryTest {
repository.add(new TaskRunningStatistics(100, new Date()));
repository.add(new TaskRunningStatistics(200, new Date()));
Optional<TaskRunningStatistics> po = repository.findLatestTaskRunningStatistics();
- Assert.assertThat(po.get().getRunningCount(), Is.is(200));
+ assertTrue(po.isPresent());
+ assertThat(po.get().getRunningCount(), is(200));
}
@Test
public void assertFindJobRunningStatisticsWhenTableIsEmpty() {
- Assert.assertThat(repository.findJobRunningStatistics(new Date()).size(), Is.is(0));
+ assertThat(repository.findJobRunningStatistics(new Date()).size(), is(0));
}
@Test
public void assertFindJobRunningStatisticsWithDifferentFromDate() {
Date now = new Date();
Date yesterday = getYesterday();
- Assert.assertTrue(repository.add(new JobRunningStatistics(100, yesterday)));
- Assert.assertTrue(repository.add(new JobRunningStatistics(100, now)));
- Assert.assertThat(repository.findJobRunningStatistics(yesterday).size(), Is.is(2));
- Assert.assertThat(repository.findJobRunningStatistics(now).size(), Is.is(1));
+ assertTrue(repository.add(new JobRunningStatistics(100, yesterday)));
+ assertTrue(repository.add(new JobRunningStatistics(100, now)));
+ assertThat(repository.findJobRunningStatistics(yesterday).size(), is(2));
+ assertThat(repository.findJobRunningStatistics(now).size(), is(1));
}
@Test
@@ -179,22 +184,23 @@ public class StatisticRdbRepositoryTest {
repository.add(new JobRunningStatistics(100, new Date()));
repository.add(new JobRunningStatistics(200, new Date()));
Optional<JobRunningStatistics> po = repository.findLatestJobRunningStatistics();
- Assert.assertThat(po.get().getRunningCount(), Is.is(200));
+ assertTrue(po.isPresent());
+ assertThat(po.get().getRunningCount(), is(200));
}
@Test
public void assertFindJobRegisterStatisticsWhenTableIsEmpty() {
- Assert.assertThat(repository.findJobRegisterStatistics(new Date()).size(), Is.is(0));
+ assertThat(repository.findJobRegisterStatistics(new Date()).size(), is(0));
}
@Test
public void assertFindJobRegisterStatisticsWithDifferentFromDate() {
Date now = new Date();
Date yesterday = getYesterday();
- Assert.assertTrue(repository.add(new JobRegisterStatistics(100, yesterday)));
- Assert.assertTrue(repository.add(new JobRegisterStatistics(100, now)));
- Assert.assertThat(repository.findJobRegisterStatistics(yesterday).size(), Is.is(2));
- Assert.assertThat(repository.findJobRegisterStatistics(now).size(), Is.is(1));
+ assertTrue(repository.add(new JobRegisterStatistics(100, yesterday)));
+ assertTrue(repository.add(new JobRegisterStatistics(100, now)));
+ assertThat(repository.findJobRegisterStatistics(yesterday).size(), is(2));
+ assertThat(repository.findJobRegisterStatistics(now).size(), is(1));
}
@Test
@@ -207,7 +213,8 @@ public class StatisticRdbRepositoryTest {
repository.add(new JobRegisterStatistics(100, new Date()));
repository.add(new JobRegisterStatistics(200, new Date()));
Optional<JobRegisterStatistics> po = repository.findLatestJobRegisterStatistics();
- Assert.assertThat(po.get().getRegisteredCount(), Is.is(200));
+ assertTrue(po.isPresent());
+ assertThat(po.get().getRegisteredCount(), is(200));
}
private Date getYesterday() {
diff --git a/elasticjob-cloud/elasticjob-cloud-executor/src/main/java/org/apache/shardingsphere/elasticjob/cloud/executor/TaskExecutor.java b/elasticjob-cloud/elasticjob-cloud-executor/src/main/java/org/apache/shardingsphere/elasticjob/cloud/executor/TaskExecutor.java
index 9c67142..ea9776f 100755
--- a/elasticjob-cloud/elasticjob-cloud-executor/src/main/java/org/apache/shardingsphere/elasticjob/cloud/executor/TaskExecutor.java
+++ b/elasticjob-cloud/elasticjob-cloud-executor/src/main/java/org/apache/shardingsphere/elasticjob/cloud/executor/TaskExecutor.java
@@ -151,9 +151,7 @@ public final class TaskExecutor implements Executor {
String applicationContextFile = jobConfig.getApplicationContext();
if (null == applicationContexts.get(applicationContextFile)) {
synchronized (applicationContexts) {
- if (null == applicationContexts.get(applicationContextFile)) {
- applicationContexts.put(applicationContextFile, new ClassPathXmlApplicationContext(applicationContextFile));
- }
+ applicationContexts.computeIfAbsent(applicationContextFile, ClassPathXmlApplicationContext::new);
}
}
return (ElasticJob) applicationContexts.get(applicationContextFile).getBean(jobConfig.getBeanName());
diff --git a/elasticjob-cloud/elasticjob-cloud-executor/src/test/java/org/apache/shardingsphere/elasticjob/cloud/executor/local/fixture/TestDataflowJob.java b/elasticjob-cloud/elasticjob-cloud-executor/src/test/java/org/apache/shardingsphere/elasticjob/cloud/executor/local/fixture/TestDataflowJob.java
index 2085e94..2a6225f 100755
--- a/elasticjob-cloud/elasticjob-cloud-executor/src/test/java/org/apache/shardingsphere/elasticjob/cloud/executor/local/fixture/TestDataflowJob.java
+++ b/elasticjob-cloud/elasticjob-cloud-executor/src/test/java/org/apache/shardingsphere/elasticjob/cloud/executor/local/fixture/TestDataflowJob.java
@@ -17,14 +17,13 @@
package org.apache.shardingsphere.elasticjob.cloud.executor.local.fixture;
-import org.apache.shardingsphere.elasticjob.cloud.api.ShardingContext;
-import org.apache.shardingsphere.elasticjob.cloud.api.dataflow.DataflowJob;
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
import lombok.Getter;
import lombok.Setter;
+import org.apache.shardingsphere.elasticjob.cloud.api.ShardingContext;
+import org.apache.shardingsphere.elasticjob.cloud.api.dataflow.DataflowJob;
import java.util.List;
+import java.util.stream.Collectors;
public final class TestDataflowJob implements DataflowJob<String> {
@@ -42,11 +41,6 @@ public final class TestDataflowJob implements DataflowJob<String> {
@Override
public void processData(final ShardingContext shardingContext, final List<String> data) {
- output = Lists.transform(input, new Function<String, String>() {
- @Override
- public String apply(final String input) {
- return input + "-d";
- }
- });
+ output = input.stream().map(s -> input + "-d").collect(Collectors.toList());
}
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/restful/RestfulServer.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/restful/RestfulServer.java
index b9208b8..290f26a 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/restful/RestfulServer.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/restful/RestfulServer.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.elasticjob.cloud.restful;
import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.spi.container.servlet.ServletContainer;
import lombok.extern.slf4j.Slf4j;
@@ -55,8 +54,8 @@ public final class RestfulServer {
* @param resourcePath resource path
* @throws Exception exception when startup
*/
- public void start(final String packages, final Optional<String> resourcePath) throws Exception {
- start(packages, resourcePath, Optional.of("/api"));
+ public void start(final String packages, final String resourcePath) throws Exception {
+ start(packages, resourcePath, "/api");
}
/**
@@ -67,14 +66,14 @@ public final class RestfulServer {
* @param servletPath servlet path
* @throws Exception exception when startup
*/
- public void start(final String packages, final Optional<String> resourcePath, final Optional<String> servletPath) throws Exception {
+ public void start(final String packages, final String resourcePath, final String servletPath) throws Exception {
log.info("Elastic Job: Start RESTful server");
HandlerList handlers = new HandlerList();
- if (resourcePath.isPresent()) {
- servletContextHandler.setBaseResource(Resource.newClassPathResource(resourcePath.get()));
+ if (null != resourcePath) {
+ servletContextHandler.setBaseResource(Resource.newClassPathResource(resourcePath));
servletContextHandler.addServlet(new ServletHolder(DefaultServlet.class), "/*");
}
- String servletPathStr = (servletPath.isPresent() ? servletPath.get() : "") + "/*";
+ String servletPathStr = (null != servletPath ? servletPath : "") + "/*";
servletContextHandler.addServlet(getServletHolder(packages), servletPathStr);
handlers.addHandler(servletContextHandler);
server.setHandler(handlers);
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationService.java
index bc77622..61712e6 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationService.java
@@ -17,14 +17,14 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
/**
* Cloud app configuration service.
@@ -59,7 +59,7 @@ public final class CloudAppConfigurationService {
* @return cloud app configuration
*/
public Optional<CloudAppConfiguration> load(final String appName) {
- return Optional.fromNullable(CloudAppConfigurationGsonFactory.fromJson(regCenter.get(CloudAppConfigurationNode.getRootNodePath(appName))));
+ return Optional.ofNullable(CloudAppConfigurationGsonFactory.fromJson(regCenter.get(CloudAppConfigurationNode.getRootNodePath(appName))));
}
/**
@@ -75,9 +75,7 @@ public final class CloudAppConfigurationService {
Collection<CloudAppConfiguration> result = new ArrayList<>(appNames.size());
for (String each : appNames) {
Optional<CloudAppConfiguration> config = load(each);
- if (config.isPresent()) {
- result.add(config.get());
- }
+ config.ifPresent(result::add);
}
return result;
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationService.java
index abd6b73..a92b43b 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationService.java
@@ -17,14 +17,14 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job;
-import com.google.common.base.Optional;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
/**
* Cloud job configuration service.
@@ -64,10 +64,7 @@ public final class CloudJobConfigurationService {
List<String> jobNames = regCenter.getChildrenKeys(CloudJobConfigurationNode.ROOT);
Collection<CloudJobConfiguration> result = new ArrayList<>(jobNames.size());
for (String each : jobNames) {
- Optional<CloudJobConfiguration> config = load(each);
- if (config.isPresent()) {
- result.add(config.get());
- }
+ load(each).ifPresent(result::add);
}
return result;
}
@@ -79,7 +76,7 @@ public final class CloudJobConfigurationService {
* @return cloud job configuration
*/
public Optional<CloudJobConfiguration> load(final String jobName) {
- return Optional.fromNullable(CloudJobConfigurationGsonFactory.fromJson(regCenter.get(CloudJobConfigurationNode.getRootNodePath(jobName))));
+ return Optional.ofNullable(CloudJobConfigurationGsonFactory.fromJson(regCenter.get(CloudJobConfigurationNode.getRootNodePath(jobName))));
}
/**
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/env/BootstrapEnvironment.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/env/BootstrapEnvironment.java
index 8fc40e4..fa54e7a 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/env/BootstrapEnvironment.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/env/BootstrapEnvironment.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.env;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.Getter;
@@ -31,6 +30,7 @@ import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
+import java.util.Optional;
import java.util.Properties;
/**
@@ -141,7 +141,7 @@ public final class BootstrapEnvironment {
dataSource.setPassword(password);
return Optional.of(new TracingConfiguration<DataSource>("RDB", dataSource));
}
- return Optional.absent();
+ return Optional.empty();
}
/**
@@ -168,7 +168,7 @@ public final class BootstrapEnvironment {
public Optional<String> getMesosRole() {
String role = getValue(EnvironmentArgument.MESOS_ROLE);
if (Strings.isNullOrEmpty(role)) {
- return Optional.absent();
+ return Optional.empty();
}
return Optional.of(role);
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/ha/FrameworkIDService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/ha/FrameworkIDService.java
index fa0e127..75c817d 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/ha/FrameworkIDService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/ha/FrameworkIDService.java
@@ -17,10 +17,11 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.ha;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
import com.google.common.base.Strings;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+
+import java.util.Optional;
/**
* FrameworkID service.
@@ -31,19 +32,19 @@ public final class FrameworkIDService {
private final CoordinatorRegistryCenter regCenter;
/**
- * Fetch FrameworkID.
+ * Fetch framework ID.
*
- * @return the optional value of FrameworkID
+ * @return framework ID
*/
public Optional<String> fetch() {
String frameworkId = regCenter.getDirectly(HANode.FRAMEWORK_ID_NODE);
- return Strings.isNullOrEmpty(frameworkId) ? Optional.<String>absent() : Optional.of(frameworkId);
+ return Strings.isNullOrEmpty(frameworkId) ? Optional.empty() : Optional.of(frameworkId);
}
/**
- * Save FrameworkID.
+ * Save framework ID.
*
- * @param id framework id
+ * @param id framework ID
*/
public void save(final String id) {
if (!regCenter.isExisted(HANode.FRAMEWORK_ID_NODE)) {
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/AppConstraintEvaluator.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/AppConstraintEvaluator.java
index 027e07b..9c3dd80 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/AppConstraintEvaluator.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/AppConstraintEvaluator.java
@@ -17,10 +17,6 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.netflix.fenzo.ConstraintEvaluator;
import com.netflix.fenzo.TaskAssignmentResult;
@@ -32,11 +28,15 @@ import com.sun.jersey.api.client.UniformInterfaceException;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
import org.codehaus.jettison.json.JSONException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
/**
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeService.java
index 2858da3..d8e42a2 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeService.java
@@ -17,25 +17,22 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfigurationService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.app.DisableAppService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.job.DisableJobService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
+import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfigurationService;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobExecutionType;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.context.JobContext;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.app.DisableAppService;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.job.DisableJobService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.failover.FailoverService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.failover.FailoverTaskInfo;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.ready.ReadyService;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
-import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
import org.codehaus.jettison.json.JSONException;
import java.util.ArrayList;
@@ -43,7 +40,9 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
+import java.util.stream.Collectors;
/**
* Mesos facade service.
@@ -120,13 +119,7 @@ public final class FacadeService {
break;
}
}
- failoverService.remove(Lists.transform(failoverTaskContexts, new Function<TaskContext, TaskContext.MetaInfo>() {
-
- @Override
- public TaskContext.MetaInfo apply(final TaskContext input) {
- return input.getMetaInfo();
- }
- }));
+ failoverService.remove(failoverTaskContexts.stream().map(TaskContext::getMetaInfo).collect(Collectors.toList()));
readyService.remove(readyJobNames);
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/MesosStateService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/MesosStateService.java
index ce7e1f2..7a0b71b 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/MesosStateService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/MesosStateService.java
@@ -17,13 +17,8 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.ha.FrameworkIDService;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
-import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
@@ -31,12 +26,16 @@ import com.sun.jersey.api.client.Client;
import lombok.Builder;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.ha.FrameworkIDService;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import java.util.Collection;
import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Mesos state service.
@@ -110,16 +109,13 @@ public class MesosStateService {
* @throws JSONException parse json exception
*/
public Collection<ExecutorStateInfo> executors(final String appName) throws JSONException {
- return Collections2.transform(findExecutors(fetch(stateUrl).getJSONArray("frameworks"), appName), new Function<JSONObject, ExecutorStateInfo>() {
- @Override
- public ExecutorStateInfo apply(final JSONObject input) {
- try {
- return ExecutorStateInfo.builder().id(getExecutorId(input)).slaveId(input.getString("slave_id")).build();
- } catch (final JSONException ex) {
- throw new RuntimeException(ex);
- }
+ return findExecutors(fetch(stateUrl).getJSONArray("frameworks"), appName).stream().map(each -> {
+ try {
+ return ExecutorStateInfo.builder().id(getExecutorId(each)).slaveId(each.getString("slave_id")).build();
+ } catch (final JSONException ex) {
+ throw new RuntimeException(ex);
}
- });
+ }).collect(Collectors.toList());
}
/**
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/ReconcileService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/ReconcileService.java
index cd8aa4c..2a53f19 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/ReconcileService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/ReconcileService.java
@@ -17,22 +17,22 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.BootstrapEnvironment;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.FrameworkConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import com.google.common.base.Function;
-import com.google.common.collect.Collections2;
import com.google.common.util.concurrent.AbstractScheduledService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.mesos.Protos;
+import org.apache.mesos.Protos.TaskStatus;
import org.apache.mesos.SchedulerDriver;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.BootstrapEnvironment;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.FrameworkConfiguration;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
+import java.util.stream.Collectors;
/**
* Reconcile service.
@@ -48,7 +48,7 @@ public class ReconcileService extends AbstractScheduledService {
private final ReentrantLock lock = new ReentrantLock();
@Override
- protected void runOneIteration() throws Exception {
+ protected void runOneIteration() {
lock.lock();
try {
explicitReconcile();
@@ -72,15 +72,10 @@ public class ReconcileService extends AbstractScheduledService {
return;
}
log.info("Requesting {} tasks reconciliation with the Mesos master", runningTask.size());
- schedulerDriver.reconcileTasks(Collections2.transform(runningTask, new Function<TaskContext, Protos.TaskStatus>() {
- @Override
- public Protos.TaskStatus apply(final TaskContext input) {
- return Protos.TaskStatus.newBuilder()
- .setTaskId(Protos.TaskID.newBuilder().setValue(input.getId()).build())
- .setSlaveId(Protos.SlaveID.newBuilder().setValue(input.getSlaveId()).build())
- .setState(Protos.TaskState.TASK_RUNNING).build();
- }
- }));
+ schedulerDriver.reconcileTasks(runningTask.stream().map(each ->
+ TaskStatus.newBuilder().setTaskId(Protos.TaskID.newBuilder().setValue(each.getId()).build())
+ .setSlaveId(Protos.SlaveID.newBuilder().setValue(each.getSlaveId()).build())
+ .setState(Protos.TaskState.TASK_RUNNING).build()).collect(Collectors.toList()));
} finally {
lock.unlock();
}
@@ -92,7 +87,7 @@ public class ReconcileService extends AbstractScheduledService {
public void implicitReconcile() {
lock.lock();
try {
- schedulerDriver.reconcileTasks(Collections.<Protos.TaskStatus>emptyList());
+ schedulerDriver.reconcileTasks(Collections.emptyList());
} finally {
lock.unlock();
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/SchedulerService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/SchedulerService.java
index 873d653..7b5abe7 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/SchedulerService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/SchedulerService.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
-import com.google.common.base.Optional;
import com.google.common.util.concurrent.Service;
import com.netflix.fenzo.TaskScheduler;
import lombok.AllArgsConstructor;
@@ -36,6 +35,8 @@ import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.Statistic
import org.apache.shardingsphere.elasticjob.tracing.JobEventBus;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
+import java.util.Optional;
+
/**
* Scheduler service.
*/
@@ -66,7 +67,7 @@ public final class SchedulerService {
public SchedulerService(final CoordinatorRegistryCenter regCenter) {
env = BootstrapEnvironment.getInstance();
facadeService = new FacadeService(regCenter);
- statisticManager = StatisticManager.getInstance(regCenter, env.getTracingConfiguration());
+ statisticManager = StatisticManager.getInstance(regCenter, env.getTracingConfiguration().orElse(null));
TaskScheduler taskScheduler = getTaskScheduler();
JobEventBus jobEventBus = getJobEventBus();
schedulerDriver = getSchedulerDriver(taskScheduler, jobEventBus, new FrameworkIDService(regCenter));
@@ -78,11 +79,8 @@ public final class SchedulerService {
}
private SchedulerDriver getSchedulerDriver(final TaskScheduler taskScheduler, final JobEventBus jobEventBus, final FrameworkIDService frameworkIDService) {
- Optional<String> frameworkIDOptional = frameworkIDService.fetch();
Protos.FrameworkInfo.Builder builder = Protos.FrameworkInfo.newBuilder();
- if (frameworkIDOptional.isPresent()) {
- builder.setId(Protos.FrameworkID.newBuilder().setValue(frameworkIDOptional.get()).build());
- }
+ frameworkIDService.fetch().ifPresent(frameworkID -> builder.setId(Protos.FrameworkID.newBuilder().setValue(frameworkID).build()));
Optional<String> role = env.getMesosRole();
String frameworkName = MesosConfiguration.FRAMEWORK_NAME;
if (role.isPresent()) {
@@ -108,10 +106,7 @@ public final class SchedulerService {
private JobEventBus getJobEventBus() {
Optional<TracingConfiguration> tracingConfiguration = env.getTracingConfiguration();
- if (tracingConfiguration.isPresent()) {
- return new JobEventBus(tracingConfiguration.get());
- }
- return new JobEventBus();
+ return tracingConfiguration.map(JobEventBus::new).orElseGet(JobEventBus::new);
}
/**
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledService.java
index 1edb951..e71d3c8 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledService.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
import com.google.common.util.concurrent.AbstractScheduledService;
import com.google.protobuf.ByteString;
import com.netflix.fenzo.TaskAssignmentResult;
@@ -56,6 +55,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.concurrent.TimeUnit;
/**
@@ -182,7 +182,7 @@ public final class TaskLaunchScheduledService extends AbstractScheduledService {
Map<Integer, String> shardingItemParameters = new ShardingItemParameters(jobConfig.getTypeConfig().getCoreConfig().getShardingItemParameters()).getMap();
Map<Integer, String> assignedShardingItemParameters = new HashMap<>(1, 1);
int shardingItem = taskContext.getMetaInfo().getShardingItems().get(0);
- assignedShardingItemParameters.put(shardingItem, shardingItemParameters.containsKey(shardingItem) ? shardingItemParameters.get(shardingItem) : "");
+ assignedShardingItemParameters.put(shardingItem, shardingItemParameters.getOrDefault(shardingItem, ""));
return new ShardingContexts(taskContext.getId(), jobConfig.getJobName(), jobConfig.getTypeConfig().getCoreConfig().getShardingTotalCount(),
jobConfig.getTypeConfig().getCoreConfig().getJobParameter(), assignedShardingItemParameters, appConfig.getEventTraceSamplingCount());
}
@@ -247,9 +247,7 @@ public final class TaskLaunchScheduledService extends AbstractScheduledService {
Source.CLOUD_SCHEDULER, taskContext.getType().toString(), String.valueOf(metaInfo.getShardingItems()), JobStatusTraceEvent.State.TASK_STAGING, "");
if (ExecutionType.FAILOVER == taskContext.getType()) {
Optional<String> taskContextOptional = facadeService.getFailoverTaskId(metaInfo);
- if (taskContextOptional.isPresent()) {
- result.setOriginalTaskId(taskContextOptional.get());
- }
+ taskContextOptional.ifPresent(result::setOriginalTaskId);
}
return result;
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/producer/ProducerManager.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/producer/ProducerManager.java
index 4fe441a..0c945b2 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/producer/ProducerManager.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/producer/ProducerManager.java
@@ -17,26 +17,27 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.producer;
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.mesos.Protos;
+import org.apache.mesos.Protos.ExecutorID;
+import org.apache.mesos.Protos.SlaveID;
+import org.apache.mesos.SchedulerDriver;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.exception.AppConfigurationException;
+import org.apache.shardingsphere.elasticjob.cloud.exception.JobConfigurationException;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobExecutionType;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.app.DisableAppService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.job.DisableJobService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
-import org.apache.shardingsphere.elasticjob.cloud.exception.AppConfigurationException;
-import org.apache.shardingsphere.elasticjob.cloud.exception.JobConfigurationException;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.ready.ReadyService;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.mesos.Protos;
-import org.apache.mesos.Protos.ExecutorID;
-import org.apache.mesos.Protos.SlaveID;
-import org.apache.mesos.SchedulerDriver;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
+
+import java.util.Optional;
/**
* Producer manager.
@@ -159,9 +160,7 @@ public final class ProducerManager {
runningService.remove(jobName);
readyService.remove(Lists.newArrayList(jobName));
Optional<CloudJobConfiguration> jobConfig = configService.load(jobName);
- if (jobConfig.isPresent()) {
- transientProducerScheduler.deregister(jobConfig.get());
- }
+ jobConfig.ifPresent(transientProducerScheduler::deregister);
}
/**
@@ -172,9 +171,7 @@ public final class ProducerManager {
public void reschedule(final String jobName) {
unschedule(jobName);
Optional<CloudJobConfiguration> jobConfig = configService.load(jobName);
- if (jobConfig.isPresent()) {
- schedule(jobConfig.get());
- }
+ jobConfig.ifPresent(this::schedule);
}
/**
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/CloudAppRestfulApi.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/CloudAppRestfulApi.java
index 2584e89..90e7aa1 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/CloudAppRestfulApi.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/CloudAppRestfulApi.java
@@ -17,21 +17,20 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.restful;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfigurationGsonFactory;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.MesosStateService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.app.DisableAppService;
+import org.apache.mesos.Protos.ExecutorID;
+import org.apache.mesos.Protos.SlaveID;
+import org.apache.shardingsphere.elasticjob.cloud.exception.AppConfigurationException;
+import org.apache.shardingsphere.elasticjob.cloud.exception.JobSystemException;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfigurationGsonFactory;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.MesosStateService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.producer.ProducerManager;
-import org.apache.shardingsphere.elasticjob.cloud.exception.AppConfigurationException;
-import org.apache.shardingsphere.elasticjob.cloud.exception.JobSystemException;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.app.DisableAppService;
import org.apache.shardingsphere.elasticjob.cloud.util.json.GsonFactory;
-import com.google.common.base.Optional;
-import org.apache.mesos.Protos.ExecutorID;
-import org.apache.mesos.Protos.SlaveID;
import org.codehaus.jettison.json.JSONException;
import javax.ws.rs.Consumes;
@@ -45,6 +44,7 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.Collection;
+import java.util.Optional;
/**
* Cloud app restful api.
@@ -143,12 +143,11 @@ public final class CloudAppRestfulApi {
*
* @param appName app name
* @return true is disabled, otherwise not
- * @throws JSONException parse json exception
*/
@GET
@Path("/{appName}/disable")
@Produces(MediaType.APPLICATION_JSON)
- public boolean isDisabled(@PathParam("appName") final String appName) throws JSONException {
+ public boolean isDisabled(@PathParam("appName") final String appName) {
return disableAppService.isDisabled(appName);
}
@@ -174,11 +173,10 @@ public final class CloudAppRestfulApi {
* Enable app.
*
* @param appName app name
- * @throws JSONException parse json exception
*/
@POST
@Path("/{appName}/enable")
- public void enable(@PathParam("appName") final String appName) throws JSONException {
+ public void enable(@PathParam("appName") final String appName) {
if (appConfigService.load(appName).isPresent()) {
disableAppService.remove(appName);
for (CloudJobConfiguration each : jobConfigService.loadAll()) {
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/CloudJobRestfulApi.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/CloudJobRestfulApi.java
index 2a28c0f..ecec1b5 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/CloudJobRestfulApi.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/CloudJobRestfulApi.java
@@ -17,12 +17,10 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.restful;
-import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.restful.search.JobEventRdbSearch;
import org.apache.shardingsphere.elasticjob.cloud.exception.JobSystemException;
import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
@@ -32,6 +30,7 @@ import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobE
import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.BootstrapEnvironment;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.FacadeService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.producer.ProducerManager;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.restful.search.JobEventRdbSearch;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.failover.FailoverTaskInfo;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.StatisticManager;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
@@ -45,7 +44,6 @@ import org.apache.shardingsphere.elasticjob.cloud.util.json.GsonFactory;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.event.JobExecutionEvent;
import org.apache.shardingsphere.elasticjob.tracing.event.JobStatusTraceEvent;
-import org.codehaus.jettison.json.JSONException;
import javax.sql.DataSource;
import javax.ws.rs.Consumes;
@@ -72,6 +70,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.Set;
/**
@@ -97,7 +96,7 @@ public final class CloudJobRestfulApi {
Preconditions.checkNotNull(regCenter);
configService = new CloudJobConfigurationService(regCenter);
facadeService = new FacadeService(regCenter);
- statisticManager = StatisticManager.getInstance(regCenter, Optional.absent());
+ statisticManager = StatisticManager.getInstance(regCenter, null);
}
/**
@@ -111,11 +110,7 @@ public final class CloudJobRestfulApi {
CloudJobRestfulApi.producerManager = producerManager;
GsonFactory.registerTypeAdapter(CloudJobConfiguration.class, new CloudJobConfigurationGsonFactory.CloudJobConfigurationGsonTypeAdapter());
Optional<TracingConfiguration> tracingConfiguration = BootstrapEnvironment.getInstance().getTracingConfiguration();
- if (tracingConfiguration.isPresent()) {
- jobEventRdbSearch = new JobEventRdbSearch((DataSource) tracingConfiguration.get().getStorage());
- } else {
- jobEventRdbSearch = null;
- }
+ jobEventRdbSearch = tracingConfiguration.map(tracingConfiguration1 -> new JobEventRdbSearch((DataSource) tracingConfiguration1.getStorage())).orElse(null);
}
/**
@@ -159,12 +154,11 @@ public final class CloudJobRestfulApi {
*
* @param jobName job name
* @return true is disabled, otherwise not
- * @throws JSONException parse json exception
*/
@GET
@Path("/{jobName}/disable")
@Produces(MediaType.APPLICATION_JSON)
- public boolean isDisabled(@PathParam("jobName") final String jobName) throws JSONException {
+ public boolean isDisabled(@PathParam("jobName") final String jobName) {
return facadeService.isJobDisabled(jobName);
}
@@ -172,11 +166,10 @@ public final class CloudJobRestfulApi {
* Enable cloud job.
*
* @param jobName job name
- * @throws JSONException parse json exception
*/
@POST
@Path("/{jobName}/enable")
- public void enable(@PathParam("jobName") final String jobName) throws JSONException {
+ public void enable(@PathParam("jobName") final String jobName) {
Optional<CloudJobConfiguration> configOptional = configService.load(jobName);
if (configOptional.isPresent()) {
facadeService.enableJob(jobName);
@@ -394,16 +387,17 @@ public final class CloudJobRestfulApi {
@Path("/statistics/tasks/results/{period}")
@Consumes(MediaType.APPLICATION_JSON)
public TaskResultStatistics getTaskResultStatistics(@PathParam("period") final String period) {
- if ("online".equals(period)) {
- return statisticManager.getTaskResultStatisticsSinceOnline();
- } else if ("lastWeek".equals(period)) {
- return statisticManager.getTaskResultStatisticsWeekly();
- } else if ("lastHour".equals(period)) {
- return statisticManager.findLatestTaskResultStatistics(StatisticInterval.HOUR);
- } else if ("lastMinute".equals(period)) {
- return statisticManager.findLatestTaskResultStatistics(StatisticInterval.MINUTE);
- } else {
- return new TaskResultStatistics(0, 0, StatisticInterval.DAY, new Date());
+ switch (period) {
+ case "online":
+ return statisticManager.getTaskResultStatisticsSinceOnline();
+ case "lastWeek":
+ return statisticManager.getTaskResultStatisticsWeekly();
+ case "lastHour":
+ return statisticManager.findLatestTaskResultStatistics(StatisticInterval.HOUR);
+ case "lastMinute":
+ return statisticManager.findLatestTaskResultStatistics(StatisticInterval.MINUTE);
+ default:
+ return new TaskResultStatistics(0, 0, StatisticInterval.DAY, new Date());
}
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/RestfulService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/RestfulService.java
index 5b60531..68f5883 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/RestfulService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/RestfulService.java
@@ -17,13 +17,12 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.restful;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.restful.RestfulServer;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.RestfulServerConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.ReconcileService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.producer.ProducerManager;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import org.apache.shardingsphere.elasticjob.cloud.restful.RestfulServer;
import org.apache.shardingsphere.elasticjob.cloud.security.WwwAuthFilter;
-import com.google.common.base.Optional;
/**
* Restful server.
@@ -48,7 +47,7 @@ public final class RestfulService {
try {
restfulServer.addFilter(WwwAuthFilter.class, "*/")
.addFilter(WwwAuthFilter.class, "*.html")
- .start(RestfulService.class.getPackage().getName(), Optional.of(CONSOLE_PATH));
+ .start(RestfulService.class.getPackage().getName(), CONSOLE_PATH);
//CHECKSTYLE:OFF
} catch (final Exception ex) {
//CHECKSTYLE:ON
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/failover/FailoverService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/failover/FailoverService.java
index d7658f3..b943836 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/failover/FailoverService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/failover/FailoverService.java
@@ -17,20 +17,19 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.state.failover;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.BootstrapEnvironment;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
-import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.context.JobContext;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import com.google.common.base.Charsets;
-import com.google.common.base.Optional;
import com.google.common.base.Strings;
import com.google.common.hash.HashCode;
import com.google.common.hash.Hashing;
import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.context.JobContext;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.BootstrapEnvironment;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
import java.util.ArrayList;
import java.util.Collection;
@@ -39,6 +38,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
/**
@@ -102,7 +102,7 @@ public final class FailoverService {
continue;
}
List<Integer> assignedShardingItems = getAssignedShardingItems(each, taskIdList, assignedTasks);
- if (!assignedShardingItems.isEmpty() && jobConfig.isPresent()) {
+ if (!assignedShardingItems.isEmpty()) {
result.add(new JobContext(jobConfig.get(), assignedShardingItems, ExecutionType.FAILOVER));
}
}
@@ -139,11 +139,7 @@ public final class FailoverService {
*/
public Optional<String> getTaskId(final TaskContext.MetaInfo metaInfo) {
String failoverTaskNodePath = FailoverNode.getFailoverTaskNodePath(metaInfo.toString());
- Optional<String> result = Optional.absent();
- if (regCenter.isExisted(failoverTaskNodePath)) {
- result = Optional.of(regCenter.get(failoverTaskNodePath));
- }
- return result;
+ return regCenter.isExisted(failoverTaskNodePath) ? Optional.of(regCenter.get(failoverTaskNodePath)) : Optional.empty();
}
/**
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/ready/ReadyService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/ready/ReadyService.java
index 89e1409..d6c0939 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/ready/ReadyService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/ready/ReadyService.java
@@ -17,19 +17,16 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.state.ready;
+import com.google.common.base.Strings;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobExecutionType;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.context.JobContext;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.BootstrapEnvironment;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
-import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Strings;
-import com.google.common.collect.Collections2;
-import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.Collection;
@@ -37,6 +34,8 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
/**
* Ready service.
@@ -120,13 +119,7 @@ public final class ReadyService {
if (!regCenter.isExisted(ReadyNode.ROOT)) {
return Collections.emptyList();
}
- Collection<String> ineligibleJobNames = Collections2.transform(ineligibleJobContexts, new Function<JobContext, String>() {
-
- @Override
- public String apply(final JobContext input) {
- return input.getJobConfig().getJobName();
- }
- });
+ Collection<String> ineligibleJobNames = ineligibleJobContexts.stream().map(input -> input.getJobConfig().getJobName()).collect(Collectors.toList());
List<String> jobNames = regCenter.getChildrenKeys(ReadyNode.ROOT);
List<JobContext> result = new ArrayList<>(jobNames.size());
for (String each : jobNames) {
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/running/RunningService.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/running/RunningService.java
index 5de4b6a..3d3819e 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/running/RunningService.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/running/RunningService.java
@@ -17,27 +17,25 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobExecutionType;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterators;
-import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext.MetaInfo;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobExecutionType;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.stream.Collectors;
/**
* Running service.
@@ -73,13 +71,8 @@ public final class RunningService {
remove(each);
continue;
}
- RUNNING_TASKS.put(each, Sets.newCopyOnWriteArraySet(Lists.transform(regCenter.getChildrenKeys(RunningNode.getRunningJobNodePath(each)), new Function<String, TaskContext>() {
-
- @Override
- public TaskContext apply(final String input) {
- return TaskContext.from(regCenter.get(RunningNode.getRunningTaskNodePath(TaskContext.MetaInfo.from(input).toString())));
- }
- })));
+ RUNNING_TASKS.put(each, Sets.newCopyOnWriteArraySet(regCenter.getChildrenKeys(RunningNode.getRunningJobNodePath(each)).stream().map(
+ input -> TaskContext.from(regCenter.get(RunningNode.getRunningTaskNodePath(MetaInfo.from(input).toString())))).collect(Collectors.toList())));
}
}
@@ -125,12 +118,7 @@ public final class RunningService {
}
private Optional<TaskContext> findTask(final TaskContext taskContext) {
- return Iterators.tryFind(getRunningTasks(taskContext.getMetaInfo().getJobName()).iterator(), new Predicate<TaskContext>() {
- @Override
- public boolean apply(final TaskContext input) {
- return input.equals(taskContext);
- }
- });
+ return getRunningTasks(taskContext.getMetaInfo().getJobName()).stream().filter(each -> each.equals(taskContext)).findFirst();
}
/**
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/StatisticManager.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/StatisticManager.java
index e963825..9a0c538 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/StatisticManager.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/StatisticManager.java
@@ -17,27 +17,26 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics;
+import lombok.AccessLevel;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.cloud.api.JobType;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job.JobRunningStatisticJob;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobExecutionType;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job.JobRunningStatisticJob;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job.RegisteredJobStatisticJob;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job.TaskResultStatisticJob;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.util.StatisticTimeUtils;
-import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRegisterStatistics;
-import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskResultStatistics;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
import org.apache.shardingsphere.elasticjob.cloud.statistics.rdb.StatisticRdbRepository;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobExecutionTypeStatistics;
+import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRegisterStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRunningStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobTypeStatistics;
+import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskResultStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskRunningStatistics;
-import com.google.common.base.Optional;
-import lombok.AccessLevel;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
import javax.sql.DataSource;
@@ -49,6 +48,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
/**
* Statistic manager.
@@ -63,7 +63,7 @@ public final class StatisticManager {
private final CloudJobConfigurationService configurationService;
- private final Optional<TracingConfiguration> tracingConfiguration;
+ private final TracingConfiguration tracingConfiguration;
private final StatisticsScheduler scheduler;
@@ -71,7 +71,7 @@ public final class StatisticManager {
private StatisticRdbRepository rdbRepository;
- private StatisticManager(final CoordinatorRegistryCenter registryCenter, final Optional<TracingConfiguration> tracingConfiguration,
+ private StatisticManager(final CoordinatorRegistryCenter registryCenter, final TracingConfiguration tracingConfiguration,
final StatisticsScheduler scheduler, final Map<StatisticInterval, TaskResultMetaData> statisticData) {
this.registryCenter = registryCenter;
this.configurationService = new CloudJobConfigurationService(registryCenter);
@@ -87,7 +87,7 @@ public final class StatisticManager {
* @param tracingConfiguration tracing configuration
* @return statistic manager
*/
- public static StatisticManager getInstance(final CoordinatorRegistryCenter regCenter, final Optional<TracingConfiguration> tracingConfiguration) {
+ public static StatisticManager getInstance(final CoordinatorRegistryCenter regCenter, final TracingConfiguration tracingConfiguration) {
if (null == instance) {
synchronized (StatisticManager.class) {
if (null == instance) {
@@ -104,9 +104,9 @@ public final class StatisticManager {
}
private static void init() {
- if (instance.tracingConfiguration.isPresent()) {
+ if (null != instance.tracingConfiguration) {
try {
- instance.rdbRepository = new StatisticRdbRepository((DataSource) instance.tracingConfiguration.get().getStorage());
+ instance.rdbRepository = new StatisticRdbRepository((DataSource) instance.tracingConfiguration.getStorage());
} catch (final SQLException ex) {
log.error("Init StatisticRdbRepository error:", ex);
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/JobRunningStatisticJob.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/JobRunningStatisticJob.java
index ad981b9..853967a 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/JobRunningStatisticJob.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/JobRunningStatisticJob.java
@@ -17,23 +17,21 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.util.StatisticTimeUtils;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
import org.apache.shardingsphere.elasticjob.cloud.statistics.rdb.StatisticRdbRepository;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRunningStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskRunningStatistics;
-import com.google.common.base.Optional;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
@@ -41,6 +39,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
/**
@@ -84,7 +83,7 @@ public final class JobRunningStatisticJob extends AbstractStatisticJob {
}
@Override
- public void execute(final JobExecutionContext context) throws JobExecutionException {
+ public void execute(final JobExecutionContext context) {
Map<String, Set<TaskContext>> allRunningTasks = runningService.getAllRunningTasks();
statisticJob(getJobRunningCount(allRunningTasks));
statisticTask(getTaskRunningCount(allRunningTasks));
@@ -92,9 +91,7 @@ public final class JobRunningStatisticJob extends AbstractStatisticJob {
private void statisticJob(final int runningCount) {
Optional<JobRunningStatistics> latestOne = repository.findLatestJobRunningStatistics();
- if (latestOne.isPresent()) {
- fillBlankIfNeeded(latestOne.get());
- }
+ latestOne.ifPresent(this::fillBlankIfNeeded);
JobRunningStatistics jobRunningStatistics = new JobRunningStatistics(runningCount, StatisticTimeUtils.getCurrentStatisticTime(EXECUTE_INTERVAL));
log.debug("Add jobRunningStatistics, runningCount is:{}", runningCount);
repository.add(jobRunningStatistics);
@@ -102,9 +99,7 @@ public final class JobRunningStatisticJob extends AbstractStatisticJob {
private void statisticTask(final int runningCount) {
Optional<TaskRunningStatistics> latestOne = repository.findLatestTaskRunningStatistics();
- if (latestOne.isPresent()) {
- fillBlankIfNeeded(latestOne.get());
- }
+ latestOne.ifPresent(this::fillBlankIfNeeded);
TaskRunningStatistics taskRunningStatistics = new TaskRunningStatistics(runningCount, StatisticTimeUtils.getCurrentStatisticTime(EXECUTE_INTERVAL));
log.debug("Add taskRunningStatistics, runningCount is:{}", runningCount);
repository.add(taskRunningStatistics);
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/RegisteredJobStatisticJob.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/RegisteredJobStatisticJob.java
index f251257..c52493a 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/RegisteredJobStatisticJob.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/RegisteredJobStatisticJob.java
@@ -17,21 +17,19 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job;
+import lombok.AllArgsConstructor;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.util.StatisticTimeUtils;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
import org.apache.shardingsphere.elasticjob.cloud.statistics.rdb.StatisticRdbRepository;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRegisterStatistics;
-import com.google.common.base.Optional;
-import lombok.AllArgsConstructor;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
@@ -39,6 +37,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
/**
* Registered job statistic.
@@ -77,11 +76,9 @@ public final class RegisteredJobStatisticJob extends AbstractStatisticJob {
}
@Override
- public void execute(final JobExecutionContext context) throws JobExecutionException {
+ public void execute(final JobExecutionContext context) {
Optional<JobRegisterStatistics> latestOne = repository.findLatestJobRegisterStatistics();
- if (latestOne.isPresent()) {
- fillBlankIfNeeded(latestOne.get());
- }
+ latestOne.ifPresent(this::fillBlankIfNeeded);
int registeredCount = configurationService.loadAll().size();
JobRegisterStatistics jobRegisterStatistics = new JobRegisterStatistics(registeredCount, StatisticTimeUtils.getCurrentStatisticTime(execInterval));
log.debug("Add jobRegisterStatistics, registeredCount is:{}", registeredCount);
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/TaskResultStatisticJob.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/TaskResultStatisticJob.java
index a3fdac9..445db8b 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/TaskResultStatisticJob.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/main/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/TaskResultStatisticJob.java
@@ -17,21 +17,19 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job;
+import lombok.AllArgsConstructor;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.TaskResultMetaData;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.util.StatisticTimeUtils;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
import org.apache.shardingsphere.elasticjob.cloud.statistics.rdb.StatisticRdbRepository;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskResultStatistics;
-import com.google.common.base.Optional;
-import lombok.AllArgsConstructor;
-import lombok.NoArgsConstructor;
-import lombok.Setter;
-import lombok.extern.slf4j.Slf4j;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
@@ -39,6 +37,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
/**
* Task result statistic.
@@ -80,11 +79,9 @@ public final class TaskResultStatisticJob extends AbstractStatisticJob {
}
@Override
- public void execute(final JobExecutionContext context) throws JobExecutionException {
+ public void execute(final JobExecutionContext context) {
Optional<TaskResultStatistics> latestOne = repository.findLatestTaskResultStatistics(statisticInterval);
- if (latestOne.isPresent()) {
- fillBlankIfNeeded(latestOne.get());
- }
+ latestOne.ifPresent(this::fillBlankIfNeeded);
TaskResultStatistics taskResultStatistics = new TaskResultStatistics(
sharedData.getSuccessCount(), sharedData.getFailedCount(), statisticInterval,
StatisticTimeUtils.getCurrentStatisticTime(statisticInterval));
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/restful/RestfulServerTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/restful/RestfulServerTest.java
index 8a83e5b..f03a5e9 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/restful/RestfulServerTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/restful/RestfulServerTest.java
@@ -17,10 +17,9 @@
package org.apache.shardingsphere.elasticjob.cloud.restful;
-import com.google.common.base.Optional;
+import org.apache.shardingsphere.elasticjob.cloud.restful.fixture.Caller;
import org.apache.shardingsphere.elasticjob.cloud.restful.fixture.TestFilter;
import org.apache.shardingsphere.elasticjob.cloud.restful.fixture.TestRestfulApi;
-import org.apache.shardingsphere.elasticjob.cloud.restful.fixture.Caller;
import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.io.ByteArrayBuffer;
@@ -50,16 +49,16 @@ public final class RestfulServerTest {
public static void setUpClass() throws Exception {
server = new RestfulServer(17000);
server.addFilter(TestFilter.class, "/*");
- server.start(TestRestfulApi.class.getPackage().getName(), Optional.<String>absent());
+ server.start(TestRestfulApi.class.getPackage().getName(), null);
}
@AfterClass
- public static void tearDown() throws Exception {
+ public static void tearDown() {
server.stop();
}
@Before
- public void setUp() throws Exception {
+ public void setUp() {
caller = Mockito.mock(Caller.class);
TestRestfulApi.setCaller(caller);
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/restful/fixture/TestRestfulApi.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/restful/fixture/TestRestfulApi.java
index 01e5ff4..d0d5dbd 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/restful/fixture/TestRestfulApi.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/restful/fixture/TestRestfulApi.java
@@ -43,12 +43,6 @@ public final class TestRestfulApi {
public Map<String, String> call(final Map<String, String> map) {
caller.call(map.get("string"));
caller.call(Integer.valueOf(map.get("integer")));
- return Maps.transformEntries(map, new Maps.EntryTransformer<String, String, String>() {
-
- @Override
- public String transformEntry(final String key, final String value) {
- return value + "_processed";
- }
- });
+ return Maps.transformEntries(map, (key, value) -> value + "_processed");
}
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationServiceTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationServiceTest.java
index 12beee3..a65d296 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationServiceTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/app/CloudAppConfigurationServiceTest.java
@@ -17,10 +17,9 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudAppConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudAppJsonConstants;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Test;
@@ -32,6 +31,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Optional;
@RunWith(MockitoJUnitRunner.class)
public final class CloudAppConfigurationServiceTest {
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationServiceTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationServiceTest.java
index ec65486..e0adc54 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationServiceTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/config/job/CloudJobConfigurationServiceTest.java
@@ -17,10 +17,9 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJsonConstants;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Test;
@@ -32,6 +31,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Optional;
@RunWith(MockitoJUnitRunner.class)
public final class CloudJobConfigurationServiceTest {
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/env/BootstrapEnvironmentTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/env/BootstrapEnvironmentTest.java
index 845540b..ea308ec 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/env/BootstrapEnvironmentTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/env/BootstrapEnvironmentTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.env;
-import com.google.common.base.Optional;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.shardingsphere.elasticjob.cloud.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
@@ -28,6 +27,7 @@ import org.junit.Test;
import org.unitils.util.ReflectionUtils;
import java.util.Map;
+import java.util.Optional;
import java.util.Properties;
public final class BootstrapEnvironmentTest {
@@ -74,9 +74,7 @@ public final class BootstrapEnvironmentTest {
properties.setProperty(BootstrapEnvironment.EnvironmentArgument.EVENT_TRACE_RDB_PASSWORD.getKey(), "password");
ReflectionUtils.setFieldValue(bootstrapEnvironment, "properties", properties);
Optional<TracingConfiguration> tracingConfiguration = bootstrapEnvironment.getTracingConfiguration();
- if (tracingConfiguration.isPresent()) {
- Assert.assertThat(tracingConfiguration.get().getStorage(), IsInstanceOf.instanceOf(BasicDataSource.class));
- }
+ tracingConfiguration.ifPresent(tracingConfiguration1 -> Assert.assertThat(tracingConfiguration1.getStorage(), IsInstanceOf.instanceOf(BasicDataSource.class)));
}
@Test
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/fixture/EmbedTestingServer.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/fixture/EmbedTestingServer.java
index 09cc389..8aabeaa 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/fixture/EmbedTestingServer.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/fixture/EmbedTestingServer.java
@@ -55,17 +55,13 @@ public final class EmbedTestingServer {
// CHECKSTYLE:ON
RegExceptionHandler.handleException(ex);
} finally {
- Runtime.getRuntime().addShutdownHook(new Thread() {
-
- @Override
- public void run() {
- try {
- testingServer.close();
- } catch (final IOException ex) {
- RegExceptionHandler.handleException(ex);
- }
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try {
+ testingServer.close();
+ } catch (final IOException ex) {
+ RegExceptionHandler.handleException(ex);
}
- });
+ }));
}
}
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/ha/FrameworkIDServiceTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/ha/FrameworkIDServiceTest.java
index dcfe835..3dde3a4 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/ha/FrameworkIDServiceTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/ha/FrameworkIDServiceTest.java
@@ -18,12 +18,13 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.ha;
import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.util.Optional;
+
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -44,7 +45,7 @@ public class FrameworkIDServiceTest {
}
@Test
- public void assertFetch() throws Exception {
+ public void assertFetch() {
when(registryCenter.getDirectly(HANode.FRAMEWORK_ID_NODE)).thenReturn("1");
Optional<String> frameworkIDOptional = frameworkIDService.fetch();
assertTrue(frameworkIDOptional.isPresent());
@@ -53,7 +54,7 @@ public class FrameworkIDServiceTest {
}
@Test
- public void assertSave() throws Exception {
+ public void assertSave() {
when(registryCenter.isExisted(HANode.FRAMEWORK_ID_NODE)).thenReturn(false);
frameworkIDService.save("1");
verify(registryCenter).isExisted(HANode.FRAMEWORK_ID_NODE);
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/AppConstraintEvaluatorTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/AppConstraintEvaluatorTest.java
index 705813d..6fd50c0 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/AppConstraintEvaluatorTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/AppConstraintEvaluatorTest.java
@@ -17,13 +17,6 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
-import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudAppConfigurationBuilder;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.netflix.fenzo.ConstraintEvaluator;
import com.netflix.fenzo.SchedulingResult;
@@ -31,24 +24,27 @@ import com.netflix.fenzo.TaskRequest;
import com.netflix.fenzo.TaskScheduler;
import com.netflix.fenzo.VMAssignmentResult;
import com.netflix.fenzo.VirtualMachineLease;
-import com.netflix.fenzo.functions.Action1;
import com.netflix.fenzo.plugins.VMLeaseObject;
import org.apache.mesos.Protos;
+import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudAppConfigurationBuilder;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
import org.codehaus.jettison.json.JSONException;
import org.hamcrest.core.Is;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.Assert;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
public final class AppConstraintEvaluatorTest {
@@ -65,28 +61,23 @@ public final class AppConstraintEvaluatorTest {
private TaskScheduler taskScheduler;
@BeforeClass
- public static void init() throws Exception {
+ public static void init() {
facadeService = Mockito.mock(FacadeService.class);
AppConstraintEvaluator.init(facadeService);
}
@Before
- public void setUp() throws Exception {
- taskScheduler = new TaskScheduler.Builder().withLeaseOfferExpirySecs(1000000000L).withLeaseRejectAction(new Action1<VirtualMachineLease>() {
-
- @Override
- public void call(final VirtualMachineLease virtualMachineLease) {
- }
- }).build();
+ public void setUp() {
+ taskScheduler = new TaskScheduler.Builder().withLeaseOfferExpirySecs(1000000000L).withLeaseRejectAction(virtualMachineLease -> { }).build();
}
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
AppConstraintEvaluator.getInstance().clearAppRunningState();
}
@Test
- public void assertFirstLaunch() throws Exception {
+ public void assertFirstLaunch() {
SchedulingResult result = taskScheduler.scheduleOnce(getTasks(), Arrays.asList(getLease(0, SUFFICIENT_CPU, SUFFICIENT_MEM), getLease(1, SUFFICIENT_CPU, SUFFICIENT_MEM)));
Assert.assertThat(result.getResultMap().size(), Is.is(2));
Assert.assertThat(result.getFailures().size(), Is.is(0));
@@ -94,14 +85,14 @@ public final class AppConstraintEvaluatorTest {
}
@Test
- public void assertFirstLaunchLackCpu() throws Exception {
+ public void assertFirstLaunchLackCpu() {
SchedulingResult result = taskScheduler.scheduleOnce(getTasks(), Arrays.asList(getLease(0, INSUFFICIENT_CPU, SUFFICIENT_MEM), getLease(1, INSUFFICIENT_CPU, SUFFICIENT_MEM)));
Assert.assertThat(result.getResultMap().size(), Is.is(2));
Assert.assertThat(getAssignedTaskNumber(result), Is.is(18));
}
@Test
- public void assertFirstLaunchLackMem() throws Exception {
+ public void assertFirstLaunchLackMem() {
SchedulingResult result = taskScheduler.scheduleOnce(getTasks(), Arrays.asList(getLease(0, SUFFICIENT_CPU, INSUFFICIENT_MEM), getLease(1, SUFFICIENT_CPU, INSUFFICIENT_MEM)));
Assert.assertThat(result.getResultMap().size(), Is.is(2));
Assert.assertThat(getAssignedTaskNumber(result), Is.is(18));
@@ -126,17 +117,17 @@ public final class AppConstraintEvaluatorTest {
}
@Test
- public void assertLackJobConfig() throws Exception {
- Mockito.when(facadeService.load("test")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ public void assertLackJobConfig() {
+ Mockito.when(facadeService.load("test")).thenReturn(Optional.empty());
SchedulingResult result = taskScheduler.scheduleOnce(Collections.singletonList(getTask("test")), Collections.singletonList(getLease(0, 1.5, 192)));
Assert.assertThat(result.getResultMap().size(), Is.is(1));
Assert.assertThat(getAssignedTaskNumber(result), Is.is(1));
}
@Test
- public void assertLackAppConfig() throws Exception {
+ public void assertLackAppConfig() {
Mockito.when(facadeService.load("test")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test")));
- Mockito.when(facadeService.loadAppConfig("test_app")).thenReturn(Optional.<CloudAppConfiguration>absent());
+ Mockito.when(facadeService.loadAppConfig("test_app")).thenReturn(Optional.empty());
SchedulingResult result = taskScheduler.scheduleOnce(Collections.singletonList(getTask("test")), Collections.singletonList(getLease(0, 1.5, 192)));
Assert.assertThat(result.getResultMap().size(), Is.is(1));
Assert.assertThat(getAssignedTaskNumber(result), Is.is(1));
@@ -177,12 +168,7 @@ public final class AppConstraintEvaluatorTest {
TaskRequest result = Mockito.mock(TaskRequest.class);
Mockito.when(result.getCPUs()).thenReturn(1.0d);
Mockito.when(result.getMemory()).thenReturn(128.0d);
- Mockito.when(result.getHardConstraints()).thenAnswer(new Answer<List<? extends ConstraintEvaluator>>() {
- @Override
- public List<? extends ConstraintEvaluator> answer(final InvocationOnMock invocationOnMock) throws Throwable {
- return ImmutableList.of(AppConstraintEvaluator.getInstance());
- }
- });
+ Mockito.when(result.getHardConstraints()).thenAnswer((Answer<List<? extends ConstraintEvaluator>>) invocationOnMock -> ImmutableList.of(AppConstraintEvaluator.getInstance()));
Mockito.when(result.getId()).thenReturn(new TaskContext(jobName, Collections.singletonList(0), ExecutionType.READY).getId());
return result;
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeServiceTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeServiceTest.java
index 99313ac..cfa41ed 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeServiceTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/FacadeServiceTest.java
@@ -17,39 +17,38 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
+import com.google.common.collect.Sets;
+import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobExecutionType;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.context.JobContext;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudAppConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.TaskNode;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.app.DisableAppService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.job.DisableJobService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
-import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.context.JobContext;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudAppConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.failover.FailoverService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.ready.ReadyService;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
import org.hamcrest.core.Is;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.unitils.util.ReflectionUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-
-import org.junit.Assert;
-import org.mockito.Mockito;
+import java.util.Optional;
@RunWith(MockitoJUnitRunner.class)
public final class FacadeServiceTest {
@@ -160,7 +159,7 @@ public final class FacadeServiceTest {
@Test
public void assertRecordFailoverTaskWhenJobConfigNotExisted() {
TaskNode taskNode = TaskNode.builder().type(ExecutionType.FAILOVER).build();
- Mockito.when(jobConfigService.load("test_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ Mockito.when(jobConfigService.load("test_job")).thenReturn(Optional.empty());
facadeService.recordFailoverTask(TaskContext.from(taskNode.getTaskNodeValue()));
Mockito.verify(failoverService, Mockito.times(0)).add(TaskContext.from(taskNode.getTaskNodeValue()));
}
@@ -206,14 +205,14 @@ public final class FacadeServiceTest {
@Test
public void assertLoadAppConfigWhenAbsent() {
- Mockito.when(appConfigService.load("test_app")).thenReturn(Optional.<CloudAppConfiguration>absent());
- Assert.assertThat(facadeService.loadAppConfig("test_app"), Is.is(Optional.<CloudAppConfiguration>absent()));
+ Mockito.when(appConfigService.load("test_app")).thenReturn(Optional.empty());
+ Assert.assertThat(facadeService.loadAppConfig("test_app"), Is.is(Optional.<CloudAppConfiguration>empty()));
}
@Test
public void assertLoadJobConfigWhenAbsent() {
- Mockito.when(jobConfigService.load("test_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
- Assert.assertThat(facadeService.load("test_job"), Is.is(Optional.<CloudJobConfiguration>absent()));
+ Mockito.when(jobConfigService.load("test_job")).thenReturn(Optional.empty());
+ Assert.assertThat(facadeService.load("test_job"), Is.is(Optional.<CloudJobConfiguration>empty()));
}
@Test
@@ -225,7 +224,7 @@ public final class FacadeServiceTest {
@Test
public void assertIsRunningForReadyJobAndNotRunning() {
- Mockito.when(runningService.getRunningTasks("test_job")).thenReturn(Collections.<TaskContext>emptyList());
+ Mockito.when(runningService.getRunningTasks("test_job")).thenReturn(Collections.emptyList());
Assert.assertFalse(facadeService.isRunning(TaskContext.from(TaskNode.builder().type(ExecutionType.READY).build().getTaskNodeValue())));
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/SchedulerEngineTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/SchedulerEngineTest.java
index 4e3b16d..1fcd854 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/SchedulerEngineTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/SchedulerEngineTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
-import com.google.common.base.Optional;
import com.netflix.fenzo.TaskScheduler;
import com.netflix.fenzo.functions.Action2;
import org.apache.mesos.Protos;
@@ -44,6 +43,7 @@ import org.unitils.util.ReflectionUtils;
import java.util.Arrays;
import java.util.List;
+import java.util.Optional;
@RunWith(MockitoJUnitRunner.class)
public final class SchedulerEngineTest {
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledServiceTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledServiceTest.java
index e3ef81d..e19793b 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledServiceTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/mesos/TaskLaunchScheduledServiceTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos;
-import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.AbstractScheduledService.Scheduler;
@@ -47,6 +46,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.HashMap;
import java.util.Map;
+import java.util.Optional;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/producer/ProducerManagerTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/producer/ProducerManagerTest.java
index f715d8f..6ee03d1 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/producer/ProducerManagerTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/producer/ProducerManagerTest.java
@@ -17,6 +17,14 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.producer;
+import com.google.common.collect.Lists;
+import org.apache.mesos.Protos;
+import org.apache.mesos.SchedulerDriver;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.exception.AppConfigurationException;
+import org.apache.shardingsphere.elasticjob.cloud.exception.JobConfigurationException;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
@@ -24,17 +32,8 @@ import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobE
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudAppConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.disable.job.DisableJobService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
-import org.apache.shardingsphere.elasticjob.cloud.exception.AppConfigurationException;
-import org.apache.shardingsphere.elasticjob.cloud.exception.JobConfigurationException;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.app.CloudAppConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.ready.ReadyService;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
-import org.apache.mesos.Protos;
-import org.apache.mesos.SchedulerDriver;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -44,6 +43,7 @@ import org.unitils.util.ReflectionUtils;
import java.util.Arrays;
import java.util.List;
+import java.util.Optional;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -106,7 +106,7 @@ public final class ProducerManagerTest {
@Test(expected = AppConfigurationException.class)
public void assertRegisterJobWithoutApp() {
- when(appConfigService.load("test_app")).thenReturn(Optional.<CloudAppConfiguration>absent());
+ when(appConfigService.load("test_app")).thenReturn(Optional.empty());
producerManager.register(transientJobConfig);
}
@@ -126,7 +126,7 @@ public final class ProducerManagerTest {
@Test
public void assertRegisterTransientJob() {
when(appConfigService.load("test_app")).thenReturn(Optional.of(appConfig));
- when(configService.load("transient_test_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ when(configService.load("transient_test_job")).thenReturn(Optional.empty());
producerManager.register(transientJobConfig);
verify(configService).add(transientJobConfig);
verify(transientProducerScheduler).register(transientJobConfig);
@@ -135,7 +135,7 @@ public final class ProducerManagerTest {
@Test
public void assertRegisterDaemonJob() {
when(appConfigService.load("test_app")).thenReturn(Optional.of(appConfig));
- when(configService.load("daemon_test_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ when(configService.load("daemon_test_job")).thenReturn(Optional.empty());
producerManager.register(daemonJobConfig);
verify(configService).add(daemonJobConfig);
verify(readyService).addDaemon("daemon_test_job");
@@ -143,7 +143,7 @@ public final class ProducerManagerTest {
@Test(expected = JobConfigurationException.class)
public void assertUpdateNotExisted() {
- when(configService.load("transient_test_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ when(configService.load("transient_test_job")).thenReturn(Optional.empty());
producerManager.update(transientJobConfig);
}
@@ -164,7 +164,7 @@ public final class ProducerManagerTest {
@Test
public void assertDeregisterNotExisted() {
- when(configService.load("transient_test_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ when(configService.load("transient_test_job")).thenReturn(Optional.empty());
producerManager.deregister("transient_test_job");
verify(configService, times(0)).remove("transient_test_job");
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/AbstractCloudRestfulApiTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/AbstractCloudRestfulApiTest.java
index 4994f7c..4eb84ec 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/AbstractCloudRestfulApiTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/restful/AbstractCloudRestfulApiTest.java
@@ -17,20 +17,19 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.restful;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.MesosStateService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.ReconcileService;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.fixture.slave.MesosSlaveServerMock;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.restful.search.JobEventRdbSearch;
+import lombok.AccessLevel;
+import lombok.Getter;
+import org.apache.mesos.SchedulerDriver;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
+import org.apache.shardingsphere.elasticjob.cloud.restful.RestfulServer;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.RestfulServerConfiguration;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.FacadeService;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.MesosStateService;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.ReconcileService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.fixture.master.MesosMasterServerMock;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.mesos.fixture.slave.MesosSlaveServerMock;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.producer.ProducerManager;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import org.apache.shardingsphere.elasticjob.cloud.restful.RestfulServer;
-import com.google.common.base.Optional;
-import lombok.AccessLevel;
-import lombok.Getter;
-import org.apache.mesos.SchedulerDriver;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.restful.search.JobEventRdbSearch;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -74,9 +73,9 @@ public abstract class AbstractCloudRestfulApiTest {
private static void initMesosServer() throws Exception {
MesosStateService.register("127.0.0.1", 9050);
masterServer = new RestfulServer(9050);
- masterServer.start(MesosMasterServerMock.class.getPackage().getName(), Optional.absent(), Optional.absent());
+ masterServer.start(MesosMasterServerMock.class.getPackage().getName(), null, null);
slaveServer = new RestfulServer(9051);
- slaveServer.start(MesosSlaveServerMock.class.getPackage().getName(), Optional.absent(), Optional.absent());
+ slaveServer.start(MesosSlaveServerMock.class.getPackage().getName(), null, null);
}
@AfterClass
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/failover/FailoverServiceTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/failover/FailoverServiceTest.java
index 89303bc..ea65b66 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/failover/FailoverServiceTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/failover/FailoverServiceTest.java
@@ -17,18 +17,16 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.state.failover;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
+import com.google.common.collect.Lists;
import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.context.JobContext;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.BootstrapEnvironment;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.TaskNode;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Before;
@@ -42,8 +40,8 @@ import org.unitils.util.ReflectionUtils;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
@RunWith(MockitoJUnitRunner.class)
@@ -58,9 +56,6 @@ public final class FailoverServiceTest {
@Mock
private RunningService runningService;
- @Mock
- private List<String> mockedFailoverQueue;
-
private FailoverService failoverService;
@Before
@@ -120,13 +115,13 @@ public final class FailoverServiceTest {
public void assertGetAllEligibleJobContextsWithRootNode() {
Mockito.when(regCenter.isExisted("/state/failover")).thenReturn(true);
Mockito.when(regCenter.getChildrenKeys("/state/failover")).thenReturn(Arrays.asList("task_empty_job", "not_existed_job", "eligible_job"));
- Mockito.when(regCenter.getChildrenKeys("/state/failover/task_empty_job")).thenReturn(Collections.<String>emptyList());
+ Mockito.when(regCenter.getChildrenKeys("/state/failover/task_empty_job")).thenReturn(Collections.emptyList());
Mockito.when(regCenter.getChildrenKeys("/state/failover/not_existed_job")).thenReturn(Arrays.asList(
TaskNode.builder().jobName("not_existed_job").build().getTaskNodePath(), TaskNode.builder().jobName("not_existed_job").shardingItem(1).build().getTaskNodePath()));
String eligibleJobNodePath1 = TaskNode.builder().jobName("eligible_job").build().getTaskNodePath();
String eligibleJobNodePath2 = TaskNode.builder().jobName("eligible_job").shardingItem(1).build().getTaskNodePath();
Mockito.when(regCenter.getChildrenKeys("/state/failover/eligible_job")).thenReturn(Arrays.asList(eligibleJobNodePath1, eligibleJobNodePath2));
- Mockito.when(configService.load("not_existed_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ Mockito.when(configService.load("not_existed_job")).thenReturn(Optional.empty());
Mockito.when(configService.load("eligible_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("eligible_job")));
Mockito.when(runningService.isTaskRunning(TaskContext.MetaInfo.from(eligibleJobNodePath1))).thenReturn(true);
Mockito.when(runningService.isTaskRunning(TaskContext.MetaInfo.from(eligibleJobNodePath2))).thenReturn(false);
@@ -168,7 +163,7 @@ public final class FailoverServiceTest {
@Test
public void assertGetAllFailoverTasksWhenRootNodeHasNoChild() {
Mockito.when(regCenter.isExisted(FailoverNode.ROOT)).thenReturn(true);
- Mockito.when(regCenter.getChildrenKeys(FailoverNode.ROOT)).thenReturn(Collections.<String>emptyList());
+ Mockito.when(regCenter.getChildrenKeys(FailoverNode.ROOT)).thenReturn(Collections.emptyList());
Assert.assertTrue(failoverService.getAllFailoverTasks().isEmpty());
Mockito.verify(regCenter).isExisted(FailoverNode.ROOT);
Mockito.verify(regCenter).getChildrenKeys(FailoverNode.ROOT);
@@ -178,7 +173,7 @@ public final class FailoverServiceTest {
public void assertGetAllFailoverTasksWhenJobNodeHasNoChild() {
Mockito.when(regCenter.isExisted(FailoverNode.ROOT)).thenReturn(true);
Mockito.when(regCenter.getChildrenKeys(FailoverNode.ROOT)).thenReturn(Lists.newArrayList("test_job"));
- Mockito.when(regCenter.getChildrenKeys(FailoverNode.getFailoverJobNodePath("test_job"))).thenReturn(Collections.<String>emptyList());
+ Mockito.when(regCenter.getChildrenKeys(FailoverNode.getFailoverJobNodePath("test_job"))).thenReturn(Collections.emptyList());
Assert.assertTrue(failoverService.getAllFailoverTasks().isEmpty());
Mockito.verify(regCenter).isExisted(FailoverNode.ROOT);
Mockito.verify(regCenter).getChildrenKeys(FailoverNode.ROOT);
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/ready/ReadyServiceTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/ready/ReadyServiceTest.java
index eb965a6..ad347b2 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/ready/ReadyServiceTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/state/ready/ReadyServiceTest.java
@@ -17,17 +17,15 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.state.ready;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
+import com.google.common.collect.Lists;
import org.apache.shardingsphere.elasticjob.cloud.context.ExecutionType;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfiguration;
+import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobExecutionType;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.context.JobContext;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.env.BootstrapEnvironment;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
-import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import org.hamcrest.core.Is;
import org.junit.Assert;
import org.junit.Before;
@@ -41,8 +39,8 @@ import org.unitils.util.ReflectionUtils;
import java.util.Arrays;
import java.util.Collections;
-import java.util.List;
import java.util.Map;
+import java.util.Optional;
@RunWith(MockitoJUnitRunner.class)
public final class ReadyServiceTest {
@@ -56,9 +54,6 @@ public final class ReadyServiceTest {
@Mock
private RunningService runningService;
- @Mock
- private List<String> mockedReadyQueue;
-
private ReadyService readyService;
@Before
@@ -70,10 +65,10 @@ public final class ReadyServiceTest {
@Test
public void assertAddTransientWithJobConfigIsNotPresent() {
- Mockito.when(configService.load("test_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ Mockito.when(configService.load("test_job")).thenReturn(Optional.empty());
readyService.addTransient("test_job");
Mockito.verify(regCenter, Mockito.times(0)).isExisted("/state/ready");
- Mockito.verify(regCenter, Mockito.times(0)).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq(""));
+ Mockito.verify(regCenter, Mockito.times(0)).persist(ArgumentMatchers.any(), ArgumentMatchers.eq(""));
}
@Test
@@ -81,7 +76,7 @@ public final class ReadyServiceTest {
Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job", CloudJobExecutionType.DAEMON)));
readyService.addTransient("test_job");
Mockito.verify(regCenter, Mockito.times(0)).isExisted("/state/ready");
- Mockito.verify(regCenter, Mockito.times(0)).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq(""));
+ Mockito.verify(regCenter, Mockito.times(0)).persist(ArgumentMatchers.any(), ArgumentMatchers.eq(""));
}
@Test
@@ -123,10 +118,10 @@ public final class ReadyServiceTest {
@Test
public void assertAddDaemonWithJobConfigIsNotPresent() {
- Mockito.when(configService.load("test_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ Mockito.when(configService.load("test_job")).thenReturn(Optional.empty());
readyService.addDaemon("test_job");
Mockito.verify(regCenter, Mockito.times(0)).isExisted("/state/ready");
- Mockito.verify(regCenter, Mockito.times(0)).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("1"));
+ Mockito.verify(regCenter, Mockito.times(0)).persist(ArgumentMatchers.any(), ArgumentMatchers.eq("1"));
}
@Test
@@ -134,7 +129,7 @@ public final class ReadyServiceTest {
Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job")));
readyService.addDaemon("test_job");
Mockito.verify(regCenter, Mockito.times(0)).isExisted("/state/ready");
- Mockito.verify(regCenter, Mockito.times(0)).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("1"));
+ Mockito.verify(regCenter, Mockito.times(0)).persist(ArgumentMatchers.any(), ArgumentMatchers.eq("1"));
}
@Test
@@ -148,7 +143,7 @@ public final class ReadyServiceTest {
public void assertAddDaemonWithSameJobName() {
Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job", CloudJobExecutionType.DAEMON)));
readyService.addDaemon("test_job");
- Mockito.verify(regCenter).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("1"));
+ Mockito.verify(regCenter).persist(ArgumentMatchers.any(), ArgumentMatchers.eq("1"));
}
@Test
@@ -156,7 +151,7 @@ public final class ReadyServiceTest {
Mockito.when(configService.load("test_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job", CloudJobExecutionType.DAEMON)));
Mockito.when(runningService.isJobRunning("test_job")).thenReturn(true);
readyService.addDaemon("test_job");
- Mockito.verify(regCenter, Mockito.never()).persist((String) ArgumentMatchers.any(), ArgumentMatchers.eq("1"));
+ Mockito.verify(regCenter, Mockito.never()).persist(ArgumentMatchers.any(), ArgumentMatchers.eq("1"));
}
@Test
@@ -169,13 +164,13 @@ public final class ReadyServiceTest {
@Test
public void assertGetAllEligibleJobContextsWithoutRootNode() {
Mockito.when(regCenter.isExisted("/state/ready")).thenReturn(false);
- Assert.assertTrue(readyService.getAllEligibleJobContexts(Collections.<JobContext>emptyList()).isEmpty());
+ Assert.assertTrue(readyService.getAllEligibleJobContexts(Collections.emptyList()).isEmpty());
Mockito.verify(regCenter).isExisted("/state/ready");
}
@Test
public void assertSetMisfireDisabledWhenJobIsNotExisted() {
- Mockito.when(configService.load("test_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ Mockito.when(configService.load("test_job")).thenReturn(Optional.empty());
readyService.setMisfireDisabled("test_job");
Mockito.verify(regCenter, Mockito.times(0)).persist("/state/ready/test_job", "1");
}
@@ -199,7 +194,7 @@ public final class ReadyServiceTest {
public void assertGetAllEligibleJobContextsWithRootNode() {
Mockito.when(regCenter.isExisted("/state/ready")).thenReturn(true);
Mockito.when(regCenter.getChildrenKeys("/state/ready")).thenReturn(Arrays.asList("not_existed_job", "running_job", "ineligible_job", "eligible_job"));
- Mockito.when(configService.load("not_existed_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ Mockito.when(configService.load("not_existed_job")).thenReturn(Optional.empty());
Mockito.when(configService.load("running_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("running_job")));
Mockito.when(configService.load("eligible_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("eligible_job")));
Mockito.when(runningService.isJobRunning("running_job")).thenReturn(true);
@@ -218,10 +213,10 @@ public final class ReadyServiceTest {
public void assertGetAllEligibleJobContextsWithRootNodeAndDaemonJob() {
Mockito.when(regCenter.isExisted("/state/ready")).thenReturn(true);
Mockito.when(regCenter.getChildrenKeys("/state/ready")).thenReturn(Arrays.asList("not_existed_job", "running_job"));
- Mockito.when(configService.load("not_existed_job")).thenReturn(Optional.<CloudJobConfiguration>absent());
+ Mockito.when(configService.load("not_existed_job")).thenReturn(Optional.empty());
Mockito.when(configService.load("running_job")).thenReturn(Optional.of(CloudJobConfigurationBuilder.createCloudJobConfiguration("running_job", CloudJobExecutionType.DAEMON)));
Mockito.when(runningService.isJobRunning("running_job")).thenReturn(true);
- Assert.assertThat(readyService.getAllEligibleJobContexts(Collections.<JobContext>emptyList()).size(), Is.is(0));
+ Assert.assertThat(readyService.getAllEligibleJobContexts(Collections.emptyList()).size(), Is.is(0));
Mockito.verify(regCenter).isExisted("/state/ready");
Mockito.verify(regCenter, Mockito.times(1)).getChildrenKeys("/state/ready");
Mockito.verify(configService).load("not_existed_job");
@@ -244,18 +239,18 @@ public final class ReadyServiceTest {
Mockito.when(regCenter.isExisted(ReadyNode.ROOT)).thenReturn(false);
Assert.assertTrue(readyService.getAllReadyTasks().isEmpty());
Mockito.verify(regCenter).isExisted(ReadyNode.ROOT);
- Mockito.verify(regCenter, Mockito.times(0)).getChildrenKeys((String) ArgumentMatchers.any());
- Mockito.verify(regCenter, Mockito.times(0)).get((String) ArgumentMatchers.any());
+ Mockito.verify(regCenter, Mockito.times(0)).getChildrenKeys(ArgumentMatchers.any());
+ Mockito.verify(regCenter, Mockito.times(0)).get(ArgumentMatchers.any());
}
@Test
public void assertGetAllTasksWhenRootNodeHasNoChild() {
Mockito.when(regCenter.isExisted(ReadyNode.ROOT)).thenReturn(true);
- Mockito.when(regCenter.getChildrenKeys(ReadyNode.ROOT)).thenReturn(Collections.<String>emptyList());
+ Mockito.when(regCenter.getChildrenKeys(ReadyNode.ROOT)).thenReturn(Collections.emptyList());
Assert.assertTrue(readyService.getAllReadyTasks().isEmpty());
Mockito.verify(regCenter).isExisted(ReadyNode.ROOT);
Mockito.verify(regCenter).getChildrenKeys(ReadyNode.ROOT);
- Mockito.verify(regCenter, Mockito.times(0)).get((String) ArgumentMatchers.any());
+ Mockito.verify(regCenter, Mockito.times(0)).get(ArgumentMatchers.any());
}
@Test
@@ -281,6 +276,6 @@ public final class ReadyServiceTest {
Assert.assertThat(result.get("test_job_2"), Is.is(5));
Mockito.verify(regCenter).isExisted(ReadyNode.ROOT);
Mockito.verify(regCenter).getChildrenKeys(ReadyNode.ROOT);
- Mockito.verify(regCenter, Mockito.times(2)).get((String) ArgumentMatchers.any());
+ Mockito.verify(regCenter, Mockito.times(2)).get(ArgumentMatchers.any());
}
}
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/StatisticManagerTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/StatisticManagerTest.java
index 684ebac..ff25d81 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/StatisticManagerTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/StatisticManagerTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics;
-import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import org.apache.shardingsphere.elasticjob.cloud.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
@@ -29,7 +28,6 @@ import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRegiste
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRunningStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskResultStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskRunningStatistics;
-import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration;
import org.hamcrest.core.Is;
import org.junit.After;
import org.junit.Assert;
@@ -42,17 +40,17 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.unitils.util.ReflectionUtils;
import java.util.Date;
+import java.util.Optional;
+
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
-public class StatisticManagerTest {
+public final class StatisticManagerTest {
@Mock
private CoordinatorRegistryCenter regCenter;
@Mock
- private Optional<TracingConfiguration> tracingConfiguration;
-
- @Mock
private StatisticRdbRepository rdbRepository;
@Mock
@@ -65,7 +63,7 @@ public class StatisticManagerTest {
@Before
public void setUp() {
- statisticManager = StatisticManager.getInstance(regCenter, tracingConfiguration);
+ statisticManager = StatisticManager.getInstance(regCenter, null);
}
@After
@@ -78,7 +76,7 @@ public class StatisticManagerTest {
@Test
public void assertGetInstance() {
- Assert.assertThat(statisticManager, Is.is(StatisticManager.getInstance(regCenter, tracingConfiguration)));
+ Assert.assertThat(statisticManager, Is.is(StatisticManager.getInstance(regCenter, null)));
}
@Test
@@ -101,7 +99,7 @@ public class StatisticManagerTest {
}
@Test
- public void assertTaskRun() throws NoSuchFieldException {
+ public void assertTaskRun() {
statisticManager.taskRunSuccessfully();
statisticManager.taskRunFailed();
}
@@ -118,7 +116,7 @@ public class StatisticManagerTest {
@Test
public void assertTaskResultStatisticsWhenRdbIsConfigured() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
- Mockito.when(rdbRepository.getSummedTaskResultStatistics(Mockito.any(Date.class), Mockito.any(StatisticInterval.class)))
+ when(rdbRepository.getSummedTaskResultStatistics(Mockito.any(Date.class), Mockito.any(StatisticInterval.class)))
.thenReturn(new TaskResultStatistics(10, 10, StatisticInterval.DAY, new Date()));
Assert.assertThat(statisticManager.getTaskResultStatisticsWeekly().getSuccessCount(), Is.is(10));
Assert.assertThat(statisticManager.getTaskResultStatisticsWeekly().getFailedCount(), Is.is(10));
@@ -130,7 +128,7 @@ public class StatisticManagerTest {
@Test
public void assertJobTypeStatistics() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "configurationService", configurationService);
- Mockito.when(configurationService.loadAll()).thenReturn(Lists.newArrayList(
+ when(configurationService.loadAll()).thenReturn(Lists.newArrayList(
CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job_simple"),
CloudJobConfigurationBuilder.createDataflowCloudJobConfiguration("test_job_dataflow"),
CloudJobConfigurationBuilder.createScriptCloudJobConfiguration("test_job_script")));
@@ -143,7 +141,7 @@ public class StatisticManagerTest {
@Test
public void assertJobExecutionTypeStatistics() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "configurationService", configurationService);
- Mockito.when(configurationService.loadAll()).thenReturn(Lists.newArrayList(
+ when(configurationService.loadAll()).thenReturn(Lists.newArrayList(
CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job_1", CloudJobExecutionType.DAEMON),
CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job_2", CloudJobExecutionType.TRANSIENT)));
Assert.assertThat(statisticManager.getJobExecutionTypeStatistics().getDaemonJobCount(), Is.is(1));
@@ -160,7 +158,7 @@ public class StatisticManagerTest {
@Test
public void assertFindTaskRunningStatisticsWhenRdbIsConfigured() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
- Mockito.when(rdbRepository.findTaskRunningStatistics(Mockito.any(Date.class)))
+ when(rdbRepository.findTaskRunningStatistics(Mockito.any(Date.class)))
.thenReturn(Lists.newArrayList(new TaskRunningStatistics(10, new Date())));
Assert.assertThat(statisticManager.findTaskRunningStatisticsWeekly().size(), Is.is(1));
Mockito.verify(rdbRepository).findTaskRunningStatistics(Mockito.any(Date.class));
@@ -175,7 +173,7 @@ public class StatisticManagerTest {
@Test
public void assertFindJobRunningStatisticsWhenRdbIsConfigured() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
- Mockito.when(rdbRepository.findJobRunningStatistics(Mockito.any(Date.class)))
+ when(rdbRepository.findJobRunningStatistics(Mockito.any(Date.class)))
.thenReturn(Lists.newArrayList(new JobRunningStatistics(10, new Date())));
Assert.assertThat(statisticManager.findJobRunningStatisticsWeekly().size(), Is.is(1));
Mockito.verify(rdbRepository).findJobRunningStatistics(Mockito.any(Date.class));
@@ -190,7 +188,7 @@ public class StatisticManagerTest {
@Test
public void assertFindJobRegisterStatisticsWhenRdbIsConfigured() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
- Mockito.when(rdbRepository.findJobRegisterStatistics(Mockito.any(Date.class)))
+ when(rdbRepository.findJobRegisterStatistics(Mockito.any(Date.class)))
.thenReturn(Lists.newArrayList(new JobRegisterStatistics(10, new Date())));
Assert.assertThat(statisticManager.findJobRegisterStatisticsSinceOnline().size(), Is.is(1));
Mockito.verify(rdbRepository).findJobRegisterStatistics(Mockito.any(Date.class));
@@ -210,7 +208,7 @@ public class StatisticManagerTest {
public void assertFindLatestTaskResultStatisticsWhenRdbIsConfigured() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
for (StatisticInterval each : StatisticInterval.values()) {
- Mockito.when(rdbRepository.findLatestTaskResultStatistics(each))
+ when(rdbRepository.findLatestTaskResultStatistics(each))
.thenReturn(Optional.of(new TaskResultStatistics(10, 5, each, new Date())));
TaskResultStatistics actual = statisticManager.findLatestTaskResultStatistics(each);
Assert.assertThat(actual.getSuccessCount(), Is.is(10));
@@ -228,7 +226,7 @@ public class StatisticManagerTest {
@Test
public void assertFindTaskResultStatisticsDailyWhenRdbIsConfigured() throws NoSuchFieldException {
ReflectionUtils.setFieldValue(statisticManager, "rdbRepository", rdbRepository);
- Mockito.when(rdbRepository.findTaskResultStatistics(Mockito.any(Date.class), Mockito.any(StatisticInterval.class)))
+ when(rdbRepository.findTaskResultStatistics(Mockito.any(Date.class), Mockito.any(StatisticInterval.class)))
.thenReturn(Lists.newArrayList(new TaskResultStatistics(10, 5, StatisticInterval.MINUTE, new Date())));
Assert.assertThat(statisticManager.findTaskResultStatisticsDaily().size(), Is.is(1));
Mockito.verify(rdbRepository).findTaskResultStatistics(Mockito.any(Date.class), Mockito.any(StatisticInterval.class));
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/JobRunningStatisticJobTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/JobRunningStatisticJobTest.java
index dab554b..051d34a 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/JobRunningStatisticJobTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/JobRunningStatisticJobTest.java
@@ -17,19 +17,13 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
+import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.TaskNode;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.state.running.RunningService;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.util.StatisticTimeUtils;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
-import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRunningStatistics;
-import org.apache.shardingsphere.elasticjob.cloud.context.TaskContext;
import org.apache.shardingsphere.elasticjob.cloud.statistics.rdb.StatisticRdbRepository;
+import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRunningStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskRunningStatistics;
import org.hamcrest.core.Is;
import org.junit.Assert;
@@ -43,7 +37,12 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
-import com.google.common.base.Optional;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
@RunWith(MockitoJUnitRunner.class)
public class JobRunningStatisticJobTest {
@@ -69,26 +68,26 @@ public class JobRunningStatisticJobTest {
}
@Test
- public void assertBuildTrigger() throws SchedulerException {
+ public void assertBuildTrigger() {
Trigger trigger = jobRunningStatisticJob.buildTrigger();
Assert.assertThat(trigger.getKey().getName(), Is.is(JobRunningStatisticJob.class.getSimpleName() + "Trigger"));
}
@Test
- public void assertGetDataMap() throws SchedulerException {
- Assert.assertThat((RunningService) jobRunningStatisticJob.getDataMap().get("runningService"), Is.is(runningService));
- Assert.assertThat((StatisticRdbRepository) jobRunningStatisticJob.getDataMap().get("repository"), Is.is(repository));
+ public void assertGetDataMap() {
+ Assert.assertThat(jobRunningStatisticJob.getDataMap().get("runningService"), Is.is(runningService));
+ Assert.assertThat(jobRunningStatisticJob.getDataMap().get("repository"), Is.is(repository));
}
@Test
public void assertExecuteWhenRepositoryIsEmpty() throws SchedulerException {
- Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.absent();
- Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.absent();
+ Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.empty();
+ Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.empty();
Mockito.when(repository.findLatestJobRunningStatistics()).thenReturn(latestJobRunningStatistics);
Mockito.when(repository.findLatestTaskRunningStatistics()).thenReturn(latestTaskRunningStatistics);
Mockito.when(repository.add(ArgumentMatchers.any(JobRunningStatistics.class))).thenReturn(true);
Mockito.when(repository.add(ArgumentMatchers.any(TaskRunningStatistics.class))).thenReturn(true);
- Mockito.when(runningService.getAllRunningTasks()).thenReturn(Collections.<String, Set<TaskContext>>emptyMap());
+ Mockito.when(runningService.getAllRunningTasks()).thenReturn(Collections.emptyMap());
jobRunningStatisticJob.execute(null);
Mockito.verify(repository).findLatestJobRunningStatistics();
Mockito.verify(repository).add(ArgumentMatchers.any(JobRunningStatistics.class));
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/RegisteredJobStatisticJobTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/RegisteredJobStatisticJobTest.java
index c37b173..12043d8 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/RegisteredJobStatisticJobTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/RegisteredJobStatisticJobTest.java
@@ -17,14 +17,13 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job;
-import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
+import com.google.common.collect.Lists;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.config.job.CloudJobConfigurationService;
+import org.apache.shardingsphere.elasticjob.cloud.scheduler.fixture.CloudJobConfigurationBuilder;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.util.StatisticTimeUtils;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
import org.apache.shardingsphere.elasticjob.cloud.statistics.rdb.StatisticRdbRepository;
import org.apache.shardingsphere.elasticjob.cloud.statistics.type.job.JobRegisterStatistics;
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,6 +32,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
+import java.util.Optional;
+
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.any;
@@ -64,20 +65,20 @@ public class RegisteredJobStatisticJobTest {
}
@Test
- public void assertBuildTrigger() throws SchedulerException {
+ public void assertBuildTrigger() {
Trigger trigger = registeredJobStatisticJob.buildTrigger();
assertThat(trigger.getKey().getName(), is(RegisteredJobStatisticJob.class.getSimpleName() + "Trigger"));
}
@Test
- public void assertGetDataMap() throws SchedulerException {
- assertThat((CloudJobConfigurationService) registeredJobStatisticJob.getDataMap().get("configurationService"), is(configurationService));
- assertThat((StatisticRdbRepository) registeredJobStatisticJob.getDataMap().get("repository"), is(repository));
+ public void assertGetDataMap() {
+ assertThat(registeredJobStatisticJob.getDataMap().get("configurationService"), is(configurationService));
+ assertThat(registeredJobStatisticJob.getDataMap().get("repository"), is(repository));
}
@Test
public void assertExecuteWhenRepositoryIsEmpty() throws SchedulerException {
- Optional<JobRegisterStatistics> latestOne = Optional.absent();
+ Optional<JobRegisterStatistics> latestOne = Optional.empty();
when(repository.findLatestJobRegisterStatistics()).thenReturn(latestOne);
when(repository.add(any(JobRegisterStatistics.class))).thenReturn(true);
when(configurationService.loadAll()).thenReturn(Lists.newArrayList(CloudJobConfigurationBuilder.createCloudJobConfiguration("test_job")));
diff --git a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/TaskResultStatisticJobTest.java b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/TaskResultStatisticJobTest.java
index 47ce2c0..3374c99 100755
--- a/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/TaskResultStatisticJobTest.java
+++ b/elasticjob-cloud/elasticjob-cloud-scheduler/src/test/java/org/apache/shardingsphere/elasticjob/cloud/scheduler/statistics/job/TaskResultStatisticJobTest.java
@@ -17,18 +17,11 @@
package org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.job;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.TaskResultMetaData;
import org.apache.shardingsphere.elasticjob.cloud.scheduler.statistics.util.StatisticTimeUtils;
-import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskResultStatistics;
import org.apache.shardingsphere.elasticjob.cloud.statistics.StatisticInterval;
import org.apache.shardingsphere.elasticjob.cloud.statistics.rdb.StatisticRdbRepository;
+import org.apache.shardingsphere.elasticjob.cloud.statistics.type.task.TaskResultStatistics;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -37,7 +30,14 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
-import com.google.common.base.Optional;
+import java.util.Optional;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class TaskResultStatisticJobTest {
@@ -66,7 +66,7 @@ public class TaskResultStatisticJobTest {
}
@Test
- public void assertBuildTrigger() throws SchedulerException {
+ public void assertBuildTrigger() {
for (StatisticInterval each : StatisticInterval.values()) {
taskResultStatisticJob.setStatisticInterval(each);
Trigger trigger = taskResultStatisticJob.buildTrigger();
@@ -75,15 +75,15 @@ public class TaskResultStatisticJobTest {
}
@Test
- public void assertGetDataMap() throws SchedulerException {
- assertThat((StatisticInterval) taskResultStatisticJob.getDataMap().get("statisticInterval"), is(statisticInterval));
- assertThat((TaskResultMetaData) taskResultStatisticJob.getDataMap().get("sharedData"), is(sharedData));
- assertThat((StatisticRdbRepository) taskResultStatisticJob.getDataMap().get("repository"), is(repository));
+ public void assertGetDataMap() {
+ assertThat(taskResultStatisticJob.getDataMap().get("statisticInterval"), is(statisticInterval));
+ assertThat(taskResultStatisticJob.getDataMap().get("sharedData"), is(sharedData));
+ assertThat(taskResultStatisticJob.getDataMap().get("repository"), is(repository));
}
@Test
public void assertExecuteWhenRepositoryIsEmpty() throws SchedulerException {
- Optional<TaskResultStatistics> latestOne = Optional.absent();
+ Optional<TaskResultStatistics> latestOne = Optional.empty();
for (StatisticInterval each : StatisticInterval.values()) {
taskResultStatisticJob.setStatisticInterval(each);
when(repository.findLatestTaskResultStatistics(each)).thenReturn(latestOne);
diff --git a/examples/elasticjob-example-embed-zk/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/EmbedZookeeperServer.java b/examples/elasticjob-example-embed-zk/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/EmbedZookeeperServer.java
index 931a7ba..88b0bcb 100644
--- a/examples/elasticjob-example-embed-zk/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/EmbedZookeeperServer.java
+++ b/examples/elasticjob-example-embed-zk/src/main/java/org/apache/shardingsphere/elasticjob/lite/example/EmbedZookeeperServer.java
@@ -46,17 +46,13 @@ public final class EmbedZookeeperServer {
// CHECKSTYLE:ON
ex.printStackTrace();
} finally {
- Runtime.getRuntime().addShutdownHook(new Thread() {
-
- @Override
- public void run() {
- try {
- Thread.sleep(1000L);
- testingServer.close();
- } catch (final InterruptedException | IOException ex) {
- }
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try {
+ Thread.sleep(1000L);
+ testingServer.close();
+ } catch (final InterruptedException | IOException ignore) {
}
- });
+ }));
}
}
}