1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.aggregator;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25
26 import org.apache.jetspeed.aggregator.impl.WorkerMonitorImpl;
27 import org.apache.jetspeed.om.window.impl.PortletWindowImpl;
28 import org.apache.pluto.om.window.PortletWindow;
29
30 /***
31 * <P>Test the aggregation service</P>
32 *
33 * @author <a href="mailto:david@bluesunrise.com">David Sean Taylor</a>
34 * @version $Id: $
35 *
36 */
37 public class TestWorkerMonitor extends TestCase
38 {
39 /***
40 * Start the tests.
41 *
42 * @param args the arguments. Not used
43 */
44 public static void main(String args[])
45 {
46 junit.awtui.TestRunner.main(new String[] { TestWorkerMonitor.class.getName()});
47 }
48
49 protected void setUp() throws Exception
50 {
51 super.setUp();
52
53
54
55 }
56
57 public static Test suite()
58 {
59
60 return new TestSuite(TestWorkerMonitor.class);
61 }
62
63 private static final int JOB_COUNT = 2;
64
65 public void testBasic() throws Exception
66 {
67 WorkerMonitor monitor = new WorkerMonitorImpl(1, 2, 1, 1);
68
69 List jobs = new ArrayList(JOB_COUNT);
70 for (int ix = 0; ix < JOB_COUNT; ix++)
71 {
72 PortletWindow window = new PortletWindowImpl("w" + String.valueOf(ix));
73 jobs.add(new MockRenderJob("Job-" + (ix + 1), 4000, window));
74 }
75 assertNotNull("monitor is null", monitor);
76 monitor.start();
77 for (int ix = 0; ix < JOB_COUNT; ix++)
78 monitor.process((RenderingJob)jobs.get(ix));
79
80 Thread.sleep(2000);
81 assertTrue("available jobs expect 0", monitor.getAvailableJobsCount() == 0);
82 assertTrue("running jobs expect 2", monitor.getRunningJobsCount() == 2);
83 assertTrue("queued jobs expect 0", monitor.getQueuedJobsCount() == 0);
84 monitor.stop();
85 }
86
87 }