This repository was archived by the owner on May 9, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +13
-1
lines changed
main/scala/org/apache/spark/streaming/mqtt
test/scala/org/apache/spark/streaming/mqtt Expand file tree Collapse file tree 3 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,6 @@ package org.apache.spark.streaming.mqtt
19
19
20
20
import scala .reflect .ClassTag
21
21
22
- import org .apache .spark .api .java .function .Function
23
22
import org .apache .spark .storage .StorageLevel
24
23
import org .apache .spark .streaming .StreamingContext
25
24
import org .apache .spark .streaming .api .java .{JavaReceiverInputDStream , JavaStreamingContext , JavaDStream }
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ import org.eclipse.paho.client.mqttv3._
28
28
import org .eclipse .paho .client .mqttv3 .persist .MqttDefaultFilePersistence
29
29
30
30
import org .apache .spark .streaming .StreamingContext
31
+ import org .apache .spark .streaming .api .java .JavaStreamingContext
31
32
import org .apache .spark .streaming .scheduler .StreamingListener
32
33
import org .apache .spark .streaming .scheduler .StreamingListenerReceiverStarted
33
34
import org .apache .spark .util .Utils
@@ -121,4 +122,15 @@ private class MQTTTestUtils extends Logging {
121
122
122
123
assert(latch.await(10 , TimeUnit .SECONDS ), " Timeout waiting for receiver to start." )
123
124
}
125
+
126
+ def waitForReceiverToStart (jssc : JavaStreamingContext ) : Unit = {
127
+ val latch = new CountDownLatch (1 )
128
+ jssc.addStreamingListener(new StreamingListener {
129
+ override def onReceiverStarted (receiverStarted : StreamingListenerReceiverStarted ) {
130
+ latch.countDown()
131
+ }
132
+ })
133
+
134
+ assert(latch.await(10 , TimeUnit .SECONDS ), " Timeout waiting for receiver to start." )
135
+ }
124
136
}
Original file line number Diff line number Diff line change @@ -884,6 +884,7 @@ def test_mqtt_stream(self):
884
884
sendData = "MQTT demo for spark streaming"
885
885
topic = self ._randomTopic ()
886
886
result = self ._startContext (topic )
887
+ self ._MQTTTestUtils .waitForReceiverToStart (self .ssc ._jssc )
887
888
self ._publishData (topic , sendData )
888
889
self .wait_for (result , len (sendData ))
889
890
self ._validateStreamResult (sendData , result )
You can’t perform that action at this time.
0 commit comments