From 17162341c3af7277dbac584beff6abf733a796d9 Mon Sep 17 00:00:00 2001 From: "xiaochun.liu" Date: Tue, 11 Feb 2020 00:18:06 +0800 Subject: [PATCH 1/3] add ResInfoTest.java ut --- .../common/utils/ResInfo.java | 12 ++++----- .../common/utils/ResInfoTest.java} | 27 +++++++++++++++---- 2 files changed, 28 insertions(+), 11 deletions(-) rename dolphinscheduler-common/src/{main/java/org/apache/dolphinscheduler/common/utils/ArrayUtils.java => test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java} (54%) diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ResInfo.java b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ResInfo.java index e0cea1d7e0..aa8d44fa42 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ResInfo.java +++ b/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ResInfo.java @@ -15,7 +15,6 @@ * limitations under the License. */ package org.apache.dolphinscheduler.common.utils; - import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.model.Server; @@ -135,14 +134,15 @@ public class ResInfo { * @return heartbeat info to Server */ public static Server parseHeartbeatForZKInfo(String heartBeatInfo){ - Server masterServer = null; + if (StringUtils.isEmpty(heartBeatInfo)) { + return null; + } String[] masterArray = heartBeatInfo.split(Constants.COMMA); - if(masterArray == null || - masterArray.length != Constants.HEARTBEAT_FOR_ZOOKEEPER_INFO_LENGTH){ - return masterServer; + if(masterArray.length != Constants.HEARTBEAT_FOR_ZOOKEEPER_INFO_LENGTH){ + return null; } - masterServer = new Server(); + Server masterServer = new Server(); masterServer.setHost(masterArray[0]); masterServer.setPort(Integer.parseInt(masterArray[1])); masterServer.setResInfo(getResInfoJson(Double.parseDouble(masterArray[2]), diff --git a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ArrayUtils.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java similarity index 54% rename from dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ArrayUtils.java rename to dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java index 163c56bbcc..1e1b154d93 100644 --- a/dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ArrayUtils.java +++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java @@ -14,13 +14,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.dolphinscheduler.common.utils; +import org.junit.Assert; +import org.junit.Test; +import java.util.Date; +import org.apache.dolphinscheduler.common.model.Server; + +public class ResInfoTest { + @Test + public void testGetHeartBeatInfo() { + String info = ResInfo.getHeartBeatInfo(new Date()); + Assert.assertEquals(info.split(",").length, 7); + } -public class ArrayUtils { + @Test + public void testParseHeartbeatForZKInfo() { + //normal info + String info = ResInfo.getHeartBeatInfo(new Date()); + Server s = ResInfo.parseHeartbeatForZKInfo(info); + Assert.assertNotNull(s); + Assert.assertNotNull(s.getResInfo()); - public static boolean isEmpty(final int[] array) { - return array == null || array.length == 0; - } + //null param + s = ResInfo.parseHeartbeatForZKInfo(null); + Assert.assertNull(s); + } } From 980b5ae5ea4ee9e5751f15066401aec4118ee14f Mon Sep 17 00:00:00 2001 From: "xiaochun.liu" Date: Tue, 11 Feb 2020 09:21:59 +0800 Subject: [PATCH 2/3] swap param --- .../org/apache/dolphinscheduler/common/utils/ResInfoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java index 1e1b154d93..0d15d9615a 100644 --- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java +++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java @@ -25,7 +25,7 @@ public class ResInfoTest { @Test public void testGetHeartBeatInfo() { String info = ResInfo.getHeartBeatInfo(new Date()); - Assert.assertEquals(info.split(",").length, 7); + Assert.assertEquals(7, info.split(",").length, ); } @Test From 0ed6156b221ef96d53917bb1ae1dece41f7aaa4c Mon Sep 17 00:00:00 2001 From: "xiaochun.liu" Date: Tue, 11 Feb 2020 09:26:43 +0800 Subject: [PATCH 3/3] swap param --- .../org/apache/dolphinscheduler/common/utils/ResInfoTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java index 0d15d9615a..e4318965b7 100644 --- a/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java +++ b/dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java @@ -25,7 +25,7 @@ public class ResInfoTest { @Test public void testGetHeartBeatInfo() { String info = ResInfo.getHeartBeatInfo(new Date()); - Assert.assertEquals(7, info.split(",").length, ); + Assert.assertEquals(7, info.split(",").length); } @Test