1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      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      /***
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          // All methods starting with "test" will be executed in the test suite.
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  }