Github user marmbrus commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11030#discussion_r51667236
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/StreamTest.scala ---
    @@ -211,37 +264,69 @@ trait StreamTest extends QueryTest with Timeouts {
                   })
     
               case StopStream =>
    -            checkState(currentStream != null, "can not stop a stream that 
is not running")
    -            currentStream.stop()
    -            currentStream = null
    +            assert(currentStream != null, "can not stop a stream that is 
not running")
    +            try failAfter(streamingTimout) {
    +              currentStream.stop()
    +              assert(!currentStream.microBatchThread.isAlive,
    +                s"microbatch thread not stopped")
    +              assert(!currentStream.isActive,
    +                "query.isActive() is false even after stopping")
    +              assert(currentStream.exception.isEmpty,
    +                "query.exception() is not empty after clean stop")
    +            } catch {
    +              case _: InterruptedException =>
    +              case _: 
org.scalatest.exceptions.TestFailedDueToTimeoutException =>
    +                failTest("Timed out while stopping and waiting for 
microbatchthread to terminate.")
    +              case t: Throwable =>
    +                failTest("Error while checking stream failure.", t)
    +            } finally {
    +              lastStream = currentStream
    +              currentStream = null
    +            }
     
               case DropBatches(num) =>
    -            checkState(currentStream == null, "dropping batches while 
running leads to corruption")
    +            assert(currentStream == null, "dropping batches while running 
leads to corruption")
                 sink.dropBatches(num)
     
    -          case ExpectFailure =>
    +          case ef: ExpectFailure[_] =>
    +            assert(currentStream != null, "dropping batches while running 
leads to corruption")
                 try failAfter(streamingTimout) {
    -              while (streamDeathCause == null) {
    -                Thread.sleep(100)
    +              val thrownException = intercept[QueryException] {
    +                currentStream.awaitTermination()
    +              }
    +              eventually("microbatch thread not stopped after termination 
with failure") {
    +                Assertions.assert(!currentStream.microBatchThread.isAlive)
                   }
    +              assert(currentStream.exception === Some(thrownException),
    +                s"incorrect exception returned by query.exception()")
    +
    +              val exception = currentStream.exception.get
    +              assert(exception.cause.getClass === ef.causeClass,
    +                "incorrect cause in exception returned by 
query.exception()\n" +
    +                  s"\tExpected: ${ef.causeClass}\n\tReturned: 
${exception.cause.getClass}")
                 } catch {
                   case _: InterruptedException =>
                   case _: 
org.scalatest.exceptions.TestFailedDueToTimeoutException =>
    -                fail(
    -                  s"""
    -                     |Timed out while waiting for failure.
    -                     |$testState
    -                   """.stripMargin)
    +                failTest("Timed out while waiting for failure.")
    +              case t: Throwable =>
    +                failTest("Error while checking stream failure", t)
    +            } finally {
    +              lastStream = currentStream
    +              currentStream = null
    +              streamDeathCause = null
    --- End diff --
    
    Also doesn't need to be finally?


---
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]

Reply via email to