Exemplo 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);
}
Exemplo n.º 2
1
static void MAMACALLTYPE
dqPublisherImplMsgCb (mamaSubscription subsc,
                      mamaMsg          msg,
                      void*            closure,
                      void*            itemClosure)
{
    mama_i32_t                 msgType = 0;
    mama_i32_t                subType = 0;
    const char*                symbol    = NULL;
    mama_status             status  = MAMA_STATUS_NOT_FOUND;
    mamaPublishTopic*         info    = NULL;
    mamaDQPublisherManagerImpl* impl = (mamaDQPublisherManagerImpl*) (closure);


    if (mamaMsg_getI32 (msg, MamaFieldSubscriptionType.mName,
                        MamaFieldSubscriptionType.mFid, &subType) == MAMA_STATUS_OK)
    {
        if (mamaMsg_getString (msg, MamaFieldSubscSymbol.mName,
                               MamaFieldSubscSymbol.mFid, &symbol) != MAMA_STATUS_OK)
        {
            if (mamaMsg_getSendSubject (msg, &symbol) != MAMA_STATUS_OK)
            {
                impl->mUserCallbacks.onError ((mamaDQPublisherManager)impl,
                                              status, "No symbol", msg);
                return;
            }
        }

        if (mamaMsg_getI32 (msg, MamaFieldSubscMsgType.mName,
                            MamaFieldSubscMsgType.mFid, &msgType) != MAMA_STATUS_OK)
        {
            impl->mUserCallbacks.onError ((mamaDQPublisherManager)impl, status,
                                          "NO msg type", msg);
            return;
        }

        if ((info  = wtable_lookup (impl->mPublisherMap, (symbol))))
        {
            switch (msgType)
            {
            case MAMA_SUBSC_REFRESH:
                if (!impl->mRefreshResponseMsg)
                {
                    mamaMsg_create(&impl->mRefreshResponseMsg);
                    mamaMsg_addU8(impl->mRefreshResponseMsg, NULL,
                                  MamaFieldMsgStatus.mFid, MAMA_MSG_STATUS_MISC);
                    mamaMsg_addU8(impl->mRefreshResponseMsg, NULL,
                                  MamaFieldMsgType.mFid, MAMA_MSG_TYPE_REFRESH);

                }
                mamaDQPublisher_send(info->pub, impl->mRefreshResponseMsg);
                impl->mUserCallbacks.onRefresh((mamaDQPublisherManager)impl,
                                               info, subType, msgType, msg );
                break;

            default:
                impl->mUserCallbacks.onRequest ((mamaDQPublisherManager)impl,
                                                info, subType, msgType, msg);
                break;
            }
        }
        else
        {
            impl->mUserCallbacks.onNewRequest ((mamaDQPublisherManager)impl,
                                               symbol,
                                               subType,
                                               msgType,
                                               msg);
        }

    }
    else
    {
        if (impl->mUserCallbacks.onMsg)
            impl->mUserCallbacks.onMsg ((mamaDQPublisherManager)impl, msg);
    }
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
0
mama_status
msgUtils_msgSubscMsgType (mamaMsg msg, short *result)
{
    int32_t val = 0;
    mama_status status =
        mamaMsg_getI32 (msg,
                        MamaFieldSubscMsgType.mName,
                        MamaFieldSubscMsgType.mFid,
                        &val);

#ifndef IGNORE_DEPRECATED_FIELDS
    if (status != MAMA_STATUS_OK)
    {
        /* Try the old (deprecated) field. */
        status = mamaMsg_getI32 (msg,
                                 MamaFieldSubscMsgTypeOld.mName,
                                 MamaFieldSubscMsgTypeOld.mFid,
                                 &val);
    }
#endif

    *result = (short)val;
    return status;
}
Exemplo n.º 6
0
mama_status
msgUtils_msgNum (mamaMsg msg, short *result)
{
    int32_t val;
    mama_status status;

    status = mamaMsg_getI32 (msg,
                             MamaFieldMsgNum.mName,
                             MamaFieldMsgNum.mFid,
                             &val);

    *result = (short)val;

    return status;
}
Exemplo n.º 7
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);
}
Exemplo n.º 8
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);
}