You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/03/17 14:17:23 UTC

[camel-k] 01/01: Fixes #1350 Remove human-readable format from timer period computation in cron trait

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch issue-1350
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit d25005a1910d81b2bc78db2227b1560f3143bf9a
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 17 15:16:20 2020 +0100

    Fixes #1350 Remove human-readable format from timer period computation in cron trait
---
 pkg/trait/cron.go      | 17 +----------------
 pkg/trait/cron_test.go | 26 +++++++++++++-------------
 2 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/pkg/trait/cron.go b/pkg/trait/cron.go
index 6d4d332..ab0421e 100644
--- a/pkg/trait/cron.go
+++ b/pkg/trait/cron.go
@@ -96,8 +96,7 @@ const (
 )
 
 var (
-	camelTimerPeriodMillis        = regexp.MustCompile(`^[0-9]+$`)
-	camelTimerPeriodHumanReadable = regexp.MustCompile(`^(?:([0-9]+)h)?(?:([0-9]+)m)?(?:([0-9]+)s)?$`)
+	camelTimerPeriodMillis = regexp.MustCompile(`^[0-9]+$`)
 
 	supportedCamelComponents = map[string]cronExtractor{
 		"timer":  timerToCronInfo,
@@ -432,20 +431,6 @@ func timerToCronInfo(camelURI string) *cronInfo {
 	var period uint64
 	if camelTimerPeriodMillis.MatchString(periodStr) {
 		period = checkedStringToUint64(periodStr)
-	} else if camelTimerPeriodHumanReadable.MatchString(periodStr) {
-		res := camelTimerPeriodHumanReadable.FindStringSubmatch(periodStr)
-		if len(res) == 4 {
-			period = 0
-			if res[1] != "" { // hours
-				period += checkedStringToUint64(res[1]) * 3600000
-			}
-			if res[2] != "" { // minutes
-				period += checkedStringToUint64(res[2]) * 60000
-			}
-			if res[3] != "" { // seconds
-				period += checkedStringToUint64(res[3]) * 1000
-			}
-		}
 	} else {
 		return nil
 	}
diff --git a/pkg/trait/cron_test.go b/pkg/trait/cron_test.go
index a12aaab..5519a2a 100644
--- a/pkg/trait/cron_test.go
+++ b/pkg/trait/cron_test.go
@@ -68,43 +68,43 @@ func TestCronFromURI(t *testing.T) {
 			uri: "timer:tick?period=120001", // invalid
 		},
 		{
-			uri:        "timer:tick?period=1m",
+			uri:        "timer:tick?period=60000",
 			cron:       "0/1 * * * ?",
 			components: "timer",
 		},
 		{
-			uri:        "timer:tick?period=5m",
+			uri:        "timer:tick?period=300000",
 			cron:       "0/5 * * * ?",
 			components: "timer",
 		},
 		{
-			uri:        "timer:tick?period=10m",
+			uri:        "timer:tick?period=600000",
 			cron:       "0/10 * * * ?",
 			components: "timer",
 		},
 		{
-			uri: "timer:tick?period=61m", // invalid
+			uri: "timer:tick?period=66000", // invalid
 		},
 		{
-			uri:        "timer:tick?period=2h",
+			uri:        "timer:tick?period=7200000",
 			cron:       "0 0/2 * * ?",
 			components: "timer",
 		},
 		{
-			uri:        "timer:tick?period=2h60m",
+			uri:        "timer:tick?period=10800000",
 			cron:       "0 0/3 * * ?",
 			components: "timer",
 		},
 		{
-			uri:        "timer:tick?period=24h",
+			uri:        "timer:tick?period=86400000",
 			cron:       "0 0 * * ?",
 			components: "timer",
 		},
 		{
-			uri: "timer:tick?period=3h60s", // invalid
+			uri: "timer:tick?period=10860000", // invalid
 		},
 		{
-			uri:        "timer:tick?period=3h59m60s",
+			uri:        "timer:tick?period=14400000",
 			cron:       "0 0/4 * * ?",
 			components: "timer",
 		},
@@ -167,26 +167,26 @@ func TestCronFromURI(t *testing.T) {
 		// Mixed scenarios
 		{
 			uri:        "cron:tab?schedule=0/2 * * * ?",
-			uri2:       "timer:tick?period=2m",
+			uri2:       "timer:tick?period=120000",
 			cron:       "0/2 * * * ?",
 			components: "cron,timer",
 		},
 		{
 			uri:        "cron:tab?schedule=0 0/2 * * ?",
-			uri2:       "timer:tick?period=2h",
+			uri2:       "timer:tick?period=7200000",
 			uri3:       "quartz:trigger?cron=0 0 0/2 * * ? ?",
 			cron:       "0 0/2 * * ?",
 			components: "cron,timer,quartz",
 		},
 		{
 			uri:  "cron:tab?schedule=1 0/2 * * ?",
-			uri2: "timer:tick?period=2h",
+			uri2: "timer:tick?period=7200000",
 			uri3: "quartz:trigger?cron=0 0 0/2 * * ? ?",
 			// invalid
 		},
 		{
 			uri:  "cron:tab?schedule=0 0/2 * * ?",
-			uri2: "timer:tick?period=3h",
+			uri2: "timer:tick?period=10800000",
 			uri3: "quartz:trigger?cron=0 0 0/2 * * ? ?",
 			// invalid
 		},