Skip to content

Commit 7a58547

Browse files
committed
Add test for job cancellation.
1 parent bd13a01 commit 7a58547

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamSuite.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,34 @@ class StreamSuite extends StreamTest {
500500
}
501501
}
502502
}
503+
504+
test("calling stop() on a query cancels related jobs") {
505+
val input = MemoryStream[Int]
506+
val query = input
507+
.toDS()
508+
.map { i =>
509+
while (!org.apache.spark.TaskContext.get().isInterrupted()) {
510+
// keep looping till interrupted by query.stop()
511+
Thread.sleep(100)
512+
}
513+
i
514+
}
515+
.writeStream
516+
.format("console")
517+
.start()
518+
519+
input.addData(1)
520+
// wait for jobs to start
521+
eventually(timeout(streamingTimeout)) {
522+
assert(sparkContext.statusTracker.getActiveJobIds().nonEmpty)
523+
}
524+
525+
query.stop()
526+
// make sure jobs are stopped
527+
eventually(timeout(streamingTimeout)) {
528+
assert(sparkContext.statusTracker.getActiveJobIds().isEmpty)
529+
}
530+
}
503531
}
504532

505533
abstract class FakeSource extends StreamSourceProvider {

0 commit comments

Comments
 (0)