activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r815963 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent: MutexTest.cpp MutexTest.h
Date Wed, 16 Sep 2009 21:02:08 GMT
Author: tabish
Date: Wed Sep 16 21:02:08 2009
New Revision: 815963

URL: http://svn.apache.org/viewvc?rev=815963&view=rev
Log:
Add a couple more tests and clean up the code a bit

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.h

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp?rev=815963&r1=815962&r2=815963&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.cpp
Wed Sep 16 21:02:08 2009
@@ -17,6 +17,14 @@
 
 #include "MutexTest.h"
 
+#include <decaf/lang/Thread.h>
+#include <decaf/lang/Runnable.h>
+#include <decaf/util/concurrent/Concurrent.h>
+#include <decaf/util/concurrent/Mutex.h>
+#include <decaf/util/Random.h>
+
+#include <time.h>
+
 using namespace std;
 using namespace decaf;
 using namespace decaf::lang;
@@ -24,6 +32,19 @@
 using namespace decaf::util::concurrent;
 
 ///////////////////////////////////////////////////////////////////////////////
+void MutexTest::testConstructor() {
+
+    Mutex mutex;
+
+    mutex.lock();
+    mutex.unlock();
+
+    CPPUNIT_ASSERT( mutex.tryLock() == true );
+
+    mutex.unlock();
+}
+
+///////////////////////////////////////////////////////////////////////////////
 class MyThread : public lang::Thread, public Synchronizable{
 private:
 
@@ -71,7 +92,7 @@
 };
 
 ///////////////////////////////////////////////////////////////////////////////
-void MutexTest::test() {
+void MutexTest::testSimpleThread() {
     MyThread test;
 
     synchronized(&test){
@@ -478,11 +499,16 @@
 
     volatile bool done;
     Mutex* mutex;
+    int index;
 
 public:
 
     volatile int value;
-    MyRecursiveLockThread(Mutex* mutex){ this->mutex = mutex; done = false; }
+    MyRecursiveLockThread(Mutex* mutex, int index){
+        this->mutex = mutex;
+        this->done = false;
+        this->index = index;
+    }
     virtual ~MyRecursiveLockThread(){}
     virtual void lock() throw(lang::Exception){
         mutex->lock();
@@ -534,17 +560,17 @@
 
         Mutex mutex;
 
-        const int numThreads = 30;
+        const int numThreads = 2;
         MyRecursiveLockThread* threads[numThreads];
 
         // Create and start all the threads.
         for( int ix=0; ix<numThreads; ++ix ){
-            threads[ix] = new MyRecursiveLockThread( &mutex );
+            threads[ix] = new MyRecursiveLockThread( &mutex, ix );
             threads[ix]->start();
         }
 
         // Sleep so all the threads can get to the wait.
-        Thread::sleep( 1100 );
+        Thread::sleep( 2000 );
 
         for( int ix=0; ix<numThreads; ++ix ){
             if( threads[ix]->done == true ){
@@ -562,7 +588,7 @@
         }
 
         // Sleep to give the threads time to wake up.
-        Thread::sleep( 1100 );
+        Thread::sleep( 2000 );
 
         for( int ix=0; ix<numThreads; ++ix ){
             if( threads[ix]->done != true ){

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.h?rev=815963&r1=815962&r2=815963&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/MutexTest.h Wed
Sep 16 21:02:08 2009
@@ -21,13 +21,6 @@
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 
-#include <decaf/lang/Thread.h>
-#include <decaf/lang/Runnable.h>
-#include <decaf/util/concurrent/Concurrent.h>
-#include <decaf/util/concurrent/Mutex.h>
-#include <decaf/util/Random.h>
-#include <time.h>
-
 namespace decaf{
 namespace util{
 namespace concurrent{
@@ -35,7 +28,8 @@
     class MutexTest : public CppUnit::TestFixture {
 
         CPPUNIT_TEST_SUITE( MutexTest );
-        CPPUNIT_TEST( test );
+        CPPUNIT_TEST( testConstructor );
+        CPPUNIT_TEST( testSimpleThread );
         CPPUNIT_TEST( testWait );
         CPPUNIT_TEST( testTimedWait );
         CPPUNIT_TEST( testNotify );
@@ -51,9 +45,10 @@
         virtual void setUp(){}
         virtual void tearDown(){}
 
+        void testConstructor();
         void testTimedWait();
         void testWait();
-        void test();
+        void testSimpleThread();
         void testNotify();
         void testNotifyAll();
         void testRecursiveLock();



Mime
View raw message