|
|
@ -14,20 +14,24 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
|
|
|
import org.apache.dolphinscheduler.api.utils.PageInfo; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
import org.apache.dolphinscheduler.common.utils.CollectionUtils; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.WorkerGroup; |
|
|
|
import org.apache.dolphinscheduler.dao.entity.WorkerGroup; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; |
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperCachedOperator; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperCachedOperator; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperConfig; |
|
|
|
import org.apache.dolphinscheduler.service.zk.ZookeeperConfig; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
@ -35,16 +39,10 @@ import org.junit.runner.RunWith; |
|
|
|
import org.mockito.InjectMocks; |
|
|
|
import org.mockito.InjectMocks; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.internal.matchers.Any; |
|
|
|
|
|
|
|
import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
import org.mockito.junit.MockitoJUnitRunner; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
@RunWith(MockitoJUnitRunner.class) |
|
|
|
public class WorkerGroupServiceTest { |
|
|
|
public class WorkerGroupServiceTest { |
|
|
|
|
|
|
|
|
|
|
@ -59,14 +57,13 @@ public class WorkerGroupServiceTest { |
|
|
|
@Mock |
|
|
|
@Mock |
|
|
|
private ZookeeperCachedOperator zookeeperCachedOperator; |
|
|
|
private ZookeeperCachedOperator zookeeperCachedOperator; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
@Before |
|
|
|
public void init() { |
|
|
|
public void init() { |
|
|
|
ZookeeperConfig zookeeperConfig = new ZookeeperConfig(); |
|
|
|
ZookeeperConfig zookeeperConfig = new ZookeeperConfig(); |
|
|
|
zookeeperConfig.setDsRoot("/dolphinscheduler_qzw"); |
|
|
|
zookeeperConfig.setDsRoot("/dolphinscheduler_qzw"); |
|
|
|
Mockito.when(zookeeperCachedOperator.getZookeeperConfig()).thenReturn(zookeeperConfig); |
|
|
|
Mockito.when(zookeeperCachedOperator.getZookeeperConfig()).thenReturn(zookeeperConfig); |
|
|
|
|
|
|
|
|
|
|
|
String workerPath = zookeeperCachedOperator.getZookeeperConfig().getDsRoot()+"/nodes" +"/worker"; |
|
|
|
String workerPath = zookeeperCachedOperator.getZookeeperConfig().getDsRoot() + Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS; |
|
|
|
|
|
|
|
|
|
|
|
List<String> workerGroupStrList = new ArrayList<>(); |
|
|
|
List<String> workerGroupStrList = new ArrayList<>(); |
|
|
|
workerGroupStrList.add("default"); |
|
|
|
workerGroupStrList.add("default"); |
|
|
@ -95,7 +92,6 @@ public class WorkerGroupServiceTest { |
|
|
|
Assert.assertEquals(pageInfo.getLists().size(), 1); |
|
|
|
Assert.assertEquals(pageInfo.getLists().size(), 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testQueryAllGroup() throws Exception { |
|
|
|
public void testQueryAllGroup() throws Exception { |
|
|
|
Map<String, Object> result = workerGroupService.queryAllGroup(); |
|
|
|
Map<String, Object> result = workerGroupService.queryAllGroup(); |
|
|
@ -103,10 +99,8 @@ public class WorkerGroupServiceTest { |
|
|
|
Assert.assertEquals(workerGroups.size(), 1); |
|
|
|
Assert.assertEquals(workerGroups.size(), 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* get processInstances |
|
|
|
* get processInstances |
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private List<ProcessInstance> getProcessInstanceList() { |
|
|
|
private List<ProcessInstance> getProcessInstanceList() { |
|
|
|
|
|
|
|
|
|
|
@ -115,4 +109,14 @@ public class WorkerGroupServiceTest { |
|
|
|
return processInstances; |
|
|
|
return processInstances; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testQueryAllGroupWithNoNodeException() { |
|
|
|
|
|
|
|
String workerPath = zookeeperCachedOperator.getZookeeperConfig().getDsRoot() + Constants.ZOOKEEPER_DOLPHINSCHEDULER_WORKERS; |
|
|
|
|
|
|
|
Mockito.when(zookeeperCachedOperator.getChildrenKeys(workerPath)).thenThrow(new RuntimeException("KeeperException$NoNodeException")); |
|
|
|
|
|
|
|
Map<String, Object> result = workerGroupService.queryAllGroup(); |
|
|
|
|
|
|
|
Set<String> workerGroups = (Set<String>) result.get(Constants.DATA_LIST); |
|
|
|
|
|
|
|
Assert.assertEquals(1, workerGroups.size()); |
|
|
|
|
|
|
|
Assert.assertEquals("default", workerGroups.toArray()[0]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|