activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r817706 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/Makefile.am main/decaf/lang/Thread.cpp test/decaf/lang/ThreadTest.cpp test/decaf/lang/ThreadTest.h
Date Tue, 22 Sep 2009 15:53:34 GMT
Author: tabish
Date: Tue Sep 22 15:53:34 2009
New Revision: 817706

URL: http://svn.apache.org/viewvc?rev=817706&view=rev
Log:
New tests with a small fix to thread join methods.  Update the Makefiles.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
    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/main/Makefile.am
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am?rev=817706&r1=817705&r2=817706&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/Makefile.am Tue Sep 22 15:53:34 2009
@@ -479,7 +479,6 @@
     decaf/internal/io/StandardErrorOutputStream.cpp \
     decaf/internal/io/StandardInputStream.cpp \
     decaf/internal/io/StandardOutputStream.cpp \
-    decaf/internal/lang/unix/ThreadImpl.cpp \
     decaf/internal/net/URIEncoderDecoder.cpp \
     decaf/internal/net/URIHelper.cpp \
     decaf/internal/nio/BufferFactory.cpp \
@@ -1086,9 +1085,6 @@
     decaf/internal/io/StandardErrorOutputStream.h \
     decaf/internal/io/StandardInputStream.h \
     decaf/internal/io/StandardOutputStream.h \
-    decaf/internal/lang/ThreadImpl.h \
-    decaf/internal/lang/unix/ThreadHandle.h \
-    decaf/internal/lang/windows/ThreadHandle.h \
     decaf/internal/net/URIEncoderDecoder.h \
     decaf/internal/net/URIHelper.h \
     decaf/internal/net/URIType.h \

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp?rev=817706&r1=817705&r2=817706&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp Tue Sep 22 15:53:34
2009
@@ -379,11 +379,10 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-void Thread::join() throw( decaf::lang::exceptions::InterruptedException )
-{
+void Thread::join() throw( decaf::lang::exceptions::InterruptedException ) {
+
     if( this->properties->state < Thread::RUNNABLE ) {
-        throw Exception( __FILE__, __LINE__,
-            "Thread::join() called without having called Thread::start()");
+        return;
     }
 
     if( this->properties->state != Thread::TERMINATED ) {
@@ -408,6 +407,10 @@
             "Thread::join( millisecs ) - Value given {%d} is less than 0", millisecs );
     }
 
+    if( this->properties->state < Thread::RUNNABLE ) {
+        return;
+    }
+
     this->join( millisecs, 0 );
 }
 
@@ -428,6 +431,10 @@
             "Thread::join( millisecs, nanos ) - Nanoseconds must be in range [0...999999]"
);
     }
 
+    if( this->properties->state < Thread::RUNNABLE ) {
+        return;
+    }
+
     #ifdef HAVE_PTHREAD_H
 
         void* theReturn = NULL;

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=817706&r1=817705&r2=817706&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 Sep 22
15:53:34 2009
@@ -243,15 +243,25 @@
 
       JoinTest test;
 
+      // Joining a non-started thread should just return.
+      CPPUNIT_ASSERT_NO_THROW( test.join() );
+      CPPUNIT_ASSERT_NO_THROW( test.join( 10 ) );
+      CPPUNIT_ASSERT_NO_THROW( test.join( 10, 10 ) );
+
+      CPPUNIT_ASSERT_MESSAGE( "Thread is alive", !test.isAlive() );
       time_t startTime = time( NULL );
       test.start();
       test.join();
       time_t endTime = time( NULL );
+      CPPUNIT_ASSERT_MESSAGE( "Joined Thread is still alive", !test.isAlive() );
 
       time_t delta = endTime - startTime;
 
       // Should be about 5 seconds that elapsed.
       CPPUNIT_ASSERT( delta >= 1 && delta <= 3 );
+
+      // Thread should be able to join itself, use a timeout so we don't freeze
+      Thread::currentThread()->join( 100 );
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -397,3 +407,14 @@
 
     CPPUNIT_ASSERT( myHandler.executed == true );
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void ThreadTest::testCurrentThread() {
+
+    CPPUNIT_ASSERT( Thread::currentThread() != NULL );
+    CPPUNIT_ASSERT( Thread::currentThread()->getName() == "Main Thread" );
+    CPPUNIT_ASSERT( Thread::currentThread()->getPriority() == Thread::NORM_PRIORITY );
+    CPPUNIT_ASSERT( Thread::currentThread()->getState() == Thread::RUNNABLE );
+
+    CPPUNIT_ASSERT( Thread::currentThread() == Thread::currentThread() );
+}

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=817706&r1=817705&r2=817706&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 Sep 22 15:53:34
2009
@@ -44,6 +44,7 @@
       CPPUNIT_TEST( testSleep );
       CPPUNIT_TEST( testSleep2Arg );
       CPPUNIT_TEST( testUncaughtExceptionHandler );
+      CPPUNIT_TEST( testCurrentThread );
       CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -67,6 +68,7 @@
         void testSleep();
         void testSleep2Arg();
         void testUncaughtExceptionHandler();
+        void testCurrentThread();
 
     };
 



Mime
View raw message