1 4 package net.sf.mybatchfwk.test; 5 6 import java.util.Calendar ; 7 import java.util.GregorianCalendar ; 8 9 import net.sf.mybatchfwk.BatchConfiguration; 10 import net.sf.mybatchfwk.BatchService; 11 import junit.framework.TestCase; 12 13 public class TestScheduledBatch extends TestCase { 14 15 public void testScheduledBatchWithDeferredStart() { 16 17 Exception error = null; 18 19 BatchConfiguration config = new BatchConfiguration(); 20 config.setThreadPoolMinSize(1); 21 config.setThreadPoolMaxSize(2); 22 config.setBlockingQueueCapacity(2); 23 config.setScheduleEnable(true); 24 25 GregorianCalendar calendar = new GregorianCalendar (); 26 calendar.add(Calendar.SECOND, 2); 27 config.setScheduleStartDate(calendar.getTime()); 28 29 BatchService service = new BatchService(); 30 service.setBatch(new SimpleBatch()); 31 try { 32 service.init(config); 33 service.launch(); 34 } catch (Exception e) { 35 service.manageFatalError(e); 36 error = e; 37 } 38 39 assertNull(error); 40 assertEquals(service.getState(), BatchService.STATE.SHUTDOWN); 41 assertEquals(service.getExecutionReport().getNumberOfCompletedTasks(), 5); 42 } 43 44 public void testScheduledBatchWithPeriodTime() { 45 46 Exception error = null; 47 48 BatchConfiguration config = new BatchConfiguration(); 49 config.setThreadPoolMinSize(1); 50 config.setThreadPoolMaxSize(2); 51 config.setBlockingQueueCapacity(2); 52 config.setScheduleEnable(true); 53 54 GregorianCalendar calendar = new GregorianCalendar (); 56 calendar.add(Calendar.SECOND, 8); 57 config.setScheduleEndDate(calendar.getTime()); 58 config.setSchedulePeriodTime(3000); 59 60 BatchService service = new BatchService(); 61 service.setBatch(new SimpleBatch()); 62 try { 63 service.init(config); 64 service.launch(); 65 } catch (Exception e) { 66 service.manageFatalError(e); 67 error = e; 68 } 69 70 assertNull(error); 71 assertEquals(service.getState(), BatchService.STATE.SHUTDOWN); 72 assertEquals(service.getExecutionReport().getNumberOfCompletedTasks(), 15); 73 } 74 75 public void testScheduledBatchWithLoop() { 76 77 Exception error = null; 78 79 BatchConfiguration config = new BatchConfiguration(); 80 config.setThreadPoolMinSize(1); 81 config.setThreadPoolMaxSize(2); 82 config.setBlockingQueueCapacity(2); 83 config.setScheduleEnable(true); 84 85 config.setSchedulePeriodTime(3000); 87 config.setScheduleNumberOfLoop(3); 88 89 BatchService service = new BatchService(); 90 service.setBatch(new SimpleBatch()); 91 try { 92 service.init(config); 93 service.launch(); 94 } catch (Exception e) { 95 service.manageFatalError(e); 96 error = e; 97 } 98 99 assertNull(error); 100 assertEquals(service.getState(), BatchService.STATE.SHUTDOWN); 101 assertEquals(service.getExecutionReport().getNumberOfCompletedTasks(), 15); 102 } 103 } 104 | Popular Tags |