01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
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: * Start the tests.
40: *
41: * @param args the arguments. Not used
42: */
43: public static void main(String args[]) {
44: junit.awtui.TestRunner
45: .main(new String[] { TestWorkerMonitor.class.getName() });
46: }
47:
48: protected void setUp() throws Exception {
49: super .setUp();
50:
51: }
52:
53: public static Test suite() {
54: // All methods starting with "test" will be executed in the test suite.
55: return new TestSuite(TestWorkerMonitor.class);
56: }
57:
58: private static final int JOB_COUNT = 2;
59:
60: public void testBasic() throws Exception {
61: WorkerMonitor monitor = new WorkerMonitorImpl(1, 2, 1, 1);
62:
63: List jobs = new ArrayList(JOB_COUNT);
64: for (int ix = 0; ix < JOB_COUNT; ix++) {
65: PortletWindow window = new PortletWindowImpl("w"
66: + String.valueOf(ix));
67: jobs
68: .add(new MockRenderJob("Job-" + (ix + 1), 4000,
69: window));
70: }
71: assertNotNull("monitor is null", monitor);
72: monitor.start();
73: for (int ix = 0; ix < JOB_COUNT; ix++)
74: monitor.process((RenderingJob) jobs.get(ix));
75:
76: Thread.sleep(2000);
77: assertTrue("available jobs expect 0", monitor
78: .getAvailableJobsCount() == 0);
79: assertTrue("running jobs expect 2", monitor
80: .getRunningJobsCount() == 2);
81: assertTrue("queued jobs expect 0",
82: monitor.getQueuedJobsCount() == 0);
83: monitor.stop();
84: }
85:
86: }
|