@@ -34,6 +34,7 @@ class ProcessorParseTimestampNativeUnittest : public ::testing::Test {
34
34
void TestInit ();
35
35
void TestProcessNoFormat ();
36
36
void TestProcessRegularFormat ();
37
+ void TestProcessNoYearFormat ();
37
38
void TestProcessRegularFormatFailed ();
38
39
void TestProcessHistoryDiscard ();
39
40
void TestProcessEventPreciseTimestampLegacy ();
@@ -45,6 +46,7 @@ class ProcessorParseTimestampNativeUnittest : public ::testing::Test {
45
46
UNIT_TEST_CASE (ProcessorParseTimestampNativeUnittest, TestInit);
46
47
UNIT_TEST_CASE (ProcessorParseTimestampNativeUnittest, TestProcessNoFormat);
47
48
UNIT_TEST_CASE (ProcessorParseTimestampNativeUnittest, TestProcessRegularFormat);
49
+ UNIT_TEST_CASE (ProcessorParseTimestampNativeUnittest, TestProcessNoYearFormat);
48
50
UNIT_TEST_CASE (ProcessorParseTimestampNativeUnittest, TestProcessRegularFormatFailed);
49
51
UNIT_TEST_CASE (ProcessorParseTimestampNativeUnittest, TestProcessHistoryDiscard);
50
52
UNIT_TEST_CASE (ProcessorParseTimestampNativeUnittest, TestProcessEventPreciseTimestampLegacy);
@@ -394,14 +396,107 @@ void ProcessorParseTimestampNativeUnittest::TestProcessRegularFormat() {
394
396
APSARA_TEST_EQUAL_FATAL (CompactJson (expectJsonSs.str ()), CompactJson (outJson));
395
397
// check observablity
396
398
APSARA_TEST_EQUAL_FATAL (0 , processor.GetContext ().GetProcessProfile ().historyFailures );
397
- APSARA_TEST_EQUAL_FATAL (2 , processorInstance.mProcInRecordsTotal ->GetValue ());
399
+ APSARA_TEST_EQUAL_FATAL (2UL , processorInstance.mProcInRecordsTotal ->GetValue ());
398
400
APSARA_TEST_EQUAL_FATAL (strlen (timebuff) * 2 , processor.mProcParseInSizeBytes ->GetValue ());
399
401
// discard history, so output is 0
400
- APSARA_TEST_EQUAL_FATAL (2 , processorInstance.mProcOutRecordsTotal ->GetValue ());
402
+ APSARA_TEST_EQUAL_FATAL (2UL , processorInstance.mProcOutRecordsTotal ->GetValue ());
401
403
// size of one timestamp and one nanosecond equals to 8 byte, respectively
402
- APSARA_TEST_EQUAL_FATAL (8 * 4 , processor.mProcParseOutSizeBytes ->GetValue ());
403
- APSARA_TEST_EQUAL_FATAL (0 , processor.mProcDiscardRecordsTotal ->GetValue ());
404
- APSARA_TEST_EQUAL_FATAL (0 , processor.mProcParseErrorTotal ->GetValue ());
404
+ APSARA_TEST_EQUAL_FATAL (8UL * 4 , processor.mProcParseOutSizeBytes ->GetValue ());
405
+ APSARA_TEST_EQUAL_FATAL (0UL , processor.mProcDiscardRecordsTotal ->GetValue ());
406
+ APSARA_TEST_EQUAL_FATAL (0UL , processor.mProcParseErrorTotal ->GetValue ());
407
+ }
408
+
409
+ void ProcessorParseTimestampNativeUnittest::TestProcessNoYearFormat () {
410
+ // make config
411
+ Json::Value config;
412
+ config[" SourceKey" ] = " time" ;
413
+ config[" SourceFormat" ] = " %m-%d %H:%M:%S.%f" ;
414
+ config[" SourceTimezone" ] = " GMT+08:00" ;
415
+ // make events
416
+ auto sourceBuffer = std::make_shared<SourceBuffer>();
417
+ PipelineEventGroup eventGroup (sourceBuffer);
418
+ time_t now = time (nullptr ); // will not be discarded by history timeout
419
+ char timebuff[32 ] = " " ;
420
+ std::tm * now_tm = std::localtime (&now);
421
+ config[" SourceYear" ] = now_tm->tm_year + 1900 ;
422
+ strftime (timebuff, sizeof (timebuff), " %m-%d %H:%M:%S.999999999" , now_tm);
423
+ std::stringstream inJsonSs;
424
+ inJsonSs << R"( {
425
+ "events":
426
+ [
427
+ {
428
+ "contents" :
429
+ {
430
+ "time" : ")"
431
+ << timebuff << R"( "
432
+ },
433
+ "timestamp" : 12345678901,
434
+ "timestampNanosecond" : 0,
435
+ "type" : 1
436
+ },
437
+ {
438
+ "contents" :
439
+ {
440
+ "time" : ")"
441
+ << timebuff << R"( "
442
+ },
443
+ "timestamp" : 12345678901,
444
+ "timestampNanosecond" : 0,
445
+ "type" : 1
446
+ }
447
+ ]
448
+ })" ;
449
+ eventGroup.FromJsonString (inJsonSs.str ());
450
+ // run function
451
+ ProcessorParseTimestampNative& processor = *(new ProcessorParseTimestampNative);
452
+ std::string pluginId = " testID" ;
453
+ ProcessorInstance processorInstance (&processor, pluginId);
454
+ APSARA_TEST_TRUE_FATAL (processorInstance.Init (config, mContext ));
455
+ std::vector<PipelineEventGroup> eventGroupList;
456
+ eventGroupList.emplace_back (std::move (eventGroup));
457
+ processorInstance.Process (eventGroupList);
458
+
459
+ // judge result
460
+ std::string outJson = eventGroupList[0 ].ToJsonString ();
461
+ std::stringstream expectJsonSs;
462
+ expectJsonSs << R"( {
463
+ "events":
464
+ [
465
+ {
466
+ "contents" :
467
+ {
468
+ "time" : ")"
469
+ << timebuff << R"( "
470
+ },
471
+ "timestamp" : )"
472
+ << now - processor.mLogTimeZoneOffsetSecond << R"( ,
473
+ "timestampNanosecond" : 999999999,
474
+ "type" : 1
475
+ },
476
+ {
477
+ "contents" :
478
+ {
479
+ "time" : ")"
480
+ << timebuff << R"( "
481
+ },
482
+ "timestamp" : )"
483
+ << now - processor.mLogTimeZoneOffsetSecond << R"( ,
484
+ "timestampNanosecond" : 999999999,
485
+ "type" : 1
486
+ }
487
+ ]
488
+ })" ;
489
+ APSARA_TEST_EQUAL_FATAL (CompactJson (expectJsonSs.str ()), CompactJson (outJson));
490
+ // check observablity
491
+ APSARA_TEST_EQUAL_FATAL (0 , processor.GetContext ().GetProcessProfile ().historyFailures );
492
+ APSARA_TEST_EQUAL_FATAL (2UL , processorInstance.mProcInRecordsTotal ->GetValue ());
493
+ APSARA_TEST_EQUAL_FATAL (strlen (timebuff) * 2 , processor.mProcParseInSizeBytes ->GetValue ());
494
+ // discard history, so output is 0
495
+ APSARA_TEST_EQUAL_FATAL (2UL , processorInstance.mProcOutRecordsTotal ->GetValue ());
496
+ // size of one timestamp and one nanosecond equals to 8 byte, respectively
497
+ APSARA_TEST_EQUAL_FATAL (8UL * 4 , processor.mProcParseOutSizeBytes ->GetValue ());
498
+ APSARA_TEST_EQUAL_FATAL (0UL , processor.mProcDiscardRecordsTotal ->GetValue ());
499
+ APSARA_TEST_EQUAL_FATAL (0UL , processor.mProcParseErrorTotal ->GetValue ());
405
500
}
406
501
407
502
void ProcessorParseTimestampNativeUnittest::TestProcessRegularFormatFailed () {
@@ -460,14 +555,14 @@ void ProcessorParseTimestampNativeUnittest::TestProcessRegularFormatFailed() {
460
555
APSARA_TEST_STREQ_FATAL (CompactJson (inJson).c_str (), CompactJson (outJson).c_str ());
461
556
// check observablity
462
557
APSARA_TEST_EQUAL_FATAL (0 , processor.GetContext ().GetProcessProfile ().historyFailures );
463
- APSARA_TEST_EQUAL_FATAL (2 , processorInstance.mProcInRecordsTotal ->GetValue ());
558
+ APSARA_TEST_EQUAL_FATAL (2UL , processorInstance.mProcInRecordsTotal ->GetValue ());
464
559
APSARA_TEST_EQUAL_FATAL (strlen (timebuff) * 2 , processor.mProcParseInSizeBytes ->GetValue ());
465
560
// discard history, so output is 0
466
- APSARA_TEST_EQUAL_FATAL (2 , processorInstance.mProcOutRecordsTotal ->GetValue ());
561
+ APSARA_TEST_EQUAL_FATAL (2UL , processorInstance.mProcOutRecordsTotal ->GetValue ());
467
562
// size of one timestamp and one nanosecond equals to 8 byte, respectively
468
- APSARA_TEST_EQUAL_FATAL (0 , processor.mProcParseOutSizeBytes ->GetValue ());
469
- APSARA_TEST_EQUAL_FATAL (0 , processor.mProcDiscardRecordsTotal ->GetValue ());
470
- APSARA_TEST_EQUAL_FATAL (2 , processor.mProcParseErrorTotal ->GetValue ());
563
+ APSARA_TEST_EQUAL_FATAL (0UL , processor.mProcParseOutSizeBytes ->GetValue ());
564
+ APSARA_TEST_EQUAL_FATAL (0UL , processor.mProcDiscardRecordsTotal ->GetValue ());
565
+ APSARA_TEST_EQUAL_FATAL (2UL , processor.mProcParseErrorTotal ->GetValue ());
471
566
}
472
567
473
568
void ProcessorParseTimestampNativeUnittest::TestProcessHistoryDiscard () {
@@ -520,13 +615,13 @@ void ProcessorParseTimestampNativeUnittest::TestProcessHistoryDiscard() {
520
615
// check observablity
521
616
std::string outJson = eventGroupList[0 ].ToJsonString ();
522
617
APSARA_TEST_EQUAL_FATAL (2 , processor.GetContext ().GetProcessProfile ().historyFailures );
523
- APSARA_TEST_EQUAL_FATAL (2 , processorInstance.mProcInRecordsTotal ->GetValue ());
618
+ APSARA_TEST_EQUAL_FATAL (2UL , processorInstance.mProcInRecordsTotal ->GetValue ());
524
619
APSARA_TEST_EQUAL_FATAL (strlen (timebuff) * 2 , processor.mProcParseInSizeBytes ->GetValue ());
525
620
// discard history, so output is 0
526
- APSARA_TEST_EQUAL_FATAL (0 , processorInstance.mProcOutRecordsTotal ->GetValue ());
527
- APSARA_TEST_EQUAL_FATAL (0 , processor.mProcParseOutSizeBytes ->GetValue ());
528
- APSARA_TEST_EQUAL_FATAL (2 , processor.mProcDiscardRecordsTotal ->GetValue ());
529
- APSARA_TEST_EQUAL_FATAL (0 , processor.mProcParseErrorTotal ->GetValue ());
621
+ APSARA_TEST_EQUAL_FATAL (0UL , processorInstance.mProcOutRecordsTotal ->GetValue ());
622
+ APSARA_TEST_EQUAL_FATAL (0UL , processor.mProcParseOutSizeBytes ->GetValue ());
623
+ APSARA_TEST_EQUAL_FATAL (2UL , processor.mProcDiscardRecordsTotal ->GetValue ());
624
+ APSARA_TEST_EQUAL_FATAL (0UL , processor.mProcParseErrorTotal ->GetValue ());
530
625
}
531
626
532
627
void ProcessorParseTimestampNativeUnittest::TestProcessEventPreciseTimestampLegacy () {
0 commit comments