Skip to content

Commit

Permalink
checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Feb 16, 2017
1 parent a298501 commit 368170e
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public final class Bootstrap {
* 启动入口.
*
* @param args 命令行参数无需传入
* @throws InterruptedException 线程中断异常
*/
// CHECKSTYLE:OFF
public static void main(final String[] args) throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public void trigger(final String jobName) {
* 查询作业详情.
*
* @param jobName 作业名称
* @return 作业配置对象
*/
@GET
@Path("/jobs/{jobName}")
Expand Down Expand Up @@ -256,6 +257,7 @@ public Collection<FailoverTaskInfo> findAllFailoverTasks() {
/**
* 检索作业运行轨迹.
*
* @param info URL信息
* @return 作业运行轨迹结果
* @throws ParseException
*/
Expand All @@ -272,6 +274,7 @@ public Result<JobExecutionEvent> findJobExecutionEvents(@Context final UriInfo i
/**
* 检索作业运行状态轨迹.
*
* @param info URL信息
* @return 作业运行轨迹结果
* @throws ParseException 转换异常
*/
Expand Down Expand Up @@ -326,6 +329,7 @@ private Map<String, Object> getQueryParameters(final UriInfo info, final String[
/**
* 获取任务运行结果统计数据.
*
* @param since 时间跨度
* @return 任务运行结果统计数据
*/
@GET
Expand All @@ -342,6 +346,7 @@ public List<TaskResultStatistics> findTaskResultStatistics(@QueryParam("since")
/**
* 获取任务运行结果统计数据.
*
* @param period 时间跨度
* @return 任务运行结果统计数据
*/
@GET
Expand All @@ -364,6 +369,7 @@ public TaskResultStatistics getTaskResultStatistics(@PathParam("period") final S
/**
* 获取任务运行统计数据集合.
*
* @param since 时间跨度
* @return 任务运行统计数据集合
*/
@GET
Expand Down Expand Up @@ -404,6 +410,7 @@ public JobExecutionTypeStatistics getJobExecutionTypeStatistics() {
/**
* 获取一周以来作业运行统计数据集合.
*
* @param since 时间跨度
* @return 一周以来任务运行统计数据集合
*/
@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ private StatisticManager(final CoordinatorRegistryCenter registryCenter, final O

/**
* 获取统计作业调度管理器.
*
*
* @param regCenter 注册中心
* @param jobEventRdbConfiguration 作业数据库事件配置
* @return 调度管理器对象
*/
public static StatisticManager getInstance(final CoordinatorRegistryCenter regCenter, final Optional<JobEventRdbConfiguration> jobEventRdbConfiguration) {
Expand Down Expand Up @@ -182,6 +184,7 @@ public TaskResultStatistics getTaskResultStatisticsSinceOnline() {
/**
* 获取最近一个统计周期的任务运行结果统计数据.
*
* @param statisticInterval 统计周期
* @return 任务运行结果统计数据对象
*/
public TaskResultStatistics findLatestTaskResultStatistics(final StatisticInterval statisticInterval) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public Map<String, Object> getDataMap() {

@Override
public void execute(final JobExecutionContext context) throws JobExecutionException {
Map<String, Set<TaskContext>> allRunnintTasks = runningService.getAllRunningTasks();
statisticJob(getJobRunningCount(allRunnintTasks));
statisticTask(getTaskRunningCount(allRunnintTasks));
Map<String, Set<TaskContext>> allRunningTasks = runningService.getAllRunningTasks();
statisticJob(getJobRunningCount(allRunningTasks));
statisticTask(getTaskRunningCount(allRunningTasks));
}

private void statisticJob(final int runningCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ public void assertRemove() {
configService.remove("test_app");
verify(regCenter).remove("/config/app/test_app");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
CloudJobConfigurationNodeTest.class,
CloudJobConfigurationServiceTest.class,
CloudJobConfigurationListenerTest.class
})
})
public class AllCloudJobConfigTests {
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ public final class CloudAppConfigurationBuilder {
public static CloudAppConfiguration createCloudAppConfiguration(final String appName) {
return new CloudAppConfiguration(appName, "http://localhost/app.jar", "bin/start.sh");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class CloudAppJsonConstants {

private static final String APP_JSON = "{\"appName\":\"%s\",\"appURL\":\"http://localhost/app.jar\",\"bootstrapScript\":\"bin/start.sh\"," +
"\"cpuCount\":1.0,\"memoryMB\":128.0,\"appCacheEnable\":true,\"eventTraceSamplingCount\":0}";
private static final String APP_JSON = "{\"appName\":\"%s\",\"appURL\":\"http://localhost/app.jar\",\"bootstrapScript\":\"bin/start.sh\","
+ "\"cpuCount\":1.0,\"memoryMB\":128.0,\"appCacheEnable\":true,\"eventTraceSamplingCount\":0}";

public static String getAppJson(final String appName) {
return String.format(APP_JSON, appName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static CloudJobConfiguration createCloudJobConfiguration(final String job
1.0d, 128.0d, jobExecutionType);
}

public static CloudJobConfiguration createCloudJobConfiguration(final String jobName, final CloudJobExecutionType jobExecutionType, int shardingTotalCount) {
public static CloudJobConfiguration createCloudJobConfiguration(final String jobName, final CloudJobExecutionType jobExecutionType, final int shardingTotalCount) {
return new CloudJobConfiguration("test_app",
new SimpleJobConfiguration(JobCoreConfiguration.newBuilder(jobName, "0/30 * * * * ?", shardingTotalCount).failover(true).misfire(true).build(), TestSimpleJob.class.getCanonicalName()),
1.0d, 128.0d, jobExecutionType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public void assertRunOneIterationWithScriptJob() throws Exception {

private TaskAssignmentResult mockTaskAssignmentResult(final String taskName, final ExecutionType executionType) {
TaskAssignmentResult result = mock(TaskAssignmentResult.class);
TaskRequest taskRequest = new JobTaskRequest(new TaskContext(taskName, Lists.newArrayList(0), executionType, "unassigned-slave"), CloudJobConfigurationBuilder.createCloudJobConfiguration(taskName));
TaskRequest taskRequest = new JobTaskRequest(
new TaskContext(taskName, Lists.newArrayList(0), executionType, "unassigned-slave"), CloudJobConfigurationBuilder.createCloudJobConfiguration(taskName));
when(result.getTaskId()).thenReturn(String.format("%s@-@0@-@%s@-@unassigned-slave@-@0", taskName, executionType.name()));
when(result.getHostname()).thenReturn("localhost");
when(result.getAssignedPorts()).thenReturn(Lists.newArrayList(1234));
Expand All @@ -136,7 +137,6 @@ private TaskAssignmentResult mockTaskAssignmentResult(final String taskName, fin
return result;
}


@Test
public void assertScheduler() throws Exception {
assertThat(taskLaunchScheduledService.scheduler(), instanceOf(Scheduler.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.dangdang.ddframe.job.cloud.scheduler.producer.ProducerManager;
import com.dangdang.ddframe.job.event.rdb.JobEventRdbSearch;
import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter;
import lombok.AccessLevel;
import lombok.Getter;
import org.apache.mesos.SchedulerDriver;
import org.junit.AfterClass;
import org.junit.Before;
Expand All @@ -34,11 +36,13 @@
@RunWith(MockitoJUnitRunner.class)
public abstract class AbstractCloudRestfulApiTest {

protected static CoordinatorRegistryCenter regCenter;
@Getter(AccessLevel.PROTECTED)
private static CoordinatorRegistryCenter regCenter;

protected static JobEventRdbSearch jobEventRdbSearch;
@Getter(AccessLevel.PROTECTED)
private static JobEventRdbSearch jobEventRdbSearch;

protected static RestfulService restfulService;
private static RestfulService restfulService;

@BeforeClass
public static void setUpClass() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ public final class CloudAppRestfulApiTest extends AbstractCloudRestfulApiTest {

@Test
public void assertRegister() throws Exception {
when(regCenter.isExisted("/config/app/test_app")).thenReturn(false);
when(getRegCenter().isExisted("/config/app/test_app")).thenReturn(false);
assertThat(sentRequest("http://127.0.0.1:19000/app", "POST", CloudAppJsonConstants.getAppJson("test_app")), is(204));
verify(regCenter).persist("/config/app/test_app", CloudAppJsonConstants.getAppJson("test_app"));
verify(getRegCenter()).persist("/config/app/test_app", CloudAppJsonConstants.getAppJson("test_app"));
sentRequest("http://127.0.0.1:19000/app", "DELETE", "test_app");
}

@Test
public void assertRegisterWithExistedName() throws Exception {
when(regCenter.isExisted("/config/app/test_app")).thenReturn(false);
when(getRegCenter().isExisted("/config/app/test_app")).thenReturn(false);
assertThat(sentRequest("http://127.0.0.1:19000/app", "POST", CloudAppJsonConstants.getAppJson("test_app")), is(204));
when(regCenter.get("/config/app/test_app")).thenReturn(CloudAppJsonConstants.getAppJson("test_app"));
when(getRegCenter().get("/config/app/test_app")).thenReturn(CloudAppJsonConstants.getAppJson("test_app"));
assertThat(sentRequest("http://127.0.0.1:19000/app", "POST", CloudAppJsonConstants.getAppJson("test_app")), is(500));
sentRequest("http://127.0.0.1:19000/app", "DELETE", "test_app");
}
Expand All @@ -57,18 +57,18 @@ public void assertRegisterWithBadRequest() throws Exception {

@Test
public void assertUpdate() throws Exception {
when(regCenter.isExisted("/config/app/test_app")).thenReturn(true);
when(regCenter.get("/config/app/test_app")).thenReturn(CloudAppJsonConstants.getAppJson("test_app"));
when(getRegCenter().isExisted("/config/app/test_app")).thenReturn(true);
when(getRegCenter().get("/config/app/test_app")).thenReturn(CloudAppJsonConstants.getAppJson("test_app"));
assertThat(sentRequest("http://127.0.0.1:19000/app", "PUT", CloudAppJsonConstants.getAppJson("test_app")), is(204));
verify(regCenter).update("/config/app/test_app", CloudAppJsonConstants.getAppJson("test_app"));
verify(getRegCenter()).update("/config/app/test_app", CloudAppJsonConstants.getAppJson("test_app"));
sentRequest("http://127.0.0.1:19000/app", "DELETE", "test_app");
}

@Test
public void assertDetail() throws Exception {
when(regCenter.get("/config/app/test_app")).thenReturn(CloudAppJsonConstants.getAppJson("test_app"));
when(getRegCenter().get("/config/app/test_app")).thenReturn(CloudAppJsonConstants.getAppJson("test_app"));
assertThat(sentGetRequest("http://127.0.0.1:19000/app/test_app"), is(CloudAppJsonConstants.getAppJson("test_app")));
verify(regCenter).get("/config/app/test_app");
verify(getRegCenter()).get("/config/app/test_app");
}

@Test
Expand All @@ -78,12 +78,12 @@ public void assertDetailWithNotExistedJob() throws Exception {

@Test
public void assertFindAllJobs() throws Exception {
when(regCenter.isExisted("/config/app")).thenReturn(true);
when(regCenter.getChildrenKeys("/config/app")).thenReturn(Lists.newArrayList("test_app"));
when(regCenter.get("/config/app/test_app")).thenReturn(CloudAppJsonConstants.getAppJson("test_app"));
when(getRegCenter().isExisted("/config/app")).thenReturn(true);
when(getRegCenter().getChildrenKeys("/config/app")).thenReturn(Lists.newArrayList("test_app"));
when(getRegCenter().get("/config/app/test_app")).thenReturn(CloudAppJsonConstants.getAppJson("test_app"));
assertThat(sentGetRequest("http://127.0.0.1:19000/app/list"), is("[" + CloudAppJsonConstants.getAppJson("test_app") + "]"));
verify(regCenter).isExisted("/config/app");
verify(regCenter).getChildrenKeys("/config/app");
verify(regCenter).get("/config/app/test_app");
verify(getRegCenter()).isExisted("/config/app");
verify(getRegCenter()).getChildrenKeys("/config/app");
verify(getRegCenter()).get("/config/app/test_app");
}
}
}
Loading

0 comments on commit 368170e

Please sign in to comment.