Browse Source

fix: Httppull source run at rule start (#2205)

Signed-off-by: Rui-Gan <1171530954@qq.com>
Regina 1 year atrás
parent
commit
61ae682524

+ 6 - 0
internal/io/http/httppull_source.go

@@ -58,6 +58,12 @@ func (hps *PullSource) initTimerPull(ctx api.StreamContext, consumer chan<- api.
 	ticker := conf.GetTicker(int64(hps.config.Interval))
 	defer ticker.Stop()
 	omd5 := ""
+
+	// Pulling data at initial start
+	logger.Debugf("Pulling data at initial start")
+	tuples := hps.doPull(ctx, conf.GetNow(), &omd5)
+	io.ReceiveTuples(ctx, consumer, tuples)
+
 	for {
 		select {
 		case rcvTime := <-ticker.C:

+ 2 - 2
internal/io/http/httppull_source_test.go

@@ -999,8 +999,8 @@ func TestPullUrlTimeRange(t *testing.T) {
 	// Mock time
 	mockclock.ResetClock(143)
 	exp := []api.SourceTuple{
+		api.NewDefaultSourceTupleWithTime(map[string]interface{}{"code": float64(200), "data": map[string]interface{}{"device_id": "d1", "humidity": float64(43), "temperature": float64(33)}}, map[string]interface{}{}, time.UnixMilli(143)),
 		api.NewDefaultSourceTupleWithTime(map[string]interface{}{"code": float64(200), "data": map[string]interface{}{"device_id": "d1", "humidity": float64(53), "temperature": float64(43)}}, map[string]interface{}{}, time.UnixMilli(253)),
-		api.NewDefaultSourceTupleWithTime(map[string]interface{}{"code": float64(200), "data": map[string]interface{}{"device_id": "d1", "humidity": float64(63), "temperature": float64(3)}}, map[string]interface{}{}, time.UnixMilli(363)),
 	}
 	c := mockclock.GetMockClock()
 	go func() {
@@ -1029,8 +1029,8 @@ func TestPullBodyTimeRange(t *testing.T) {
 	// Mock time
 	mockclock.ResetClock(143)
 	exp := []api.SourceTuple{
+		api.NewDefaultSourceTupleWithTime(map[string]interface{}{"code": float64(200), "data": map[string]interface{}{"device_id": "d1", "humidity": float64(43), "temperature": float64(33)}}, map[string]interface{}{}, time.UnixMilli(143)),
 		api.NewDefaultSourceTupleWithTime(map[string]interface{}{"code": float64(200), "data": map[string]interface{}{"device_id": "d1", "humidity": float64(53), "temperature": float64(43)}}, map[string]interface{}{}, time.UnixMilli(253)),
-		api.NewDefaultSourceTupleWithTime(map[string]interface{}{"code": float64(200), "data": map[string]interface{}{"device_id": "d1", "humidity": float64(63), "temperature": float64(3)}}, map[string]interface{}{}, time.UnixMilli(363)),
 	}
 	c := mockclock.GetMockClock()
 	go func() {

+ 3 - 3
test/http_pull_rule.jmx

@@ -216,7 +216,7 @@
           <hashTree>
             <JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="JSON Assertion" enabled="true">
               <stringProp name="JSON_PATH">$.source_demo_0_records_in_total</stringProp>
-              <stringProp name="EXPECTED_VALUE">0</stringProp>
+              <stringProp name="EXPECTED_VALUE">1</stringProp>
               <boolProp name="JSONVALIDATION">true</boolProp>
               <boolProp name="EXPECT_NULL">false</boolProp>
               <boolProp name="INVERT">false</boolProp>
@@ -245,7 +245,7 @@
           <hashTree>
             <JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="JSON Assertion" enabled="true">
               <stringProp name="JSON_PATH">$.source_demo_0_records_in_total</stringProp>
-              <stringProp name="EXPECTED_VALUE">1</stringProp>
+              <stringProp name="EXPECTED_VALUE">2</stringProp>
               <boolProp name="JSONVALIDATION">true</boolProp>
               <boolProp name="EXPECT_NULL">false</boolProp>
               <boolProp name="INVERT">false</boolProp>
@@ -254,7 +254,7 @@
             <hashTree/>
             <JSONPathAssertion guiclass="JSONPathAssertionGui" testclass="JSONPathAssertion" testname="JSON Assertion" enabled="true">
               <stringProp name="JSON_PATH">$.sink_mqtt_1_0_records_in_total</stringProp>
-              <stringProp name="EXPECTED_VALUE">1</stringProp>
+              <stringProp name="EXPECTED_VALUE">2</stringProp>
               <boolProp name="JSONVALIDATION">true</boolProp>
               <boolProp name="EXPECT_NULL">false</boolProp>
               <boolProp name="INVERT">false</boolProp>