HeartSaVioR commented on a change in pull request #26610: [SPARK-29973][SS] 
Make `processedRowsPerSecond` calculated more accurately and meaningfully
URL: https://github.com/apache/spark/pull/26610#discussion_r348916686
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingQueryStatusAndProgressSuite.scala
 ##########
 @@ -215,6 +218,60 @@ class StreamingQueryStatusAndProgressSuite extends 
StreamTest with Eventually {
     }
   }
 
+  test("SPARK-29973: Make `processedRowsPerSecond` calculated more accurately 
and meaningfully") {
+    import testImplicits._
+
+    clock = new StreamManualClock
+    val inputData = MemoryStream[Int]
+    val query = inputData.toDS()
+
+    testStream(query)(
+      StartStream(Trigger.ProcessingTime(1000), triggerClock = clock),
+      AssertStreamExecThreadIsWaitingForTime(1000),
+      AdvanceManualClock(1000),
+      WaitUntilBatchProcessed,
+      AssertOnQuery(query => {
+        assert(query.lastProgress.numInputRows == 0)
+        assert(query.lastProgress.processedRowsPerSecond == 0.0d)
+        true
+      }),
+      AddData(inputData, 1, 2),
+      AssertStreamExecThreadIsWaitingForTime(2000),
+      AdvanceManualClock(1000),
+      WaitUntilBatchProcessed,
+      AssertOnQuery(query => {
+        assert(query.lastProgress.numInputRows == 2)
+        assert(query.lastProgress.processedRowsPerSecond == 2000d)
+        true
+      }),
+      StopStream
+    )
+  }
+
+  case class AssertStreamExecThreadIsWaitingForTime(targetTime: Long)
+    extends AssertOnQuery(q => {
+      eventually(Timeout(streamingTimeout)) {
+        if (q.exception.isEmpty) {
+          assert(clock.isStreamWaitingFor(targetTime))
+        }
+      }
+      if (q.exception.isDefined) {
+        throw q.exception.get
+      }
+      true
+    }, "")
+
+  def WaitUntilBatchProcessed: AssertOnQuery = Execute { q =>
 
 Review comment:
   If my understanding is correct, it's same with 
AssertStreamExecThreadIsWaitingForTime - I don't think it should exist 
separately.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to