-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[Watcher] Improved error messages for CronEvalTool #32800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
11fab60
a784510
40d86d8
161c0d4
51dcb90
5bbadcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ | |
import org.elasticsearch.cli.Command; | ||
import org.elasticsearch.cli.CommandTestCase; | ||
|
||
import java.util.Calendar; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
public class CronEvalToolTests extends CommandTestCase { | ||
@Override | ||
protected Command newCommand() { | ||
|
@@ -20,4 +24,28 @@ public void testParse() throws Exception { | |
String output = execute(countOption, Integer.toString(count), "0 0 0 1-6 * ?"); | ||
assertTrue(output, output.contains("Here are the next " + count + " times this cron expression will trigger")); | ||
} | ||
|
||
public void testGetNextValidTimes() throws Exception { | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for readability, just put |
||
String output = execute( | ||
"0 3 23 8 9 ? " + (Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT).get(Calendar.YEAR) + 1)); | ||
assertTrue(output, output.contains("There are 1 times this cron expression will trigger:")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you replace
This way the assertion will return something helpful instead of just being true or false in order to ease debugging. |
||
assertFalse(output.contains("ERROR")); | ||
assertFalse(output.contains("2.\t")); | ||
} | ||
{ | ||
String output = execute( | ||
"0 3 23 */4 9 ? " + (Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT).get(Calendar.YEAR) + 1)); | ||
assertTrue(output, output.contains("There are 8 times this cron expression will trigger:")); | ||
assertFalse(output, output.contains("Here are the next 10 times this cron expression will trigger:")); | ||
assertFalse(output, output.contains("ERROR")); | ||
} | ||
{ | ||
Exception expectThrows = expectThrows(Exception.class, () -> execute( | ||
"0 3 23 */4 9 ? " + (Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT).get(Calendar.YEAR) - 1))); | ||
String message = expectThrows.getMessage(); | ||
assertTrue(message, message.contains("Could not compute future times since")); | ||
assertTrue(message, message.contains("(perhaps the cron expression only points to times in the past?)")); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this special handling here (introducing state that requires following by filling up the list). Just adding the additional if-statement plus break should be sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the change as originally the following results were printed by the cli tool:
0 0 0 1-6 * ?
resulted inAnd a one time cron, such as
0 3 23 8 9 ? 2019
resulted inI found it is a little bit confusing that in this case the message was
Here are the next 10 time
and only a single one was printed, hence I tried to clarify the message.I will revert the change.