14
14
import org.springframework.test.context.ContextConfiguration;
15
15
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17
class MyRunnable implements Runnable {
21
this.name = "MyRunnable";
25
System.out.println("Process was run");
27
Thread.currentThread().sleep((int)(1000*Math.random()));
24
this.name = "MyRunnable";
29
System.out.println( "Process was run" );
32
Thread.currentThread().sleep( (int) (1000 * Math.random()) );
35
@RunWith(SpringJUnit4ClassRunner.class)
36
@ContextConfiguration(locations = {"classpath*:/META-INF/dhis/beans.xml"})
37
public class DefaultSchedulingTest {
38
DefaultSchedulingImpl test;
42
test = new DefaultSchedulingImpl();
46
public void addTaskForSchedulingTest() {
47
System.out.println("START TEST 1");
48
int id = test.addTaskForScheduling(new MyRunnable(), new Date(System.currentTimeMillis() + 2000), true, false);
49
assertNotNull(test.getScheduledTask(id));
51
Thread.currentThread().sleep(30000);
56
System.out.println("END TEST 1");
60
public void delTaskFromScheduling() {
61
// TODO Auto-generated method stub
62
int id = test.addTaskForScheduling(new MyRunnable(), new Date(System.currentTimeMillis() + 1000), true, false);
63
test.delTaskFromScheduling(id);
64
assertNull(test.getScheduledTask(id));
68
public void getAllScheduledTasks() {
70
test.addTaskForScheduling(new MyRunnable(), new Date(System.currentTimeMillis() + 1000), false, false);
71
Thread.currentThread().sleep(1000);
72
test.addTaskForScheduling(new MyRunnable(), new Date(System.currentTimeMillis() + 1000), false, false);
73
Thread.currentThread().sleep(1000);
74
test.addTaskForScheduling(new MyRunnable(), new Date(System.currentTimeMillis() + 1000), false, false);
75
Thread.currentThread().sleep(1000);
76
test.addTaskForScheduling(new MyRunnable(), new Date(System.currentTimeMillis() + 1000), false, false);
77
Thread.currentThread().sleep(1000);
78
test.addTaskForScheduling(new MyRunnable(), new Date(System.currentTimeMillis() + 1000), false, false);
81
assertEquals(5, test.getAllScheduledTasks().size());
83
Thread.currentThread().sleep(5000);
88
// TODO Auto-generated method stub
92
public void getScheduledTask() {
93
// TODO Auto-generated method stub
94
int id = test.addTaskForScheduling(new MyRunnable(), new Date(System.currentTimeMillis() + 10000), true, false);
95
assertNotNull(test.getScheduledTask(id));
99
public void getLoggingForSpecificTask() {
100
// TODO Auto-generated method stub
104
public void startLogging() {
105
// TODO Auto-generated method stub
107
assertTrue(test.shouldLog);
111
public void stopLogging() {
112
// TODO Auto-generated method stub
114
assertFalse(test.shouldLog);
117
public void getAllLogging() {
118
// TODO Auto-generated method stub
122
public void updateScheduledTask() {
123
// TODO Auto-generated method stub
124
int id = test.addTaskForScheduling(new MyRunnable(), new Date(System.currentTimeMillis() + 100000), false, false);
126
Date before = test.getScheduledTask(id).getDate();
128
test.updateScheduledTask(id, new Date(System.currentTimeMillis() + 5000), false, false);
129
Date after = test.getScheduledTask(id).getDate();
130
assertTrue(before.compareTo(after) > 0);
133
Thread.currentThread().sleep(10000);
135
catch (Exception e) {
41
@RunWith( SpringJUnit4ClassRunner.class )
42
@ContextConfiguration( locations = { "classpath*:/META-INF/dhis/beans.xml" } )
43
public class DefaultSchedulingTest
45
DefaultSchedulingImpl test;
50
test = new DefaultSchedulingImpl();
54
public void addTaskForSchedulingTest()
56
System.out.println( "START TEST 1" );
57
int id = test.addTaskForScheduling( new MyRunnable(), new Date( System.currentTimeMillis() + 2000 ), true,
59
assertNotNull( test.getScheduledTask( id ) );
62
Thread.currentThread().sleep( 30000 );
68
System.out.println( "END TEST 1" );
72
public void delTaskFromScheduling()
74
// TODO Auto-generated method stub
75
int id = test.addTaskForScheduling( new MyRunnable(), new Date( System.currentTimeMillis() + 1000 ), true,
77
test.delTaskFromScheduling( id );
78
assertNull( test.getScheduledTask( id ) );
82
public void getAllScheduledTasks()
86
test.addTaskForScheduling( new MyRunnable(), new Date( System.currentTimeMillis() + 1000 ), false, false, "test" );
87
Thread.currentThread().sleep( 1000 );
88
test.addTaskForScheduling( new MyRunnable(), new Date( System.currentTimeMillis() + 1000 ), false, false, "test" );
89
Thread.currentThread().sleep( 1000 );
90
test.addTaskForScheduling( new MyRunnable(), new Date( System.currentTimeMillis() + 1000 ), false, false, "test" );
91
Thread.currentThread().sleep( 1000 );
92
test.addTaskForScheduling( new MyRunnable(), new Date( System.currentTimeMillis() + 1000 ), false, false, "test" );
93
Thread.currentThread().sleep( 1000 );
94
test.addTaskForScheduling( new MyRunnable(), new Date( System.currentTimeMillis() + 1000 ), false, false, "test" );
96
assertEquals( 5, test.getAllScheduledTasks().size() );
98
Thread.currentThread().sleep( 5000 );
100
catch ( Exception e )
104
// TODO Auto-generated method stub
108
public void getScheduledTask()
110
// TODO Auto-generated method stub
111
int id = test.addTaskForScheduling( new MyRunnable(), new Date( System.currentTimeMillis() + 10000 ), true,
113
assertNotNull( test.getScheduledTask( id ) );
117
public void getLoggingForSpecificTask()
119
// TODO Auto-generated method stub
123
public void startLogging()
125
// TODO Auto-generated method stub
127
assertTrue( test.shouldLog );
131
public void stopLogging()
133
// TODO Auto-generated method stub
135
assertFalse( test.shouldLog );
138
public void getAllLogging()
140
// TODO Auto-generated method stub
144
public void updateScheduledTask()
146
// TODO Auto-generated method stub
147
int id = test.addTaskForScheduling( new MyRunnable(), new Date( System.currentTimeMillis() + 100000 ), false,
150
Date before = test.getScheduledTask( id ).getDate();
152
test.updateScheduledTask( id, new Date( System.currentTimeMillis() + 5000 ), false, false );
153
Date after = test.getScheduledTask( id ).getDate();
154
assertTrue( before.compareTo( after ) > 0 );
158
Thread.currentThread().sleep( 10000 );
160
catch ( Exception e )