Changeset 352 for kraken-cron/src
- Timestamp:
- 10/17/09 14:47:45 (11 months ago)
- Location:
- kraken-cron/src/main/java/org/krakenapps/cron
- Files:
-
- 1 removed
- 13 modified
- 1 moved
-
CronScript.java (modified) (7 diffs)
-
CronService.java (modified) (1 diff)
-
Schedule.java (modified) (11 diffs)
-
impl/CronConfig.java (modified) (1 diff)
-
impl/CronField.java (modified) (12 diffs)
-
impl/CronServiceImpl.java (modified) (7 diffs)
-
impl/IllegalTypeException.java (modified) (1 diff)
-
impl/Job.java (modified) (4 diffs)
-
impl/NextOccurenceCalculator.java (moved) (moved from kraken-cron/src/main/java/org/krakenapps/cron/impl/NextOccurenceGenerator.java) (2 diffs)
-
impl/QueryStringGenerator.java (modified) (2 diffs)
-
impl/Scheduler.java (modified) (5 diffs)
-
test/DummyBundleContext.java (deleted)
-
test/JobTest.java (modified) (2 diffs)
-
test/NextOccurTest.java (modified) (10 diffs)
-
test/ScheduleBuildTest.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kraken-cron/src/main/java/org/krakenapps/cron/CronScript.java
r346 r352 2 2 3 3 import java.text.ParseException; 4 import java.util.NoSuchElementException; 4 5 5 6 import org.krakenapps.api.Script; … … 74 75 builder.set(CronField.Type.Day_of_Week, args[4]); 75 76 manager.registerSchedule(builder.build()); 76 77 77 78 context.println("Cron : registered."); 78 79 } catch (ParseException e) { … … 88 89 context.println("Cron : unregistered."); 89 90 } catch (NumberFormatException e) { 90 context.print("USAGE : SCHEDULE_ID"); 91 context.println("USAGE : SCHEDULE_ID"); 92 } catch (NoSuchElementException e){ 93 context.println("cron script: no schedule of given id %d", Integer.parseInt(args[0])); 91 94 } 92 95 } … … 95 98 public void usage(String[] args) { 96 99 context.println("SYNTAX :"); 97 context.println("* * * * * R UNNABLE_NAME\n\r" + "- - - - -\n\r" + "| | | | |\n\r"100 context.println("* * * * * Runnable instance.name\n\r" + "- - - - -\n\r" + "| | | | |\n\r" 98 101 + "| | | | +----- day of week (0 - 6) (Sunday=0)\n\r" + "| | | +------- month (1 - 12)\n\r" 99 102 + "| | +--------- day of month (1 - 31)\n\r" + "| +----------- hour (0 - 23)\n\r" … … 128 131 context.println("run completed."); 129 132 } catch (Exception e) { 130 context.println("run error: " + e.toString());133 context.println("run() error: " + e.toString()); 131 134 logger.warn("cron script: run error", e); 132 135 } … … 139 142 140 143 @ScriptUsage(description = "list all active Runnables") 141 public void runnable (String[] args) throws InvalidSyntaxException {144 public void runnables(String[] args) throws InvalidSyntaxException { 142 145 context.println("======================"); 143 146 context.println(" Active Runnable List"); … … 155 158 } 156 159 } catch (InvalidSyntaxException e) { 157 logger.warn("cron script: runnable error", e);160 logger.warn("cron script: runnables error", e); 158 161 } 159 162 } -
kraken-cron/src/main/java/org/krakenapps/cron/CronService.java
r346 r352 11 11 public interface CronService { 12 12 void registerSchedule(Schedule schedule); 13 13 14 void unregisterSchedule(int i); 15 14 16 List<String> getScheduleList(); 17 15 18 List<String> getJobList(); 16 19 } -
kraken-cron/src/main/java/org/krakenapps/cron/Schedule.java
r346 r352 2 2 3 3 import java.text.ParseException; 4 import java.util.Calendar;5 import java.util.Date;6 4 import java.util.HashMap; 7 5 import java.util.Map; 8 6 9 7 import org.krakenapps.cron.impl.CronField; 10 import org.krakenapps.cron.impl.IllegalTypeException;11 8 import org.krakenapps.cron.impl.CronField.Type; 12 9 … … 18 15 */ 19 16 public final class Schedule { 20 17 18 /** 19 * fieldName to CronField mapping 20 */ 21 21 private final Map<String, CronField> map; 22 22 private final String taskName; … … 27 27 } 28 28 29 private Schedule(Builder builder) {29 private Schedule(Builder builder) { 30 30 this.map = new HashMap<String, CronField>(); 31 31 this.map.put("Minute", builder.map.get("Minute")); … … 35 35 CronField dom = builder.map.get("DayOfMonth"); 36 36 CronField dow = builder.map.get("DayOfWeek"); 37 try {38 CronField.solveCollision(dom, dow);39 } catch (Exception e) {40 // must succeed. ignore.37 try { 38 CronField.solveCollision(dom, dow); 39 } catch (Exception e) { 40 // must succeed. ignore. 41 41 } 42 42 this.map.put("DayOfMonth", dom); … … 45 45 } 46 46 47 48 47 /** 49 48 * returns task Name 50 49 */ 51 public String getTask InstanceName() {50 public String getTaskName() { 52 51 return this.taskName; 53 52 } … … 55 54 @Override 56 55 public String toString() { 57 return String.format("%8s %8s %8s %8s %8s / %8s", map.get("Minute"), 58 map.get("Hour"), map.get("DayOfMonth"), map.get("Month"), map 59 .get("DayOfWeek"), taskName); 56 return String.format("%8s %8s %8s %8s %8s / %8s", map.get("Minute"), map.get("Hour"), map.get("DayOfMonth"), 57 map.get("Month"), map.get("DayOfWeek"), taskName); 60 58 } 61 59 … … 76 74 @Override 77 75 public boolean equals(Object sche) { 78 return (sche instanceof Schedule) 79 && this.toString().equals(((Schedule) sche).toString()); 76 return (sche instanceof Schedule) && this.toString().equals(((Schedule) sche).toString()); 80 77 } 81 78 … … 100 97 this.taskName = taskName; 101 98 try { 102 this.map.put("Minute", new CronField(CronField.Type.Minute, 103 null)); 99 this.map.put("Minute", new CronField(CronField.Type.Minute, null)); 104 100 this.map.put("Hour", new CronField(CronField.Type.Hour, null)); 105 this.map.put("DayOfMonth", new CronField( 106 CronField.Type.Day_of_Month, null)); 107 this.map 108 .put("Month", new CronField(CronField.Type.Month, null)); 109 this.map.put("DayOfWeek", new CronField( 110 CronField.Type.Day_of_Week, null)); 101 this.map.put("DayOfMonth", new CronField(CronField.Type.Day_of_Month, null)); 102 this.map.put("Month", new CronField(CronField.Type.Month, null)); 103 this.map.put("DayOfWeek", new CronField(CronField.Type.Day_of_Week, null)); 111 104 } catch (ParseException e) { 112 105 // must succeed. ignored. … … 115 108 116 109 /** 117 * Set cron field with given expression. 118 * Following expressions are supported. 119 * 1. comma(',') as list. e.g:"1,3,4,8" (space inside the list must not 120 * be used) 121 * 2. dash('-') as range. e.g:"1-6", which means 1 to 6 122 * 3. asterisk('*') as wild. e.g:"*", which means every~ 123 * 4. slash('/') as interval. e.g:"* /5" which means every five~ (without whitespace) 124 */ 125 public Builder set(CronField.Type type, String exp) 126 throws ParseException { 110 * Set cron field with given expression. Following expressions are 111 * supported. 112 * 1. comma(',') as list. e.g:"1,3,4,8" (space inside the list must not be used) 113 * 2. dash('-') as range. e.g:"1-6", which means 1 to 6 114 * 3. asterisk('*') as wild. e.g:"*", which means every~ 115 * 4. slash('/') as interval. e.g:"* /5" which means every five~ (without whitespace) 116 */ 117 public Builder set(CronField.Type type, String exp) throws ParseException { 127 118 this.map.put(type.toString(), new CronField(type, exp)); 128 119 return this; … … 130 121 131 122 /** 132 * returns schedule object representing scheduling rule of current build 133 * object. e.g. new 134 * Schedule.Builder("test").set(CronField.Type.Minute,"5").build(); 123 * returns schedule object representing scheduling rule of current build object. 124 * e.g. new Schedule.Builder("test").set(CronField.Type.Minute,"5").build(); 135 125 * represents schedule of "5 * * * * / test" 136 126 */ 137 public Schedule build() {127 public Schedule build() { 138 128 return new Schedule(this); 139 129 } … … 201 191 } 202 192 193 203 194 } -
kraken-cron/src/main/java/org/krakenapps/cron/impl/CronConfig.java
r346 r352 18 18 */ 19 19 public class CronConfig { 20 // jdbc operations21 20 final Logger logger = LoggerFactory.getLogger(CronConfig.class.getName()); 22 21 private Connection connection; -
kraken-cron/src/main/java/org/krakenapps/cron/impl/CronField.java
r346 r352 6 6 7 7 /** 8 * component of {@link Schedule}. 9 * represents a field of the schedule.8 * component of {@link Schedule}. represents a field of the schedule. 9 * 10 10 * @author periphery 11 11 * @since 1.0.0 … … 17 17 private final String exp; 18 18 19 20 19 public enum Type { 21 Minute("Minute", 60, 0), Hour("Hour", 24, 0), Day_of_Month( 22 "DayOfMonth", 31, 1), Month("Month", 12, 1), Day_of_Week( 23 "DayOfWeek", 7, 0); 24 private final String string; //name of the type. 25 private final int bitLength; 20 Minute("Minute", 60, 0), 21 Hour("Hour", 24, 0), 22 Day_of_Month("DayOfMonth", 31, 1), 23 Month("Month", 12, 1), 24 Day_of_Week("DayOfWeek", 7, 0); 25 26 private final String fieldName; // name of the type. 27 private final int bitLength; 26 28 private final int base; 27 29 28 Type(String arg, int bitLength, int base) {29 this. string = arg;30 Type(String fieldName, int bitLength, int base) { 31 this.fieldName = fieldName; 30 32 this.bitLength = bitLength; 31 33 this.base = base; … … 33 35 34 36 public String toString() { 35 return this. string;37 return this.fieldName; 36 38 } 37 39 … … 44 46 } 45 47 46 private int getLast() {48 private int getLast() { 47 49 return this.getBase() + this.getBitLength() - 1; 48 50 } 51 49 52 /** 50 53 * return true if the num is out of range of given type. valid range of … … 56 59 } 57 60 58 59 61 private void setBits(BitSet bits, int num) { 60 62 if (this.base == 0) … … 63 65 bits.set(num - 1); 64 66 } 67 65 68 /** 66 69 * initialize to all_false if type is day of week. … … 70 73 bits.set(0, this.bitLength); 71 74 } 72 73 private boolean isAllTrue(BitSet bits) {75 76 private boolean isAllTrue(BitSet bits) { 74 77 return bits.nextClearBit(0) >= this.bitLength; 75 78 } 76 private boolean isAllFalse(BitSet bits){ 79 80 private boolean isAllFalse(BitSet bits) { 77 81 return (bits.nextSetBit(0) == -1); 78 82 } … … 86 90 87 91 /** 88 * parse expression and set bitmap. 89 * if the expression is null, it is same as expression "*"(wild card) 90 */ 91 private static String parseExp(CronField.Type type, BitSet bits, String exp) 92 throws ParseException { 93 //filter "*" or null. 92 * parse expression and set bitmap. if the expression is null, it is same as 93 * expression "*"(wild card) 94 */ 95 private static String parseExp(CronField.Type type, BitSet bits, String exp) throws ParseException { 96 // filter "*" or null. 94 97 if (exp == null || exp.matches("[*]")) { 95 98 type.setBits(bits); 96 99 return "*"; 97 //filter empty string. throw Exception.100 // filter empty string. throw Exception. 98 101 } else if (exp.length() == 0) { 99 throw new ParseException( 100 "cron field cannot be set with an empty string : " + exp, 0); 101 //filter list type. 102 throw new ParseException("cron field cannot be set with an empty string : " + exp, 0); 103 // filter list type. 102 104 } else if (exp.matches("([0-9]+[,])+[0-9]+")) { 103 105 String[] splited = exp.split("[,]"); … … 105 107 parseExp(type, bits, sp);// recursive call 106 108 } 107 //filter interval type109 // filter interval type 108 110 } else if (exp.matches("[*]/[0-9]+")) { 109 111 try { … … 113 115 } 114 116 } catch (Exception e) { 115 throw new ParseException( 116 "wrong interval format. e.g. 2/* = every 2nd : " + exp, 117 0); 117 throw new ParseException("wrong interval format. e.g. 2/* = every 2nd : " + exp, 0); 118 118 } 119 //filter range type119 // filter range type 120 120 } else if (exp.matches("[0-9]+[-][0-9]+")) { 121 121 int from = Integer.parseInt(exp.split("[-]")[0]); 122 122 int to = Integer.parseInt(exp.split("[-]")[1]); 123 123 if (to < from || type.invalid(to) || type.invalid(from)) 124 throw new ParseException("invalida range. e.g. 2-5 = 2 to 5 : " 125 + exp, 0); 124 throw new ParseException("invalida range. e.g. 2-5 = 2 to 5 : " + exp, 0); 126 125 for (int i = from; !type.invalid(i) && i <= to; i++) { 127 126 type.setBits(bits, i); 128 127 } 129 //filter single number128 // filter single number 130 129 } else if (exp.matches("[0-9]+")) { 131 130 int num = Integer.parseInt(exp); … … 137 136 return exp; 138 137 } 139 140 /** 141 * if day_of_week is not all_false and day_of_month is all_true, 142 * set day_of_month to all_false. 143 * this is because it is natural to think "0 0 * * 0" as 'weekly' not 'daily'. 144 * this is the reason why day_of_week is initially set to all_false. 145 * @param dom day of month 146 * @param dow day of week 147 * @throws IllegalTypeException when called with cronfield except for dom and dow. 138 139 /** 140 * if day_of_week is not all_false and day_of_month is all_true, set 141 * day_of_month to all_false. this is because it is natural to think 142 * "0 0 * * 0" as 'weekly' not 'daily'. this is the reason why day_of_week 143 * is initially set to all_false. 144 * 145 * @param dom 146 * day of month 147 * @param dow 148 * day of week 149 * @throws IllegalTypeException 150 * when called with cronfield except for dom and dow. 148 151 */ 149 152 public static void solveCollision(CronField dom, CronField dow) throws IllegalTypeException { 150 if (dom.type != Type.Day_of_Month || dow.type != Type.Day_of_Week)153 if (dom.type != Type.Day_of_Month || dow.type != Type.Day_of_Week) 151 154 throw new IllegalTypeException("solveCollision should only be called with dom and dow."); 152 if(dom.type.isAllTrue(dom.bits) && !dow.type.isAllFalse(dow.bits)){ 155 156 if (dom.type.isAllTrue(dom.bits) && !dow.type.isAllFalse(dow.bits)) { 153 157 dom.bits.clear(); 154 158 } 155 159 } 156 157 /** 158 * returns next matching occurrence after given start value.(including start value itself) 160 161 /** 162 * returns next matching occurrence after given start value.(including start 163 * value itself) 164 * 159 165 * @param start 160 166 * @return next matching occurrence 161 * @throws IllegalTypeException when called with dom or dow. should call next(Calender, CronField) instead. 162 */ 163 public int next(int start) throws IllegalTypeException{ 164 if(this.type.equals(CronField.Type.Day_of_Month) || this.type.equals(CronField.Type.Day_of_Week)) 165 throw new IllegalTypeException("not allowed for day_of_month and day_of_week. use next(Calendar, CronField) instead."); 167 * @throws IllegalTypeException 168 * when called with dom or dow. should call next(Calender, 169 * CronField) instead. 170 */ 171 public int next(int start) throws IllegalTypeException { 172 if (this.type.equals(CronField.Type.Day_of_Month) || this.type.equals(CronField.Type.Day_of_Week)) 173 throw new IllegalTypeException( 174 "not allowed for day_of_month and day_of_week. use next(Calendar, CronField) instead."); 166 175 return this.bits.nextSetBit(start); 167 176 } … … 169 178 /** 170 179 * returns the first matching occurrence. 180 * 171 181 * @return first matching occurrence. 172 * @throws IllegalTypeException when called with dom or dow. should call first(Calender, CronField) instead. 182 * @throws IllegalTypeException 183 * when called with dom or dow. should call first(Calender, 184 * CronField) instead. 173 185 */ 174 186 public int first() throws IllegalTypeException { 175 if(this.type.equals(CronField.Type.Day_of_Month) || this.type.equals(CronField.Type.Day_of_Week)) 176 throw new IllegalTypeException("not allowed for day_of_month and day_of_week. use next(Calendar, CronField) instead."); 177 return this.next(0); 178 } 179 180 /** 181 * returns next matching occurrence after given start value.(including start value itself) 187 if (this.type.equals(CronField.Type.Day_of_Month) || this.type.equals(CronField.Type.Day_of_Week)) 188 throw new IllegalTypeException( 189 "not allowed for day_of_month and day_of_week. use next(Calendar, CronField) instead."); 190 191 return this.next(0); 192 } 193 194 /** 195 * returns next matching occurrence after given start value.(including start 196 * value itself) 197 * 182 198 * @param base 183 * @param dow day of week 199 * @param dow 200 * day of week 184 201 * @return 185 * @throws IllegalTypeException when called with a cronField except for dom 202 * @throws IllegalTypeException 203 * when called with a cronField except for dom 186 204 */ 187 205 public int next(Calendar base, CronField dow) throws IllegalTypeException { 188 if (!this.type.equals(CronField.Type.Day_of_Month))206 if (!this.type.equals(CronField.Type.Day_of_Month)) 189 207 throw new IllegalTypeException("only for day_of_month. use next(Calendar, CronField) instead."); 190 return dow2month(base, dow).nextSetBit(base.get(Calendar.DAY_OF_MONTH) -1); 191 } 208 209 return dow2month(base, dow).nextSetBit(base.get(Calendar.DAY_OF_MONTH) - 1); 210 } 211 192 212 /** 193 213 * returns the first matching occurrence. 214 * 194 215 * @return first matching occurrence. 195 * @throws IllegalTypeException when called with a cronField except for dom 196 */ 197 public int first(Calendar base, CronField dow) throws IllegalTypeException{ 198 if(!this.type.equals(CronField.Type.Day_of_Month)) 216 * @throws IllegalTypeException 217 * when called with a cronField except for dom 218 */ 219 public int first(Calendar base, CronField dow) throws IllegalTypeException { 220 if (!this.type.equals(CronField.Type.Day_of_Month)) 199 221 throw new IllegalTypeException("only for day_of_month. use next(Calendar, CronField) instead."); 222 200 223 return dow2month(base, dow).nextSetBit(0); 201 224 } 202 203 // for merging day_of_month and day_of_week.204 // generates new bitmap.205 private BitSet dow2month(Calendar base, CronField dow) {225 226 // for merging day_of_month and day_of_week. 227 // generates new bitmap. 228 private BitSet dow2month(Calendar base, CronField dow) { 206 229 Calendar clone = (Calendar) base.clone(); 207 230 clone.set(Calendar.DAY_OF_MONTH, 1); 208 int weekDayOf_1 = clone.get(Calendar.DAY_OF_WEEK) - 1; //1 for offset 209 //merge dow and dom bitmaps. 231 int weekDayOf_1 = clone.get(Calendar.DAY_OF_WEEK) - 1; // 1 for offset 232 233 // merge dow and dom bitmaps. 210 234 BitSet dow2month = mergeBits(weekDayOf_1, this.bits, dow.bits); 211 //turn off for surplus days of month. (e.g. turn off 30 and 31 from Feb.) 235 // turn off for surplus days of month. (e.g. turn off 30 and 31 from 236 // Feb.) 237 212 238 clone.add(Calendar.MONTH, 1); 213 239 clone.add(Calendar.DAY_OF_MONTH, -1); 214 240 int lastDayOfMonth = clone.get(Calendar.DAY_OF_MONTH); 215 for(int i = lastDayOfMonth; i<this.type.bitLength; i++) 241 242 for (int i = lastDayOfMonth; i < this.type.bitLength; i++) 216 243 dow2month.clear(i); 244 217 245 return dow2month; 218 246 } 219 //generate 31 length bitmap by duplicating dow bitmap. 220 private static BitSet mergeBits(int weekDayOf_1, BitSet dom, BitSet dow){ 247 248 // generate 31 length bitmap by duplicating dow bitmap. 249 private static BitSet mergeBits(int weekDayOf_1, BitSet dom, BitSet dow) { 221 250 BitSet dow2month = new BitSet(); 222 for (int i=0; i<CronField.Type.Day_of_Month.getBitLength(); i++){223 int weekDayOf_i = (i + weekDayOf_1) %7;251 for (int i = 0; i < CronField.Type.Day_of_Month.getBitLength(); i++) { 252 int weekDayOf_i = (i + weekDayOf_1) % 7; 224 253 dow2month.set(i, dow.get(weekDayOf_i)); 225 254 } 226 dow2month.or(dom); //dow bits and dom bits are merged by OR operation. 255 256 dow2month.or(dom); // dow bits and dom bits are merged by OR operation. 227 257 return dow2month; 228 258 } 229 259 230 260 @Override 231 public String toString() {261 public String toString() { 232 262 return this.exp; 233 263 } -
kraken-cron/src/main/java/org/krakenapps/cron/impl/CronServiceImpl.java
r346 r352 6 6 import java.util.List; 7 7 import java.util.Map; 8 import java.util.NoSuchElementException; 8 9 import java.util.concurrent.ConcurrentHashMap; 9 10 import java.util.concurrent.ConcurrentMap; … … 24 25 public class CronServiceImpl implements CronService { 25 26 private static BundleContext bundleContext; 27 /** 28 * schedule id to Schedule mapping. 29 */ 26 30 private ConcurrentMap<Integer, Schedule> map; 27 31 private final CronConfig config; 32 private final Scheduler scheduler = new Scheduler(); 28 33 29 34 public CronServiceImpl(BundleContext context) throws ParseException { … … 34 39 35 40 /** 36 * register schedule. 37 * schedule is saved in db, and added to scheduler. 41 * register schedule. schedule is saved in db, and added to scheduler. 38 42 */ 39 43 @Override 40 public void registerSchedule(Schedule schedule) {44 public void registerSchedule(Schedule schedule) { 41 45 int id = config.addEntry(schedule); 42 46 this.map.put(id, schedule); 43 Scheduler.instance.insertToQueue(id, schedule);47 scheduler.put(id, schedule); 44 48 } 45 49 46 50 /** 47 * unregister schedule. 48 * schedule is removed from db, and from scheduler. 51 * unregister schedule. schedule is removed from db, and from scheduler. 49 52 */ 50 53 @Override 51 public void unregisterSchedule(int i){ 54 public void unregisterSchedule(int i) { 55 if(null==this.map.remove(i)) throw new NoSuchElementException(); 52 56 config.removeEntry(i); 53 this.map.remove(i); 54 Scheduler.instance.deleteFromQueue(i); 57 scheduler.remove(i); 55 58 } 56 59 … … 58 61 * start scheduler 59 62 */ 60 public void validate() {61 Scheduler.instance.start(getMap());63 public void validate() { 64 scheduler.start(getMap()); 62 65 } 63 66 … … 66 69 */ 67 70 public void invalidate() { 68 Scheduler.instance.stop();71 scheduler.stop(); 69 72 } 70 73 71 74 /** 72 75 * load schedules from db. 73 * @throws ParseException when data in db is corrupted and unable to parse as schedule. 76 * 77 * @throws ParseException 78 * when data in db is corrupted and unable to parse as schedule. 74 79 */ 75 80 private void refreshMap() throws ParseException { … … 92 97 @Override 93 98 public List<String> getJobList() { 94 return Scheduler.instance.getJobList();99 return scheduler.getJobList(); 95 100 } 96 101 … … 100 105 101 106 /** 102 * get reference of current active Runnable given its . 107 * get reference of current active Runnable given its instance name. 108 * 103 109 * @param context 104 * @param instanceName instance name of the Runnable 110 * @param instanceName 111 * instance name of the Runnable 105 112 * @return 106 * @throws InvalidSyntaxException when given instance name is not a valid string. 113 * @throws InvalidSyntaxException 114 * when given instance name is not a valid string. 107 115 */ 108 private static Runnable getRef(BundleContext context, String instanceName) 109 throws InvalidSyntaxException { 110 ServiceReference[] refs; 111 refs = context.getServiceReferences(Runnable.class.getName(), 112 "(instance.name=" + instanceName + ")"); 116 private static Runnable getRef(BundleContext context, String instanceName) throws InvalidSyntaxException { 117 ServiceReference[] refs = context.getServiceReferences(Runnable.class.getName(), "(instance.name=" + instanceName + ")"); 113 118 if (refs == null || refs.length == 0) { 114 119 throw new NullPointerException(); 115 120 } 121 116 122 Runnable task = ((Runnable) context.getService(refs[0])); 117 123 return task; -
kraken-cron/src/main/java/org/krakenapps/cron/impl/IllegalTypeException.java
r323 r352 3 3 /** 4 4 * throws when given cron field type is not allowed for the method. 5 * 5 6 * @author periphery 6 7 * 7 8 */ 8 9 public class IllegalTypeException extends Exception { 10 private static final long serialVersionUID = 1L; 9 11 10 12 public IllegalTypeException(String string) { -
kraken-cron/src/main/java/org/krakenapps/cron/impl/Job.java
r346 r352 1 1 package org.krakenapps.cron.impl; 2 2 3 import java.util.Calendar;4 3 import java.util.Date; 5 import java.util.Map;6 4 7 5 import org.krakenapps.cron.Schedule; … … 14 12 * @since 1.0.0 15 13 */ 16 public class Job implements Comparable<Job> , Cloneable{14 public class Job implements Comparable<Job>, Cloneable { 17 15 public final int scheduleId; 18 16 public final Schedule schedule; 19 17 public Date date; 20 21 public Job(int schduleId, Schedule schedule) {18 19 public Job(int schduleId, Schedule schedule) { 22 20 this.scheduleId = schduleId; 23 21 this.schedule = schedule; … … 25 23 } 26 24 27 public boolean timeToDo(){28 return timeToDo(new Date());25 public boolean isTimeToDo() { 26 return isTimeToDo(new Date()); 29 27 } 30 31 //return true for jobs whose time passed 32 public boolean timeToDo(Date now){ 33 if(now.getTime()/1000 - date.getTime()/1000 < 0){ 28 29 /** 30 * return true for jobs whose time passed. 31 */ 32 public boolean isTimeToDo(Date now) { 33 if (now.getTime() / 1000 - date.getTime() / 1000 < 0) { 34 34 return false; 35 } else{35 } else { 36 36 return true; 37 37 } 38 38 } 39 40 public int getScheduleId() {39 40 public int getScheduleId() { 41 41 return this.scheduleId; 42 42 } 43 43 44 44 @Override 45 45 public int compareTo(Job o) { 46 46 return this.date.compareTo(o.date); 47 47 } 48 48 49 49 public void setNextOccurence(Date now) { 50 this.date = NextOccurence Generator.getNextOccurence(schedule, now);50 this.date = NextOccurenceCalculator.getNextOccurence(schedule, now); 51 51 } 52 52 53 53 public void setNextOccurence() { 54 this.date = NextOccurence Generator.getNextOccurence(schedule, new Date());54 this.date = NextOccurenceCalculator.getNextOccurence(schedule, new Date()); 55 55 } 56 57 58 59 public String toString(){ 60 return String.format("[%3d] %15s / %8s", this.scheduleId, this.date, this.schedule.getTaskInstanceName()); 56 57 public String toString() { 58 return String.format("[%3d] %15s / %8s", this.scheduleId, this.date, this.schedule.getTaskName()); 61 59 } 62 60 63 61 @Override 64 public Job clone() {65 try {62 public Job clone() { 63 try { 66 64 return (Job) super.clone(); 67 } catch (Exception e) {65 } catch (Exception e) { 68 66 throw new AssertionError(); 69 67 } … … 71 69 72 70 public void run() throws NullPointerException, InvalidSyntaxException { 73 Runnable task = CronServiceImpl.getRef(this.schedule.getTask InstanceName());74 if (task == null){71 Runnable task = CronServiceImpl.getRef(this.schedule.getTaskName()); 72 if (task == null) { 75 73 throw new NullPointerException("runnable not active"); 76 74 } 75 77 76 task.run(); 78 77 } -
kraken-cron/src/main/java/org/krakenapps/cron/impl/NextOccurenceCalculator.java
r346 r352 6 6 import org.krakenapps.cron.Schedule; 7 7 8 public abstract class NextOccurence Generator {8 public abstract class NextOccurenceCalculator { 9 9 private static final int MONTH_TYPE = 1; 10 10 private static final int DAY_TYPE = 2; … … 40 40 private static final int calendarTypes[] = { Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, 41 41 Calendar.HOUR_OF_DAY, Calendar.MINUTE }; 42 42 43 private static final int upperCalendarTypes[] = { 0, Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH, 43 44 Calendar.HOUR_OF_DAY }; -
kraken-cron/src/main/java/org/krakenapps/cron/impl/QueryStringGenerator.java
r344 r352 5 5 /** 6 6 * generates query string for hsql db. 7 * 7 8 * @author periphery 8 9 * … … 39 40 day_of_week, task, sche.get(CronField.Type.Minute), sche.get(CronField.Type.Hour), sche.get(CronField.Type.Day_of_Month), 40 41 sche.get(CronField.Type.Month), sche.get(CronField.Type.Day_of_Week), 41 sche.getTask InstanceName());42 sche.getTaskName()); 42 43 } 43 44 -
kraken-cron/src/main/java/org/krakenapps/cron/impl/Scheduler.java
r346 r352 21 21 private final Thread loop = new Thread(new Loop()); 22 22 private boolean running; 23 public static Scheduler instance = new Scheduler();24 25 private Scheduler() {26 }27 23 28 24 public void stop() { … … 53 49 * new schedule to add 54 50 */ 55 public void insertToQueue(int id, Schedule sche) {51 public void put(int id, Schedule sche) { 56 52 Job job = new Job(id, sche); 57 53 synchronized (queue) { … … 66 62 * id of the deleting schedule 67 63 */ 68 public void deleteFromQueue(int id) {64 public void remove(int id) { 69 65 synchronized (queue) { 70 66 for (Object job : queue.toArray()) { … … 141 137 public boolean itIsTime() { 142 138 try { 143 return queue.peek(). timeToDo();139 return queue.peek().isTimeToDo(); 144 140 } catch (Exception e) { // empty queue 145 141 return false; … … 161 157 job.run(); 162 158 } catch (NullPointerException e) { 163 logger.debug("Cron: unable to run " + job + ". runnable \'" + job.schedule.getTask InstanceName()159 logger.debug("Cron: unable to run " + job + ". runnable \'" + job.schedule.getTaskName() 164 160 + "\' is not active."); 165 161 } catch (InvalidSyntaxException e) { -
kraken-cron/src/main/java/org/krakenapps/cron/test/JobTest.java
r323 r352 14 14 public class JobTest { 15 15 @Test 16 public void test TimeToDo() {16 public void testisTimeToDo() { 17 17 try { 18 18 Schedule sche1 = new Schedule.Builder("job").build(); 19 19 Job job1 = new Job(21, sche1); 20 assertEquals(job1. timeToDo(), true);20 assertEquals(job1.isTimeToDo(), true); 21 21 22 22 Schedule sche2 = new Schedule.Builder("job").build("*/3 * * * *"); … … 32 32 date = cal.getTime(); 33 33 34 assertFalse(job2. timeToDo(date));// not yet34 assertFalse(job2.isTimeToDo(date));// not yet 35 35 36 36 cal.set(Calendar.MINUTE, 1); 37 37 date = cal.getTime(); 38 assertFalse(job2. timeToDo(date));// not yet38 assertFalse(job2.isTimeToDo(date));// not yet 39 39 40 40 cal.set(Calendar.MINUTE, 2); 41 41 date = cal.getTime(); 42 assertFalse(job2. timeToDo(date));// not yet42 assertFalse(job2.isTimeToDo(date));// not yet 43 43 44 44 cal.set(Calendar.MINUTE, 3);// now 45 45 date = cal.getTime(); 46 assertTrue(job2. timeToDo(date));46 assertTrue(job2.isTimeToDo(date)); 47 47 48 48 cal.set(Calendar.MINUTE, 4);// still 49 49 date = cal.getTime(); 50 assertTrue(job2. timeToDo(date));50 assertTrue(job2.isTimeToDo(date)); 51 51 52 52 cal.set(Calendar.SECOND, 20);// time over 53 53 date = cal.getTime(); 54 assertTrue(job2. timeToDo(date));54 assertTrue(job2.isTimeToDo(date)); 55 55 56 56 cal.set(Calendar.SECOND, 40);// time over 57 57 date = cal.getTime(); 58 assertTrue(job2. timeToDo(date));58 assertTrue(job2.isTimeToDo(date)); 59 59 60 60 } catch (InvalidSyntaxException e) { 61 // TODO Auto-generated catch block62 61 e.printStackTrace(); 63 62 } catch (Exception e) { 64 // TODO Auto-generated catch block65 63 e.printStackTrace(); 66 64 } -
kraken-cron/src/main/java/org/krakenapps/cron/test/NextOccurTest.java
r346 r352 1 1 package org.krakenapps.cron.test; 2 2 3 import java.text.SimpleDateFormat; 3 4 import java.util.Calendar; 4 5 import java.util.Date; … … 7 8 import org.junit.Test; 8 9 import org.krakenapps.cron.Schedule; 9 import org.krakenapps.cron.impl.NextOccurence Generator;10 import org.krakenapps.cron.impl.NextOccurenceCalculator; 10 11 import org.osgi.framework.InvalidSyntaxException; 11 12 import static org.junit.Assert.*; … … 13 14 public class NextOccurTest { 14 15 16 @SuppressWarnings("deprecation") 15 17 @Test 16 18 public void testNext1() throws InvalidSyntaxException, Exception { 19 17 20 18 // Schedule sche1 = new19 // Schedule.Builder("test1").build("*/30 * 3,18 * 0");20 // Schedule sche2 = new21 // Schedule.Builder("test2").build("20-40 * * 4-7 *");22 21 Date date = new Date(Date.parse("Feb 27, 2009 8:14 PM")); 23 22 System.out.println("============ test1 : " + date + "============="); … … 36 35 Schedule sche12 = new Schedule.Builder("awef").build("* * 31 * 0"); 37 36 38 // System.out.println(sche1.getNextOccurence(date));39 // System.out.println(sche2.getNextOccurence(date));40 // System.out.println(sche3.getNextOccurence(date));41 // System.out.println(sche4.getNextOccurence( date));42 // System.out.println(sche5.getNextOccurence(date));43 // System.out.println(sche6.getNextOccurence(date));44 // System.out.println(sche7.getNextOccurence(date));45 // System.out.println(sche8.getNextOccurence(date));46 // System.out.println(sche9.getNextOccurence(date));47 // System.out.println(sche10.getNextOccurence(date));48 // System.out.println(sche11.getNextOccurence( date));49 // System.out.println(sche12.getNextOccurence( date));50 51 37 52 assertEquals(NextOccurence Generator.getNextOccurence(sche1, date).toString(),"Fri Feb 27 20:14:00 KST 2009");53 assertEquals(NextOccurence Generator.getNextOccurence(sche2, date).toString(),"Fri Feb 27 21:00:00 KST 2009");54 assertEquals(NextOccurence Generator.getNextOccurence(sche3, date).toString(),"Sat Feb 28 00:00:00 KST 2009");55 assertEquals(NextOccurence Generator.getNextOccurence(sche4, date).toString(),"Sun Mar 01 00:00:00 KST 2009");56 assertEquals(NextOccurence Generator.getNextOccurence(sche5, date).toString(),"Fri Jan 01 00:00:00 KST 2010");57 assertEquals(NextOccurence Generator.getNextOccurence(sche6, date).toString(),"Fri Feb 27 20:30:00 KST 2009");58 assertEquals(NextOccurence Generator.getNextOccurence(sche7, date).toString(),"Fri Feb 27 20:17:00 KST 2009");59 assertEquals(NextOccurence Generator.getNextOccurence(sche8, date).toString(),"Fri Feb 27 21:03:00 KST 2009");60 assertEquals(NextOccurence Generator.getNextOccurence(sche9, date).toString(),"Sat Feb 28 00:00:00 KST 2009");61 assertEquals(NextOccurence Generator.getNextOccurence(sche10, date).toString(),"Thu Mar 05 00:00:00 KST 2009");62 assertEquals(NextOccurence Generator.getNextOccurence(sche11, date).toString(),"Mon Mar 02 00:00:00 KST 2009");63 assertEquals(NextOccurence Generator.getNextOccurence(sche12, date).toString(),"Sun Mar 01 00:00:00 KST 2009");38 assertEquals(NextOccurenceCalculator.getNextOccurence(sche1, date).toString(),"Fri Feb 27 20:14:00 KST 2009"); 39 assertEquals(NextOccurenceCalculator.getNextOccurence(sche2, date).toString(),"Fri Feb 27 21:00:00 KST 2009"); 40 assertEquals(NextOccurenceCalculator.getNextOccurence(sche3, date).toString(),"Sat Feb 28 00:00:00 KST 2009"); 41 assertEquals(NextOccurenceCalculator.getNextOccurence(sche4, date).toString(),"Sun Mar 01 00:00:00 KST 2009"); 42 assertEquals(NextOccurenceCalculator.getNextOccurence(sche5, date).toString(),"Fri Jan 01 00:00:00 KST 2010"); 43 assertEquals(NextOccurenceCalculator.getNextOccurence(sche6, date).toString(),"Fri Feb 27 20:30:00 KST 2009"); 44 assertEquals(NextOccurenceCalculator.getNextOccurence(sche7, date).toString(),"Fri Feb 27 20:17:00 KST 2009"); 45 assertEquals(NextOccurenceCalculator.getNextOccurence(sche8, date).toString(),"Fri Feb 27 21:03:00 KST 2009"); 46 assertEquals(NextOccurenceCalculator.getNextOccurence(sche9, date).toString(),"Sat Feb 28 00:00:00 KST 2009"); 47 assertEquals(NextOccurenceCalculator.getNextOccurence(sche10, date).toString(),"Thu Mar 05 00:00:00 KST 2009"); 48 assertEquals(NextOccurenceCalculator.getNextOccurence(sche11, date).toString(),"Mon Mar 02 00:00:00 KST 2009"); 49 assertEquals(NextOccurenceCalculator.getNextOccurence(sche12, date).toString(),"Sun Mar 01 00:00:00 KST 2009"); 64 50 } 65 51 52 @SuppressWarnings("deprecation") 66 53 @Test 67 54 public void testNext2() throws InvalidSyntaxException, Exception { 68 55 69 // Schedule sche1 = new70 // Schedule.Builder("test1").build("*/30 * 3,18 * 0");71 // Schedule sche2 = new72 // Schedule.Builder("test2").build("20-40 * * 4-7 *");73 56 Date date = new Date(Date.parse("Aug 6, 2009 1:11 AM")); 74 57 System.out.println("============ test2 : " + date + "============="); … … 86 69 Schedule sche11 = new Schedule.Builder("awef").build("0 0 5,28 3 1"); 87 70 88 // System.out.println(sche1.getNextOccurence(date)); 89 // System.out.println(sche2.getNextOccurence(date)); 90 // System.out.println(sche3.getNextOccurence(date)); 91 // System.out.println(sche4.getNextOccurence(date)); 92 // System.out.println(sche5.getNextOccurence(date)); 93 // System.out.println(sche6.getNextOccurence(date)); 94 // System.out.println(sche7.getNextOccurence(date)); 95 // System.out.println(sche8.getNextOccurence(date)); 96 // System.out.println(sche9.getNextOccurence(date)); 97 // System.out.println(sche10.getNextOccurence( date)); 98 // System.out.println(sche11.getNextOccurence( date)); 99 // 100 assertEquals(NextOccurenceGenerator.getNextOccurence(sche1, date).toString(),"Thu Aug 06 01:11:00 KST 2009"); 101 assertEquals(NextOccurenceGenerator.getNextOccurence(sche2, date).toString(),"Thu Aug 06 02:00:00 KST 2009"); 102 assertEquals(NextOccurenceGenerator.getNextOccurence(sche3, date).toString(),"Fri Aug 07 00:00:00 KST 2009"); 103 assertEquals(NextOccurenceGenerator.getNextOccurence(sche4, date).toString(),"Sun Aug 09 00:00:00 KST 2009"); 104 assertEquals(NextOccurenceGenerator.getNextOccurence(sche5, date).toString(),"Fri Jan 01 00:00:00 KST 2010"); 105 assertEquals(NextOccurenceGenerator.getNextOccurence(sche6, date).toString(),"Thu Aug 06 01:30:00 KST 2009"); 106 assertEquals(NextOccurenceGenerator.getNextOccurence(sche7, date).toString(),"Thu Aug 06 01:17:00 KST 2009"); 107 assertEquals(NextOccurenceGenerator.getNextOccurence(sche8, date).toString(),"Thu Aug 06 03:03:00 KST 2009"); 108 assertEquals(NextOccurenceGenerator.getNextOccurence(sche9, date).toString(),"Fri Aug 28 00:00:00 KST 2009"); 109 assertEquals(NextOccurenceGenerator.getNextOccurence(sche10, date).toString(),"Fri Mar 05 00:00:00 KST 2010"); 110 assertEquals(NextOccurenceGenerator.getNextOccurence(sche11, date).toString(),"Mon Mar 01 00:00:00 KST 2010"); 71 assertEquals(NextOccurenceCalculator.getNextOccurence(sche1, date).toString(),"Thu Aug 06 01:11:00 KST 2009"); 72 assertEquals(NextOccurenceCalculator.getNextOccurence(sche2, date).toString(),"Thu Aug 06 02:00:00 KST 2009"); 73 assertEquals(NextOccurenceCalculator.getNextOccurence(sche3, date).toString(),"Fri Aug 07 00:00:00 KST 2009"); 74 assertEquals(NextOccurenceCalculator.getNextOccurence(sche4, date).toString(),"Sun Aug 09 00:00:00 KST 2009"); 75 assertEquals(NextOccurenceCalculator.getNextOccurence(sche5, date).toString(),"Fri Jan 01 00:00:00 KST 2010"); 76 assertEquals(NextOccurenceCalculator.getNextOccurence(sche6, date).toString(),"Thu Aug 06 01:30:00 KST 2009"); 77 assertEquals(NextOccurenceCalculator.getNextOccurence(sche7, date).toString(),"Thu Aug 06 01:17:00 KST 2009"); 78 assertEquals(NextOccurenceCalculator.getNextOccurence(sche8, date).toString(),"Thu Aug 06 03:03:00 KST 2009"); 79 assertEquals(NextOccurenceCalculator.getNextOccurence(sche9, date).toString(),"Fri Aug 28 00:00:00 KST 2009"); 80 assertEquals(NextOccurenceCalculator.getNextOccurence(sche10, date).toString(),"Fri Mar 05 00:00:00 KST 2010"); 81 assertEquals(NextOccurenceCalculator.getNextOccurence(sche11, date).toString(),"Mon Mar 01 00:00:00 KST 2010"); 111 82 } 112 83 … … 118 89 System.out.println("============ daily : " + date1 + "============="); 119 90 for(int i = 0 ; i < 20; i++){ 120 date1 = NextOccurence Generator.getNextOccurence(sche, date1);91 date1 = NextOccurenceCalculator.getNextOccurence(sche, date1); 121 92 System.out.println(date1); 122 93 date1 = new Date(date1.getTime() + 60 * 1000); … … 131 102 System.out.println("============ weekly : " + date1 + "============="); 132 103 for(int i = 0 ; i < 20; i++){ 133 date1 = NextOccurence Generator.getNextOccurence(sche, date1);104 date1 = NextOccurenceCalculator.getNextOccurence(sche, date1); 134 105 System.out.println(date1); 135 106 date1 = new Date(date1.getTime() + 60 * 1000); … … 144 115 System.out.println("============ mondayAnd10th : " + date1 + "============="); 145 116 for(int i = 0 ; i < 20; i++){ 146 date1 = NextOccurence Generator.getNextOccurence(sche, date1);117 date1 = NextOccurenceCalculator.getNextOccurence(sche, date1); 147 118 System.out.println(date1); 148 119 date1 = new Date(date1.getTime() + 60 * 1000); … … 150 121 } 151 122 123 @SuppressWarnings("deprecation") 152 124 @Test 153 125 public void test31th() throws InvalidSyntaxException, Exception{ … … 157 129 System.out.println("============ 31th : " + date1 + "============="); 158 130 for(int i = 0 ; i < 20; i++){ 159 date1 = NextOccurence Generator.getNextOccurence(sche, date1);131 date1 = NextOccurenceCalculator.getNextOccurence(sche, date1); 160 132 System.out.println(date1); 161 133 Calendar cal = Calendar.getInstance(); -
kraken-cron/src/main/java/org/krakenapps/cron/test/ScheduleBuildTest.java
r323 r352 14 14 public void testBuildManual() throws Exception { 15 15 try { 16 Schedule test = new Schedule.Builder("daily").set( 17 CronField.Type.Day_of_Week, "0").set( 18 CronField.Type.Day_of_Month, "*/10").set( 19 CronField.Type.Hour, "4-10").set(CronField.Type.Minute, 16 Schedule test = new Schedule.Builder("daily").set(CronField.Type.Day_of_Week, "0").set( 17 CronField.Type.Day_of_Month, "*/10").set(CronField.Type.Hour, "4-10").set(CronField.Type.Minute, 20 18 "0,3,59").set(CronField.Type.Month, "12").build(); 21 Schedule test2 = new Schedule.Builder("daily").set( 22 CronField.Type.Day_of_Week, "3").set( 23 CronField.Type.Day_of_Month, "1").set(CronField.Type.Hour, 24 "0-23").set(CronField.Type.Minute, "2,3,3").build(); 19 Schedule test2 = new Schedule.Builder("daily").set(CronField.Type.Day_of_Week, "3").set( 20 CronField.Type.Day_of_Month, "1").set(CronField.Type.Hour, "0-23").set(CronField.Type.Minute, 21 "2,3,3").build(); 25 22 26 23 System.out.println("test1" + test); … … 28 25 29 26 assertEquals(test.fieldMembers(CronField.Type.Minute), "{0, 3, 59}"); 30 assertEquals(test.fieldMembers(CronField.Type.Day_of_Month), 31 "{0, 10, 20, 30}"); // interval 32 assertEquals(test.fieldMembers(CronField.Type.Hour), 33 "{4, 5, 6, 7, 8, 9, 10}"); // range 27 assertEquals(test.fieldMembers(CronField.Type.Day_of_Month), "{0, 10, 20, 30}"); // interval 28 assertEquals(test.fieldMembers(CronField.Type.Hour), "{4, 5, 6, 7, 8, 9, 10}"); // range 34 29 assertEquals(test.fieldMembers(CronField.Type.Month), "{11}"); 35 30 36 31 assertEquals(test2.fieldMembers(CronField.Type.Minute), "{2, 3}"); // specify 37 assertEquals(test2.fieldMembers(CronField.Type.Month), 38 "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}"); // default 32 assertEquals(test2.fieldMembers(CronField.Type.Month), "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}"); // default 39 33 40 assertEquals(test, new Schedule.Builder("daily") 41 .build("0,3,59 4-10 */10 12 0")); 34 assertEquals(test, new Schedule.Builder("daily").build("0,3,59 4-10 */10 12 0")); 42 35 } catch (Exception e) { 43 36 fail(); … … 45 38 } 46 39 } 47 40 48 41 @Test 49 42 public void testBuildString() throws InvalidSyntaxException, Exception { … … 52 45 System.out.println("test3" + test3); 53 46 54 assertEquals(test3.fieldMembers(CronField.Type.Day_of_Week), 55 "{3, 4, 5, 6}"); 47 assertEquals(test3.fieldMembers(CronField.Type.Day_of_Week), "{3, 4, 5, 6}"); 56 48 assertEquals(test3.fieldMembers(CronField.Type.Day_of_Month), "{0}"); 57 49 assertEquals(test3.fieldMembers(CronField.Type.Month), "{0}"); 58 50 } catch (Exception e) { 59 51 fail(); 60 // TODO: handle exception61 52 } 62 53 … … 77 68 System.out.println("test7" + test7); 78 69 79 assertEquals(test8, new Schedule.Builder("daily") 80 .build("* * * * * ")); 81 assertEquals(test4, new Schedule.Builder("daily") 82 .build("0 0 1 1 *")); 83 assertEquals(test5, new Schedule.Builder("daily") 84 .build("0 0 1 * *")); 85 assertEquals(test6, new Schedule.Builder("daily") 86 .build("0 0 * * *")); 87 assertEquals(test7, new Schedule.Builder("daily") 88 .build("0 0 * * 0")); 70 assertEquals(test8, new Schedule.Builder("daily").build("* * * * * ")); 71 assertEquals(test4, new Schedule.Builder("daily").build("0 0 1 1 *")); 72 assertEquals(test5, new Schedule.Builder("daily").build("0 0 1 * *")); 73 assertEquals(test6, new Schedule.Builder("daily").build("0 0 * * *")); 74 assertEquals(test7, new Schedule.Builder("daily").build("0 0 * * 0")); 89 75 } catch (Exception e) { 90 76 fail(); … … 105 91 } catch (Exception e) { 106 92 fail(); 107 // TODO: handle exception108 93 } 109 94 } … … 113 98 try { 114 99 Schedule test8 = new Schedule.Builder("daily").build(); 115 Schedule test9 = new Schedule.Builder("daily").set( 116 CronField.Type.Day_of_Week, "*").build(); 117 Schedule test10 = new Schedule.Builder("daily").set( 118 CronField.Type.Day_of_Week, "3").build(); 100 Schedule test9 = new Schedule.Builder("daily").set(CronField.Type.Day_of_Week, "*").build(); 101 Schedule test10 = new Schedule.Builder("daily").set(CronField.Type.Day_of_Week, "3").build(); 119 102 System.out.println("test8" + test8); 120 103 System.out.println("test9" + test9); … … 136 119 fail(); 137 120 } catch (ParseException e) { 138 // TODO Auto-generated catch block 139 } 121 } 140 122 try { 141 123 new Schedule.Builder("daily").set(CronField.Type.Day_of_Month, "0"); 142 124 fail(); 143 125 } catch (ParseException e) { 144 // TODO Auto-generated catch block 145 } 126 } 146 127 try { 147 128 new Schedule.Builder("daily").set(CronField.Type.Hour, "24"); 148 129 fail(); 149 130 } catch (ParseException e) { 150 // TODO Auto-generated catch block 151 } 131 } 152 132 try { 153 133 new Schedule.Builder("daily").set(CronField.Type.Hour, "-4"); 154 134 fail(); 155 135 } catch (ParseException e) { 156 // TODO Auto-generated catch block 157 } 136 } 158 137 try { 159 138 new Schedule.Builder("daily").build("0 0 0 0"); 160 139 fail(); 161 140 } catch (ParseException e) { 162 // TODO Auto-generated catch block 163 }catch (Exception e) { 164 // TODO Auto-generated catch block 141 } catch (Exception e) { 165 142 } 166 143 }
