You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2009/12/01 19:51:32 UTC
svn commit: r885863 - in
/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang:
ThreadTest.cpp ThreadTest.h
Author: tabish
Date: Tue Dec 1 18:51:31 2009
New Revision: 885863
URL: http://svn.apache.org/viewvc?rev=885863&view=rev
Log:
Adds an additional test scenario to the test case.
Modified:
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp
activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp?rev=885863&r1=885862&r2=885863&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.cpp Tue Dec 1 18:51:31 2009
@@ -19,6 +19,7 @@
#include <decaf/util/concurrent/Mutex.h>
#include <decaf/lang/System.h>
+#include <decaf/util/Random.h>
#include <decaf/lang/exceptions/InterruptedException.h>
#include <decaf/lang/exceptions/RuntimeException.h>
@@ -139,6 +140,26 @@
};
+ class RandomSleepRun : public Thread{
+ private:
+
+ static Random rand;
+
+ public:
+
+ RandomSleepRun() {}
+ virtual ~RandomSleepRun(){}
+
+ virtual void run(){
+
+ // Sleep for Random time.
+ Thread::sleep( rand.nextInt( 2000 ) );
+ }
+
+ };
+
+ Random RandomSleepRun::rand( System::currentTimeMillis() );
+
class BadRunnable : public Runnable {
public:
@@ -312,6 +333,25 @@
}
////////////////////////////////////////////////////////////////////////////////
+void ThreadTest::testJoin4() {
+
+ // Start all the threads.
+ const unsigned int numThreads = 200;
+ RandomSleepRun threads[numThreads];
+ for( unsigned int ix = 0; ix < numThreads; ++ix ){
+ threads[ix].start();
+ }
+
+ // Join them all to ensure they complete as expected
+ for( unsigned int ix = 0; ix < numThreads; ++ix ){
+ threads[ix].join();
+ }
+
+ // Thread should be able to join itself, use a timeout so we don't freeze
+ Thread::currentThread()->join( 100 );
+}
+
+////////////////////////////////////////////////////////////////////////////////
void ThreadTest::testSetPriority() {
std::auto_ptr<Runnable> runnable( new SimpleThread( 10 ) );
Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h?rev=885863&r1=885862&r2=885863&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/lang/ThreadTest.h Tue Dec 1 18:51:31 2009
@@ -39,6 +39,7 @@
CPPUNIT_TEST( testJoin1 );
CPPUNIT_TEST( testJoin2 );
CPPUNIT_TEST( testJoin3 );
+ CPPUNIT_TEST( testJoin4 );
CPPUNIT_TEST( testSetPriority );
CPPUNIT_TEST( testIsAlive );
CPPUNIT_TEST( testGetId );
@@ -65,6 +66,7 @@
void testJoin1();
void testJoin2();
void testJoin3();
+ void testJoin4();
void testSetPriority();
void testIsAlive();
void testGetId();