Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/7796#discussion_r36249030
--- Diff:
external/kafka/src/test/scala/org/apache/spark/streaming/kafka/DirectKafkaStreamSuite.scala
---
@@ -350,6 +353,69 @@ class DirectKafkaStreamSuite
ssc.stop()
}
+ test("using rate controller"){
+ val topic = "backpressure"
+ val topicPartition = TopicAndPartition(topic, 0)
+ kafkaTestUtils.createTopic(topic)
+ val kafkaParams = Map(
+ "metadata.broker.list" -> kafkaTestUtils.brokerAddress,
+ "auto.offset.reset" -> "smallest"
+ )
+
+ val collectedData =
+ new mutable.ArrayBuffer[Array[String]]() with
mutable.SynchronizedBuffer[Array[String]]
+ // Send data to Kafka and wait for it to be received
+ def sendDataAndWaitForReceive(data: Seq[Int]) {
+ val strings = data.map { _.toString}
+ kafkaTestUtils.sendMessages(topic, strings.map { _ -> 1}.toMap)
+ eventually(timeout(20 seconds), interval(50 milliseconds)) {
+ assert(strings.forall { collectedData.flatten.contains })
+ }
+ }
+
+ val sparkConf = new SparkConf()
+ // Safe, even with streaming, because we're using the direct API.
+ // Using 1 core is necessary to make the test more predictable.
+ .setMaster("local[1]")
+ .setAppName(this.getClass.getSimpleName)
+ .set("spark.streaming.kafka.maxRatePerPartition", "100")
+
+ // Setup the streaming context
+ ssc = new StreamingContext(sparkConf, Milliseconds(100))
+
+ val kafkaStream = withClue("Error creating direct stream") {
+ val kc = new KafkaCluster(kafkaParams)
+ val messageHandler = (mmd: MessageAndMetadata[String, String]) =>
(mmd.key, mmd.message)
+ val m = kc.getEarliestLeaderOffsets(Set(topicPartition))
+ .fold(e => Map.empty[TopicAndPartition, Long], m => m.mapValues(lo
=> lo.offset))
+
+ new DirectKafkaInputDStream[String, String, StringDecoder,
StringDecoder, (String, String)](
--- End diff --
Please uses the public API, KafkaUtils.createDirectStream. Then you dont
have to use the messageHandler method either.
---
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]