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  
18  package org.apache.commons.pipeline.driver;
19  
20  import java.util.concurrent.LinkedBlockingQueue;
21  
22  import junit.framework.Test;
23  import junit.framework.TestSuite;
24  
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  import org.apache.commons.pipeline.Feeder;
28  import org.apache.commons.pipeline.StageDriver.State;
29  
30  /**
31   *
32   *
33   */
34  public class DedicatedThreadStageDriverTest extends AbstractStageDriverTest {
35      private Log log;
36      
37      public DedicatedThreadStageDriverTest(String testName) {
38          super(testName);
39          this.log = LogFactory.getLog(DedicatedThreadStageDriverTest.class);
40      }
41      
42      public static Test suite() {
43          TestSuite suite = new TestSuite(DedicatedThreadStageDriverTest.class);
44          
45          return suite;
46      }
47          /**
48       * Test of getFeeder method, of class org.apache.commons.pipeline.driver.SynchronousStageDriver.
49       */
50      public void testGetFeeder() {
51          log.debug("testGetFeeder ---------------------------------------------");
52          DedicatedThreadStageDriver instance = new DedicatedThreadStageDriver(stage, context, new LinkedBlockingQueue<Object>(), 500, FaultTolerance.NONE);
53          
54          Feeder feeder = instance.getFeeder();
55          assertNotNull(feeder);        
56      }
57      
58      /**
59       * Due to the design of the DedicatedThreadStageDriver, it is meaningless
60       * to independently test the start or finish methods; however, testing 
61       * both together is meaningful. This test also provides verification of
62       * proper behavior of the getState() method.
63       */
64      public void testStartFinish() throws Exception {
65          log.debug("testStartFinish -------------------------------------------");
66          DedicatedThreadStageDriver instance = new DedicatedThreadStageDriver(stage, context, new LinkedBlockingQueue<Object>(), 500, FaultTolerance.NONE);
67          
68          assertEquals(State.STOPPED, instance.getState());
69          
70          instance.start();
71          
72          assertTrue(instance.getState() == State.STARTED || instance.getState() == State.RUNNING);
73          
74          instance.finish();
75          
76          assertEquals(State.STOPPED, instance.getState());
77      }
78  
79          
80      /*********************
81       * INTEGRATION TESTS *
82       *********************/
83      
84      public void testSingleStage() throws Exception {        
85          log.debug("testSingleStage -------------------------------------------");
86          StageDriverTestUtils.testSingleStage(this, new DedicatedThreadStageDriverFactory());
87      }
88      
89      public void testMultiStage() throws Exception {        
90          log.debug("testMultiStage --------------------------------------------");
91          StageDriverTestUtils.testMultiStage(this, new DedicatedThreadStageDriverFactory());
92      }
93      
94      public void testMultiFaultingStage() throws Exception {       
95          log.debug("testMultiFaultingStage ------------------------------------");
96          DedicatedThreadStageDriverFactory factory = new DedicatedThreadStageDriverFactory();
97          factory.setFaultTolerance(FaultTolerance.CHECKED);
98          
99          StageDriverTestUtils.testMultiFaultingStage(this, factory);
100     }
101 }