[SPARK-36109][SS][TEST] Check data after adding data to topic in KafkaSourceStressSuite
### What changes were proposed in this pull request?
This patch proposes to check data after adding data to topic in `KafkaSourceStressSuite`.
### Why are the changes needed?
The test logic in `KafkaSourceStressSuite` is not stable. For example, https://github.com/apache/spark/runs/3049244904.
Once we add data to a topic and then delete the topic before checking data, the expected answer is different to retrieved data from the sink.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Existing tests.
Closes #33311 from viirya/stream-assert.
Authored-by: Liang-Chi Hsieh <viirya@gmail.com>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
(cherry picked from commit 201566cdd5
)
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
This commit is contained in:
parent
9e802f25aa
commit
19478bdf52
|
@ -2429,8 +2429,9 @@ class KafkaSourceStressSuite extends KafkaSourceTest {
|
|||
(d, running) => {
|
||||
Random.nextInt(5) match {
|
||||
case 0 => // Add a new topic
|
||||
topics = topics ++ Seq(newStressTopic)
|
||||
AddKafkaData(topics.toSet, d: _*)(message = s"Add topic $newStressTopic",
|
||||
val newTopic = newStressTopic
|
||||
topics = topics ++ Seq(newTopic)
|
||||
AddKafkaData(topics.toSet, d: _*)(message = s"Add topic $newTopic",
|
||||
topicAction = (topic, partition) => {
|
||||
if (partition.isEmpty) {
|
||||
testUtils.createTopic(topic, partitions = nextInt(1, 6))
|
||||
|
|
|
@ -283,7 +283,7 @@ trait StreamTest extends QueryTest with SharedSparkSession with TimeLimits with
|
|||
|
||||
/** Assert that a condition on the active query is true */
|
||||
class AssertOnQuery(val condition: StreamExecution => Boolean, val message: String)
|
||||
extends StreamAction {
|
||||
extends StreamAction with StreamMustBeRunning {
|
||||
override def toString: String = s"AssertOnQuery(<condition>, $message)"
|
||||
}
|
||||
|
||||
|
@ -871,6 +871,10 @@ trait StreamTest extends QueryTest with SharedSparkSession with TimeLimits with
|
|||
|
||||
case r if r < 0.7 => // AddData
|
||||
addRandomData()
|
||||
// In some suites, e.g. `KafkaSourceStressSuite`, we delete Kafka topic in the
|
||||
// `addData` closure. In the case, the topic with added data might be deleted
|
||||
// before next check. So we must check data after adding data here.
|
||||
addCheck()
|
||||
|
||||
case _ => // StopStream
|
||||
addCheck()
|
||||
|
|
Loading…
Reference in a new issue