Esempio n. 1
1
TEST_F(MamaFieldCacheTestC, getFullMsg1)
{
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    mamaFieldCacheField field = NULL;
    mamaFieldCacheField_create(&field, 10, MAMA_FIELD_TYPE_BOOL, NULL);
    mamaFieldCacheField_setBool(field, 1);
    mamaFieldCache_applyField(fieldCache, field);

    /* This field must never be published */
    mamaFieldCacheField_create(&field, 25, MAMA_FIELD_TYPE_F64, NULL);
    mamaFieldCacheField_setF64(field, 3.1);
    mamaFieldCacheField_setPublish(field, 0);
    mamaFieldCache_applyField(fieldCache, field);

    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    mamaFieldCache_applyField(fieldCache, field);

    // Creating a string field without a value. Even if this field is added to the
    // cache, it will not be added to the message because we cannot add a NULL
    // string to a mama message
    mamaFieldCacheField_create(&field, 110, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCache_applyField(fieldCache, field);

    mamaFieldCacheField_create(&field, 90, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world", 0);
    mamaFieldCache_applyField(fieldCache, field);

    mamaMsg message;
    mamaMsg_create(&message);

    // should use add* methods to populate the message because the message is empty
    mamaFieldCache_getFullMessage(fieldCache, message);

    mama_bool_t resultBool = 0;
    ret = mamaMsg_getBool(message, "test_bool", 10, &resultBool);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    mama_f64_t resultF64;
    ret = mamaMsg_getF64(message, "test_f32", 25, &resultF64);
    ASSERT_EQ(MAMA_STATUS_NOT_FOUND, ret);
    mama_i32_t resultI32;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    const char* resultString;
    ret = mamaMsg_getString(message, "test_string", 90, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);

    ASSERT_EQ(1, resultBool);
    ASSERT_DOUBLE_EQ(-100, resultI32);
    ASSERT_STREQ("hello world", resultString);

    mamaMsg_destroy (message);
    ret = mamaFieldCache_destroy(fieldCache);
}
Esempio n. 2
1
TEST_F(MamaFieldCacheTestC, getDeltaMsgTrackingModif)
{
    mama_size_t size = 0;
    mama_bool_t modified = 0;
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    // tracking modification state globally at cache level
    mamaFieldCache_setTrackModified(fieldCache, 1);

    mamaFieldCacheField field = NULL;
    // This field must be always published
    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified before publishing -> always publish
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mAlwaysPublishFields, &size);
    ASSERT_EQ(1, size);
    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(0, size);

    mamaMsg message;
    mamaMsg_create(&message);

    // reset the modified field and remove from list for field 66
    mamaFieldCache_getDeltaMessage(fieldCache, message);
    mamaMsg_destroy(message);
    message = NULL;

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mAlwaysPublishFields, &size);
    ASSERT_EQ(1, size);
    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(0, size);

    // This field will be published
    mamaFieldCacheField_create(&field, 10, MAMA_FIELD_TYPE_BOOL, NULL);
    mamaFieldCacheField_setBool(field, 1);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Check if modified before publishing
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    // This field must never be published because publish is false
    mamaFieldCacheField_create(&field, 25, MAMA_FIELD_TYPE_F64, NULL);
    mamaFieldCacheField_setF64(field, 3.1);
    // Disable publishing
    mamaFieldCacheField_setPublish(field, 0);
    // Check modified can be anything - no publishing anyway... see above
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    // This field will always be published
    mamaFieldCacheField_create(&field, 90, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world", 0);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    // This field will always be published
    mamaFieldCacheField_create(&field, 91, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world again", 0);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    mamaMsg_create(&message);

    mamaFieldCache_getDeltaMessage(fieldCache, message);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(0, size);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 10, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_FALSE(modified);

    mama_bool_t resultBool;
    ret = mamaMsg_getBool(message, "test_bool", 10, &resultBool);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(1, resultBool);
    mama_f64_t resultF64;
    ret = mamaMsg_getF64(message, "test_f32", 25, &resultF64);
    ASSERT_EQ(MAMA_STATUS_NOT_FOUND, ret);
    mama_i32_t resultI32;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(-100, resultI32);
    const char* resultString;
    ret = mamaMsg_getString(message, "test_string", 90, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_STREQ("hello world", resultString);
    ret = mamaMsg_getString(message, "test_string", 91, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_STREQ("hello world again", resultString);

    mamaMsg_destroy (message);

    ret = mamaFieldCache_destroy(fieldCache);
}
Esempio n. 3
0
TEST_F(MamaFieldCacheTestC, getDeltaMsgAlwaysPublishFields)
{
    mama_bool_t modified = 0;
    mama_size_t numFields = 0;
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    // tracking modification state globally at cache level
    mamaFieldCache_setTrackModified(fieldCache, 1);

    mamaFieldCacheField field = NULL;
    // This field must be always published
    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified before publishing -> always publish
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    mama_size_t size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(0, size);
    mamaFieldCacheList_getSize(fieldCache->mAlwaysPublishFields, &size);
    ASSERT_EQ(1, size);

    mamaMsg message;
    mamaMsg_create(&message);

    mamaFieldCache_getDeltaMessage(fieldCache, message);
    mamaMsg_getNumFields(message, &numFields);
    ASSERT_EQ(1, numFields);
    mamaMsg_destroy(message);
    message = NULL;

    mamaMsg_create(&message);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 66, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_FALSE(modified);

    mamaFieldCache_getDeltaMessage(fieldCache, message);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 66, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_FALSE(modified);

    mama_i32_t resultI32 = 0;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(-100, resultI32);

    mamaMsg_destroy (message);
    ret = mamaFieldCache_destroy(fieldCache);
}
Esempio n. 4
0
void mamaDQPublisherManager_destroy (mamaDQPublisherManager manager)
{
    /* Get the impl. */
    mamaDQPublisherManagerImpl* impl  = (mamaDQPublisherManagerImpl*) manager;
    if(NULL != impl)
    {
        /* Destroy the publisher. */
        if(NULL != impl->mPublisher)
        {
            mamaPublisher_destroy(impl->mPublisher);
        }

        /* Destroy the subscription. */
        if(NULL != impl->mSubscription)
        {
            mamaSubscription_destroy(impl->mSubscription);
            mamaSubscription_deallocate(impl->mSubscription);
        }

        /* Destroy the inbox. */
        if(NULL != impl->mInbox)
        {
            mamaInbox_destroy(impl->mInbox);
        }

        /* Destroy the re-usable messages. */
        if(NULL != impl->mRefreshResponseMsg)
        {
            mamaMsg_destroy(impl->mRefreshResponseMsg);
        }
        if(NULL != impl->mNoSubscribersMsg)
        {
            mamaMsg_destroy(impl->mNoSubscribersMsg);
        }
        if(NULL != impl->mSyncRequestMsg)
        {
            mamaMsg_destroy(impl->mSyncRequestMsg);
        }

        /* Free the namespace. */
        if(NULL != impl->mNameSpace)
        {
            free(impl->mNameSpace);
        }

        /* Destroy the publisher table. */
        if(NULL != impl->mPublisherMap)
        {
            wtable_destroy ( impl->mPublisherMap );
        }

        /* Free the impl itself. */
        free(impl);
    }
}
Esempio n. 5
0
mama_status
mamaQueueImpl_detachMsg (mamaQueue queue,
                         mamaMsg   msg)
{
    mamaQueueImpl* impl = (mamaQueueImpl*)queue;
    mama_status    status   =   MAMA_STATUS_OK;

    if (!impl)
        return MAMA_STATUS_NULL_ARG;

    if (msg == impl->mMsg)
    {
        if (MAMA_STATUS_OK!=(status=mamaMsg_create (&(impl->mMsg))))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueueImpl_detachMsg():"
                      " Could not create new message.");
            impl->mMsg = msg;
            return status;
        }

        /*We now have to set the bridge and queue on this new message*/
        if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setBridgeImpl (impl->mMsg,
                        impl->mBridgeImpl)))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueueImpl_detachMsg():"
                      " Could not set bridge on new message.");
            mamaMsg_destroy (impl->mMsg);
            impl->mMsg = msg;
            return status;
        }

        /*We don't want to destroy the bridge message when the mamamsg is
         * destroyed as we won't own it*/
        if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setMessageOwner (impl->mMsg, 0)))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueueImpl_detachMsg():"
                      " Could not set owner on new message.");
            return status;
        }

        if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setQueue (impl->mMsg, queue)))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueueImpl_detachMsg():"
                      " Could not set queue on new message.");
            mamaMsg_destroy (impl->mMsg);
            impl->mMsg = msg;
            return status;
        }
    }
    return MAMA_STATUS_OK;
}
Esempio n. 6
0
mama_status
dqContext_cacheMsg (mamaDqContext *ctx, mamaMsg msg)
{       
    mama_status     status  =   MAMA_STATUS_OK;

    if (ctx->mCache == NULL)
    {
        return status;
    }

    if (ctx->mCache[ctx->mCurCacheIdx] != NULL)
    {
        mamaMsg_destroy (ctx->mCache[ctx->mCurCacheIdx]);
    }

    mamaMsg_detach (msg);
    ctx->mCache [ctx->mCurCacheIdx++] = msg;

    if (ctx->mCurCacheIdx == ctx->mCacheSize)
    {
        ctx->mCurCacheIdx = 0;
    }

    /*Associate the cache context with the message.
      This must be done after it has been detached*/
    if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setDqStrategyContext (msg,
                    ctx)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "dqContext_cacheMsg: "
                  "Could not set context on detached message.");
        return status;
    }

    return status;
}
Esempio n. 7
0
/*  Description: Create a mamaDictionary from a file and write to a msg.
 *  The dictionary file includes a field type of UNKNOWN, which is logged with name and fid.
 *                   
 *  Expected Result: MAMA_STATUS_OK
 */
