org.apache.ojb.junit
Class JUnitExtensions.MultiThreadedTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.ojb.junit.JUnitExtensions.MultiThreadedTestCase
All Implemented Interfaces:
junit.framework.Test
Enclosing class:
JUnitExtensions

public static class JUnitExtensions.MultiThreadedTestCase
extends junit.framework.TestCase

A multi-threaded JUnit test case. To perform test cases that spin off threads to do tests:

That's it. An example is below:
 public class MTTest extends JUnitExtensions.MultiThreadedTestCase
 {
   MTTest (String s) { super (s); }
   public class CounterThread extends JUnitExtensions.TestCaseRunnable
   {
     public void runTestCase () throws Throwable
     {
       for (int i = 0; i < 1000; i++)
       {
         System.out.println ("Counter Thread: " + Thread.currentThread () + " : " + i);
         // Do some testing...
         if (Thread.currentThread ().isInterrupted ()) {
           return;
         }
       }
     }
   }

   public void test1 ()
   {
     TestCaseRunnable tct [] = new TestCaseRunnable [5];
     for (int i = 0; i < 5; i++)
     {
       tct[i] = new CounterThread ();
      }
     runTestCaseRunnables (tct);
   }
 }
 

Category: Test
Not guaranteed to be thread safe.


Constructor Summary
JUnitExtensions.MultiThreadedTestCase(java.lang.String s)
          Simple constructor.
 
Method Summary
 void interruptThreads()
          Interrupt the running threads.
 void run(junit.framework.TestResult result)
          Override run so we can squirrel away the test result.
 
Methods inherited from class junit.framework.TestCase
countTestCases, getName, run, runBare, setName, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JUnitExtensions.MultiThreadedTestCase

public JUnitExtensions.MultiThreadedTestCase(java.lang.String s)
Simple constructor.

Method Detail

interruptThreads

public void interruptThreads()
Interrupt the running threads.


run

public void run(junit.framework.TestResult result)
Override run so we can squirrel away the test result.

Specified by:
run in interface junit.framework.Test
Overrides:
run in class junit.framework.TestCase


(C) 2002 - 2006 Apache Software Foundation
All rights reserved. Published under the Apache License 2.0.
http://db.apache.org/ojb
Version: 1.0.4, 2005-12-30