Github user zsxwing commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20189#discussion_r160829808
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingQuerySuite.scala
 ---
    @@ -424,6 +424,31 @@ class StreamingQuerySuite extends StreamTest with 
BeforeAndAfter with Logging wi
         }
       }
     
    +  test("SPARK-22975: MetricsReporter defaults when there was no progress 
reported") {
    +    withSQLConf("spark.sql.streaming.metricsEnabled" -> "true") {
    +      BlockingSource.latch = new CountDownLatch(1)
    --- End diff --
    
    You can use `memory` source and `console` sink to simplify the codes like 
this:
    ```
      test("SPARK-22975: MetricsReporter defaults when there was no progress 
reported") {
        withSQLConf("spark.sql.streaming.metricsEnabled" -> "true") {
          withTempDir { tempDir =>
            val sq = MemoryStream[Int].toDF
              .writeStream
              .format("console")
              .start()
              .asInstanceOf[StreamingQueryWrapper]
              .streamingQuery
    
            val gauges = sq.streamMetrics.metricRegistry.getGauges
            assert(gauges.get("latency").getValue.asInstanceOf[Long] == 0)
            
assert(gauges.get("processingRate-total").getValue.asInstanceOf[Double] == 0.0)
            assert(gauges.get("inputRate-total").getValue.asInstanceOf[Double] 
== 0.0)
            sq.stop()
          }
        }
      }
    ```


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to