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);
}
Exemplo n.º 2
0
void LinkedHashSetTest::testCopy2() {

    LinkedList<int> collection;

    for (int i = 0; i < 50; ++i) {
        collection.add(i);
    }

    LinkedHashSet<int> set;

    set.copy(collection);

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

    for (int i = 0; i < 50; ++i) {
        CPPUNIT_ASSERT(set.contains(i));
    }

    CPPUNIT_ASSERT(set.equals(collection));
}
void OpenwireNonBlockingRedeliveryTest::testMessageDeleiveredWhenNonBlockingEnabled() {

    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));
    session->commit();
    connection->close();
    destroyDestination(getBrokerURL(), destinationName);
}