13
13
// limitations under the License.
14
14
15
15
16
+ #include " PipelineEventGroup.h"
17
+ #include " PipelineEventPtr.h"
16
18
#include " collection_pipeline/batch/BatchStatus.h"
17
19
#include " collection_pipeline/batch/FlushStrategy.h"
18
20
#include " unittest/Unittest.h"
@@ -113,6 +115,8 @@ void SLSEventFlushStrategyUnittest::TestNeedFlush() {
113
115
PipelineEventGroup eventGroup (make_shared<SourceBuffer>());
114
116
PipelineEventPtr event (eventGroup.CreateLogEvent (), false , nullptr );
115
117
event->SetTimestamp (1717398001 );
118
+ PipelineEventPtr metricEvent (eventGroup.CreateMetricEvent (), false , nullptr );
119
+ metricEvent->SetTimestamp (time (nullptr ));
116
120
117
121
SLSEventBatchStatus status;
118
122
status.mCnt = 2 ;
@@ -122,6 +126,7 @@ void SLSEventFlushStrategyUnittest::TestNeedFlush() {
122
126
APSARA_TEST_TRUE (mStrategy .NeedFlushByCnt (status));
123
127
APSARA_TEST_FALSE (mStrategy .NeedFlushBySize (status));
124
128
APSARA_TEST_FALSE (mStrategy .NeedFlushByTime (status, event));
129
+ APSARA_TEST_FALSE (mStrategy .NeedFlushByTime (status, metricEvent));
125
130
126
131
status.mCnt = 1 ;
127
132
status.mSizeBytes = 100 ;
@@ -130,6 +135,7 @@ void SLSEventFlushStrategyUnittest::TestNeedFlush() {
130
135
APSARA_TEST_FALSE (mStrategy .NeedFlushByCnt (status));
131
136
APSARA_TEST_TRUE (mStrategy .NeedFlushBySize (status));
132
137
APSARA_TEST_FALSE (mStrategy .NeedFlushByTime (status, event));
138
+ APSARA_TEST_FALSE (mStrategy .NeedFlushByTime (status, metricEvent));
133
139
134
140
status.mCnt = 1 ;
135
141
status.mSizeBytes = 50 ;
@@ -138,6 +144,7 @@ void SLSEventFlushStrategyUnittest::TestNeedFlush() {
138
144
APSARA_TEST_FALSE (mStrategy .NeedFlushByCnt (status));
139
145
APSARA_TEST_FALSE (mStrategy .NeedFlushBySize (status));
140
146
APSARA_TEST_TRUE (mStrategy .NeedFlushByTime (status, event));
147
+ APSARA_TEST_TRUE (mStrategy .NeedFlushByTime (status, metricEvent));
141
148
142
149
status.mCnt = 1 ;
143
150
status.mSizeBytes = 50 ;
@@ -146,6 +153,11 @@ void SLSEventFlushStrategyUnittest::TestNeedFlush() {
146
153
APSARA_TEST_FALSE (mStrategy .NeedFlushByCnt (status));
147
154
APSARA_TEST_FALSE (mStrategy .NeedFlushBySize (status));
148
155
APSARA_TEST_TRUE (mStrategy .NeedFlushByTime (status, event));
156
+ APSARA_TEST_FALSE (mStrategy .NeedFlushByTime (status, metricEvent));
157
+ metricEvent->SetTimestamp (time (nullptr ) - 302 );
158
+ APSARA_TEST_TRUE (mStrategy .NeedFlushByTime (status, metricEvent));
159
+ metricEvent->SetTimestamp (time (nullptr ) + 301 );
160
+ APSARA_TEST_TRUE (mStrategy .NeedFlushByTime (status, metricEvent));
149
161
}
150
162
151
163
UNIT_TEST_CASE (SLSEventFlushStrategyUnittest, TestNeedFlush)
0 commit comments