Browse Source

Adapting partial code(file name start with T) to the sonar cloud rule (#2271)

pull/2/head
gabry.wu 5 years ago committed by GitHub
parent
commit
d83a94a305
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/TaskCountDto.java
  2. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
  3. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskRecordService.java
  4. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java
  5. 2
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java
  6. 6
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java
  7. 36
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/thread/ThreadPoolExecutors.java
  8. 8
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java
  9. 4
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java
  10. 4
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
  11. 4
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java
  12. 2
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskScheduleThread.java
  13. 6
      dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/queue/TaskQueueZkImpl.java
  14. 24
      dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/queue/TaskQueueZKImplTest.java

36
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/dto/TaskCountDto.java

@ -43,36 +43,36 @@ public class TaskCountDto {
} }
private void countTaskDtos(List<ExecuteStatusCount> taskInstanceStateCounts){ private void countTaskDtos(List<ExecuteStatusCount> taskInstanceStateCounts){
int submitted_success = 0; int submittedSuccess = 0;
int running_exeution = 0; int runningExeution = 0;
int ready_pause = 0; int readyPause = 0;
int pause = 0; int pause = 0;
int ready_stop = 0; int readyStop = 0;
int stop = 0; int stop = 0;
int failure = 0; int failure = 0;
int success = 0; int success = 0;
int need_fault_tolerance = 0; int needFaultTolerance = 0;
int kill = 0; int kill = 0;
int waitting_thread = 0; int waittingThread = 0;
for(ExecuteStatusCount taskInstanceStateCount : taskInstanceStateCounts){ for(ExecuteStatusCount taskInstanceStateCount : taskInstanceStateCounts){
ExecutionStatus status = taskInstanceStateCount.getExecutionStatus(); ExecutionStatus status = taskInstanceStateCount.getExecutionStatus();
totalCount += taskInstanceStateCount.getCount(); totalCount += taskInstanceStateCount.getCount();
switch (status){ switch (status){
case SUBMITTED_SUCCESS: case SUBMITTED_SUCCESS:
submitted_success += taskInstanceStateCount.getCount(); submittedSuccess += taskInstanceStateCount.getCount();
break; break;
case RUNNING_EXEUTION: case RUNNING_EXEUTION:
running_exeution += taskInstanceStateCount.getCount(); runningExeution += taskInstanceStateCount.getCount();
break; break;
case READY_PAUSE: case READY_PAUSE:
ready_pause += taskInstanceStateCount.getCount(); readyPause += taskInstanceStateCount.getCount();
break; break;
case PAUSE: case PAUSE:
pause += taskInstanceStateCount.getCount(); pause += taskInstanceStateCount.getCount();
break; break;
case READY_STOP: case READY_STOP:
ready_stop += taskInstanceStateCount.getCount(); readyStop += taskInstanceStateCount.getCount();
break; break;
case STOP: case STOP:
stop += taskInstanceStateCount.getCount(); stop += taskInstanceStateCount.getCount();
@ -84,13 +84,13 @@ public class TaskCountDto {
success += taskInstanceStateCount.getCount(); success += taskInstanceStateCount.getCount();
break; break;
case NEED_FAULT_TOLERANCE: case NEED_FAULT_TOLERANCE:
need_fault_tolerance += taskInstanceStateCount.getCount(); needFaultTolerance += taskInstanceStateCount.getCount();
break; break;
case KILL: case KILL:
kill += taskInstanceStateCount.getCount(); kill += taskInstanceStateCount.getCount();
break; break;
case WAITTING_THREAD: case WAITTING_THREAD:
waitting_thread += taskInstanceStateCount.getCount(); waittingThread += taskInstanceStateCount.getCount();
break; break;
default: default:
@ -98,17 +98,17 @@ public class TaskCountDto {
} }
} }
this.taskCountDtos = new ArrayList<>(); this.taskCountDtos = new ArrayList<>();
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUBMITTED_SUCCESS, submitted_success)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUBMITTED_SUCCESS, submittedSuccess));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.RUNNING_EXEUTION, running_exeution)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.RUNNING_EXEUTION, runningExeution));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_PAUSE, ready_pause)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_PAUSE, readyPause));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.PAUSE, pause)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.PAUSE, pause));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_STOP, ready_stop)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.READY_STOP, readyStop));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.STOP, stop)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.STOP, stop));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.FAILURE, failure)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.FAILURE, failure));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUCCESS, success)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.SUCCESS, success));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.NEED_FAULT_TOLERANCE, need_fault_tolerance)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.NEED_FAULT_TOLERANCE, needFaultTolerance));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.KILL, kill)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.KILL, kill));
this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.WAITTING_THREAD, waitting_thread)); this.taskCountDtos.add(new TaskStateCount(ExecutionStatus.WAITTING_THREAD, waittingThread));
} }

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java

