Browse Source

update unit test (#743)

* change log level to debug

* add unit test

* update escheduler-dao unit test

* update escheduler-api unit test

* update escheduler-api unit test
pull/2/head
dailidong 5 years ago committed by GitHub
parent
commit
7c9da3eddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      escheduler-api/src/main/java/cn/escheduler/api/service/LoggerService.java
  2. 4
      escheduler-api/src/main/java/cn/escheduler/api/service/ProcessInstanceService.java
  3. 3
      escheduler-api/src/main/java/cn/escheduler/api/service/SessionService.java
  4. 10
      escheduler-api/src/test/java/cn/escheduler/api/HttpClientTest.java
  5. 91
      escheduler-api/src/test/java/cn/escheduler/api/controller/AbstractControllerTest.java
  6. 35
      escheduler-api/src/test/java/cn/escheduler/api/controller/DataSourceControllerTest.java
  7. 26
      escheduler-api/src/test/java/cn/escheduler/api/controller/ExecutorControllerTest.java
  8. 41
      escheduler-api/src/test/java/cn/escheduler/api/controller/LoggerControllerTest.java
  9. 24
      escheduler-api/src/test/java/cn/escheduler/api/controller/LoginControllerTest.java
  10. 39
      escheduler-api/src/test/java/cn/escheduler/api/controller/MonitorControllerTest.java
  11. 55
      escheduler-api/src/test/java/cn/escheduler/api/controller/ProcessDefinitionControllerTest.java
  12. 6
      escheduler-api/src/test/java/cn/escheduler/api/service/DataAnalysisServiceTest.java
  13. 5
      escheduler-api/src/test/java/cn/escheduler/api/service/DataSourceServiceTest.java
  14. 12
      escheduler-api/src/test/java/cn/escheduler/api/service/ExecutorServiceTest.java
  15. 11
      escheduler-api/src/test/java/cn/escheduler/api/service/LoggerServiceTest.java
  16. 21
      escheduler-api/src/test/java/cn/escheduler/api/service/ProcessDefinitionServiceTest.java
  17. 21
      escheduler-api/src/test/java/cn/escheduler/api/service/ProcessInstanceServiceTest.java
  18. 7
      escheduler-api/src/test/java/cn/escheduler/api/service/ResourcesServiceTest.java
  19. 11
      escheduler-api/src/test/java/cn/escheduler/api/service/SchedulerServiceTest.java
  20. 8
      escheduler-api/src/test/java/cn/escheduler/api/service/SessionServiceTest.java
  21. 15
      escheduler-api/src/test/java/cn/escheduler/api/service/TaskInstanceServiceTest.java
  22. 5
      escheduler-api/src/test/java/cn/escheduler/api/service/TenantServiceTest.java
  23. 7
      escheduler-api/src/test/java/cn/escheduler/api/service/UdfFuncServiceTest.java
  24. 5
      escheduler-api/src/test/java/cn/escheduler/api/service/UsersServiceTest.java
  25. 11
      escheduler-api/src/test/java/cn/escheduler/api/utils/ZookeeperMonitorUtilsTest.java
  26. 53
      escheduler-api/src/test/resources/dao/data_source.properties
  27. 2
      escheduler-common/src/main/java/cn/escheduler/common/zk/AbstractZKClient.java
  28. 3
      escheduler-common/src/test/java/cn/escheduler/common/utils/HadoopUtilsTest.java
  29. 3
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/AccessTokenMapperTest.java
  30. 5
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/CommandMapperTest.java
  31. 12
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/MasterServerMapperTest.java
  32. 2
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessDefinitionMapperTest.java
  33. 12
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/TenantMapperTest.java
  34. 6
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UdfFuncMapperTest.java
  35. 8
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserAlertGroupMapperTest.java
  36. 50
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserMapperTest.java
  37. 53
      escheduler-dao/src/test/resources/dao/data_source.properties
  38. 13
      escheduler-server/src/main/java/cn/escheduler/server/worker/task/dependent/DependentTask.java
  39. 5
      escheduler-server/src/test/java/cn/escheduler/server/worker/task/dependent/DependentTaskTest.java
  40. 100
      escheduler-server/src/test/java/cn/escheduler/server/zk/StandaloneZKServerForTest.java

6
escheduler-api/src/main/java/cn/escheduler/api/service/LoggerService.java

@ -49,8 +49,12 @@ public class LoggerService {
*/
public Result queryLog(int taskInstId, int skipLineNum, int limit) {
TaskInstance taskInstance = processDao.findTaskInstanceById(taskInstId);
if (taskInstance == null){
return new Result(Status.TASK_INSTANCE_NOT_FOUND.getCode(), Status.TASK_INSTANCE_NOT_FOUND.getMsg());
}
String host = taskInstance.getHost();
if(StringUtils.isEmpty(host)){
return new Result(Status.TASK_INSTANCE_NOT_FOUND.getCode(), Status.TASK_INSTANCE_NOT_FOUND.getMsg());

4
escheduler-api/src/main/java/cn/escheduler/api/service/ProcessInstanceService.java

@ -574,6 +574,10 @@ public class ProcessInstanceService extends BaseDAGService {
ProcessInstance processInstance = processInstanceMapper.queryDetailById(processInstanceId);
if (processInstance == null) {
throw new RuntimeException("workflow instance is null");
}
Map<String, String> timeParams = BusinessTimeUtils
.getBusinessTime(processInstance.getCmdTypeIfComplement(),
processInstance.getScheduleTime());

3
escheduler-api/src/main/java/cn/escheduler/api/service/SessionService.java

@ -130,8 +130,9 @@ public class SessionService extends BaseService{
/**
* sign out
* remove ip restrictions
*
* @param ip
* @param ip no use
* @param loginUser
*/
public void signOut(String ip, User loginUser) {

10
escheduler-api/src/test/java/cn/escheduler/api/HttpClientTest.java

@ -26,7 +26,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -35,7 +34,6 @@ import java.net.URI;
import java.util.ArrayList;
import java.util.List;
@Ignore
public class HttpClientTest {
private static final Logger logger = LoggerFactory.getLogger(HttpClientTest.class);
@ -46,7 +44,7 @@ public class HttpClientTest {
CloseableHttpClient httpclient = HttpClients.createDefault();
// create http post request
HttpPost httpPost = new HttpPost("http://127.0.0.1:12345/escheduler/projects/create");
HttpPost httpPost = new HttpPost("http://localhost:12345/escheduler/projects/create");
httpPost.setHeader("token", "123");
// set parameters
List<NameValuePair> parameters = new ArrayList<NameValuePair>();
@ -64,7 +62,7 @@ public class HttpClientTest {
// eponse status code 200
if (response.getStatusLine().getStatusCode() == 200) {
String content = EntityUtils.toString(response.getEntity(), "UTF-8");
System.out.println(content);
logger.info(content);
}
} finally {
if (response != null) {
@ -87,7 +85,7 @@ public class HttpClientTest {
// parameters.add(new BasicNameValuePair("pageSize", "10"));
// define the parameters of the request
URI uri = new URIBuilder("http://192.168.220.247:12345/escheduler/projects/%E5%85%A8%E9%83%A8%E6%B5%81%E7%A8%8B%E6%B5%8B%E8%AF%95/process/list")
URI uri = new URIBuilder("http://localhost:12345/escheduler/projects/%E5%85%A8%E9%83%A8%E6%B5%81%E7%A8%8B%E6%B5%8B%E8%AF%95/process/list")
.build();
// create http GET request
@ -129,7 +127,7 @@ public class HttpClientTest {
parameters.add(new BasicNameValuePair("projectId", "0"));
// define the parameters of the request
URI uri = new URIBuilder("http://192.168.220.247:12345/escheduler/projects/analysis/queue-count")
URI uri = new URIBuilder("http://localhost:12345/escheduler/projects/analysis/queue-count")
.setParameters(parameters)
.build();

91
escheduler-api/src/test/java/cn/escheduler/api/controller/AbstractControllerTest.java

@ -0,0 +1,91 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.api.controller;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.service.SessionService;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.common.utils.JSONUtils;
import cn.escheduler.dao.model.User;
import org.apache.commons.lang3.StringUtils;
import org.junit.*;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ApiApplicationServer.class)
public class AbstractControllerTest {
private static Logger logger = LoggerFactory.getLogger(AbstractControllerTest.class);
public static final String SESSION_ID = "sessionId";
protected MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Autowired
private SessionService sessionService;
protected User user;
protected String sessionId;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
createSession();
}
@After
public void after(){
sessionService.signOut("127.0.0.1", user);
}
private void createSession(){
User loginUser = new User();
loginUser.setId(1);
loginUser.setUserType(UserType.GENERAL_USER);
user = loginUser;
String session = sessionService.createSession(loginUser, "127.0.0.1");
sessionId = session;
Assert.assertTrue(StringUtils.isNotEmpty(session));
}
}

35
escheduler-api/src/test/java/cn/escheduler/api/controller/DataSourceControllerTest.java

@ -20,48 +20,31 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
public class DataSourceControllerTest {
private static Logger logger = LoggerFactory.getLogger(DataSourceControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
/**
* data source controller test
*/
public class DataSourceControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(DataSourceControllerTest.class);
@Test
public void queryDataSource() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/datasources/list").header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82").param("type","HIVE"))
MvcResult mvcResult = mockMvc.perform(get("/datasources/list").header("sessionId", sessionId).param("type","HIVE"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn();
@ -70,11 +53,12 @@ public class DataSourceControllerTest {
logger.info(mvcResult.getResponse().getContentAsString());
}
@Ignore
@Test
public void connectDataSource() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("name","hvie数据源");
paramsMap.add("name","hive data source");
paramsMap.add("type","HIVE");
paramsMap.add("host","192.168.xx.xx");
paramsMap.add("port","10000");
@ -83,7 +67,7 @@ public class DataSourceControllerTest {
paramsMap.add("password","");
paramsMap.add("other","");
MvcResult mvcResult = mockMvc.perform(post("/datasources/connect")
.header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82")
.header("sessionId", sessionId)
.params(paramsMap))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@ -93,4 +77,5 @@ public class DataSourceControllerTest {
logger.info(mvcResult.getResponse().getContentAsString());
}
}

26
escheduler-api/src/test/java/cn/escheduler/api/controller/ExecutorControllerTest.java

@ -20,43 +20,25 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
public class ExecutorControllerTest {
/**
* executor controller test
*/
public class ExecutorControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(ExecutorControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test
public void startCheckProcessDefinition() throws Exception {

41
escheduler-api/src/test/java/cn/escheduler/api/controller/LoggerControllerTest.java

@ -20,60 +20,39 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
public class LoggerControllerTest {
private static Logger logger = LoggerFactory.getLogger(DataAnalysisControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
/**
* logger controller test
*/
public class LoggerControllerTest extends AbstractControllerTest {
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
private static Logger logger = LoggerFactory.getLogger(DataAnalysisControllerTest.class);
@Test
public void queryLog() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("taskInstId","6007");
paramsMap.add("taskInstId","-1");
paramsMap.add("skipLineNum","0");
paramsMap.add("limit","1000");
MvcResult mvcResult = mockMvc.perform(get("/log/detail")
.header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82")
.header("sessionId", sessionId)
.params(paramsMap))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
// .andExpect(status().isOk())
// .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString());
}
}

24
escheduler-api/src/test/java/cn/escheduler/api/controller/LoginControllerTest.java

@ -21,15 +21,11 @@ import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@ -38,31 +34,25 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
public class LoginControllerTest {
/**
* login controller test
*/
public class LoginControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(SchedulerControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test
public void login() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("userName","admin");
paramsMap.add("userPassword","admin123");
paramsMap.add("userPassword","escheduler123");
MvcResult mvcResult = mockMvc.perform(get("/login")
MvcResult mvcResult = mockMvc.perform(post("/login")
.params(paramsMap))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))

39
escheduler-api/src/test/java/cn/escheduler/api/controller/MonitorControllerTest.java

@ -2,57 +2,32 @@ package cn.escheduler.api.controller;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.ResourceType;
import cn.escheduler.common.utils.JSONUtils;
import com.alibaba.fastjson.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.junit.Assert.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
public class MonitorControllerTest {
/**
* monitor controller test
*/
public class MonitorControllerTest extends AbstractControllerTest {
private static final Logger logger = LoggerFactory.getLogger(MonitorControllerTest.class);
public static final String SESSION_ID = "sessionId";
public static String SESSION_ID_VALUE;
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
SESSION_ID_VALUE = "bad76fc4-2eb4-4aae-b32b-d650e4beb6af";
}
@Test
public void listMaster() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/monitor/master/list")
.header(SESSION_ID, SESSION_ID_VALUE)
.header(SESSION_ID, sessionId)
/* .param("type", ResourceType.FILE.name())*/ )
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@ -72,7 +47,7 @@ public class MonitorControllerTest {
@Test
public void queryDatabaseState() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/monitor/database")
.header(SESSION_ID, SESSION_ID_VALUE)
.header(SESSION_ID, sessionId)
/* .param("type", ResourceType.FILE.name())*/ )
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@ -90,7 +65,7 @@ public class MonitorControllerTest {
@Test
public void queryZookeeperState() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/monitor/zookeeper/list")
.header(SESSION_ID, SESSION_ID_VALUE)
.header(SESSION_ID, sessionId)
/* .param("type", ResourceType.FILE.name())*/ )
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))

55
escheduler-api/src/test/java/cn/escheduler/api/controller/ProcessDefinitionControllerTest.java

@ -41,57 +41,28 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* process definition controller test
*/
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
public class ProcessDefinitionControllerTest {
private static Logger logger = LoggerFactory.getLogger(ProcessDefinitionControllerTest.class);
private MockMvc mockMvc;
public class ProcessDefinitionControllerTest extends AbstractControllerTest{
@Autowired
private WebApplicationContext webApplicationContext;
private static Logger logger = LoggerFactory.getLogger(ProcessDefinitionControllerTest.class);
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test
public void createProcessDefinition() throws Exception {
//String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-50438\",\"name\":\"shell_01\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo \\\"123\\\"\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{\"self\":\"NO_DEP_PRE\",\"outer\":{\"strategy\":\"NONE\",\"taskList\":[]}},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"preTasks\":[]}]}";
String json = "{\n" +
" \"globalParams\": [ ], \n" +
" \"tasks\": [\n" +
" {\n" +
" \"type\": \"SHELL\", \n" +
" \"id\": \"tasks-50438\", \n" +
" \"name\": \"shell_01\", \n" +
" \"params\": {\n" +
" \"resourceList\": [ ], \n" +
" \"localParams\": [ ], \n" +
" \"rawScript\": \"echo \\\"123\\\"\"\n" +
" }, \n" +
" \"desc\": \"\", \n" +
" \"runFlag\": \"NORMAL\", \n" +
" \"dependence\": {\n" +
" \"self\": \"NO_DEP_PRE\", \n" +
" \"outer\": {\n" +
" \"strategy\": \"NONE\", \n" +
" \"taskList\": [ ]\n" +
" }\n" +
" }, \n" +
" \"maxRetryTimes\": \"0\", \n" +
" \"retryInterval\": \"1\", \n" +
" \"preTasks\": [ ]\n" +
" }\n" +
" ]\n" +
"}";
String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}";
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}";
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("name","shell_process_01_test");
paramsMap.add("name","dag_test");
paramsMap.add("processDefinitionJson",json);
paramsMap.add("locations", locations);
paramsMap.add("connects", "[]");
paramsMap.add("desc", "desc test");
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/process/save","project_test1")
.header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82")
.header(SESSION_ID, sessionId)
.params(paramsMap))
.andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))

6
escheduler-api/src/test/java/cn/escheduler/api/service/DataAnalysisServiceTest.java

@ -16,12 +16,12 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -29,12 +29,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class DataAnalysisServiceTest {
private static final Logger logger = LoggerFactory.getLogger(DataAnalysisServiceTest.class);

5
escheduler-api/src/test/java/cn/escheduler/api/service/DataSourceServiceTest.java

@ -16,13 +16,13 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.common.enums.DbType;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -33,9 +33,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class DataSourceServiceTest {
private static final Logger logger = LoggerFactory.getLogger(DataSourceServiceTest.class);

12
escheduler-api/src/test/java/cn/escheduler/api/service/ExecutorServiceTest.java

@ -16,6 +16,7 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import org.junit.Assert;
@ -32,21 +33,24 @@ import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class ExecutorServiceTest {
private static final Logger logger = LoggerFactory.getLogger(ExecutorServiceTest.class);
@Autowired
private ExecutorService executorService;
@Ignore
@Test
public void startCheckByProcessDefinedId(){
Map<String, Object> map = executorService.startCheckByProcessDefinedId(214);
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
Map<String, Object> map = executorService.startCheckByProcessDefinedId(1234);
Assert.assertNull(map);
}
@Test
public void putMsgWithParamsTest() {

11
escheduler-api/src/test/java/cn/escheduler/api/service/LoggerServiceTest.java

@ -16,12 +16,12 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -30,9 +30,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class LoggerServiceTest {
private static final Logger logger = LoggerFactory.getLogger(LoggerServiceTest.class);
@ -45,7 +44,9 @@ public class LoggerServiceTest {
User loginUser = new User();
loginUser.setId(27);
loginUser.setUserType(UserType.GENERAL_USER);
Result result = loggerService.queryLog(6007, 0, 100);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
Result result = loggerService.queryLog(-1, 0, 100);
Assert.assertEquals(Status.TASK_INSTANCE_NOT_FOUND.getCode(),result.getCode().intValue());
}
}

21
escheduler-api/src/test/java/cn/escheduler/api/service/ProcessDefinitionServiceTest.java

@ -16,13 +16,13 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import com.alibaba.fastjson.JSON;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -33,9 +33,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class ProcessDefinitionServiceTest {
private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionServiceTest.class);
@ -46,11 +45,11 @@ public class ProcessDefinitionServiceTest {
public void queryProccessDefinitionList() throws Exception {
User loginUser = new User();
loginUser.setId(27);
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> map = processDefinitionService.queryProccessDefinitionList(loginUser,"project_test1");
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
logger.info(JSON.toJSONString(map));
}
@ -58,11 +57,11 @@ public class ProcessDefinitionServiceTest {
public void queryProcessDefinitionListPagingTest() throws Exception {
User loginUser = new User();
loginUser.setId(27);
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> map = processDefinitionService.queryProcessDefinitionListPaging(loginUser, "project_test1", "",1, 5,0);
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
logger.info(JSON.toJSONString(map));
}
@ -70,11 +69,11 @@ public class ProcessDefinitionServiceTest {
public void deleteProcessDefinitionByIdTest() throws Exception {
User loginUser = new User();
loginUser.setId(2);
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> map = processDefinitionService.deleteProcessDefinitionById(loginUser, "li_sql_test", 6);
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
logger.info(JSON.toJSONString(map));
}
@ -82,10 +81,10 @@ public class ProcessDefinitionServiceTest {
public void batchDeleteProcessDefinitionByIds() throws Exception {
User loginUser = new User();
loginUser.setId(2);
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> map = processDefinitionService.batchDeleteProcessDefinitionByIds(loginUser, "li_test_1", "2,3");
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
logger.info(JSON.toJSONString(map));
}
}

21
escheduler-api/src/test/java/cn/escheduler/api/service/ProcessInstanceServiceTest.java

@ -16,6 +16,7 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.common.enums.DependResult;
@ -24,7 +25,6 @@ import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import com.alibaba.fastjson.JSON;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -36,9 +36,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class ProcessInstanceServiceTest {
private static final Logger logger = LoggerFactory.getLogger(ProcessInstanceServiceTest.class);
@ -47,9 +46,13 @@ public class ProcessInstanceServiceTest {
@Test
public void viewVariables() throws Exception {
Map<String, Object> map = processInstanceService.viewVariables(1389);
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
logger.info(JSON.toJSONString(map));
try {
Map<String, Object> map = processInstanceService.viewVariables(-1);
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
logger.info(JSON.toJSONString(map));
}catch (Exception e){
logger.error(e.getMessage(), e);
}
}
@Test
@ -74,7 +77,7 @@ public class ProcessInstanceServiceTest {
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> map = processInstanceService.queryProcessInstanceList(loginUser, "project_test1", 0, "", "", "", ExecutionStatus.FAILURE, "", 1, 5);
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
logger.info(JSON.toJSONString(map));
}
@ -82,11 +85,11 @@ public class ProcessInstanceServiceTest {
public void batchDeleteProcessInstanceByIds() throws Exception {
User loginUser = new User();
loginUser.setId(2);
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> map = processInstanceService.batchDeleteProcessInstanceByIds(loginUser, "li_test_1", "4,2,300");
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
logger.info(JSON.toJSONString(map));
}
}

7
escheduler-api/src/test/java/cn/escheduler/api/service/ResourcesServiceTest.java

@ -16,13 +16,13 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.common.enums.ResourceType;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -33,9 +33,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class ResourcesServiceTest {
private static final Logger logger = LoggerFactory.getLogger(ResourcesServiceTest.class);
@ -45,7 +44,7 @@ public class ResourcesServiceTest {
@Test
public void querytResourceList(){
User loginUser = new User();
loginUser.setId(27);
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> map = resourcesService.queryResourceList(loginUser, ResourceType.FILE);

11
escheduler-api/src/test/java/cn/escheduler/api/service/SchedulerServiceTest.java

@ -16,6 +16,7 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.common.enums.ReleaseState;
@ -23,7 +24,6 @@ import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.Project;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -34,9 +34,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class SchedulerServiceTest {
private static final Logger logger = LoggerFactory.getLogger(ExecutorServiceTest.class);
@ -46,14 +45,14 @@ public class SchedulerServiceTest {
@Test
public void testSetScheduleState(){
User loginUser = new User();
loginUser.setId(27);
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Project project = new Project();
project.setName("project_test1");
project.setId(21);
project.setId(-1);
Map<String, Object> map = schedulerService.setScheduleState(loginUser, project.getName(), 44, ReleaseState.ONLINE);
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
}
}

8
escheduler-api/src/test/java/cn/escheduler/api/service/SessionServiceTest.java

@ -16,11 +16,11 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -29,10 +29,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class SessionServiceTest {
private static final Logger logger = LoggerFactory.getLogger(SessionServiceTest.class);
@Autowired
@ -42,7 +42,7 @@ public class SessionServiceTest {
public void createSession(){
User loginUser = new User();
loginUser.setId(27);
loginUser.setId(1);
loginUser.setUserType(UserType.GENERAL_USER);
String session = sessionService.createSession(loginUser, "127.0.0.1");

15
escheduler-api/src/test/java/cn/escheduler/api/service/TaskInstanceServiceTest.java

@ -16,13 +16,13 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.PageInfo;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -33,9 +33,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class TaskInstanceServiceTest {
private static final Logger logger = LoggerFactory.getLogger(TaskInstanceServiceTest.class);
@ -46,14 +45,18 @@ public class TaskInstanceServiceTest {
public void queryTaskListPaging(){
User loginUser = new User();
loginUser.setId(27);
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> map = taskInstanceService.queryTaskListPaging(loginUser, "project_test1", 0, "",
"2019-02-26 19:48:00", "2019-02-26 19:48:22", "", null, "", 1, 20);
Assert.assertEquals(Status.SUCCESS, map.get(Constants.STATUS));
Assert.assertEquals(Status.PROJECT_NOT_FOUNT, map.get(Constants.STATUS));
PageInfo pageInfo = (PageInfo) map.get("data");
logger.info(pageInfo.getLists().toString());
if(pageInfo != null){
logger.info(pageInfo.getLists().toString());
}
}
}

5
escheduler-api/src/test/java/cn/escheduler/api/service/TenantServiceTest.java

@ -16,12 +16,12 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -32,9 +32,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class TenantServiceTest {
private static final Logger logger = LoggerFactory.getLogger(TenantServiceTest.class);

7
escheduler-api/src/test/java/cn/escheduler/api/service/UdfFuncServiceTest.java

@ -16,13 +16,13 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.api.utils.PageInfo;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -33,9 +33,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class UdfFuncServiceTest {
private static final Logger logger = LoggerFactory.getLogger(UdfFuncServiceTest.class);
@ -46,7 +45,7 @@ public class UdfFuncServiceTest {
public void queryUdfFuncListPaging(){
User loginUser = new User();
loginUser.setId(19);
loginUser.setId(-1);
loginUser.setUserType(UserType.GENERAL_USER);
Map<String, Object> map = udfFuncService.queryUdfFuncListPaging(loginUser, "", 1, 10);

5
escheduler-api/src/test/java/cn/escheduler/api/service/UsersServiceTest.java

@ -16,12 +16,12 @@
*/
package cn.escheduler.api.service;
import cn.escheduler.api.ApiApplicationServer;
import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Constants;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@ -32,9 +32,8 @@ import org.springframework.test.context.junit4.SpringRunner;
import java.util.Map;
@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes = ApiApplicationServer.class)
public class UsersServiceTest {
private static final Logger logger = LoggerFactory.getLogger(UsersServiceTest.class);

11
escheduler-api/src/test/java/cn/escheduler/api/utils/ZookeeperMonitorUtilsTest.java

@ -2,13 +2,12 @@ package cn.escheduler.api.utils;
import cn.escheduler.common.model.MasterServer;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.util.List;
@Ignore
/**
* zookeeper monitor utils test
*/
public class ZookeeperMonitorUtilsTest {
@ -22,8 +21,8 @@ public class ZookeeperMonitorUtilsTest {
List<MasterServer> workerServerList = zookeeperMonitor.getWorkerServers();
Assert.assertEquals(masterServerList.size(), 1);
Assert.assertEquals(workerServerList.size(), 1);
Assert.assertTrue(masterServerList.size() >= 0);
Assert.assertTrue(workerServerList.size() >= 0);
}

53
escheduler-api/src/test/resources/dao/data_source.properties

@ -0,0 +1,53 @@
# base spring data source configuration
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.10.32:3306/escheduler?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root@123
# connection configuration
spring.datasource.initialSize=5
# min connection number
spring.datasource.minIdle=5
# max connection number
spring.datasource.maxActive=50
# max wait time for get a connection in milliseconds. if configuring maxWait, fair locks are enabled by default and concurrency efficiency decreases.
# If necessary, unfair locks can be used by configuring the useUnfairLock attribute to true.
spring.datasource.maxWait=60000
# milliseconds for check to close free connections
spring.datasource.timeBetweenEvictionRunsMillis=60000
# the Destroy thread detects the connection interval and closes the physical connection in milliseconds if the connection idle time is greater than or equal to minEvictableIdleTimeMillis.
spring.datasource.timeBetweenConnectErrorMillis=60000
# the longest time a connection remains idle without being evicted, in milliseconds
spring.datasource.minEvictableIdleTimeMillis=300000
#the SQL used to check whether the connection is valid requires a query statement. If validation Query is null, testOnBorrow, testOnReturn, and testWhileIdle will not work.
spring.datasource.validationQuery=SELECT 1
#check whether the connection is valid for timeout, in seconds
spring.datasource.validationQueryTimeout=3
# when applying for a connection, if it is detected that the connection is idle longer than time Between Eviction Runs Millis,
# validation Query is performed to check whether the connection is valid
spring.datasource.testWhileIdle=true
#execute validation to check if the connection is valid when applying for a connection
spring.datasource.testOnBorrow=true
#execute validation to check if the connection is valid when the connection is returned
spring.datasource.testOnReturn=false
spring.datasource.defaultAutoCommit=true
spring.datasource.keepAlive=true
# open PSCache, specify count PSCache for every connection
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
# data quality analysis is not currently in use. please ignore the following configuration
# task record flag
task.record.flag=false
task.record.datasource.url=jdbc:mysql://192.168.xx.xx:3306/etl?characterEncoding=UTF-8
task.record.datasource.username=xx
task.record.datasource.password=xx

2
escheduler-common/src/main/java/cn/escheduler/common/zk/AbstractZKClient.java

@ -368,7 +368,7 @@ public abstract class AbstractZKClient {
masterMap.putIfAbsent(server, new String(bytes));
}
} catch (Exception e) {
e.printStackTrace();
logger.error("get server list failed : " + e.getMessage(), e);
}
return masterMap;

3
escheduler-common/src/test/java/cn/escheduler/common/utils/HadoopUtilsTest.java

@ -16,6 +16,7 @@
*/
package cn.escheduler.common.utils;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -23,7 +24,7 @@ import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
@Ignore
public class HadoopUtilsTest {
private static final Logger logger = LoggerFactory.getLogger(HadoopUtilsTest.class);

3
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/AccessTokenMapperTest.java

@ -18,6 +18,7 @@ package cn.escheduler.dao.mapper;
import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.model.AccessToken;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -60,4 +61,6 @@ public class AccessTokenMapperTest {
}
}

5
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/CommandMapperTest.java

@ -24,12 +24,13 @@ import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.model.Command;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.util.List;
@Ignore
/**
* command test
*/
public class CommandMapperTest {
CommandMapper commandMapper;

12
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/MasterServerMapperTest.java

@ -16,11 +16,11 @@
*/
package cn.escheduler.dao.mapper;
import cn.escheduler.common.utils.OSUtils;
import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.common.model.MasterServer;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@ -28,7 +28,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import java.util.Date;
import java.util.List;
@Ignore
@SpringBootTest
public class MasterServerMapperTest {
@ -37,26 +36,29 @@ public class MasterServerMapperTest {
@Before
public void before(){
masterServerMapper =ConnectionFactory.getSqlSession().getMapper(MasterServerMapper.class);
masterServerMapper = ConnectionFactory.getSqlSession().getMapper(MasterServerMapper.class);
}
@Test
public void queryAllMaster() {
MasterServer masterServer = new MasterServer();
String host = "127.22.2.1";
String host = OSUtils.getHost();
masterServer.setHost(host);
masterServer.setLastHeartbeatTime(new Date());
masterServer.setPort(19282);
masterServer.setCreateTime(new Date());
masterServer.setZkDirectory("/root");
masterServer.setZkDirectory("/escheduler/masters/" + host + "_0000000001");
masterServerMapper.insert(masterServer);
Assert.assertNotEquals(masterServer.getId(), 0);
masterServer.setPort(12892);
int update = masterServerMapper.update(masterServer);
Assert.assertEquals(update, 1);
List<MasterServer> masterServers = masterServerMapper.queryAllMaster();
MasterServer findMaster = null;

2
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessDefinitionMapperTest.java

@ -21,13 +21,11 @@ import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.model.ProcessDefinition;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.util.Date;
import java.util.List;
@Ignore
public class ProcessDefinitionMapperTest {

12
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/TenantMapperTest.java

@ -20,13 +20,11 @@ import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.model.Tenant;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
@Ignore
public class TenantMapperTest {
@ -42,18 +40,22 @@ public class TenantMapperTest {
public void testMapper(){
Tenant tenant = new Tenant();
tenant.setTenantName("大数据平台部");
tenant.setTenantName("bigdata");
tenant.setQueueId(1);
tenant.setCreateTime(new Date());
tenant.setUpdateTime(new Date());
tenantMapper.insert(tenant);
Assert.assertNotEquals(tenant.getId(), 0);
tenant.setTenantName("大数据平台部test");
tenant.setTenantName("bigdata-test");
int update = tenantMapper.update(tenant);
Assert.assertEquals(update, 1);
tenant = tenantMapper.queryById(tenant.getId());
Assert.assertEquals(tenant.getTenantName(), "大数据平台部test");
Assert.assertEquals(tenant.getTenantName(), "bigdata-test");
int delete = tenantMapper.deleteById(tenant.getId());
Assert.assertEquals(delete, 1);

6
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UdfFuncMapperTest.java

@ -20,14 +20,12 @@ import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.model.Resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
@Ignore
public class UdfFuncMapperTest {
private final Logger logger = LoggerFactory.getLogger(UdfFuncMapperTest.class);
@ -53,10 +51,14 @@ public class UdfFuncMapperTest {
resource.setUpdateTime(new Date());
resourceMapper.insert(resource);
Assert.assertNotEquals(resource.getId(), 0);
resource.setAlias("aa123");
resourceMapper.update(resource);
resource = resourceMapper.queryResourceById(resource.getId());
Assert.assertEquals(resource.getAlias(), "aa123");
int delete = resourceMapper.delete(resource.getId());
Assert.assertEquals(delete, 1);
}

8
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserAlertGroupMapperTest.java

@ -20,13 +20,11 @@ import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.model.UserAlertGroup;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
@Ignore
public class UserAlertGroupMapperTest {
@ -47,12 +45,10 @@ public class UserAlertGroupMapperTest {
userAlertGroup.setUpdateTime(new Date());
userAlertGroupMapper.insert(userAlertGroup);
Assert.assertNotEquals(userAlertGroup.getId(), 0);
int delete = userAlertGroupMapper.deleteByAlertgroupId(userAlertGroup.getAlertgroupId());
Assert.assertEquals(delete, 1);
int delete = userAlertGroupMapper.deleteByAlertgroupId(userAlertGroup.getAlertgroupId());
Assert.assertEquals(delete, 1);
}

50
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/UserMapperTest.java

@ -18,29 +18,35 @@ package cn.escheduler.dao.mapper;
import cn.escheduler.common.enums.UserType;
import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.model.AccessToken;
import cn.escheduler.dao.model.User;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.util.Date;
import java.util.Random;
@Ignore
/**
* user test
*/
public class UserMapperTest {
UserMapper userMapper;
AccessTokenMapper accessTokenMapper;
int userId;
@Before
public void before(){
userMapper = ConnectionFactory.getSqlSession().getMapper(UserMapper.class);
accessTokenMapper = ConnectionFactory.getSqlSession().getMapper(AccessTokenMapper.class);
}
@Test
public void testInsert(){
User user = new User();
user.setUserName("Dr.strange");
user.setUserName("Dr.strange" + new Date().getTime());
user.setUserPassword("1234567890");
user.setEmail("wwww@123.com");
user.setPhone("12345678901");
@ -51,32 +57,40 @@ public class UserMapperTest {
userMapper.insert(user);
Assert.assertNotEquals(user.getId(), 0);
user.setUserName("Dr.chemistry");
user.setUserName("Dr.chemistry" + new Random().nextInt(10));
int update = userMapper.update(user);
Assert.assertEquals(update, 1);
user = userMapper.queryById(user.getId());
Assert.assertEquals(user.getUserName(), "Dr.chemistry");
int delete = userMapper.delete(user.getId());
Assert.assertEquals(delete, 1);
Assert.assertNotEquals(user.getUserName(), "Dr.chemistry" + new Date().getTime());
AccessToken accessToken = new AccessToken();
accessToken.setUserId(user.getId());
accessToken.setExpireTime(new Date());
accessToken.setToken("ssssssssssssssssssssssssss");
accessToken.setCreateTime(new Date());
accessToken.setUpdateTime(new Date());
accessTokenMapper.insert(accessToken);
userId = user.getId();
User user2 = userMapper.queryUserByToken("ssssssssssssssssssssssssss");
Assert.assertTrue(user2.getId() >= 0);
}
@Test
public void queryQueueByProcessInstanceId(){
String queue = userMapper.queryQueueByProcessInstanceId(41388);
Assert.assertEquals(queue, "ait");
String queue = userMapper.queryQueueByProcessInstanceId(-1000);
Assert.assertNotEquals(queue, "ait");
}
@Test
public void testQueryUserByToken(){
User user = userMapper.queryUserByToken("ad9e8fccfc11bd18bb45aa994568b8ef");
Assert.assertEquals(user.getUserName(), "qiaozhanwei");
}
@Test
public void test(){
User user = userMapper.queryDetailsById(19);
System.out.println(user);
public void testDelete() {
int delete = userMapper.delete(userId);
Assert.assertTrue(delete >= 0);
}
}

53
escheduler-dao/src/test/resources/dao/data_source.properties

@ -0,0 +1,53 @@
# base spring data source configuration
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://192.168.10.32:3306/escheduler?characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root@123
# connection configuration
spring.datasource.initialSize=5
# min connection number
spring.datasource.minIdle=5
# max connection number
spring.datasource.maxActive=50
# max wait time for get a connection in milliseconds. if configuring maxWait, fair locks are enabled by default and concurrency efficiency decreases.
# If necessary, unfair locks can be used by configuring the useUnfairLock attribute to true.
spring.datasource.maxWait=60000
# milliseconds for check to close free connections
spring.datasource.timeBetweenEvictionRunsMillis=60000
# the Destroy thread detects the connection interval and closes the physical connection in milliseconds if the connection idle time is greater than or equal to minEvictableIdleTimeMillis.
spring.datasource.timeBetweenConnectErrorMillis=60000
# the longest time a connection remains idle without being evicted, in milliseconds
spring.datasource.minEvictableIdleTimeMillis=300000
#the SQL used to check whether the connection is valid requires a query statement. If validation Query is null, testOnBorrow, testOnReturn, and testWhileIdle will not work.
spring.datasource.validationQuery=SELECT 1
#check whether the connection is valid for timeout, in seconds
spring.datasource.validationQueryTimeout=3
# when applying for a connection, if it is detected that the connection is idle longer than time Between Eviction Runs Millis,
# validation Query is performed to check whether the connection is valid
spring.datasource.testWhileIdle=true
#execute validation to check if the connection is valid when applying for a connection
spring.datasource.testOnBorrow=true
#execute validation to check if the connection is valid when the connection is returned
spring.datasource.testOnReturn=false
spring.datasource.defaultAutoCommit=true
spring.datasource.keepAlive=true
# open PSCache, specify count PSCache for every connection
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
# data quality analysis is not currently in use. please ignore the following configuration
# task record flag
task.record.flag=false
task.record.datasource.url=jdbc:mysql://192.168.xx.xx:3306/etl?characterEncoding=UTF-8
task.record.datasource.username=xx
task.record.datasource.password=xx

13
escheduler-server/src/main/java/cn/escheduler/server/worker/task/dependent/DependentTask.java

@ -22,6 +22,7 @@ import cn.escheduler.common.enums.ExecutionStatus;
import cn.escheduler.common.model.DependentTaskModel;
import cn.escheduler.common.task.AbstractParameters;
import cn.escheduler.common.task.dependent.DependentParameters;
import cn.escheduler.common.thread.Stopper;
import cn.escheduler.common.utils.DependentUtils;
import cn.escheduler.common.utils.JSONUtils;
import cn.escheduler.dao.DaoFactory;
@ -85,17 +86,25 @@ public class DependentTask extends AbstractTask {
try{
TaskInstance taskInstance = null;
while(true){
while(Stopper.isRunning()){
taskInstance = processDao.findTaskInstanceById(this.taskProps.getTaskInstId());
if(taskInstance == null){
exitStatusCode = -1;
break;
}
if(taskInstance.getState() == ExecutionStatus.KILL){
this.cancel = true;
}
if(this.cancel || allDependentTaskFinish()){
break;
}
Thread.sleep(Constants.SLEEP_TIME_MILLIS);
Thread.sleep(Constants.SLEEP_TIME_MILLIS);
}
if(cancel){
exitStatusCode = Constants.EXIT_CODE_KILL;
}else{

5
escheduler-server/src/test/java/cn/escheduler/server/worker/task/dependent/DependentTaskTest.java

@ -19,12 +19,10 @@ package cn.escheduler.server.worker.task.dependent;
import cn.escheduler.common.Constants;
import cn.escheduler.server.worker.task.TaskProps;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Ignore
public class DependentTaskTest {
private static final Logger logger = LoggerFactory.getLogger(DependentTaskTest.class);
@ -33,11 +31,8 @@ public class DependentTaskTest {
@Test
public void testDependInit(){
TaskProps taskProps = new TaskProps();
String dependString = "{\n" +
"\"dependTaskList\":[\n" +
" {\n" +

100
escheduler-server/src/test/java/cn/escheduler/server/zk/StandaloneZKServerForTest.java

@ -0,0 +1,100 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.escheduler.server.zk;
import cn.escheduler.common.thread.ThreadPoolExecutors;
import org.apache.zookeeper.server.ServerConfig;
import org.apache.zookeeper.server.ZooKeeperServerMain;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
import org.junit.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.Properties;
/**
* just for test
*/
public class StandaloneZKServerForTest {
private static final Logger logger = LoggerFactory.getLogger(StandaloneZKServerForTest.class);
private static volatile ZooKeeperServerMain zkServer = null;
@Before
public void before() {
logger.info("standalone zookeeper server for test service start ");
ThreadPoolExecutors.getInstance().execute(new Runnable() {
@Override
public void run() {
//delete zk data dir ?
File zkFile = new File(System.getProperty("java.io.tmpdir"), "zookeeper");
// if(zkFile.exists()){
// zkFile.delete();
// }
startStandaloneServer("2000", zkFile.getAbsolutePath(), "2181", "10", "5");
}
});
}
/**
* start zk server
* @param tickTime zookeeper ticktime
* @param dataDir zookeeper data dir
* @param clientPort zookeeper client port
* @param initLimit zookeeper init limit
* @param syncLimit zookeeper sync limit
*/
private void startStandaloneServer(String tickTime, String dataDir, String clientPort, String initLimit, String syncLimit) {
Properties props = new Properties();
props.setProperty("tickTime", tickTime);
props.setProperty("dataDir", dataDir);
props.setProperty("clientPort", clientPort);
props.setProperty("initLimit", initLimit);
props.setProperty("syncLimit", syncLimit);
QuorumPeerConfig quorumConfig = new QuorumPeerConfig();
try {
quorumConfig.parseProperties(props);
if(zkServer == null ){
synchronized (StandaloneZKServerForTest.class){
if(zkServer == null ){
zkServer = new ZooKeeperServerMain();
final ServerConfig config = new ServerConfig();
config.readFrom(quorumConfig);
zkServer.runFromConfig(config);
}
}
}
} catch (Exception e) {
logger.error("start standalone server fail!", e);
}
}
}
Loading…
Cancel
Save