activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r991562 - in /activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util: IdGeneratorTest.cpp IdGeneratorTest.h
Date Wed, 01 Sep 2010 15:09:21 GMT
Author: tabish
Date: Wed Sep  1 15:09:21 2010
New Revision: 991562

URL: http://svn.apache.org/viewvc?rev=991562&view=rev
Log:
test for: https://issues.apache.org/activemq/browse/AMQCPP-314

Modified:
    activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp
    activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.h

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp?rev=991562&r1=991561&r2=991562&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp
(original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.cpp
Wed Sep  1 15:09:21 2010
@@ -19,9 +19,58 @@
 
 #include <activemq/util/IdGenerator.h>
 
+#include <decaf/lang/Thread.h>
+
 using namespace activemq;
 using namespace activemq::util;
 
+using namespace decaf;
+using namespace decaf::lang;
+
+////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+    class CreateIdThread : public Thread {
+    public:
+
+        bool failed;
+
+        CreateIdThread() : failed( false ) {}
+
+    public:
+
+        virtual void run() {
+
+            try{
+                IdGenerator idGen;
+
+                CPPUNIT_ASSERT( idGen.generateId() != "" );
+                CPPUNIT_ASSERT( idGen.generateId() != "" );
+
+                std::string id1 = idGen.generateId();
+                std::string id2 = idGen.generateId();
+
+                CPPUNIT_ASSERT( id1 != id2 );
+
+                std::size_t idPos = id1.find("ID:");
+
+                CPPUNIT_ASSERT( idPos == 0 );
+
+                std::size_t firstColon = id1.find(':');
+                std::size_t lastColon = id1.rfind(':');
+
+                CPPUNIT_ASSERT( firstColon != lastColon );
+                CPPUNIT_ASSERT( ( lastColon - firstColon ) > 1 );
+            }
+            catch(...) {
+                failed = true;
+            }
+        }
+
+    };
+
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 IdGeneratorTest::IdGeneratorTest() {
 }
@@ -62,3 +111,34 @@ void IdGeneratorTest::testCompare() {
     CPPUNIT_ASSERT( IdGenerator::compare( id1, id2 ) < 0 );
     CPPUNIT_ASSERT( IdGenerator::compare( id2, id1 ) > 0 );
 }
+
+////////////////////////////////////////////////////////////////////////////////
+void IdGeneratorTest::testThreadSafety() {
+
+    bool failed = false;
+
+    static const int COUNT = 50;
+
+    std::vector<CreateIdThread*> threads;
+
+    for( int i = 0; i < COUNT; i++ ) {
+        threads.push_back( new CreateIdThread );
+    }
+
+    for( int i = 0; i < COUNT; i++ ) {
+        threads[i]->start();
+    }
+
+    for( int i = 0; i < COUNT; i++ ) {
+        threads[i]->join();
+    }
+
+    for( int i = 0; i < COUNT; i++ ) {
+        if( !failed ) {
+            threads[i]->failed ? failed = true : failed = false;
+        }
+        delete threads[i];
+    }
+
+    CPPUNIT_ASSERT_MESSAGE( "One of the Thread Tester failed", !failed );
+}

Modified: activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.h?rev=991562&r1=991561&r2=991562&view=diff
==============================================================================
--- activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.h
(original)
+++ activemq/activemq-cpp/branches/activemq-cpp-3.2.x/activemq-cpp/src/test/activemq/util/IdGeneratorTest.h
Wed Sep  1 15:09:21 2010
@@ -30,6 +30,7 @@ namespace util {
         CPPUNIT_TEST( testConstructor1 );
         CPPUNIT_TEST( testConstructor2 );
         CPPUNIT_TEST( testCompare );
+        CPPUNIT_TEST( testThreadSafety );
         CPPUNIT_TEST_SUITE_END();
 
     public:
@@ -40,6 +41,7 @@ namespace util {
         void testConstructor1();
         void testConstructor2();
         void testCompare();
+        void testThreadSafety();
 
     };
 



Mime
View raw message