|
@@ -14,67 +14,53 @@
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
+
|
|
|
package org.apache.dolphinscheduler.server.master.dispatch.host;
|
|
|
|
|
|
+import com.google.common.collect.Sets;
|
|
|
|
|
|
-import org.apache.dolphinscheduler.common.utils.NetUtils;
|
|
|
import org.apache.dolphinscheduler.common.utils.StringUtils;
|
|
|
import org.apache.dolphinscheduler.remote.utils.Host;
|
|
|
import org.apache.dolphinscheduler.server.master.dispatch.context.ExecutionContext;
|
|
|
-import org.apache.dolphinscheduler.server.registry.DependencyConfig;
|
|
|
import org.apache.dolphinscheduler.server.registry.ZookeeperNodeManager;
|
|
|
-import org.apache.dolphinscheduler.server.registry.ZookeeperRegistryCenter;
|
|
|
import org.apache.dolphinscheduler.server.utils.ExecutionContextTestUtils;
|
|
|
-import org.apache.dolphinscheduler.server.worker.config.WorkerConfig;
|
|
|
-import org.apache.dolphinscheduler.server.worker.registry.WorkerRegistry;
|
|
|
-import org.apache.dolphinscheduler.server.zk.SpringZKServer;
|
|
|
-import org.apache.dolphinscheduler.service.zk.CuratorZookeeperClient;
|
|
|
-import org.apache.dolphinscheduler.service.zk.ZookeeperCachedOperator;
|
|
|
-import org.apache.dolphinscheduler.service.zk.ZookeeperConfig;
|
|
|
+
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.test.context.ContextConfiguration;
|
|
|
-import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+import org.mockito.InjectMocks;
|
|
|
+import org.mockito.Mock;
|
|
|
+import org.mockito.Mockito;
|
|
|
+import org.mockito.junit.MockitoJUnitRunner;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* round robin host manager test
|
|
|
*/
|
|
|
-@RunWith(SpringRunner.class)
|
|
|
-@ContextConfiguration(classes={DependencyConfig.class, SpringZKServer.class, WorkerRegistry.class, ZookeeperRegistryCenter.class, WorkerConfig.class,
|
|
|
- ZookeeperNodeManager.class, ZookeeperCachedOperator.class, ZookeeperConfig.class, CuratorZookeeperClient.class})
|
|
|
+@RunWith(MockitoJUnitRunner.class)
|
|
|
public class RoundRobinHostManagerTest {
|
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
+ @Mock
|
|
|
private ZookeeperNodeManager zookeeperNodeManager;
|
|
|
|
|
|
- @Autowired
|
|
|
- private WorkerRegistry workerRegistry;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private WorkerConfig workerConfig;
|
|
|
+ @InjectMocks
|
|
|
+ RoundRobinHostManager roundRobinHostManager;
|
|
|
|
|
|
@Test
|
|
|
- public void testSelectWithEmptyResult(){
|
|
|
- RoundRobinHostManager roundRobinHostManager = new RoundRobinHostManager();
|
|
|
- roundRobinHostManager.setZookeeperNodeManager(zookeeperNodeManager);
|
|
|
+ public void testSelectWithEmptyResult() {
|
|
|
+ Mockito.when(zookeeperNodeManager.getWorkerGroupNodes("default")).thenReturn(null);
|
|
|
ExecutionContext context = ExecutionContextTestUtils.getExecutionContext(10000);
|
|
|
Host emptyHost = roundRobinHostManager.select(context);
|
|
|
Assert.assertTrue(StringUtils.isEmpty(emptyHost.getAddress()));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testSelectWithResult(){
|
|
|
- workerRegistry.registry();
|
|
|
- RoundRobinHostManager roundRobinHostManager = new RoundRobinHostManager();
|
|
|
- roundRobinHostManager.setZookeeperNodeManager(zookeeperNodeManager);
|
|
|
+ public void testSelectWithResult() {
|
|
|
+ Mockito.when(zookeeperNodeManager.getWorkerGroupNodes("default")).thenReturn(Sets.newHashSet("192.168.1.1:22:100"));
|
|
|
ExecutionContext context = ExecutionContextTestUtils.getExecutionContext(10000);
|
|
|
Host host = roundRobinHostManager.select(context);
|
|
|
Assert.assertTrue(StringUtils.isNotEmpty(host.getAddress()));
|
|
|
- Assert.assertTrue(host.getAddress().equalsIgnoreCase(NetUtils.getHost() + ":" + workerConfig.getListenPort()));
|
|
|
- workerRegistry.unRegistry();
|
|
|
+ Assert.assertTrue(host.getAddress().equalsIgnoreCase("192.168.1.1:22"));
|
|
|
}
|
|
|
}
|