001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2007 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: SchedulerCoreTest.java 6906 2007-04-19 03:06:05Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.scheduler;
025:
026: import junit.framework.TestCase;
027: import java.util.Calendar;
028: import java.text.SimpleDateFormat;
029:
030: import org.apache.commons.logging.Log;
031: import org.apache.commons.logging.LogFactory;
032:
033: public class SchedulerCoreTest extends TestCase {
034:
035: private Log log = LogFactory.getLog(SchedulerCoreTest.class);
036:
037: /**
038: * @param name
039: */
040: public SchedulerCoreTest(String name) {
041: super (name);
042: }
043:
044: /* (non-Javadoc)
045: * @see junit.framework.TestCase#setUp()
046: */
047: protected void setUp() throws Exception {
048: super .setUp();
049: }
050:
051: /* (non-Javadoc)
052: * @see junit.framework.TestCase#tearDown()
053: */
054: protected void tearDown() throws Exception {
055: super .tearDown();
056: }
057:
058: public void testStandardSchedule() throws Exception {
059: SchedulerCore schedulerCore = new SchedulerCore();
060: schedulerCore.start();
061:
062: StandardSchedule stdSched = new StandardSchedule();
063:
064: stdSched.setSeconds("0,15,30,45");
065: stdSched.setMinutes("*");
066: stdSched.setHours("*");
067: stdSched.setDayOfMonth("*");
068: stdSched.setMonth("*");
069: stdSched.setDayOfWeek("?");
070:
071: TestStandardProcessor jobProcessor = new TestStandardProcessor();
072:
073: schedulerCore.submitStandardJob("Job1", "Group1", jobProcessor,
074: stdSched);
075:
076: Thread.sleep(90 * 1000L); //Sleep 90 seconds to let job run
077:
078: schedulerCore.removeJob("Job1", "Group1");
079:
080: schedulerCore.shutdown();
081: }
082:
083: public void testAutoRetryScheduleSuccess() throws Exception {
084:
085: SchedulerCore schedulerCore = new SchedulerCore();
086: schedulerCore.start();
087:
088: SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
089: Calendar cal = Calendar.getInstance();
090: cal.set(Calendar.SECOND, 0);
091: cal.add(Calendar.MINUTE, 1);
092: String startTime = dateFormat.format(cal.getTime());
093: cal.add(Calendar.MINUTE, 2);
094: String endTime = dateFormat.format(cal.getTime());
095:
096: log.info("Start Time = " + startTime);
097: log.info("End Time = " + endTime);
098: AutoRetrySchedule arSched = new AutoRetrySchedule();
099: arSched.setStartTime(startTime);
100: arSched.setEndTime(endTime);
101: arSched.setRetryInterval(15);
102: arSched.setDayOfMonth("*");
103: arSched.setMonth("*");
104: arSched.setDayOfWeek("?");
105:
106: TestAutoRetryProcessor jobProcessor = new TestAutoRetryProcessor();
107:
108: schedulerCore.submitAutoRetryJob("Job1", "Group1",
109: jobProcessor, arSched);
110:
111: Thread.sleep(180 * 1000L); //200 seconds to give enough time to reach end time
112:
113: schedulerCore.removeJob("Job1", "Group1");
114:
115: schedulerCore.shutdown();
116: }
117:
118: public void testAutoRetryScheduleFail() throws Exception {
119:
120: SchedulerCore schedulerCore = new SchedulerCore();
121: schedulerCore.start();
122:
123: SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
124: Calendar cal = Calendar.getInstance();
125: cal.set(Calendar.SECOND, 0);
126: cal.add(Calendar.MINUTE, 1);
127: String startTime = dateFormat.format(cal.getTime());
128: cal.add(Calendar.MINUTE, 1);
129: String endTime = dateFormat.format(cal.getTime());
130:
131: log.info("Start Time = " + startTime);
132: log.info("End Time = " + endTime);
133: AutoRetrySchedule arSched = new AutoRetrySchedule();
134: arSched.setStartTime(startTime);
135: arSched.setEndTime(endTime);
136: arSched.setRetryInterval(15);
137: arSched.setDayOfMonth("*");
138: arSched.setMonth("*");
139: arSched.setDayOfWeek("?");
140:
141: TestAutoRetryProcessor jobProcessor = new TestAutoRetryProcessor();
142:
143: schedulerCore.submitAutoRetryJob("Job1", "Group1",
144: jobProcessor, arSched);
145:
146: Thread.sleep(120 * 1000L); //120 seconds to give enough time to reach end time
147:
148: schedulerCore.removeJob("Job1", "Group1");
149:
150: schedulerCore.shutdown();
151: }
152:
153: }
|