qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cctriel...@apache.org
Subject svn commit: r834607 - in /qpid/trunk/qpid/cpp/src: qpid/broker/Queue.cpp tests/QueueTest.cpp
Date Tue, 10 Nov 2009 19:17:33 GMT
Author: cctrieloff
Date: Tue Nov 10 19:17:32 2009
New Revision: 834607

URL: http://svn.apache.org/viewvc?rev=834607&view=rev
Log:
Also remove liner search from seek() & add tests

Modified:
    qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp
    qpid/trunk/qpid/cpp/src/tests/QueueTest.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp?rev=834607&r1=834606&r2=834607&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/broker/Queue.cpp Tue Nov 10 19:17:32 2009
@@ -429,6 +429,7 @@
     }
 }
 
+// Find the next message 
 bool Queue::seek(QueuedMessage& msg, Consumer::shared_ptr c) {
     Mutex::ScopedLock locker(messageLock);
     if (!messages.empty() && messages.back().position > c->position) {
@@ -436,13 +437,11 @@
             msg = getFront();
             return true;
         } else {        
-            //TODO: can improve performance of this search, for now just searching linearly
from end
-            Messages::reverse_iterator pos;
-            for (Messages::reverse_iterator i = messages.rbegin(); i != messages.rend() &&
i->position > c->position; i++) {
-                pos = i;
+            Messages::iterator pos = findAt(c->position);
+            if (pos != messages.end() && pos+1 != messages.end()) {
+                msg = *(pos+1);
+                return true;
             }
-            msg = *pos;
-            return true;
         }
     }
     listeners.addListener(c);

Modified: qpid/trunk/qpid/cpp/src/tests/QueueTest.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/QueueTest.cpp?rev=834607&r1=834606&r2=834607&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/QueueTest.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/QueueTest.cpp Tue Nov 10 19:17:32 2009
@@ -280,6 +280,58 @@
 
 }
 
+
+QPID_AUTO_TEST_CASE(testSeek){
+
+	Queue::shared_ptr queue(new Queue("my-queue", true));
+
+    intrusive_ptr<Message> msg1 = create_message("e", "A");
+    intrusive_ptr<Message> msg2 = create_message("e", "B");
+    intrusive_ptr<Message> msg3 = create_message("e", "C");
+
+	//enqueue 2 messages
+    queue->deliver(msg1);
+    queue->deliver(msg2);
+    queue->deliver(msg3);
+
+    TestConsumer::shared_ptr consumer(new TestConsumer(false));
+    SequenceNumber seq(2);
+    consumer->position = seq;
+
+    QueuedMessage qm;
+    queue->dispatch(consumer);
+    
+    BOOST_CHECK_EQUAL(msg3.get(), consumer->last.get());
+    queue->dispatch(consumer);
+    queue->dispatch(consumer); // make sure over-run is safe
+ 
+}
+
+QPID_AUTO_TEST_CASE(testSearch){
+
+	Queue::shared_ptr queue(new Queue("my-queue", true));
+
+    intrusive_ptr<Message> msg1 = create_message("e", "A");
+    intrusive_ptr<Message> msg2 = create_message("e", "B");
+    intrusive_ptr<Message> msg3 = create_message("e", "C");
+
+	//enqueue 2 messages
+    queue->deliver(msg1);
+    queue->deliver(msg2);
+    queue->deliver(msg3);
+
+    SequenceNumber seq(2);
+    QueuedMessage qm = queue->find(seq);
+    
+    BOOST_CHECK_EQUAL(seq.getValue(), qm.position.getValue());
+    
+    queue->acquire(qm);
+    BOOST_CHECK_EQUAL(queue->getMessageCount(), 2u);
+    SequenceNumber seq1(3);
+    QueuedMessage qm1 = queue->find(seq1);
+    BOOST_CHECK_EQUAL(seq1.getValue(), qm1.position.getValue());
+    
+}
 const std::string nullxid = "";
 
 class SimpleDummyCtxt : public TransactionContext {};



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message