-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable cron expression on flush (#572)
Default behavior to look for HOUR i.e. the flush interval. If the flush interval is not set, it is considered OFF (default backward compatible behavior). Similar behavior for CRON.
- Loading branch information
1 parent
06d6c7c
commit 485299b
Showing
8 changed files
with
197 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
priam/src/test/java/com/netflix/priam/scheduler/TestFlushTask.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.netflix.priam.scheduler | ||
|
||
import com.netflix.priam.FakeConfiguration | ||
import com.netflix.priam.cluster.management.FlushTask | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
/** | ||
Created by aagrawal on 7/15/17. | ||
*/ | ||
@Unroll | ||
class TestFlushTask extends Specification { | ||
|
||
def "Exception for value #flushSchedulerType, #flushCronExpression, #flushInterval"() { | ||
when: | ||
FlushTask.getTimer(new FlushConfiguration(flushSchedulerType, flushCronExpression, flushInterval)) | ||
|
||
then: | ||
def error = thrown(expectedException) | ||
|
||
where: | ||
flushSchedulerType | flushCronExpression | flushInterval || expectedException | ||
"sdf" | null | null || UnsupportedTypeException | ||
"hour" | null | "2" || IllegalArgumentException | ||
"hour" | "0 0 2 * * ?" | "2" || IllegalArgumentException | ||
"cron" | "abc" | null || Exception | ||
"cron" | "abc" | "daily=2" || Exception | ||
"hour" | null | "hour=2,daily=2" || IllegalArgumentException | ||
} | ||
|
||
def "SchedulerType for value #flushSchedulerType, #flushCronExpression, #flushInterval is null"() { | ||
expect: | ||
FlushTask.getTimer(new FlushConfiguration(flushSchedulerType, flushCronExpression, flushInterval)) == result | ||
|
||
where: | ||
flushSchedulerType | flushCronExpression | flushInterval || result | ||
"hour" | null | null || null | ||
"cron" | null | null || null | ||
"hour" | "abc" | null || null | ||
"cron" | null | "abc" || null | ||
} | ||
|
||
def "SchedulerType for value #flushSchedulerType, #flushCronExpression, #flushInterval is #result"() { | ||
expect: | ||
FlushTask.getTimer(new FlushConfiguration(flushSchedulerType, flushCronExpression, flushInterval)).getCronExpression() == result | ||
|
||
where: | ||
flushSchedulerType | flushCronExpression | flushInterval || result | ||
"hour" | null | "daily=2" || "0 0 2 * * ?" | ||
"hour" | null | "hour=2" || "0 2 0/1 * * ?" | ||
"cron" | "0 0 0/1 1/1 * ? *" | null || "0 0 0/1 1/1 * ? *" | ||
"cron" | "0 0 0/1 1/1 * ? *" | "daily=2" || "0 0 0/1 1/1 * ? *" | ||
} | ||
|
||
|
||
private class FlushConfiguration extends FakeConfiguration { | ||
private String flushSchedulerType, flushCronExpression, flushInterval; | ||
|
||
FlushConfiguration(String flushSchedulerType, String flushCronExpression, String flushInterval) { | ||
this.flushCronExpression = flushCronExpression; | ||
this.flushSchedulerType = flushSchedulerType; | ||
this.flushInterval = flushInterval; | ||
} | ||
|
||
@Override | ||
public SchedulerType getFlushSchedulerType() throws UnsupportedTypeException { | ||
return SchedulerType.lookup(flushSchedulerType); | ||
} | ||
|
||
@Override | ||
public String getFlushCronExpression() { | ||
return flushCronExpression; | ||
} | ||
|
||
@Override | ||
public String getFlushInterval() { | ||
return flushInterval; | ||
} | ||
} | ||
|
||
} |