Skip to content

Commit

Permalink
[LIVY-659][TEST] Fix travis failed on can kill spark-submit while it'…
Browse files Browse the repository at this point in the history
…s running

## What changes were proposed in this pull request?

Fix travis failed on "can kill spark-submit while it's running"

The cause of failed is as follows:

1. The test does not mock the method getApplicationReport of mockYarnClient, so yarnClient.getApplicationReport will return null.

2. If the thread yarnAppMonitorThread run before the test executing app.kill(), yarnAppMonitorThread will throw NullPointerException when execute appReport.getDiagnostics.

3. Then the NullPointerException was caught by yarnAppMonitorThread, and yarnAppMonitorThread changeState(SparkApp.State.FAILED).

4. At last, the test execute app.kill(), but the app state is FAILED, so it won't execute process.foreach(_.destroy()), which cause verify(mockSparkSubmit, times(1)).destroy() failed.

## How was this patch tested?

Existed UT and IT.

Author: runzhiwang <[email protected]>

Closes apache#226 from runzhiwang/LIVY-659.
  • Loading branch information
runzhiwang authored and jerryshao committed Sep 6, 2019
1 parent 3cdb7b2 commit 3c4eab9
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions server/src/test/scala/org/apache/livy/utils/SparkYarnAppSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.apache.hadoop.yarn.util.ConverterUtils
import org.mockito.Mockito._
import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer
import org.scalatest.concurrent.Eventually
import org.scalatest.FunSpec
import org.scalatest.mock.MockitoSugar.mock

Expand Down Expand Up @@ -200,10 +201,19 @@ class SparkYarnAppSpec extends FunSpec with LivyBaseUnitTestSuite {

it("can kill spark-submit while it's running") {
Clock.withSleepMethod(mockSleep) {
val diag = "DIAG"
val livyConf = new LivyConf()
livyConf.set(LivyConf.YARN_APP_LOOKUP_TIMEOUT, "0")

val mockAppReport = mock[ApplicationReport]
when(mockAppReport.getApplicationId).thenReturn(appId)
when(mockAppReport.getDiagnostics).thenReturn(diag)
when(mockAppReport.getFinalApplicationStatus).thenReturn(FinalApplicationStatus.SUCCEEDED)
when(mockAppReport.getYarnApplicationState).thenReturn(RUNNING)

val mockYarnClient = mock[YarnClient]
when(mockYarnClient.getApplicationReport(appId)).thenReturn(mockAppReport)

val mockSparkSubmit = mock[LineBufferedProcess]

val sparkSubmitRunningLatch = new CountDownLatch(1)
Expand All @@ -222,10 +232,14 @@ class SparkYarnAppSpec extends FunSpec with LivyBaseUnitTestSuite {
None,
livyConf,
mockYarnClient)
cleanupThread(app.yarnAppMonitorThread) {
app.kill()
verify(mockSparkSubmit, times(1)).destroy()
sparkSubmitRunningLatch.countDown()

Eventually.eventually(Eventually.timeout(10 seconds), Eventually.interval(100 millis)) {
assert(app.isRunning)
cleanupThread(app.yarnAppMonitorThread) {
app.kill()
verify(mockSparkSubmit, times(1)).destroy()
sparkSubmitRunningLatch.countDown()
}
}
}
}
Expand Down

0 comments on commit 3c4eab9

Please sign in to comment.