void ProcessEventsWithPartLogUnittest::TestProcessEventsWithPartLog()

in core/unittest/processor/ProcessorMergeMultilineLogNativeUnittest.cpp [870:1326]


void ProcessEventsWithPartLogUnittest::TestProcessEventsWithPartLog() {
    // case: P
    {
        // make config
        Json::Value config;
        config["MergeType"] = "flag";
        // make processor
        // ProcessorMergeMultilineLogNative
        ProcessorMergeMultilineLogNative processorMergeMultilineLogNative;
        processorMergeMultilineLogNative.SetContext(mContext);
        processorMergeMultilineLogNative.SetMetricsRecordRef(ProcessorMergeMultilineLogNative::sName, "1");
        APSARA_TEST_TRUE(processorMergeMultilineLogNative.Init(config));
        // make eventGroup
        auto sourceBuffer = std::make_shared<SourceBuffer>();
        PipelineEventGroup eventGroup(sourceBuffer);
        std::string inJson = R"({
            "events": [
                {
                    "contents" :
                    {
                        "P": "",
                        "content": "Exception"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ],
            "metadata": {
                "has.part.log": "P"
            }
        })";
        eventGroup.FromJsonString(inJson);

        // run test function
        processorMergeMultilineLogNative.Process(eventGroup);
        // judge result
        std::stringstream expectJson;
        expectJson << R"({
            "events": [
                {
                    "contents":{
                        "content":"Exception"
                    },
                    "timestamp":12345678901,
                    "timestampNanosecond":0,
                    "type":1
                }
            ]
        })";
        std::string outJson = eventGroup.ToJsonString();
        APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
    }
    // case: F
    {
        // make config
        Json::Value config;
        config["MergeType"] = "flag";
        // make processor
        // ProcessorMergeMultilineLogNative
        ProcessorMergeMultilineLogNative processorMergeMultilineLogNative;
        processorMergeMultilineLogNative.SetContext(mContext);
        processorMergeMultilineLogNative.SetMetricsRecordRef(ProcessorMergeMultilineLogNative::sName, "1");
        APSARA_TEST_TRUE(processorMergeMultilineLogNative.Init(config));
        // make eventGroup
        auto sourceBuffer = std::make_shared<SourceBuffer>();
        PipelineEventGroup eventGroup(sourceBuffer);
        std::string inJson = R"({
            "events": [
                {
                    "contents" :
                    {
                        "content": "Exception"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ]
        })";
        eventGroup.FromJsonString(inJson);

        // run test function
        processorMergeMultilineLogNative.Process(eventGroup);
        // judge result
        std::stringstream expectJson;
        expectJson << R"({
            "events": [
                {
                    "contents":{
                        "content":"Exception"
                    },
                    "timestamp":12345678901,
                    "timestampNanosecond":0,
                    "type":1
                }
            ]
        })";
        std::string outJson = eventGroup.ToJsonString();
        APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
    }
    // case: P+P
    {
        // make config
        Json::Value config;
        config["MergeType"] = "flag";
        // make processor
        // ProcessorMergeMultilineLogNative
        ProcessorMergeMultilineLogNative processorMergeMultilineLogNative;
        processorMergeMultilineLogNative.SetContext(mContext);
        processorMergeMultilineLogNative.SetMetricsRecordRef(ProcessorMergeMultilineLogNative::sName, "1");
        APSARA_TEST_TRUE(processorMergeMultilineLogNative.Init(config));
        // make eventGroup
        auto sourceBuffer = std::make_shared<SourceBuffer>();
        PipelineEventGroup eventGroup(sourceBuffer);
        std::string inJson = R"({
            "events": [
                {
                    "contents" :
                    {
                        "P": "",
                        "content": "Except"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "P": "",
                        "content": "ion"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ],
            "metadata": {
                "has.part.log": "P"
            }
        })";
        eventGroup.FromJsonString(inJson);

        // run test function
        processorMergeMultilineLogNative.Process(eventGroup);
        // judge result
        std::stringstream expectJson;
        expectJson << R"({
            "events": [
                {
                    "contents":{
                        "content":"Exception"
                    },
                    "timestamp":12345678901,
                    "timestampNanosecond":0,
                    "type":1
                }
            ]
        })";
        std::string outJson = eventGroup.ToJsonString();
        APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
    }
    // case: P+F
    {
        // make config
        Json::Value config;
        config["MergeType"] = "flag";
        // make processor
        // ProcessorMergeMultilineLogNative
        ProcessorMergeMultilineLogNative processorMergeMultilineLogNative;
        processorMergeMultilineLogNative.SetContext(mContext);
        processorMergeMultilineLogNative.SetMetricsRecordRef(ProcessorMergeMultilineLogNative::sName, "1");
        APSARA_TEST_TRUE(processorMergeMultilineLogNative.Init(config));
        // make eventGroup
        auto sourceBuffer = std::make_shared<SourceBuffer>();
        PipelineEventGroup eventGroup(sourceBuffer);
        std::string inJson = R"({
            "events": [
                {
                    "contents" :
                    {
                        "P": "",
                        "content": "Except"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "content": "ion"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ],
            "metadata": {
                "has.part.log": "P"
            }
        })";
        eventGroup.FromJsonString(inJson);

        // run test function
        processorMergeMultilineLogNative.Process(eventGroup);
        // judge result
        std::stringstream expectJson;
        expectJson << R"({
            "events": [
                {
                    "contents":{
                        "content":"Exception"
                    },
                    "timestamp":12345678901,
                    "timestampNanosecond":0,
                    "type":1
                }
            ]
        })";
        std::string outJson = eventGroup.ToJsonString();
        APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
    }
    // case: F+P
    {
        // make config
        Json::Value config;
        config["MergeType"] = "flag";
        // make processor
        // ProcessorMergeMultilineLogNative
        ProcessorMergeMultilineLogNative processorMergeMultilineLogNative;
        processorMergeMultilineLogNative.SetContext(mContext);
        processorMergeMultilineLogNative.SetMetricsRecordRef(ProcessorMergeMultilineLogNative::sName, "1");
        APSARA_TEST_TRUE(processorMergeMultilineLogNative.Init(config));
        // make eventGroup
        auto sourceBuffer = std::make_shared<SourceBuffer>();
        PipelineEventGroup eventGroup(sourceBuffer);
        std::string inJson = R"({
            "events": [
                {
                    "contents" :
                    {
                        "content": "Except"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "P": "",
                        "content": "ion"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ],
            "metadata": {
                "has.part.log": "P"
            }
        })";
        eventGroup.FromJsonString(inJson);

        // run test function
        processorMergeMultilineLogNative.Process(eventGroup);
        // judge result
        std::stringstream expectJson;
        expectJson << R"({
            "events": [
                {
                    "contents" :
                    {
                        "content": "Except"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "content": "ion"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ]
        })";
        std::string outJson = eventGroup.ToJsonString();
        APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
    }
    // case: F+P+F
    {
        // make config
        Json::Value config;
        config["MergeType"] = "flag";
        // make processor
        // ProcessorMergeMultilineLogNative
        ProcessorMergeMultilineLogNative processorMergeMultilineLogNative;
        processorMergeMultilineLogNative.SetContext(mContext);
        processorMergeMultilineLogNative.SetMetricsRecordRef(ProcessorMergeMultilineLogNative::sName, "1");
        APSARA_TEST_TRUE(processorMergeMultilineLogNative.Init(config));
        // make eventGroup
        auto sourceBuffer = std::make_shared<SourceBuffer>();
        PipelineEventGroup eventGroup(sourceBuffer);
        std::string inJson = R"({
            "events": [
                {
                    "contents" :
                    {
                        "content": "Exc"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "P": "",
                        "content": "ept"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "content": "ion"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ],
            "metadata": {
                "has.part.log": "P"
            }
        })";
        eventGroup.FromJsonString(inJson);

        // run test function
        processorMergeMultilineLogNative.Process(eventGroup);
        // judge result
        std::stringstream expectJson;
        expectJson << R"({
            "events": [
                {
                    "contents" :
                    {
                        "content": "Exc"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "content": "eption"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ]
        })";
        std::string outJson = eventGroup.ToJsonString();
        APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
    }
    // case: P+F+P
    {
        // make config
        Json::Value config;
        config["MergeType"] = "flag";
        // make processor
        // ProcessorMergeMultilineLogNative
        ProcessorMergeMultilineLogNative processorMergeMultilineLogNative;
        processorMergeMultilineLogNative.SetContext(mContext);
        processorMergeMultilineLogNative.SetMetricsRecordRef(ProcessorMergeMultilineLogNative::sName, "1");
        APSARA_TEST_TRUE(processorMergeMultilineLogNative.Init(config));
        // make eventGroup
        auto sourceBuffer = std::make_shared<SourceBuffer>();
        PipelineEventGroup eventGroup(sourceBuffer);
        std::string inJson = R"({
            "events": [
                {
                    "contents" :
                    {
                        "P": "",
                        "content": "Exc"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "content": "ept"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "P": "",
                        "content": "ion"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ],
            "metadata": {
                "has.part.log": "P"
            }
        })";
        eventGroup.FromJsonString(inJson);

        // run test function
        processorMergeMultilineLogNative.Process(eventGroup);
        // judge result
        std::stringstream expectJson;
        expectJson << R"({
            "events": [
                {
                    "contents" :
                    {
                        "content": "Except"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                },
                {
                    "contents" :
                    {
                        "content": "ion"
                    },
                    "timestamp" : 12345678901,
                    "timestampNanosecond" : 0,
                    "type" : 1
                }
            ]
        })";
        std::string outJson = eventGroup.ToJsonString();
        APSARA_TEST_STREQ(CompactJson(expectJson.str()).c_str(), CompactJson(outJson).c_str());
    }
}