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

    https://github.com/apache/spark/pull/4229#discussion_r34660546
  
    --- Diff: python/pyspark/streaming/tests.py ---
    @@ -827,6 +828,52 @@ def test_flume_polling_multiple_hosts(self):
             self._testMultipleTimes(self._testFlumePollingMultipleHosts)
     
     
    +class MQTTStreamTests(PySparkStreamingTestCase):
    +    timeout = 20  # seconds
    +    duration = 1
    +
    +    def setUp(self):
    +        super(MQTTStreamTests, self).setUp()
    +
    +        MQTTTestUtilsClz = 
self.ssc._jvm.java.lang.Thread.currentThread().getContextClassLoader() \
    +            .loadClass("org.apache.spark.streaming.mqtt.MQTTTestUtils")
    +        self._MQTTTestUtils = MQTTTestUtilsClz.newInstance()
    +        self._MQTTTestUtils.setup()
    +
    +    def tearDown(self):
    +        if self._MQTTTestUtils is not None:
    +            self._MQTTTestUtils.teardown()
    +            self._MQTTTestUtils = None
    +
    +        super(MQTTStreamTests, self).tearDown()
    +
    +    def _randomTopic(self):
    +        return "topic-%d" % random.randint(0, 10000)
    +
    +    def _validateStreamResult(self, sendData, dstream):
    +        result = []
    +
    +        def get_output(_, rdd):
    +            for data in rdd.collect():
    +                result.append(data)
    +
    +        dstream.foreachRDD(get_output)
    +        receiveData = ' '.join(result[0])
    +        self.assertEqual(sendData, receiveData)
    +
    +    def test_mqtt_stream(self):
    +        """Test the Python MQTT stream API."""
    +        topic = self._randomTopic()
    +        sendData = "MQTT demo for spark streaming"
    +        ssc = self.ssc
    +
    +        self._MQTTTestUtils.waitForReceiverToStart(ssc)
    --- End diff --
    
    You should send `ssc._jssc`, JavaStreamingContext to the Scala codes. `ssc` 
is a Python object, which cannot be used in Scala.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to