예제 #1
0
void QueueItem::addSource(const UserPtr& aUser) {
	dcassert(!isSource(aUser));
	SourceIter i = getBadSource(aUser);
	if(i != badSources.end()) {
		sources.push_back(*i);
		badSources.erase(i);
	} else {
		sources.push_back(Source(aUser));
	}
}
예제 #2
0
/**
 * Test publisher with NULL callback.
 */
TEST_F(MamaPublisherTest, PublishWithNullCallback)
{
    int numPublishes = 10;

    // Allocate a publisher
    MamaPublisher *publisher = new MamaPublisher();

    // Get the default queue
    MamaQueue *queue = Mama::getDefaultEventQueue(m_bridge);

    // Create the publisher
    publisher->createWithCallbacks(m_transport, queue, NULL, NULL, getSymbol(), getBadSource(), NULL);

    // Process messages until the first message is received
    Mama::startBackground(m_bridge, this);

    MamaMsg* msg = new MamaMsg();
    msg->create();
    msg->addU8("", MamaFieldMsgType.mFid, MAMA_MSG_TYPE_INITIAL);
    msg->addU8("", MamaFieldMsgStatus.mFid, MAMA_MSG_STATUS_OK);
    msg->addString("", 11, "TEST STRING");    // MdFeedName

    for (int i = 0; i < numPublishes; ++i)
    {
        publisher->send(msg);
    }
    sleep (1);

    // Destroy the publisher
    publisher->destroy();            

    delete publisher;
    delete queue;

    Mama::stop(m_bridge);
}
예제 #3
0
/*  Description: Create a mamaPublisher with event callbacks and mamaMsg, send the msg using 
 *               mamaPublisher then destroy both. A non-entitled source is used to generate
 *               publisher error events. But the callbacks are not set, so no callbacks 
 *               should be received.
 *
 *  Expected Result: MAMA_STATUS_OK
 */
TEST_F (MamaPublisherTestC, EventSendWithCallbacksNoCallbacks)
{
    mamaPublisher    publisher = NULL;
    mamaTransport    tport     = NULL;
    const char*      symbol    = getSymbol();
    const char*      source    = getBadSource();
    mamaMsg          msg       = NULL;
    mamaQueue        queue     = NULL;
    mamaPublisherCallbacks* cb = NULL;
    int              i         = 0;
    int              numErrors = 10;

    pubOnCreateCount = 0;
    pubOnErrorCount = 0;
    pubOnDestroyCount = 0;

    mamaPublisherCallbacks_allocate(&cb);
    cb->onError = NULL;
    cb->onCreate = NULL;
    cb->onDestroy = NULL;

    ASSERT_EQ (MAMA_STATUS_OK, mama_open());

    ASSERT_EQ (MAMA_STATUS_OK,
               mamaMsg_create (&msg));

    ASSERT_EQ (MAMA_STATUS_OK,
               mamaMsg_addString (msg, symbol, 101, source));

    ASSERT_EQ (MAMA_STATUS_OK,
               mama_getDefaultEventQueue (mBridge, &queue));
 
    ASSERT_EQ (MAMA_STATUS_OK,
               mamaTransport_allocate (&tport));

    ASSERT_EQ (MAMA_STATUS_OK,
               mamaTransport_create (tport, getTransport(), mBridge));

    ASSERT_EQ (MAMA_STATUS_OK,
		mamaTransport_setTransportTopicCallback (tport, (mamaTransportTopicCB) transportTopicCb, NULL));

    ASSERT_EQ (MAMA_STATUS_OK,
               mamaPublisher_createWithCallbacks (&publisher, tport, queue, symbol, source, NULL, cb, NULL));

    for (i = 0; i < numErrors; i++)
    {
        ASSERT_EQ (MAMA_STATUS_OK,
                   mamaPublisher_send (publisher, msg));
    }

    ASSERT_EQ (MAMA_STATUS_OK,
               mamaPublisher_destroy (publisher));

    ASSERT_EQ (MAMA_STATUS_OK,
               mamaTransport_destroy (tport));

    ASSERT_EQ (MAMA_STATUS_OK, mama_close());

    ASSERT_EQ (0, pubOnCreateCount);
    ASSERT_EQ (0, pubOnErrorCount);
    ASSERT_EQ (0, pubOnDestroyCount);

    mamaPublisherCallbacks_deallocate(cb);
}
예제 #4
0
/**
 * Test publisher with callbacks and errors
 */
TEST_F(MamaPublisherTest, DISABLED_PublishWithCallbacksBadSource)
{
    int numPublishes = 10;
	int waits = 0;

    // Create a callback object
    TestCallback *testCallback = new TestCallback();

    // Allocate a publisher
    MamaPublisher *publisher = new MamaPublisher();

    // Get the default queue
    MamaQueue *queue = Mama::getDefaultEventQueue(m_bridge);

    // Create the publisher
    publisher->createWithCallbacks(m_transport, queue, testCallback, NULL, getSymbol(), getBadSource(), NULL);

    // Process messages until the first message is received
    Mama::startBackground(m_bridge, this);

    MamaMsg* msg = new MamaMsg();
    msg->create();
    msg->addU8("", MamaFieldMsgType.mFid, MAMA_MSG_TYPE_INITIAL);
    msg->addU8("", MamaFieldMsgStatus.mFid, MAMA_MSG_STATUS_OK);
    msg->addString("", 11, "TEST STRING");    // MdFeedName

    for (int i = 0; i < numPublishes; ++i)
    {
        publisher->send(msg);
    }

    // Destroy the publisher
    publisher->destroy();            

    // Wait for onDestroy
	while (testCallback->getOnDestroyCount() == 0)
	{
		if (waits++ > 10) break;    /* way too long to wait for onDestroy */
        sleep(1);
	}
    ASSERT_EQ(1, testCallback->getOnDestroyCount());

    delete publisher;
    delete queue;
    delete testCallback;

    Mama::stop(m_bridge);

    ASSERT_EQ(1, testCallback->getOnCreateCount());
    ASSERT_EQ(numPublishes, testCallback->getOnErrorCount());
}