activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r707090 - in /activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire: OpenwireCmsTemplateTest.cpp OpenwireCmsTemplateTest.h
Date Wed, 22 Oct 2008 14:35:25 GMT
Author: tabish
Date: Wed Oct 22 07:35:24 2008
New Revision: 707090

URL: http://svn.apache.org/viewvc?rev=707090&view=rev
Log:
https://issues.apache.org/activemq/browse/AMQCPP-200

Remove the sleep call from the testBasics test and replace with a latch.

Modified:
    activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp
    activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h

Modified: activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp?rev=707090&r1=707089&r2=707090&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp
(original)
+++ activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.cpp
Wed Oct 22 07:35:24 2008
@@ -83,27 +83,27 @@
 {
     try {
         const unsigned int NUM_MESSAGES = IntegrationCommon::defaultMsgCount;
-        
-        Receiver receiver( IntegrationCommon::getInstance().getOpenwireURL(), 
-                false, 
-                "testBasics1", 
+
+        Receiver receiver( IntegrationCommon::getInstance().getOpenwireURL(),
+                false,
+                "testBasics1",
                 NUM_MESSAGES);
         Thread rt(&receiver);
         rt.start();
-        
+
         // Wait for receiver thread to start.
-        decaf::lang::Thread::sleep(100);
-        
-        Sender sender( IntegrationCommon::getInstance().getOpenwireURL(), 
-                false, 
-                "testBasics1", 
+        receiver.waitUntilReady();
+
+        Sender sender( IntegrationCommon::getInstance().getOpenwireURL(),
+                false,
+                "testBasics1",
                 NUM_MESSAGES);
         Thread st(&sender);
         st.start();
-        
+
         st.join();
         rt.join();
-        
+
         unsigned int numReceived = receiver.getNumReceived();
         if( IntegrationCommon::debug ) {
             printf("received: %d\n", numReceived );
@@ -124,28 +124,28 @@
         activemq::core::ActiveMQConnectionFactory cf("tcp://localhost:61666"); // Invalid
URL (at least by default)
         activemq::cmsutil::CmsTemplate cmsTemplate(&cf);
         cmsTemplate.setDefaultDestinationName("testReceive1");
-        try {                
+        try {
             cmsTemplate.receive();
             CPPUNIT_FAIL("failed to throw expected exception");
         }
         catch( ActiveMQException& ex) {
             // Expected.
         }
-        
+
         // Now change to a good url and verify that we can reuse the same
         // CmsTemplate successfully.
         activemq::core::ActiveMQConnectionFactory cf2(IntegrationCommon::getInstance().getOpenwireURL());
         cmsTemplate.setConnectionFactory(&cf2);
-        
+
         // Send 1 message.
-        Sender sender( IntegrationCommon::getInstance().getOpenwireURL(), 
-                false, 
-                "testReceive1", 
+        Sender sender( IntegrationCommon::getInstance().getOpenwireURL(),
+                false,
+                "testReceive1",
                 1);
         Thread st(&sender);
         st.start();
         st.join();
-        
+
         // Receive the message.
         cms::Message* message = cmsTemplate.receive();
         CPPUNIT_ASSERT(message != NULL);
@@ -165,7 +165,7 @@
         activemq::core::ActiveMQConnectionFactory cf("tcp://localhost:61666"); // Invalid
URL (at least by default)
         activemq::cmsutil::CmsTemplate cmsTemplate(&cf);
         cmsTemplate.setDefaultDestinationName("testSend1");
-        try {                      
+        try {
             TextMessageCreator msgCreator("hello world");
             cmsTemplate.send(&msgCreator);
             CPPUNIT_FAIL("failed to throw expected exception");
@@ -173,7 +173,7 @@
         catch( ActiveMQException& ex) {
             // Expected.
         }
-        
+
         // Now change to a good url and verify that we can reuse the same
         // CmsTemplate successfully.
         activemq::core::ActiveMQConnectionFactory cf2(IntegrationCommon::getInstance().getOpenwireURL());

Modified: activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h?rev=707090&r1=707089&r2=707090&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h
(original)
+++ activemq/activemq-cpp/trunk/src/test-integration/integration/connector/openwire/OpenwireCmsTemplateTest.h
Wed Oct 22 07:35:24 2008
@@ -26,6 +26,8 @@
 #include <activemq/cmsutil/CmsTemplate.h>
 #include <activemq/cmsutil/MessageCreator.h>
 
+#include <decaf/util/concurrent/CountDownLatch.h>
+
 namespace integration{
 namespace connector{
 namespace openwire{
@@ -35,9 +37,9 @@
         CPPUNIT_TEST_SUITE( OpenwireCmsTemplateTest );
         CPPUNIT_TEST( testBasics );
         CPPUNIT_TEST( testReceiveException );
-        CPPUNIT_TEST( testSendException );        
+        CPPUNIT_TEST( testSendException );
         CPPUNIT_TEST_SUITE_END();
-        
+
         class TextMessageCreator : public activemq::cmsutil::MessageCreator {
         private:
             std::string text;
@@ -46,26 +48,26 @@
                 this->text = text;
             }
             virtual ~TextMessageCreator() {}
-            
+
             std::string getText() const {
                 return text;
             }
-            
-            virtual cms::Message* createMessage(cms::Session* session ) 
+
+            virtual cms::Message* createMessage(cms::Session* session )
                         throw (cms::CMSException) {
                 return session->createTextMessage(text);
-            } 
+            }
         };
-        
+
         class Sender : public decaf::lang::Runnable {
         private:
-                    
+
             activemq::core::ActiveMQConnectionFactory cf;
             activemq::cmsutil::CmsTemplate cmsTemplate;
             int count;
-            
+
         public:
-            
+
             Sender( const std::string& url, bool pubSub, const std::string& destName,
int count ) {
                 cf.setBrokerURL(url);
                 cmsTemplate.setConnectionFactory(&cf);
@@ -73,36 +75,39 @@
                 cmsTemplate.setDefaultDestinationName(destName);
                 this->count = count;
             }
-            
+
             virtual ~Sender(){
             }
-            
-            virtual void run() {                
+
+            virtual void run() {
                 try {
-                                    
+
                     // Send a batch of messages.
                     TextMessageCreator tmc("hello world");
                     for( int ix=0; ix<count; ++ix ) {
                         cmsTemplate.send(&tmc);
                     }
-                                                        
+
                 } catch( cms::CMSException& ex) {
                     ex.printStackTrace();
                 }
             }
         };
-        
+
         class Receiver : public decaf::lang::Runnable {
         private:
-            
+
             activemq::core::ActiveMQConnectionFactory cf;
             activemq::cmsutil::CmsTemplate cmsTemplate;
             int count;
             int numReceived;
-            
+            decaf::util::concurrent::CountDownLatch ready;
+
         public:
-            
-            Receiver( const std::string& url, bool pubSub, const std::string& destName,
int count ) {
+
+            Receiver( const std::string& url, bool pubSub, const std::string& destName,
int count )
+                : ready(1) {
+
                 cf.setBrokerURL(url);
                 cmsTemplate.setConnectionFactory(&cf);
                 cmsTemplate.setPubSubDomain(pubSub);
@@ -114,23 +119,28 @@
             int getNumReceived() const {
                 return numReceived;
             }
+            virtual void waitUntilReady() {
+                ready.await();
+            }
+
             virtual void run() {
-                
+
                 try {
                     numReceived = 0;
-                    
+
+                    ready.countDown();
                     // Receive a batch of messages.
                     for( int ix=0; ix<count; ++ix ) {
                         cms::Message* message = cmsTemplate.receive();
                         numReceived++;
-                        delete message;                    
+                        delete message;
                     }
                 } catch( cms::CMSException& ex) {
                     ex.printStackTrace();
                 }
             }
         };
-        
+
     public:
 
         OpenwireCmsTemplateTest(){}
@@ -138,7 +148,7 @@
 
         virtual void setUp();
         virtual void tearDown();
-                
+
         virtual void testBasics();
         virtual void testReceiveException();
         virtual void testSendException();



Mime
View raw message