ScheduleConfig: make the startTime and interval keys configurable
To make the ScheduleConfig better (re)usable the Config keys have to be configurable. The default keys "startTime" and "interval" will not be a perfect choice for every scenario. For example, if a plugin wants to use the ScheduleConfig and have its configuration inside a '[plugin "name"]' subsection then the "startTime" key may be confusing: [plugin "name"] startTime = ... as one could believe that this would be the start time of the plugin. Change-Id: Ic4a213b08957ec7c1f4945ec5ae299bb74e82f02
This commit is contained in:
@@ -19,6 +19,7 @@ import static java.util.concurrent.TimeUnit.HOURS;
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
@@ -54,6 +55,26 @@ public class ScheduleConfigTest {
|
||||
assertEquals(ms(1, HOURS), initialDelay("Mon 11:00", "1d"));
|
||||
assertEquals(ms(23, HOURS), initialDelay("Mon 09:00", "1d"));
|
||||
assertEquals(ms(1, DAYS), initialDelay("Mon 10:00", "1d"));
|
||||
assertEquals(ms(1, DAYS), initialDelay("Mon 10:00", "1d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomKeys() throws ConfigInvalidException {
|
||||
Config rc = readConfig(MessageFormat.format(
|
||||
"[section \"subsection\"]\n{0} = {1}\n{2} = {3}\n",
|
||||
"myStartTime", "01:00", "myInterval", "1h"));
|
||||
|
||||
ScheduleConfig scheduleConfig;
|
||||
|
||||
scheduleConfig = new ScheduleConfig(rc, "section",
|
||||
"subsection", "myInterval", "myStartTime");
|
||||
assertNotEquals(scheduleConfig.getInterval(), ScheduleConfig.MISSING_CONFIG);
|
||||
assertNotEquals(scheduleConfig.getInitialDelay(), ScheduleConfig.MISSING_CONFIG);
|
||||
|
||||
scheduleConfig = new ScheduleConfig(rc, "section",
|
||||
"subsection", "nonExistent", "myStartTime");
|
||||
assertEquals(scheduleConfig.getInterval(), ScheduleConfig.MISSING_CONFIG);
|
||||
assertEquals(scheduleConfig.getInitialDelay(), ScheduleConfig.MISSING_CONFIG);
|
||||
}
|
||||
|
||||
private static long initialDelay(String startTime, String interval)
|
||||
|
Reference in New Issue
Block a user