void OpenwireNonBlockingRedeliveryTest::testMessageRedeliveriesAreInOrder() {

    LinkedHashSet< Pointer<MessageId> > received;
    LinkedHashSet< Pointer<MessageId> > beforeRollback;
    LinkedHashSet< Pointer<MessageId> > afterRollback;

    const int MSG_COUNT = 100;
    const std::string destinationName = "testMessageDeleiveredWhenNonBlockingEnabled";

    destroyDestination(getBrokerURL(), destinationName);

    Pointer<ActiveMQConnectionFactory> connectionFactory(new ActiveMQConnectionFactory(getBrokerURL()));
    Pointer<Connection> connection(connectionFactory->createConnection());
    Pointer<Session> session(connection->createSession(Session::SESSION_TRANSACTED));
    Pointer<Destination> destination(session->createQueue(destinationName));
    Pointer<MessageConsumer> consumer(session->createConsumer(destination.get()));

    ReceivedListener receivedListener(&received);
    consumer->setMessageListener(&receivedListener);
    sendMessages(getBrokerURL(), destinationName, MSG_COUNT);

    connection->start();

    CPPUNIT_ASSERT_MESSAGE("Pre-Rollack received size incorrect", assertTrue(received, MSG_COUNT));

    beforeRollback.addAll(received);
    received.clear();
    session->rollback();

    CPPUNIT_ASSERT_MESSAGE("Post-Rollack received size incorrect", assertTrue(received, MSG_COUNT));

    afterRollback.addAll(received);
    received.clear();

    CPPUNIT_ASSERT_EQUAL(beforeRollback.size(), afterRollback.size());
    CPPUNIT_ASSERT(beforeRollback.equals(afterRollback));

    Pointer< Iterator<Pointer<MessageId> > > after(afterRollback.iterator());
    Pointer< Iterator<Pointer<MessageId> > > before(beforeRollback.iterator());

    while (before->hasNext() && after->hasNext()) {
        Pointer<MessageId> original = before->next();
        Pointer<MessageId> rolledBack = after->next();

        long long originalSeq = original->getProducerSequenceId();
        long long rolledbackSeq = rolledBack->getProducerSequenceId();

        CPPUNIT_ASSERT_EQUAL(originalSeq, rolledbackSeq);
    }

    session->commit();
    connection->close();
    destroyDestination(getBrokerURL(), destinationName);
}
void LinkedHashSetTest::testIterator() {

    LinkedHashSet<int> set;
    populateSet(set);
    Pointer< Iterator<int> > iter(set.iterator());
    // Tests that the LinkedHashSet iterates in order of insertion.
    for (int j = 0; iter->hasNext(); j++) {
        int value = iter->next();
        CPPUNIT_ASSERT_MESSAGE("Incorrect element found", value == j);
    }

    {
        LinkedHashSet<string> set;

        set.add( "fred1" );
        set.add( "fred2" );
        set.add( "fred3" );

        Iterator<string>* iterator1 = set.iterator();
        CPPUNIT_ASSERT( iterator1 != NULL );
        CPPUNIT_ASSERT( iterator1->hasNext() == true );

        int count = 0;
        while( iterator1->hasNext() ) {
            iterator1->next();
            ++count;
        }

        CPPUNIT_ASSERT( count == set.size() );

        Iterator<string>* iterator2 = set.iterator();

        while( iterator2->hasNext() ) {
            iterator2->next();
            iterator2->remove();
        }

        CPPUNIT_ASSERT( set.isEmpty() );

        delete iterator1;
        delete iterator2;
    }
}