TEST_F (MamaDictionaryTestC, LoadFromFileAndWriteToMsg)
{
    mamaDictionary dictionary;
    mamaMsg msg;
    char buf[1024];
    const char* path = getenv("WOMBAT_PATH");
    size_t dictionarySize;
    size_t msgSize;
    
    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_create(&dictionary));

    ASSERT_NE (path, (const char*) NULL);
    snprintf(buf, sizeof(buf), "%s/dictionary1.txt", path);
    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_populateFromFile(dictionary, buf));

    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_getDictionaryMessage(dictionary, &msg));

    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_getSize(dictionary, &dictionarySize));

    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_getNumFields(msg, &msgSize));

    /* Expect one less in msg since there is an unknown in the dictionary */
    ASSERT_EQ (dictionarySize-1, msgSize);

    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_destroy(msg));

    ASSERT_EQ (MAMA_STATUS_OK, mamaDictionary_destroy(dictionary));
}
Esempio n. 8
0
TEST_F(MamaFieldCacheIteratorTestC, iteratorLoop)
{
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);
    ASSERT_EQ(MAMA_STATUS_OK, ret);

    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f32", 25, 12.3);
    mamaMsg_addI32(message, "test_i32", 66, -101);
    mamaMsg_addString(message, "test_string", 90, "hello world");
    mamaMsg_addString(message, "test_string_empty", 88, "");
    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    mamaFieldCacheIterator iterator;
    mamaFieldCacheIterator_create(&iterator, fieldCache);
    
    int counter = 0;
    mamaFieldCacheField current = NULL;
    while (mamaFieldCacheIterator_hasNext(iterator))
    {
        current = mamaFieldCacheIterator_next(iterator);
        ASSERT_TRUE(current);
        counter++;
    }
    ASSERT_EQ(5, counter);

    mamaFieldCacheIterator_destroy(iterator);
    mamaMsg_destroy(message);

    ret = mamaFieldCache_destroy(fieldCache);
}
Esempio n. 9
0
TEST_F(MamaFieldCacheIteratorTestC, iteratorBegin)
{
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    
    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f32", 25, 12.3);
    mamaMsg_addI32(message, "test_i32", 66, -101);
    mamaMsg_addString(message, "test_string", 90, "hello world");
    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    mamaFieldCacheIterator iterator;
    mamaFieldCacheIterator_create(&iterator, fieldCache);
    
    mamaFieldCacheField field = NULL;
    
    mama_fid_t fid = 0;
    field = mamaFieldCacheIterator_begin(iterator);
    ASSERT_TRUE(field);
    mamaFieldCacheField_getFid(field, &fid);
    ASSERT_EQ(10, fid);
    
    mamaFieldCacheIterator_destroy(iterator);
    mamaMsg_destroy(message);

    ret = mamaFieldCache_destroy(fieldCache);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
}
Esempio n. 10
0
mama_status
mamaConflationManager_destroy (mamaConflationManager mgr)
{
    mamaConflationMgr* impl = (mamaConflationMgr*)mgr;

    if (impl == NULL)
        return MAMA_STATUS_INVALID_ARG;

    if (impl->mStarted)
    {
        if (MAMA_STATUS_OK != 
            mamaConflationManager_end (mgr))
        {
            mama_log (MAMA_LOG_LEVEL_FINE, "Failed to stop conflation.");
        }
    }
            
    if (impl->mInstalled)
    {
        if (MAMA_STATUS_OK != 
            mamaConflationManager_uninstallConflationManager (mgr))
        {
            mama_log (MAMA_LOG_LEVEL_FINE, "Failed to uninstall conflation.");
        }
    }
    
    wombatQueue_destroy (impl->mMsgQueue);
    
    if (impl->mMsg)
        mamaMsg_destroy (impl->mMsg);

    free (impl);
    return  MAMA_STATUS_OK;
}
mama_status
mamaStatsGenerator_destroy (mamaStatsGenerator statsGenerator)
{
    mamaStatsGeneratorImpl* impl = (mamaStatsGeneratorImpl*)statsGenerator;

    if(impl)
    {
    impl->mStatsLogger = NULL;

    if (impl->mStatMsg != NULL)
    {
        mamaMsg_destroy (impl->mStatMsg);
        impl->mStatMsg = NULL;
    }

    if (impl->mStatsCollectors != NULL)
    {
        list_destroy (impl->mStatsCollectors, NULL, NULL);
    }

    free (impl);

    }
    return MAMA_STATUS_OK;
}
Esempio n. 12
0
void MsgNewIteratorTestC::TearDown(void)
{
    /* Cleanup the memory. */
    mamaMsgIterator_destroy (iterator);
    mamaDictionary_destroy  (dict);
    mamaMsg_destroy (msg);

    mama_close();
}
Esempio n. 13
0
TEST_F(MamaFieldCacheIteratorTestC, iteratorNext)
{
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    
    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f32", 25, 12.3);
    mamaMsg_addI32(message, "test_i32", 66, -101);
    mamaMsg_addString(message, "test_string", 90, "hello world");
    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    mamaFieldCacheIterator iterator;
    mamaFieldCacheIterator_create(&iterator, fieldCache);
    
    mamaFieldCacheField begin = NULL;
    begin = mamaFieldCacheIterator_begin(iterator);
    
    ASSERT_TRUE(mamaFieldCacheIterator_hasNext(iterator));

    mamaFieldCacheField current = NULL;
    current = mamaFieldCacheIterator_next(iterator);
    ASSERT_TRUE(current);
    ASSERT_TRUE(current == begin);

    mama_fid_t fid = 0;
    ASSERT_TRUE(mamaFieldCacheIterator_hasNext(iterator));
    current = mamaFieldCacheIterator_next(iterator);
    ASSERT_TRUE(current);
    mamaFieldCacheField_getFid(current, &fid);
    ASSERT_EQ(25, fid);
    
    ASSERT_TRUE(mamaFieldCacheIterator_hasNext(iterator));
    current = mamaFieldCacheIterator_next(iterator);
    ASSERT_TRUE(current);
    mamaFieldCacheField_getFid(current, &fid);
    ASSERT_EQ(66, fid);
    
    ASSERT_TRUE(mamaFieldCacheIterator_hasNext(iterator));
    current = mamaFieldCacheIterator_next(iterator);
    mamaFieldCacheField_getFid(current, &fid);
    ASSERT_EQ(90, fid);
    
    ASSERT_FALSE(mamaFieldCacheIterator_hasNext(iterator));
    
    current = mamaFieldCacheIterator_next(iterator);
    ASSERT_FALSE(current);

    mamaFieldCacheIterator_destroy(iterator);
    mamaMsg_destroy(message);

    ret = mamaFieldCache_destroy(fieldCache);
}
Esempio n. 14
0
TEST_F(MamaFieldCacheTestC, applyMsgUsingNames)
{
    mamaFieldCache fieldCache = NULL;
    mama_size_t size = 0;
    const char* name = "";
    mama_status ret = mamaFieldCache_create(&fieldCache);
    mamaFieldCache_setUseFieldNames(fieldCache, 1);

    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f64", 25, 12.3);
    mamaMsg_addI32(message, "test_i32", 66, -101);
    mamaMsg_addString(message, "test_string", 90, "hello world");

    ret = mamaFieldCache_applyMessage(fieldCache, message, NULL);

    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ret = mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(4, size);

    mamaFieldCacheField field = NULL;
    ret = mamaFieldCache_find(fieldCache, 10, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(10, field->mFid);
    mamaFieldCacheField_getName(field, &name);
    ASSERT_STREQ("test_bool", name);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 25, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(25, field->mFid);
    mamaFieldCacheField_getName(field, &name);
    ASSERT_STREQ("test_f64", name);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 66, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(66, field->mFid);
    mamaFieldCacheField_getName(field, &name);
    ASSERT_STREQ("test_i32", name);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 90, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(90, field->mFid);
    mamaFieldCacheField_getName(field, &name);
    ASSERT_STREQ("test_string", name);

    mamaMsg_destroy (message);

    ret = mamaFieldCache_destroy(fieldCache);
}
void RMDSBridgeSubscription::SendStatusMessage( mamaMsgStatus secStatus )
{
	if (isShutdown_)
	{
		// just don't bother making the callback
		return;
	}
	// create and send a message containing the (failed) status
	mamaMsg msg;
	mamaMsg_createForPayload(&msg, MAMA_PAYLOAD_TICK42RMDS);

	mamaMsg_addI32(msg, MamaFieldMsgType.mName, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_SEC_STATUS);
	mamaMsg_addI32(msg, MamaFieldMsgStatus.mName, MamaFieldMsgStatus.mFid, secStatus);

    const CommonFields &commonFields = UpaMamaCommonFields::CommonFields();
	mamaMsg_addString(msg, commonFields.wIssueSymbol.mama_field_name.c_str(),commonFields.wIssueSymbol.mama_fid, symbol_.c_str());
	mamaMsg_addString(msg, commonFields.wSymbol.mama_field_name.c_str(), commonFields.wSymbol.mama_fid, symbol_.c_str());

	mama_status status = MAMA_STATUS_OK;
	try
	{
		status = mamaSubscription_processMsg(subscription_, msg);
	}
	catch (...)
	{
		mamaMsg_destroy(msg);	
		t42log_error("RMDSBridgeSubscription::OnMessage - caught exception calling mamaSubscription_processMsg for %s", symbol_.c_str());
	}


	if (MAMA_STATUS_OK != status)
	{
		mama_log (MAMA_LOG_LEVEL_ERROR,
			"RMDSBridgeSubscription::OnMessage: "
			"mamaSubscription_processMsg() failed. [%d]",
			status);
	}

	mamaMsg_destroy(msg);	
}
Esempio n. 16
0
static mama_status
mamaMsgField_destroyLastVectorMsg (mamaMsgFieldImpl *impl)
{
    if (impl != NULL)
    {
        int i = 0;
        for (i = 0; i < impl->myLastVectorMsgLen; i++)
            mamaMsg_destroy (impl->myLastVectorMsg[i]);

        free (impl->myLastVectorMsg);
        impl->myLastVectorMsg    = NULL;
        impl->myLastVectorMsgLen = 0;

        for (i = 0; i < impl->myLastVectorPayloadMsgLen; i++)
            mamaMsg_destroy (impl->myLastVectorPayloadMsg[i]);

        free (impl->myLastVectorPayloadMsg);
        impl->myLastVectorPayloadMsg    = NULL;
        impl->myLastVectorPayloadMsgLen = 0;
    }
    return MAMA_STATUS_OK;
}
Esempio n. 17
0
mama_status mamaMsgField_destroy (
    mamaMsgField         field)
{
    mamaMsgFieldImpl* impl = (mamaMsgFieldImpl*)(field);
    mamaMsgField_destroyLastVectorMsg (impl);

    if (impl->mySubMsg != NULL)
    {
        mamaMsg_destroy (impl->mySubMsg);
        impl->mySubMsg = NULL;
    }

    free (impl);
    return MAMA_STATUS_OK;
}
Esempio n. 18
0
static void MAMACALLTYPE
sendRecap     (mamaQueue queue, void* closure)
{
    recapInfo* info = (recapInfo*) closure;


    mamaMsg_updateU8(gSubscriptionList[info->index].cachedMsg, NULL, MamaFieldMsgType.mFid, MAMA_MSG_TYPE_INITIAL);

    if (info->msg)
    {
        mamaDQPublisher_sendReply(gSubscriptionList[info->index].pub, info->msg, gSubscriptionList[info->index].cachedMsg);
        mamaMsg_destroy( info->msg);

    }
    else
        mamaDQPublisher_send(gSubscriptionList[info->index].pub, gSubscriptionList[info->index].cachedMsg);


    free (info);
}
Esempio n. 19
0
/*  Description:     Create a mamaMsg, add strings to fields in the message,
 *                   and iterate through the fields printing values via 
 *                   callback method.
 *
 *  Expected Result: MAMA_STATUS_OK
 */
TEST_F (MsgIterateTestC, IteratorCallback)
{
    /* create a mama message. */
    mamaMsg msg = NULL;
    mamaMsg_create (&msg);

    /* add a fields to the message. */
    mamaMsg_addString (msg, "string", 101, "This is an iteration test.");
    mamaMsg_addU8     (msg, "u8", 102, 8);
    mamaMsg_addU16    (msg, "u16", 103, 16);
    mamaMsg_addU32    (msg, "u32", 104, 32);
    mamaMsg_addU64    (msg, "u64", 105, 64);

    /* iterate through the msg's fields */
    ASSERT_EQ (MAMA_STATUS_OK,
               mamaMsg_iterateFields (msg, msgOnField, NULL, (void*) 2));
    
    /* destroy the message. */
    mamaMsg_destroy (msg);
}
Esempio n. 20
0
mama_status dqContext_clearCache (mamaDqContext *ctx, int freeArray)
{
    if (ctx->mCache != NULL)
    {
        int i = 0;
        for (i = 0; i < ctx->mCacheSize; i++)
        {
            if (ctx->mCache[i] != NULL)
            {
                mamaMsg_destroy (ctx->mCache[i]);
                ctx->mCache[i] = NULL;
            }
        }
        ctx->mCurCacheIdx = 0;

        if (freeArray)
        {
            free (ctx->mCache);
            ctx->mCache = NULL;
        }
    }
    return MAMA_STATUS_OK;
}
Esempio n. 21
0
TEST_F(MamaFieldCacheTestC, getDeltaMsgNotTrackingModif)
{
    mama_bool_t modified = 0;
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    // setting explicitely to non-tracking mode
    mamaFieldCache_setTrackModified(fieldCache, 0);

    // This field will be published
    mamaFieldCacheField field = NULL;
    mamaFieldCacheField_create(&field, 10, MAMA_FIELD_TYPE_BOOL, NULL);
    mamaFieldCacheField_setBool(field, 1);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Check if modified before publishing - who cares... global check modified is disabled
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    // This field will not be published
    mamaFieldCacheField_create(&field, 25, MAMA_FIELD_TYPE_F64, NULL);
    mamaFieldCacheField_setF64(field, 3.1);
    // Disable publishing
    mamaFieldCacheField_setPublish(field, 0);
    // Check modified can be anything - no publishing anyway... see above
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    // This field will be published
    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Check if modified - who cares... global check modified is disabled
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    // This field will be published
    mamaFieldCacheField_create(&field, 90, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world", 0);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified - who cares... global check modified is disabled
    mamaFieldCacheField_setCheckModified(field, 0);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    // This field will be published
    mamaFieldCacheField_create(&field, 91, MAMA_FIELD_TYPE_STRING, NULL);
    mamaFieldCacheField_setString(field, "hello world again", 0);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Don't check if modified - who cares... global check modified is disabled
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    mamaMsg message;
    mamaMsg_create(&message);

    // This results in a Full message because track modified is false
    mamaFieldCache_getDeltaMessage(fieldCache, message);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 10, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    // The modified flag is not modified if the cache is not tracking modifications
    ASSERT_FALSE(modified);

    mama_bool_t resultBool;
    ret = mamaMsg_getBool(message, "test_bool", 10, &resultBool);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(1, resultBool);
    mama_f64_t resultF64;
    ret = mamaMsg_getF64(message, "test_f32", 25, &resultF64);
    ASSERT_EQ(MAMA_STATUS_NOT_FOUND, ret);
    mama_i32_t resultI32;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(-100, resultI32);
    const char* resultString;
    ret = mamaMsg_getString(message, "test_string", 90, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_STREQ("hello world", resultString);
    ret = mamaMsg_getString(message, "test_string", 91, &resultString);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_STREQ("hello world again", resultString);

    mamaMsg_destroy (message);

    ret = mamaFieldCache_destroy(fieldCache);
}
Esempio n. 22
0
TEST_F (MsgIterateTestC, CreateIterator)
{   
    mama_fid_t      fid         = 0;
    mamaMsgIterator iterator    = NULL;
    mamaMsgField    field       = NULL;
    mamaFieldType   type        = MAMA_FIELD_TYPE_UNKNOWN;    

    /* Create a mama message. */
    mamaMsg msg = NULL;
    mamaMsg_create (&msg);
    
    /* add a fields to the message. */
    mamaMsg_addString (msg, "string", 101, "This is an iteration test.");
    mamaMsg_addU8     (msg, "u8", 102, 8);
    mamaMsg_addU16    (msg, "u16", 103, 16);
    mamaMsg_addU32    (msg, "u32", 104, 32);
    mamaMsg_addU64    (msg, "u64", 105, 64);
   
    /* Create iterator and message field required.*/
    ASSERT_EQ (MAMA_STATUS_OK, 
               mamaMsgIterator_create (&iterator,NULL));
    
    mamaMsgIterator_associate (iterator,msg);
    
    while ((field = mamaMsgIterator_next(iterator)) != NULL)
    {
        /* Operate on contents of each field. */
        mamaMsgField_getFid (field, &fid);
        mamaMsgField_getType (field, &type);
        switch(type)
        {
            case MAMA_FIELD_TYPE_STRING:
            {
                char buffer[MAX_FIELD_STR_LEN];
                ASSERT_EQ (101, fid);
                mamaMsgField_getAsString (field, buffer, MAX_FIELD_STR_LEN);
                ASSERT_STREQ ("This is an iteration test.", buffer);
                break;
            }
            case MAMA_FIELD_TYPE_U8:
            {
                mama_u8_t buffer = 0;
                ASSERT_EQ (102, fid);
                mamaMsgField_getU8 (field, &buffer);
                ASSERT_EQ (8, buffer);
                break;
            }
            case MAMA_FIELD_TYPE_U16:
            {
                mama_u16_t buffer = 0;
                ASSERT_EQ (103, fid);
                mamaMsgField_getU16 (field, &buffer);
                ASSERT_EQ (16, buffer);
                break;
            }
            case MAMA_FIELD_TYPE_U32:
            {
                mama_u32_t buffer = 0;
                ASSERT_EQ (104, fid);
                mamaMsgField_getU32 (field, &buffer);
                ASSERT_EQ (32, buffer);
                break;
            }
            case MAMA_FIELD_TYPE_U64:
            {
                mama_u64_t buffer = 0;
                ASSERT_EQ (105, fid);
                mamaMsgField_getU64 (field, &buffer);
                ASSERT_EQ (64, buffer);
                break;
            }
            default:
                break;
        }
    }

    /* destroy the message. */
    mamaMsg_destroy (msg);
}
Esempio n. 23
0
void MamaMsgUtilsTestC::TearDown(void)
{
    /* Destroy the message after each test */
    ASSERT_EQ (MAMA_STATUS_OK, mamaMsg_destroy (msg));
    msg = NULL;
}
Esempio n. 24
0
/**
 * Called when message removed from queue by dispatch thread
 *
 * @param data The Avis Attributes* clone (must be freed)
 * @param closure The subscriber
 */
static void MAMACALLTYPE
avis_queue_callback (mamaQueue queue,
                     void*     closure)
{
    mama_status status     = MAMA_STATUS_OK;
    mamaMsg     tmpMsg     = NULL;
    msgBridge   bridgeMsg  = NULL;
    const void* buf        = NULL;
    mama_size_t bufSize    = 0;

    avisCallbackContext* ctx = (avisCallbackContext*) closure;

    void* data       = ctx->attributes;
    void* subscriber = ctx->subscriber;

    /* cant do anything without a subscriber */
    if (!subscriber)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avis_callback(): called with NULL subscriber!");

        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*Make sure that the subscription is processing messages*/
    if ((!avisSub(subscriber)->mIsNotMuted) || 
        (!avisSub(subscriber)->mIsValid))
    {
        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*This is the reuseable message stored on the associated MamaQueue*/
    tmpMsg = mamaQueueImpl_getMsg(avisSub(subscriber)->mQueue);
    if (!tmpMsg)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get cached mamaMsg from event queue.");

        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*Get the bridge message from the mamaMsg*/
    if (MAMA_STATUS_OK!=(status=mamaMsgImpl_getBridgeMsg (tmpMsg,
                    &bridgeMsg)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "avis_callback(): "
                  "Could not get bridge message from cached"
                  " queue mamaMsg [%d]", status);

        attributes_destroy (data);
        free (ctx);
        return;
    }

    /*Set the buffer and the reply handle on the bridge message structure*/
    if (MAMA_STATUS_OK!=(status=mamaMsgImpl_setMsgBuffer (tmpMsg,
                                data,
                                0, MAMA_PAYLOAD_AVIS)))
    {
        mama_log (MAMA_LOG_LEVEL_ERROR,
                  "avis_callback(): mamaMsgImpl_setMsgBuffer() failed. [%d]",
                  status);

        attributes_destroy (data);
        free (ctx);
        return;
    }

    if (MAMA_STATUS_OK == mamaMsg_getOpaque (
            tmpMsg, ENCLOSED_MSG_FIELD_NAME, 0, &buf, &bufSize) && 
            bufSize > 0)
    {
        mamaMsg         encMsg = NULL;
        mamaBridgeImpl* bridge = 
            mamaSubscription_getBridgeImpl (avisSub(subscriber)->mMamaSubscription);

        status = mamaMsg_createFromByteBuffer (&encMsg, buf, bufSize);

        if (MAMA_STATUS_OK != status)
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "avis_callback(): "
                      "Could not create message from enclosed byte buffer. [%d]",
                      status);

            attributes_destroy (data);
            free (ctx);
            return;
        }

        mamaMsgImpl_useBridgePayload (encMsg, bridge);
        mamaMsgImpl_getBridgeMsg (encMsg, &bridgeMsg);

        /*Set the buffer and the reply handle on the bridge message structure*/
        avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0);

        if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINEST)
        {
            mama_log (MAMA_LOG_LEVEL_FINEST, "avis_callback(): "
                      "Received enclosed message: %s", mamaMsg_toString (encMsg));
        }

        if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg
                    (avisSub(subscriber)->mMamaSubscription, encMsg)))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "avis_callback(): "
                      "mamaSubscription_processMsg() failed. [%d]",
                      status);
        }

        mamaMsg_destroy (encMsg);
    }
    else
    {
        avisBridgeMamaMsgImpl_setAttributesAndSecure (bridgeMsg, data, 0);

        if (gMamaLogLevel >= MAMA_LOG_LEVEL_FINEST)
        {
            mama_log (MAMA_LOG_LEVEL_FINEST, "avis_callback(): "
                           "Received message: %s", mamaMsg_toString (tmpMsg));
        }

        /*Process the message as normal*/
        if (MAMA_STATUS_OK != (status=mamaSubscription_processMsg
                    (avisSub(subscriber)->mMamaSubscription, tmpMsg)))
        {
            mama_log (MAMA_LOG_LEVEL_ERROR,
                      "avis_callback(): "
                      "mamaSubscription_processMsg() failed. [%d]",
                      status);
        }
    }

    free (ctx);
}
Esempio n. 25
0
mama_status
mamaQueue_destroy (mamaQueue queue)
{
    mamaQueueImpl* impl = (mamaQueueImpl*)queue;
    mama_status    status = MAMA_STATUS_OK;

    mama_log (MAMA_LOG_LEVEL_FINEST, "Entering mamaQueue_destroy for queue 0x%X.", queue);

    impl->mIsDispatching = 0;
    if (!queue)
    {
        mama_log (MAMA_LOG_LEVEL_ERROR, "mamaQueue_destroy(): NULL queue.");
        return MAMA_STATUS_NULL_ARG;
    }

    /* The queue can only be destroyed if there are no open event objects. */
    status = MAMA_STATUS_QUEUE_OPEN_OBJECTS;

    /* Only continue if the object count is 0. */
    if(0 == wInterlocked_read(&impl->mNumberOpenObjects))
    {
        if (impl->mMamaQueueBridgeImpl)
        {
            if (MAMA_STATUS_OK!=(status=impl->mBridgeImpl->bridgeMamaQueueDestroy (
                        impl->mMamaQueueBridgeImpl)))
            {
                mama_log (MAMA_LOG_LEVEL_ERROR,
                      "mamaQueue_destroy(): Could not destroy queue bridge.");
                     /*We should continue and free up the rest of the structure.*/
            }
        }

        if (impl->mDispatcher)
        {
            /* We don't want the dispatcher to access a destroyed queue */
            ((mamaDispatcherImpl*)(impl->mDispatcher))->mIsDispatching = 0;
            ((mamaDispatcherImpl*)(impl->mDispatcher))->mQueue = NULL;
        }

        /*Destroy the cached mamaMsg - no longer needed*/
        if (impl->mMsg) mamaMsg_destroy (impl->mMsg);

        if (impl->mInitialStat)
        {
            mamaStat_destroy (impl->mInitialStat);
            impl->mInitialStat = NULL;
        }

        if (impl->mRecapStat)
        {
            mamaStat_destroy (impl->mRecapStat);
            impl->mRecapStat = NULL;
        }

        if (impl->mUnknownMsgStat)
        {
            mamaStat_destroy (impl->mUnknownMsgStat);
            impl->mUnknownMsgStat = NULL;
        }

        if (impl->mMessageStat)
        {
            mamaStat_destroy (impl->mMessageStat);
            impl->mMessageStat = NULL;
        }

        if (impl->mQueueSizeStat)
        {
            mamaStat_destroy (impl->mQueueSizeStat);
            impl->mQueueSizeStat = NULL;
        }

        if (impl->mSubscriptionStat)
        {
            mamaStat_destroy (impl->mSubscriptionStat);
            impl->mSubscriptionStat = NULL;
        }

        if (impl->mTimeoutStat)
        {
            mamaStat_destroy (impl->mTimeoutStat);
            impl->mTimeoutStat = NULL;
        }

        if (impl->mWombatMsgsStat)
        {
            mamaStat_destroy (impl->mWombatMsgsStat);
            impl->mWombatMsgsStat = NULL;
        }

        if (impl->mFastMsgsStat)
        {
            mamaStat_destroy (impl->mFastMsgsStat);
            impl->mFastMsgsStat = NULL;
        }

        if (impl->mRvMsgsStat)
        {
            mamaStat_destroy (impl->mRvMsgsStat);
            impl->mRvMsgsStat = NULL;
        }

        if (impl->mStatsCollector)
        {
            mamaStatsGenerator_removeStatsCollector  (mamaInternal_getStatsGenerator(), impl->mStatsCollector);
            mamaStatsCollector_destroy (impl->mStatsCollector);
            impl->mStatsCollector = NULL;
        }
         if (impl->mQueueName)
            free ((void*)impl->mQueueName);

        impl->mBridgeImpl          = NULL;
        impl->mMamaQueueBridgeImpl = NULL;
        impl->mMsg                 = NULL;

        /* Destroy the counter lock */
        wInterlocked_destroy(&impl->mNumberOpenObjects);

        free (impl);

        mama_log (MAMA_LOG_LEVEL_FINEST, "Leaving mamaQueue_destroy for queue 0x%X.", queue);
        status = MAMA_STATUS_OK;
    }

    return status;
}
Esempio n. 26
0
TEST_F(MamaFieldCacheTestC, applyMsgUpdate)
{
    mamaFieldCache fieldCache = NULL;
    mama_bool_t modified = 0;
    mama_size_t size = 0;
    mama_size_t len = 0;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    mamaMsg message;
    mamaMsg_create(&message);
    mamaMsg_addBool(message, "test_bool", 10, 1);
    mamaMsg_addF64(message, "test_f64", 25, 12.3);
    mamaMsg_addString(message, "test_string", 90, "hello world");

    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    ret = mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(3, size);

    mamaFieldCacheField field = NULL;
    ret = mamaFieldCache_find(fieldCache, 10, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(10, field->mFid);
    mama_bool_t resultBool = 0;
    mamaFieldCacheField_getBool(field, &resultBool);
    ASSERT_EQ(1, resultBool);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 25, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(25, field->mFid);
    mama_f64_t resultF64 = 0;
    mamaFieldCacheField_getF64(field, &resultF64);
    ASSERT_DOUBLE_EQ(12.3, resultF64);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    field = NULL;
    ret = mamaFieldCache_find(fieldCache, 90, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(90, field->mFid);
    const char* resultString = NULL;
    mamaFieldCacheField_getString(field, &resultString, &len);
    ASSERT_STREQ("hello world", resultString);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(3, size);

    mamaMsg_clear(message);

    mamaMsg_addF64(message, "test_f32", 25, 10.9);
    mamaMsg_addI32(message, "test_i32", 60, -123);

    mamaFieldCache_applyMessage(fieldCache, message, NULL);

    ret = mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(4, size);

    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(4, size);

    ret = mamaFieldCache_find(fieldCache, 10, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(10, field->mFid);
    resultBool = 0;
    mamaFieldCacheField_getBool(field, &resultBool);
    ASSERT_EQ(1, resultBool);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    ret = mamaFieldCache_find(fieldCache, 60, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(60, field->mFid);
    mama_i32_t resultI32 = 0;
    mamaFieldCacheField_getI32(field, &resultI32);
    ASSERT_DOUBLE_EQ(-123, resultI32);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    ret = mamaFieldCache_find(fieldCache, 25, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(25, field->mFid);
    resultF64 = 0;
    mamaFieldCacheField_getF64(field, &resultF64);
    ASSERT_DOUBLE_EQ(10.9, resultF64);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    ret = mamaFieldCache_find(fieldCache, 90, NULL, &field);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(90, field->mFid);
    resultString = NULL;
    mamaFieldCacheField_getString(field, &resultString, &len);
    ASSERT_STREQ("hello world", resultString);
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_TRUE(modified);

    ret = mamaFieldCache_destroy(fieldCache);
    mamaMsg_destroy(message);
}
Esempio n. 27
0
void populateMessageFromDictionary (mamaDictionaryImpl* impl,
                                    mamaMsg             msg)
{
    int         i      = 0;
    mama_status status = MAMA_STATUS_OK;

    const mama_bool_t bool_vector[] = {0};
    const char char_vector[] = {' '};
    const mama_i8_t i8_vector[] = {1};
    const mama_u8_t u8_vector[] = {1};
    const mama_i16_t i16_vector[] = {1};
    const mama_u16_t u16_vector[] = {1};
    const mama_i32_t i32_vector[] = {1};
    const mama_u32_t u32_vector[] = {1};
    const mama_i64_t i64_vector[] = {1};
    const mama_u64_t u64_vector[] = {1};
    const mama_f32_t f32_vector[] = {1.0f};
    const mama_f64_t f64_vector[] = {1.0};
    const char*      string_vector[] = {" "};

    mamaMsg msgArray[1];
    mamaMsg tempMsg   =   NULL;

    mamaPrice price_vector[1];
    mamaPrice price = NULL;

    mamaDateTime dateTime_vector[1];
    mamaDateTime dateTime = NULL;


    mamaMsg_create (&tempMsg);
    mamaMsg_addI32 (tempMsg, NULL, 1, 0);
    msgArray[0] = tempMsg;

    mamaPrice_create (&price);
    mamaPrice_setValue (price,123.45);
    price_vector[0] = price;

    mamaDateTime_create (&dateTime);
    mamaDateTime_setToNow (dateTime);
    dateTime_vector[0] = dateTime;
    
    for (i=0;i<impl->mDictSize;i++)
    {
        if (impl->mDict[i])
        {
            mamaFieldDescriptor fd = impl->mDict[i];
            mama_fid_t      fid     = mamaFieldDescriptor_getFid  (fd);
            const char*     name    = mamaFieldDescriptor_getName (fd);
            mamaFieldType   type    = mamaFieldDescriptor_getType (fd);

            switch (type)
            {
                case MAMA_FIELD_TYPE_MSG:
                    ADD_TO_DICT (Msg, tempMsg);
                    break;
                case MAMA_FIELD_TYPE_OPAQUE:
                    mamaMsg_addOpaque (msg, name, fid, (void*)" ", 2);
                    break;
                case MAMA_FIELD_TYPE_STRING:
                    ADD_TO_DICT (String, "");
                    break;
                case MAMA_FIELD_TYPE_BOOL:
                    ADD_TO_DICT (Bool, 0);
                    break;
                case MAMA_FIELD_TYPE_CHAR:
                    ADD_TO_DICT (Char, ' ');
                    break;
                case MAMA_FIELD_TYPE_I8:
                    ADD_TO_DICT (I8, 0);
                    break;
                case MAMA_FIELD_TYPE_U8:
                    ADD_TO_DICT (U8, 0);
                    break;
                case MAMA_FIELD_TYPE_I16:
                    ADD_TO_DICT (I16, 0);
                    break;
                case MAMA_FIELD_TYPE_U16:
                    ADD_TO_DICT (U16, 0);
                    break;
                case MAMA_FIELD_TYPE_I32:
                    ADD_TO_DICT (I32, 0);
                    break;
                case MAMA_FIELD_TYPE_U32:
                    ADD_TO_DICT (U32, 0);
                    break;
                case MAMA_FIELD_TYPE_I64:
                    ADD_TO_DICT (I64, 0);
                    break;
                case MAMA_FIELD_TYPE_U64:
                    ADD_TO_DICT (U64, 0);
                    break;
                case MAMA_FIELD_TYPE_F32:
                    ADD_TO_DICT (F32, 0.0f);
                    break;
                case MAMA_FIELD_TYPE_F64:
                    ADD_TO_DICT (F64, 0.0);
                    break;
                case MAMA_FIELD_TYPE_TIME:
                    ADD_TO_DICT (DateTime, dateTime);
                    break;
                case MAMA_FIELD_TYPE_PRICE:
                    ADD_TO_DICT (Price, price);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_BOOL:
                    ADD_VECTOR_TO_DICT (Bool, bool_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_CHAR:
                    ADD_VECTOR_TO_DICT (Char, char_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I8:
                    ADD_VECTOR_TO_DICT (I8, i8_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U8:
                    ADD_VECTOR_TO_DICT (U8, u8_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I16:
                    ADD_VECTOR_TO_DICT (I16, i16_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U16:
                    ADD_VECTOR_TO_DICT (U16, u16_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I32:
                    ADD_VECTOR_TO_DICT (I32, i32_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U32:
                    ADD_VECTOR_TO_DICT (U32, u32_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_I64:
                    ADD_VECTOR_TO_DICT (I64, i64_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_U64:
                    ADD_VECTOR_TO_DICT (U64, u64_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_F32:
                    ADD_VECTOR_TO_DICT (F32, f32_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_F64:
                    ADD_VECTOR_TO_DICT (F64, f64_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_STRING:
                    ADD_VECTOR_TO_DICT (String, string_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_MSG:
                    ADD_VECTOR_TO_DICT (Msg, msgArray);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_TIME:
                    ADD_VECTOR_TO_DICT (DateTime, dateTime_vector);
                    break;
                case MAMA_FIELD_TYPE_VECTOR_PRICE:
                    ADD_VECTOR_TO_DICT (Price, price_vector);
                    break;
                default:
					/* error with unknown type */
                    mama_log (MAMA_LOG_LEVEL_NORMAL, "Could not add type to "
                              "dict message - not supported. [%s] fid=%d name=%s",
                              mamaFieldTypeToString (type), fid, name);
                    break;
            }
        }
    }

    mamaPrice_destroy (price);
    mamaDateTime_destroy (dateTime);
    mamaMsg_destroy (tempMsg);
}
Esempio n. 28
0
TEST_F(MamaFieldCacheTestC, getDeltaMsgMultipleUpdates)
{
    mama_size_t size = 0;
    mama_bool_t modified = 0;
    mamaFieldCache fieldCache = NULL;
    mama_status ret = mamaFieldCache_create(&fieldCache);

    // tracking modification state globally at cache level
//    mamaFieldCache_setTrackModified(fieldCache, 1);

    mamaFieldCacheField field = NULL;
    mamaFieldCacheField_create(&field, 66, MAMA_FIELD_TYPE_I32, NULL);
    mamaFieldCacheField_setI32(field, -100);
    // Enable publishing
    mamaFieldCacheField_setPublish(field, 1);
    // Check if modified before publishing
    mamaFieldCacheField_setCheckModified(field, 1);

    mamaFieldCache_applyField(fieldCache, field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    // apply a second time before getDeltaMsg is called
    mamaFieldCacheField_setI32(field, 80);
    mamaFieldCache_applyField(fieldCache, field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    mamaFieldCacheField_destroy(field);

    // This field must never be published because publish is false
    mamaFieldCacheField_create(&field, 25, MAMA_FIELD_TYPE_F64, NULL);
    mamaFieldCacheField_setF64(field, 3.1);
    // Disable publishing
    mamaFieldCacheField_setPublish(field, 0);
    // Check modified can be anything - no publishing anyway... see above
    mamaFieldCacheField_setCheckModified(field, 1);
    mamaFieldCache_applyField(fieldCache, field);
    mamaFieldCacheField_destroy(field);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    size = 0;
    mamaFieldCacheList_getSize(fieldCache->mModifiedFields, &size);
    ASSERT_EQ(1, size);

    mamaMsg message = NULL;
    mamaMsg_create(&message);

    mamaFieldCache_getDeltaMessage(fieldCache, message);

    ASSERT_EQ(MAMA_STATUS_OK, mamaFieldCache_find(fieldCache, 66, "", &field));
    mamaFieldCacheField_isModified(field, &modified);
    ASSERT_FALSE(modified);

    mama_i32_t resultI32 = 0;
    ret = mamaMsg_getI32(message, "test_i32", 66, &resultI32);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_EQ(80, resultI32);

    mama_f64_t resultF64;
    ret = mamaMsg_getF64(message, "test_f32", 25, &resultF64);
    ASSERT_EQ(MAMA_STATUS_NOT_FOUND, ret);

    mamaMsg_destroy (message);

    ret = mamaFieldCache_destroy(fieldCache);
}