Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/15820#discussion_r88758879
--- Diff:
external/kafka-0-10-sql/src/test/scala/org/apache/spark/sql/kafka010/KafkaSourceSuite.scala
---
@@ -223,52 +228,184 @@ class KafkaSourceSuite extends KafkaSourceTest {
)
}
- test("assign from latest offsets") {
- val topic = newTopic()
- testFromLatestOffsets(topic, false, "assign" -> assignString(topic, 0
to 4))
- }
+ test("access offset 0 in Spark job but the topic has been deleted") {
+ KafkaSourceSuite.collectedData.clear()
- test("assign from earliest offsets") {
val topic = newTopic()
- testFromEarliestOffsets(topic, false, "assign" -> assignString(topic,
0 to 4))
- }
+ testUtils.createTopic(topic, partitions = 1)
+ testUtils.sendMessages(topic, (1 to 10).map(_.toString).toArray)
- test("assign from specific offsets") {
- val topic = newTopic()
- testFromSpecificOffsets(topic, "assign" -> assignString(topic, 0 to 4))
- }
+ val reader = spark
+ .readStream
+ .format("kafka")
+ .option("kafka.bootstrap.servers", testUtils.brokerAddress)
+ .option("kafka.metadata.max.age.ms", "1")
+ .option("subscribe", topic)
+ // If a topic is deleted and we try to poll data starting from
offset 0,
+ // the Kafka consumer will just block until timeout and return an
empty result.
+ // So set the timeout to 1 second to make this test fast.
+ .option("kafkaConsumer.pollTimeoutMs", "1000")
+ .option("startingOffsets", "earliest")
+ .option("failOnDataLoss", "false")
+ val kafka = reader.load()
+ .selectExpr("CAST(key AS STRING)", "CAST(value AS STRING)")
+ .as[(String, String)]
+ KafkaSourceSuite.globalTestUtils = testUtils
+ val query = kafka.map(kv => kv._2.toInt).writeStream.foreach(new
ForeachWriter[Int] {
--- End diff --
add explanation.
---
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]