activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1513619 - in /activemq/activemq-cpp/trunk/activemq-cpp/src: main/decaf/lang/Thread.cpp main/decaf/lang/Thread.h test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.cpp test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.h
Date Tue, 13 Aug 2013 19:19:54 GMT
Author: tabish
Date: Tue Aug 13 19:19:54 2013
New Revision: 1513619

URL: http://svn.apache.org/r1513619
Log:
test for: https://issues.apache.org/jira/browse/AMQCPP-506

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.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=1513619&r1=1513618&r2=1513619&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 Aug 13 19:19:54
2013
@@ -46,8 +46,8 @@ using namespace decaf::util;
 using namespace decaf::util::concurrent;
 
 ////////////////////////////////////////////////////////////////////////////////
-namespace decaf{
-namespace lang{
+namespace decaf {
+namespace lang {
 
     class ThreadProperties {
     private:
@@ -147,18 +147,18 @@ void Thread::start() {
 
     try {
 
-        if( Threading::getThreadState(this->properties->handle) > Thread::NEW )
{
+        if (Threading::getThreadState(this->properties->handle) > Thread::NEW) {
             throw IllegalThreadStateException(
                 __FILE__, __LINE__,
                 "Thread::start - Thread already started");
         }
 
         Threading::start(this->properties->handle);
-     }
-     DECAF_CATCH_RETHROW( IllegalThreadStateException )
-     DECAF_CATCH_RETHROW( RuntimeException )
-     DECAF_CATCH_EXCEPTION_CONVERT( NullPointerException, RuntimeException )
-     DECAF_CATCHALL_THROW( RuntimeException )
+    }
+    DECAF_CATCH_RETHROW(IllegalThreadStateException)
+    DECAF_CATCH_RETHROW(RuntimeException)
+    DECAF_CATCH_EXCEPTION_CONVERT(NullPointerException, RuntimeException)
+    DECAF_CATCHALL_THROW(RuntimeException)
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -169,7 +169,7 @@ void Thread::join() {
 ////////////////////////////////////////////////////////////////////////////////
 void Thread::join(long long millisecs) {
 
-    if( millisecs < 0 ) {
+    if (millisecs < 0) {
         throw IllegalArgumentException(
             __FILE__, __LINE__,
             "Thread::join( millisecs ) - Value given {%d} is less than 0", millisecs );
@@ -181,13 +181,13 @@ void Thread::join(long long millisecs) {
 ////////////////////////////////////////////////////////////////////////////////
 void Thread::join(long long millisecs, int nanos) {
 
-    if( millisecs < 0 ) {
+    if (millisecs < 0) {
         throw IllegalArgumentException(
             __FILE__, __LINE__,
             "Thread::join( millisecs, nanos ) - Value given {%d} is less than 0", millisecs
);
     }
 
-    if( nanos < 0 || nanos > 999999 ) {
+    if (nanos < 0 || nanos > 999999) {
         throw IllegalArgumentException(
             __FILE__, __LINE__,
             "Thread::join( millisecs, nanos ) - Nanoseconds must be in range [0...999999]"
);
@@ -204,13 +204,13 @@ void Thread::sleep(long long millisecs) 
 ////////////////////////////////////////////////////////////////////////////////
 void Thread::sleep(long long millisecs, int nanos) {
 
-    if( millisecs < 0 ) {
+    if (millisecs < 0) {
         throw IllegalArgumentException(
             __FILE__, __LINE__,
             "Thread::sleep( millisecs, nanos ) - Value given {%d} is less than 0", millisecs
);
     }
 
-    if( nanos < 0 || nanos > 999999 ) {
+    if (nanos < 0 || nanos > 999999) {
         throw IllegalArgumentException(
             __FILE__, __LINE__,
             "Thread::sleep( millisecs, nanos ) - Nanoseconds must be in range [0...999999]"
);
@@ -279,7 +279,6 @@ void Thread::setDefaultUncaughtException
 
 ////////////////////////////////////////////////////////////////////////////////
 std::string Thread::toString() const {
-
     return std::string(Threading::getThreadName(this->properties->handle)) + ": Priority="
+
            Integer::toString(Threading::getThreadPriority(this->properties->handle))
+
            ", ThreadID=" + Long::toString( Threading::getThreadId(this->properties->handle));

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h?rev=1513619&r1=1513618&r2=1513619&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Thread.h Tue Aug 13 19:19:54
2013
@@ -25,15 +25,15 @@
 #include <decaf/lang/Runnable.h>
 #include <decaf/util/Config.h>
 
-namespace decaf{
-namespace internal{
-namespace util{
-namespace concurrent{
+namespace decaf {
+namespace internal {
+namespace util {
+namespace concurrent {
     class Threading;
     struct ThreadHandle;
 }}}
-namespace lang
-{
+namespace lang {
+
     class ThreadGroup;
     class ThreadProperties;
 
@@ -81,7 +81,7 @@ namespace lang
         static const int MAX_PRIORITY = 10;
 
         /** Represents the various states that the Thread can be in during its lifetime.
*/
-        enum State{
+        enum State {
 
             /** Before a Thread is started it exists in this State. */
             NEW = 0,

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.cpp?rev=1513619&r1=1513618&r2=1513619&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.cpp
Tue Aug 13 19:19:54 2013
@@ -2280,3 +2280,61 @@ void ReentrantReadWriteLockTest::testWri
     std::string ls = lock.writeLock().toString();
     CPPUNIT_ASSERT(ls.find_first_of("Locked") != std::string::npos);
 }
+
+////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+    const int MAX_ITERATION = 5000;
+
+    class TestMultipleReaderThreadsRunnable : public Runnable {
+    private:
+
+        ReentrantReadWriteLockTest* test;
+        ReentrantReadWriteLock* lock;
+
+    private:
+
+        TestMultipleReaderThreadsRunnable(const TestMultipleReaderThreadsRunnable&);
+        TestMultipleReaderThreadsRunnable operator= (const TestMultipleReaderThreadsRunnable&);
+
+    public:
+
+        TestMultipleReaderThreadsRunnable(ReentrantReadWriteLockTest* test, ReentrantReadWriteLock*
lock) :
+            Runnable(), test(test), lock(lock) {}
+        virtual ~TestMultipleReaderThreadsRunnable() {}
+
+        virtual void run() {
+            try {
+                for (int i = 0; i < MAX_ITERATION; ++i) {
+                    test->threadAssertTrue(lock->readLock().tryLock());
+                    lock->readLock().unlock();
+                }
+            } catch (Exception& ex) {
+                test->threadUnexpectedException();
+            }
+        }
+    };
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void ReentrantReadWriteLockTest::testMultipleReaderThreads() {
+    const int THREAD_QTY = 50;
+
+    ReentrantReadWriteLock lock;
+    TestMultipleReaderThreadsRunnable runnable(this, &lock);
+
+    std::vector<Thread*> threads;
+    for (int i = 0; i < THREAD_QTY; ++i) {
+        threads.push_back(new Thread(&runnable));
+    }
+
+    for (int i = 0; i < THREAD_QTY; ++i) {
+        threads[i]->start();
+    }
+
+    for (int i = 0; i < THREAD_QTY; ++i) {
+        threads[i]->join();
+        delete threads[i];
+    }
+}
+

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.h?rev=1513619&r1=1513618&r2=1513619&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.h
(original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/test/decaf/util/concurrent/locks/ReentrantReadWriteLockTest.h
Tue Aug 13 19:19:54 2013
@@ -90,6 +90,7 @@ namespace locks {
         CPPUNIT_TEST( testHasWaiters );
         CPPUNIT_TEST( testGetWaitQueueLength );
         CPPUNIT_TEST( testGetWaitingThreads );
+        CPPUNIT_TEST( testMultipleReaderThreads );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -158,6 +159,7 @@ namespace locks {
         void testHasWaiters();
         void testGetWaitQueueLength();
         void testGetWaitingThreads();
+        void testMultipleReaderThreads();
 
     };
 



Mime
View raw message