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

    https://github.com/apache/spark/pull/9186#discussion_r44626086
  
    --- Diff: python/pyspark/streaming/tests.py ---
    @@ -403,6 +404,80 @@ def func(dstream):
             self._test_func(input, func, expected)
     
     
    +class StreamingListenerTests(PySparkStreamingTestCase):
    +
    +    duration = .5
    +
    +    class BatchInfoCollector(StreamingListener):
    +
    +        def __init__(self):
    +            super(StreamingListener, self).__init__()
    +            self.batchInfosCompleted = []
    +            self.batchInfosStarted = []
    +            self.batchInfosSubmitted = []
    +
    +        def onBatchSubmitted(self, batchSubmitted):
    +            self.batchInfosSubmitted.append(batchSubmitted.batchInfo())
    +
    +        def onBatchStarted(self, batchStarted):
    +            self.batchInfosStarted.append(batchStarted.batchInfo())
    +
    +        def onBatchCompleted(self, batchCompleted):
    +            self.batchInfosCompleted.append(batchCompleted.batchInfo())
    +
    +    def test_batch_info_reports(self):
    +        batch_collector = self.BatchInfoCollector()
    +        self.ssc.addStreamingListener(batch_collector)
    +        input = [[1], [2], [3], [4]]
    +
    +        def func(dstream):
    +            return dstream.map(int)
    +        expected = [[1], [2], [3], [4]]
    +        self._test_func(input, func, expected)
    +
    +        batchInfosSubmitted = batch_collector.batchInfosSubmitted
    +        batchInfosStarted = batch_collector.batchInfosStarted
    +        batchInfosCompleted = batch_collector.batchInfosCompleted
    +
    +        self.wait_for(batchInfosCompleted, 4)
    +
    +        self.assertEqual(len(batchInfosSubmitted), 4)
    +        for info in batchInfosSubmitted:
    +            self.assertGreaterEqual(info.batchTime().milliseconds(), 0)
    +            self.assertGreaterEqual(info.submissionTime(), 0)
    +            self.assertTrue(info.streamIdToInputInfo().isEmpty())
    +            self.assertFalse(info.outputOperationInfos().isEmpty())
    +            self.assertIsNotNone(info.outputOperationInfos().get(0))
    +            self.assertEqual(info.schedulingDelay(), -1)
    +            self.assertEqual(info.processingDelay(), -1)
    +            self.assertEqual(info.totalDelay(), -1)
    +            self.assertEqual(info.numRecords(), 0)
    +
    +        self.assertEqual(len(batchInfosStarted), 4)
    --- End diff --
    
    len(batchInfosSubmitted) may be greater than 4 since Streaming keeps 
launching batches.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to