Github user zsxwing commented on a diff in the pull request: https://github.com/apache/spark/pull/9186#discussion_r43113846 --- Diff: python/pyspark/streaming/tests.py --- @@ -398,6 +399,69 @@ 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(self.getEventInfo(batchSubmitted)) + + def onBatchStarted(self, batchStarted): + self.batchInfosStarted.append(self.getEventInfo(batchStarted)) + + def onBatchCompleted(self, batchCompleted): + self.batchInfosCompleted.append(self.getEventInfo(batchCompleted)) + + 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) + + # Test occasionally fails without a delay + time.sleep(.1) --- End diff -- Take a look at `PySparkStreamingTestCase.wait_for`. You can use it to wait for the expected results or timeout.
--- 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