org.apache.ojb.broker
Class JUnitExtensions.MultiThreadedTestCase

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.ojb.broker.JUnitExtensions.MultiThreadedTestCase
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
LockingMultithreadedTest, MetadataMultithreadedTest, MultithreadedReadTest, SMMultiThreadedTest
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.


Nested Class Summary
protected  class JUnitExtensions.MultiThreadedTestCase.TestCaseRunnable
          A test case thread.
 
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.
protected  void runTestCaseRunnables(JUnitExtensions.MultiThreadedTestCase.TestCaseRunnable[] runnables)
          Run the test case threads.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runBare, runTest, setName, setUp, tearDown, 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
clone, equals, finalize, 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.


runTestCaseRunnables

protected void runTestCaseRunnables(JUnitExtensions.MultiThreadedTestCase.TestCaseRunnable[] runnables)
Run the test case threads.



Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14