@ -32,8 +32,6 @@ import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper;
import org.apache.dolphinscheduler.service.process.ProcessService; import org.apache.dolphinscheduler.service.process.ProcessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -46,8 +44,6 @@ import java.util.*;
@Service @Service
public class TaskInstanceService extends BaseService { public class TaskInstanceService extends BaseService {
private static final Logger logger = LoggerFactory.getLogger(TaskInstanceService.class);
@Autowired @Autowired
ProjectMapper projectMapper; ProjectMapper projectMapper;

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskRecordService.java

@ -21,8 +21,6 @@ import org.apache.dolphinscheduler.api.utils.PageInfo;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.dao.TaskRecordDao; import org.apache.dolphinscheduler.dao.TaskRecordDao;
import org.apache.dolphinscheduler.dao.entity.TaskRecord; import org.apache.dolphinscheduler.dao.entity.TaskRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap; import java.util.HashMap;
@ -37,8 +35,6 @@ import static org.apache.dolphinscheduler.common.Constants.*;
@Service @Service
public class TaskRecordService extends BaseService{ public class TaskRecordService extends BaseService{
private static final Logger logger = LoggerFactory.getLogger(TaskRecordService.class);
/** /**
* query task record list paging * query task record list paging
* *

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TenantService.java

@ -310,7 +310,7 @@ public class TenantService extends BaseService{
Map<String, Object> result = new HashMap<>(5); Map<String, Object> result = new HashMap<>(5);
List<Tenant> resourceList = tenantMapper.queryByTenantCode(tenantCode); List<Tenant> resourceList = tenantMapper.queryByTenantCode(tenantCode);
if (resourceList != null && resourceList.size() > 0) { if (CollectionUtils.isNotEmpty(resourceList)) {
result.put(Constants.DATA_LIST, resourceList); result.put(Constants.DATA_LIST, resourceList);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
} else { } else {
@ -346,6 +346,6 @@ public class TenantService extends BaseService{
*/ */
private boolean checkTenantExists(String tenantCode) { private boolean checkTenantExists(String tenantCode) {
List<Tenant> tenants = tenantMapper.queryByTenantCode(tenantCode); List<Tenant> tenants = tenantMapper.queryByTenantCode(tenantCode);
return (tenants != null && tenants.size() > 0); return CollectionUtils.isNotEmpty(tenants);
} }
} }

2
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/enums/TaskStateType.java

@ -60,7 +60,7 @@ public enum TaskStateType {
default: default:
break; break;
} }
return null; return new int[0];
} }
} }

6
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/model/TaskNode.java

