-
Notifications
You must be signed in to change notification settings - Fork 12k
[ISSUE #8262] [Enhancement] Add tests and harden UtilAll.isItTimeToDo #10409
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
base: develop
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import java.net.UnknownHostException; | ||
| import java.nio.ByteBuffer; | ||
| import java.util.Arrays; | ||
| import java.util.Calendar; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Properties; | ||
|
|
@@ -34,6 +35,7 @@ | |
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.within; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| public class UtilAllTest { | ||
|
|
@@ -151,6 +153,20 @@ public void testSplit() { | |
| assertEquals(Collections.EMPTY_LIST, UtilAll.split("", comma)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testIsItTimeToDo() { | ||
| int currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); | ||
| assertTrue(UtilAll.isItTimeToDo(String.valueOf(currentHour))); | ||
| assertTrue(UtilAll.isItTimeToDo("foo; " + currentHour + " ; 25")); | ||
| assertTrue(UtilAll.isItTimeToDo(" " + currentHour + " ")); | ||
|
|
||
| assertFalse(UtilAll.isItTimeToDo(null)); | ||
|
Contributor
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. This test depends on the hour read here matching the hour read inside |
||
| assertFalse(UtilAll.isItTimeToDo("")); | ||
| assertFalse(UtilAll.isItTimeToDo(" ; ")); | ||
| assertFalse(UtilAll.isItTimeToDo("not_a_number")); | ||
| assertFalse(UtilAll.isItTimeToDo("99")); | ||
| } | ||
|
|
||
| static class DemoConfig { | ||
| private int demoWidth = 0; | ||
| private int demoLength = 0; | ||
|
|
||
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.
Could we avoid silently ignoring invalid
whentokens here, or at least log a warning when a token cannot be parsed or is outside the 0-23 range? This helper is used by scheduled maintenance paths such as commitlog cleanup and topic queue mapping cleanup. IfdeleteWhenor a similar schedule is misconfigured, returningfalseforever would silently disable the task and make the operator miss the configuration problem. The previous behavior failed loudly; changing that to silent ignore seems risky without some visibility.