|
@@ -16,13 +16,19 @@
|
|
|
*/
|
|
|
package org.apache.dolphinscheduler.common.utils;
|
|
|
|
|
|
-import org.junit.Test;
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
+import static org.junit.Assert.assertFalse;
|
|
|
+import static org.junit.Assert.assertNotNull;
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+import org.apache.dolphinscheduler.common.CommonTest;
|
|
|
+import org.apache.dolphinscheduler.common.Constants;
|
|
|
|
|
|
import java.net.InetAddress;
|
|
|
|
|
|
-import static org.junit.Assert.*;
|
|
|
-import static org.mockito.Mockito.mock;
|
|
|
-import static org.mockito.Mockito.when;
|
|
|
+import org.junit.Test;
|
|
|
|
|
|
|
|
|
* NetUtilsTest
|
|
@@ -36,6 +42,22 @@ public class NetUtilsTest {
|
|
|
assertEquals("localhost:1234", NetUtils.getAddr("localhost", 1234));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testGetHost() throws Exception {
|
|
|
+ InetAddress address = mock(InetAddress.class);
|
|
|
+ when(address.getCanonicalHostName()).thenReturn("dolphinscheduler-worker-0.dolphinscheduler-worker-headless.default.svc.cluster.local");
|
|
|
+ when(address.getHostName()).thenReturn("dolphinscheduler-worker-0");
|
|
|
+ when(address.getHostAddress()).thenReturn("172.17.0.15");
|
|
|
+ assertEquals("172.17.0.15", NetUtils.getHost(address));
|
|
|
+ CommonTest.setFinalStatic(Constants.class.getDeclaredField("KUBERNETES_MODE"), true);
|
|
|
+ assertEquals("dolphinscheduler-worker-0.dolphinscheduler-worker-headless.default.svc.cluster.local", NetUtils.getHost(address));
|
|
|
+ address = mock(InetAddress.class);
|
|
|
+ when(address.getCanonicalHostName()).thenReturn("dolphinscheduler-worker-0");
|
|
|
+ when(address.getHostName()).thenReturn("dolphinscheduler-worker-0");
|
|
|
+ CommonTest.setFinalStatic(Constants.class.getDeclaredField("KUBERNETES_MODE"), true);
|
|
|
+ assertEquals("dolphinscheduler-worker-0.dolphinscheduler-worker-headless", NetUtils.getHost(address));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testGetLocalHost() {
|
|
|
assertNotNull(NetUtils.getHost());
|