From bb4dae70737f8d954c1c7f59c37fbb5f62a2ad2c Mon Sep 17 00:00:00 2001 From: jsonwan Date: Fri, 11 Mar 2022 11:20:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?bugfix:=20=E9=80=9A=E8=BF=87ESB=20V3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=88=9B=E5=BB=BA=E4=B8=80=E6=AC=A1=E6=80=A7?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=8A=A5=E9=94=99=20#701?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bk/job/crontab/util/CronExpressionUtil.java | 11 +++++++---- .../job/crontab/util/CronExpressionUtilTest.java | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 src/backend/job-crontab/service-job-crontab/src/test/java/com/tencent/bk/job/crontab/util/CronExpressionUtilTest.java diff --git a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/util/CronExpressionUtil.java b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/util/CronExpressionUtil.java index 184a3ec932..5aa7fe3219 100644 --- a/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/util/CronExpressionUtil.java +++ b/src/backend/job-crontab/service-job-crontab/src/main/java/com/tencent/bk/job/crontab/util/CronExpressionUtil.java @@ -28,6 +28,7 @@ import com.cronutils.model.Cron; import com.cronutils.model.definition.CronDefinitionBuilder; import com.cronutils.parser.CronParser; +import org.apache.commons.lang3.StringUtils; import static com.cronutils.model.CronType.QUARTZ; import static com.cronutils.model.CronType.UNIX; @@ -41,16 +42,18 @@ public class CronExpressionUtil { private static final CronParser UNIX_PARSER = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(UNIX)); public static String fixExpressionForQuartz(String expression) { + if (StringUtils.isBlank(expression)) { + return expression; + } Cron unixCron = UNIX_PARSER.parse(expression); unixCron.validate(); return CronMapper.fromUnixToQuartz().map(unixCron).validate().asString(); } public static String fixExpressionForUser(String expression) { + if (StringUtils.isBlank(expression)) { + return expression; + } return CronMapper.fromQuartzToUnix().map(QUARTZ_PARSER.parse(expression)).asString(); } - - public static void main(String[] args) { - System.out.println(CronExpressionUtil.fixExpressionForUser("0 30 10 8 * ? *")); - } } diff --git a/src/backend/job-crontab/service-job-crontab/src/test/java/com/tencent/bk/job/crontab/util/CronExpressionUtilTest.java b/src/backend/job-crontab/service-job-crontab/src/test/java/com/tencent/bk/job/crontab/util/CronExpressionUtilTest.java new file mode 100644 index 0000000000..5f6ff4077c --- /dev/null +++ b/src/backend/job-crontab/service-job-crontab/src/test/java/com/tencent/bk/job/crontab/util/CronExpressionUtilTest.java @@ -0,0 +1,16 @@ +package com.tencent.bk.job.crontab.util; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CronExpressionUtilTest { + + @Test + public void testFixExpression() { + String fixedCron = CronExpressionUtil.fixExpressionForUser("0 30 10 8 * ? *"); + assertThat(fixedCron.equals("30 10 8 * *")).isTrue(); + assertThat(CronExpressionUtil.fixExpressionForUser(" ").equals(" ")).isTrue(); + assertThat(CronExpressionUtil.fixExpressionForUser(null)).isNull(); + } +} From c77ff562cfd8ce1e7b027f74f8df752412545861 Mon Sep 17 00:00:00 2001 From: jsonwan Date: Fri, 11 Mar 2022 11:37:12 +0800 Subject: [PATCH 2/2] =?UTF-8?q?bugfix:=20=E9=80=9A=E8=BF=87ESB=20V3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=88=9B=E5=BB=BA=E4=B8=80=E6=AC=A1=E6=80=A7?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E6=8A=A5=E9=94=99=20#701?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit format --- .../tencent/bk/job/crontab/util/CronExpressionUtilTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/job-crontab/service-job-crontab/src/test/java/com/tencent/bk/job/crontab/util/CronExpressionUtilTest.java b/src/backend/job-crontab/service-job-crontab/src/test/java/com/tencent/bk/job/crontab/util/CronExpressionUtilTest.java index 5f6ff4077c..ab0862f5fe 100644 --- a/src/backend/job-crontab/service-job-crontab/src/test/java/com/tencent/bk/job/crontab/util/CronExpressionUtilTest.java +++ b/src/backend/job-crontab/service-job-crontab/src/test/java/com/tencent/bk/job/crontab/util/CronExpressionUtilTest.java @@ -9,8 +9,8 @@ public class CronExpressionUtilTest { @Test public void testFixExpression() { String fixedCron = CronExpressionUtil.fixExpressionForUser("0 30 10 8 * ? *"); - assertThat(fixedCron.equals("30 10 8 * *")).isTrue(); - assertThat(CronExpressionUtil.fixExpressionForUser(" ").equals(" ")).isTrue(); + assertThat("30 10 8 * *".equals(fixedCron)).isTrue(); + assertThat(" ".equals(CronExpressionUtil.fixExpressionForUser(" "))).isTrue(); assertThat(CronExpressionUtil.fixExpressionForUser(null)).isNull(); } }