@ -293,14 +293,14 @@ public class TaskNode {
public TaskTimeoutParameter getTaskTimeoutParameter() { public TaskTimeoutParameter getTaskTimeoutParameter() {
if(StringUtils.isNotEmpty(this.getTimeout())){ if(StringUtils.isNotEmpty(this.getTimeout())){
String formatStr = String.format("%s,%s", TaskTimeoutStrategy.WARN.name(), TaskTimeoutStrategy.FAILED.name()); String formatStr = String.format("%s,%s", TaskTimeoutStrategy.WARN.name(), TaskTimeoutStrategy.FAILED.name());
String timeout = this.getTimeout().replace(formatStr,TaskTimeoutStrategy.WARNFAILED.name()); String taskTimeout = this.getTimeout().replace(formatStr,TaskTimeoutStrategy.WARNFAILED.name());
return JSON.parseObject(timeout,TaskTimeoutParameter.class); return JSON.parseObject(taskTimeout,TaskTimeoutParameter.class);
} }
return new TaskTimeoutParameter(false); return new TaskTimeoutParameter(false);
} }
public boolean isConditionsTask(){ public boolean isConditionsTask(){
return this.getType().toUpperCase().equals(TaskType.CONDITIONS.toString()); return TaskType.CONDITIONS.toString().equalsIgnoreCase(this.getType());
} }
@Override @Override

36
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/thread/ThreadPoolExecutors.java

@ -74,21 +74,21 @@ public class ThreadPoolExecutors {
* @param event * @param event
*/ */
public void execute(final Runnable event) { public void execute(final Runnable event) {
Executor executor = getExecutor(); Executor eventExecutor = getExecutor();
if (executor == null) { if (eventExecutor == null) {
logger.error("Cannot execute [" + event + "] because the executor is missing."); logger.error("Cannot execute [{}}] because the executor is missing.", event);
} else { } else {
executor.execute(event); eventExecutor.execute(event);
} }
} }
public Future<?> submit(Runnable event) { public Future<?> submit(Runnable event) {
Executor executor = getExecutor(); Executor eventExecutor = getExecutor();
if (executor == null) { if (eventExecutor == null) {
logger.error("Cannot submit [" + event + "] because the executor is missing."); logger.error("Cannot submit [{}}] because the executor is missing.", event);
} else { } else {
return executor.submit(event); return eventExecutor.submit(event);
} }
return null; return null;
@ -97,11 +97,11 @@ public class ThreadPoolExecutors {
public Future<?> submit(Callable<?> task) { public Future<?> submit(Callable<?> task) {
Executor executor = getExecutor(); Executor taskExecutor = getExecutor();
if (executor == null) { if (taskExecutor == null) {
logger.error("Cannot submit [" + task + "] because the executor is missing."); logger.error("Cannot submit [{}] because the executor is missing.", task);
} else { } else {
return executor.submit(task); return taskExecutor.submit(task);
} }
return null; return null;
@ -110,8 +110,8 @@ public class ThreadPoolExecutors {
public void printStatus() { public void printStatus() {
Executor executor = getExecutor(); Executor printExecutor = getExecutor();
executor.getStatus().dumpInfo(); printExecutor.getStatus().dumpInfo();
} }
@ -125,7 +125,7 @@ public class ThreadPoolExecutors {
List<Runnable> wasRunning = executor.threadPoolExecutor List<Runnable> wasRunning = executor.threadPoolExecutor
.shutdownNow(); .shutdownNow();
if (!wasRunning.isEmpty()) { if (!wasRunning.isEmpty()) {
logger.info(executor + " had " + wasRunning + " on shutdown"); logger.info("{} had {} on shutdown", executor, wasRunning);
} }
} }
} }
@ -138,7 +138,7 @@ public class ThreadPoolExecutors {
/** /**
* how long to retain excess threads * how long to retain excess threads
*/ */
final long keepAliveTimeInMillis = 1000; static final long KEEP_ALIVE_TIME_IN_MILLIS = 1000;
/** /**
* the thread pool executor that services the requests * the thread pool executor that services the requests
*/ */
@ -146,7 +146,7 @@ public class ThreadPoolExecutors {
/** /**
* work queue to use - unbounded queue * work queue to use - unbounded queue
*/ */
final BlockingQueue<Runnable> q = new LinkedBlockingQueue<Runnable>(); final BlockingQueue<Runnable> q = new LinkedBlockingQueue<>();
private final String name; private final String name;
private static final AtomicLong seqids = new AtomicLong(0); private static final AtomicLong seqids = new AtomicLong(0);
private final long id; private final long id;
@ -156,7 +156,7 @@ public class ThreadPoolExecutors {
this.name = name; this.name = name;
//create the thread pool executor //create the thread pool executor
this.threadPoolExecutor = new TrackingThreadPoolExecutor( this.threadPoolExecutor = new TrackingThreadPoolExecutor(
maxThreads, maxThreads, keepAliveTimeInMillis, maxThreads, maxThreads, KEEP_ALIVE_TIME_IN_MILLIS,
TimeUnit.MILLISECONDS, q); TimeUnit.MILLISECONDS, q);
// name the threads for this threadpool // name the threads for this threadpool
ThreadFactoryBuilder tfb = new ThreadFactoryBuilder(); ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();

8
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/placeholder/TimePlaceholderUtils.java

@ -35,12 +35,12 @@ public class TimePlaceholderUtils {
/** /**
* Prefix of the position to be replaced * Prefix of the position to be replaced
*/ */
public static final String placeholderPrefix = "$["; public static final String PLACEHOLDER_PREFIX = "$[";
/** /**
* The suffix of the position to be replaced * The suffix of the position to be replaced
*/ */
public static final String placeholderSuffix = "]"; public static final String PLACEHOLDER_SUFFIX = "]";
/** /**
* Replaces all placeholders of format {@code ${name}} with the value returned * Replaces all placeholders of format {@code ${name}} with the value returned
@ -66,7 +66,7 @@ public class TimePlaceholderUtils {
* be ignored ({@code true}) or cause an exception ({@code false}) * be ignored ({@code true}) or cause an exception ({@code false})
*/ */
private static PropertyPlaceholderHelper getPropertyPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) { private static PropertyPlaceholderHelper getPropertyPlaceholderHelper(boolean ignoreUnresolvablePlaceholders) {
return new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix, null, ignoreUnresolvablePlaceholders); return new PropertyPlaceholderHelper(PLACEHOLDER_PREFIX, PLACEHOLDER_SUFFIX, null, ignoreUnresolvablePlaceholders);
} }
/** /**
@ -503,7 +503,7 @@ public class TimePlaceholderUtils {
* @return calculate need minutes * @return calculate need minutes
*/ */
public static Integer calcMinutes(String minuteExpression) { public static Integer calcMinutes(String minuteExpression) {
int index = minuteExpression.indexOf("/"); int index = minuteExpression.indexOf('/');
String calcExpression; String calcExpression;

4
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/TaskRecordDao.java

@ -84,9 +84,9 @@ public class TaskRecordDao {
Class.forName(driver); Class.forName(driver);
conn = DriverManager.getConnection(url, username, password); conn = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
logger.error("Exception ", e); logger.error("Class not found Exception ", e);
} catch (SQLException e) { } catch (SQLException e) {
logger.error("Exception ", e); logger.error("SQL Exception ", e);
} }
return conn; return conn;
} }

4
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java

@ -78,7 +78,7 @@ public class TaskInstanceMapperTest {
TaskInstance taskInstance = insertOne(); TaskInstance taskInstance = insertOne();
//update //update
int update = taskInstanceMapper.updateById(taskInstance); int update = taskInstanceMapper.updateById(taskInstance);
Assert.assertEquals(update, 1); Assert.assertEquals(1, update);
taskInstanceMapper.deleteById(taskInstance.getId()); taskInstanceMapper.deleteById(taskInstance.getId());
} }
@ -89,7 +89,7 @@ public class TaskInstanceMapperTest {
public void testDelete(){ public void testDelete(){
TaskInstance taskInstance = insertOne(); TaskInstance taskInstance = insertOne();
int delete = taskInstanceMapper.deleteById(taskInstance.getId()); int delete = taskInstanceMapper.deleteById(taskInstance.getId());
Assert.assertEquals(delete, 1); Assert.assertEquals(1, delete);
} }
/** /**

4
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java

@ -64,7 +64,7 @@ public class TenantMapperTest {
tenant.setUpdateTime(new Date()); tenant.setUpdateTime(new Date());
//update //update
int update = tenantMapper.updateById(tenant); int update = tenantMapper.updateById(tenant);
Assert.assertEquals(update, 1); Assert.assertEquals(1, update);
tenantMapper.deleteById(tenant.getId()); tenantMapper.deleteById(tenant.getId());
} }
@ -75,7 +75,7 @@ public class TenantMapperTest {
public void testDelete(){ public void testDelete(){
Tenant tenant = insertOne(); Tenant tenant = insertOne();
int delete = tenantMapper.deleteById(tenant.getId()); int delete = tenantMapper.deleteById(tenant.getId());
Assert.assertEquals(delete, 1); Assert.assertEquals(1, delete);
} }
/** /**

2
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/runner/TaskScheduleThread.java

@ -230,7 +230,7 @@ public class TaskScheduleThread implements Runnable {
taskInstance.getId() + ".log"; taskInstance.getId() + ".log";
} }
}catch (Exception e){ }catch (Exception e){
logger.error("logger" + e); logger.error("logger {}", e.getMessage(), e);
logPath = ""; logPath = "";
} }
return logPath; return logPath;

6
dolphinscheduler-service/src/main/java/org/apache/dolphinscheduler/service/queue/TaskQueueZkImpl.java

@ -18,6 +18,7 @@ package org.apache.dolphinscheduler.service.queue;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.utils.CollectionUtils;
import org.apache.dolphinscheduler.common.utils.IpUtils; import org.apache.dolphinscheduler.common.utils.IpUtils;
import org.apache.dolphinscheduler.common.utils.OSUtils; import org.apache.dolphinscheduler.common.utils.OSUtils;
import org.apache.dolphinscheduler.service.zk.ZookeeperOperator; import org.apache.dolphinscheduler.service.zk.ZookeeperOperator;
@ -67,8 +68,7 @@ public class TaskQueueZkImpl implements ITaskQueue {
@Override @Override
public List<String> getAllTasks(String key) { public List<String> getAllTasks(String key) {
try { try {
List<String> list = zookeeperOperator.getChildrenKeys(getTasksPath(key)); return zookeeperOperator.getChildrenKeys(getTasksPath(key));
return list;
} catch (Exception e) { } catch (Exception e) {
logger.error("get all tasks from tasks queue exception",e); logger.error("get all tasks from tasks queue exception",e);
} }
@ -141,7 +141,7 @@ public class TaskQueueZkImpl implements ITaskQueue {
try{ try{
List<String> list = zookeeperOperator.getChildrenKeys(getTasksPath(key)); List<String> list = zookeeperOperator.getChildrenKeys(getTasksPath(key));
if(list != null && list.size() > 0){ if(CollectionUtils.isNotEmpty(list)){
String workerIp = OSUtils.getHost(); String workerIp = OSUtils.getHost();
String workerIpLongStr = String.valueOf(IpUtils.ipToLong(workerIp)); String workerIpLongStr = String.valueOf(IpUtils.ipToLong(workerIp));

24
dolphinscheduler-service/src/test/java/org/apache/dolphinscheduler/service/queue/TaskQueueZKImplTest.java

@ -58,11 +58,11 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
init(); init();
// get all // get all
List<String> allTasks = tasksQueue.getAllTasks(Constants.DOLPHINSCHEDULER_TASKS_QUEUE); List<String> allTasks = tasksQueue.getAllTasks(Constants.DOLPHINSCHEDULER_TASKS_QUEUE);
assertEquals(allTasks.size(),2); assertEquals(2, allTasks.size());
//delete all //delete all
tasksQueue.delete(); tasksQueue.delete();
allTasks = tasksQueue.getAllTasks(Constants.DOLPHINSCHEDULER_TASKS_QUEUE); allTasks = tasksQueue.getAllTasks(Constants.DOLPHINSCHEDULER_TASKS_QUEUE);
assertEquals(allTasks.size(),0); assertEquals(0, allTasks.size());
} }
@Test @Test
public void hasTask(){ public void hasTask(){
@ -126,10 +126,10 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
//add //add
init(); init();
List<String> taskList = tasksQueue.poll(Constants.DOLPHINSCHEDULER_TASKS_QUEUE, 2); List<String> taskList = tasksQueue.poll(Constants.DOLPHINSCHEDULER_TASKS_QUEUE, 2);
assertEquals(taskList.size(),2); assertEquals(2, taskList.size());
assertEquals(taskList.get(0),"0_1_1_1_-1"); assertEquals("0_1_1_1_-1", taskList.get(0));
assertEquals(taskList.get(1),"1_0_1_1_-1"); assertEquals("1_0_1_1_-1", taskList.get(1));
} }
/** /**
@ -153,7 +153,7 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
String task = "1_0_1_1_-1"; String task = "1_0_1_1_-1";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task); tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size //check size
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),1); assertEquals(1, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
} }
@ -166,10 +166,10 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
String task = "1_0_1_1_-1"; String task = "1_0_1_1_-1";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task); tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size //check size
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),1); assertEquals(1, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
//remove and get size //remove and get size
tasksQueue.srem(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task); tasksQueue.srem(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),0); assertEquals(0, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
} }
/** /**
@ -179,17 +179,17 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
public void smembers(){ public void smembers(){
//first init //first init
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),0); assertEquals(0, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
//add //add
String task = "1_0_1_1_-1"; String task = "1_0_1_1_-1";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task); tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size //check size
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),1); assertEquals(1, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
//add //add
task = "0_1_1_1_"; task = "0_1_1_1_";
tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task); tasksQueue.sadd(Constants.DOLPHINSCHEDULER_TASKS_QUEUE,task);
//check size //check size
assertEquals(tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size(),2); assertEquals(2, tasksQueue.smembers(Constants.DOLPHINSCHEDULER_TASKS_QUEUE).size());
} }
@ -222,7 +222,7 @@ public class TaskQueueZKImplTest extends BaseTaskQueueTest {
} }
String node1 = tasksQueue.poll(Constants.DOLPHINSCHEDULER_TASKS_QUEUE, 1).get(0); String node1 = tasksQueue.poll(Constants.DOLPHINSCHEDULER_TASKS_QUEUE, 1).get(0);
assertEquals(node1,"0"); assertEquals("0", node1);
} }

Loading…
Cancel
Save