Loading dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ResInfo.java +6 −6 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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]), Loading dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ArrayUtils.java→dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java +22 −5 Original line number Diff line number Diff line Loading @@ -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(7, info.split(",").length); } 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); } } Loading
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ResInfo.java +6 −6 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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]), Loading
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/ArrayUtils.java→dolphinscheduler-common/src/test/java/org/apache/dolphinscheduler/common/utils/ResInfoTest.java +22 −5 Original line number Diff line number Diff line Loading @@ -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(7, info.split(",").length); } 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); } }