|
| 1 | +package spark.jobserver |
| 2 | + |
| 3 | +import akka.actor.{ ActorRef, ActorSystem, Props } |
| 4 | +import akka.testkit.{ ImplicitSender, TestKit } |
| 5 | +import com.typesafe.config.{ Config, ConfigFactory, ConfigValueFactory } |
| 6 | +import akka.testkit.TestProbe |
| 7 | +import spark.jobserver.CommonMessages.{ JobErroredOut, JobResult } |
| 8 | +import spark.jobserver.io.JobDAOActor |
| 9 | +import collection.JavaConversions._ |
| 10 | + |
| 11 | +class NamedObjectsJobSpec extends JobSpecBase(JobManagerSpec.getNewSystem) { |
| 12 | + |
| 13 | + //private val emptyConfig = ConfigFactory.parseString("spark.jobserver.named-object-creation-timeout = 60 s") |
| 14 | + |
| 15 | + before { |
| 16 | + dao = new InMemoryDAO |
| 17 | + daoActor = system.actorOf(JobDAOActor.props(dao)) |
| 18 | + manager = system.actorOf(JobManagerActor.props(JobManagerSpec.getContextConfig(adhoc = false))) |
| 19 | + supervisor = TestProbe().ref |
| 20 | + |
| 21 | + manager ! JobManagerActor.Initialize(daoActor, None) |
| 22 | + |
| 23 | + expectMsgClass(classOf[JobManagerActor.Initialized]) |
| 24 | + |
| 25 | + uploadTestJar() |
| 26 | + |
| 27 | + } |
| 28 | + |
| 29 | + val jobName = "spark.jobserver.NamedObjectsTestJob" |
| 30 | + |
| 31 | + private def getCreateConfig(createDF: Boolean, createRDD: Boolean) : Config = { |
| 32 | + ConfigFactory.parseString("spark.jobserver.named-object-creation-timeout = 60 s, " + |
| 33 | + NamedObjectsTestJobConfig.CREATE_DF + " = " + createDF + ", " + |
| 34 | + NamedObjectsTestJobConfig.CREATE_RDD + " = " + createRDD) |
| 35 | + } |
| 36 | + |
| 37 | + private def getDeleteConfig(names: List[String]) : Config = { |
| 38 | + ConfigFactory.parseString("spark.jobserver.named-object-creation-timeout = 60 s, " + |
| 39 | + NamedObjectsTestJobConfig.DELETE+" = [" + names.mkString(", ") + "]") |
| 40 | + } |
| 41 | + |
| 42 | + describe("NamedObjects (RDD)") { |
| 43 | + it("should survive from one job to another one") { |
| 44 | + |
| 45 | + manager ! JobManagerActor.StartJob("demo", jobName, getCreateConfig(false, true), errorEvents ++ syncEvents) |
| 46 | + val JobResult(_, names: Array[String]) = expectMsgClass(classOf[JobResult]) |
| 47 | + names should contain("rdd1") |
| 48 | + |
| 49 | + manager ! JobManagerActor.StartJob("demo", jobName, getCreateConfig(false, false), errorEvents ++ syncEvents) |
| 50 | + val JobResult(_, names2: Array[String]) = expectMsgClass(classOf[JobResult]) |
| 51 | + |
| 52 | + names2 should contain("rdd1") |
| 53 | + names2 should not contain("df1") |
| 54 | + |
| 55 | + //clean-up |
| 56 | + manager ! JobManagerActor.StartJob("demo", jobName, getDeleteConfig(List("rdd1")), errorEvents ++ syncEvents) |
| 57 | + val JobResult(_, names3: Array[String]) = expectMsgClass(classOf[JobResult]) |
| 58 | + |
| 59 | + names3 should not contain("rdd1") |
| 60 | + names3 should not contain("df1") |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + describe("NamedObjects (DataFrame)") { |
| 65 | + it("should survive from one job to another one") { |
| 66 | + |
| 67 | + manager ! JobManagerActor.StartJob("demo", jobName, getCreateConfig(true, false), errorEvents ++ syncEvents) |
| 68 | + val JobResult(_, names: Array[String]) = expectMsgClass(classOf[JobResult]) |
| 69 | + |
| 70 | + names should contain("df1") |
| 71 | + |
| 72 | + manager ! JobManagerActor.StartJob("demo", jobName, getCreateConfig(false, false), errorEvents ++ syncEvents) |
| 73 | + val JobResult(_, names2: Array[String]) = expectMsgClass(classOf[JobResult]) |
| 74 | + |
| 75 | + names2 should equal(names) |
| 76 | + |
| 77 | + //clean-up |
| 78 | + manager ! JobManagerActor.StartJob("demo", jobName, getDeleteConfig(List("df1")), errorEvents ++ syncEvents) |
| 79 | + val JobResult(_, names3: Array[String]) = expectMsgClass(classOf[JobResult]) |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + describe("NamedObjects (DataFrame + RDD)") { |
| 84 | + it("should survive from one job to another one") { |
| 85 | + |
| 86 | + manager ! JobManagerActor.StartJob("demo", jobName, getCreateConfig(true, true), errorEvents ++ syncEvents) |
| 87 | + val JobResult(_, names: Array[String]) = expectMsgClass(classOf[JobResult]) |
| 88 | + |
| 89 | + names should contain("rdd1") |
| 90 | + names should contain("df1") |
| 91 | + |
| 92 | + manager ! JobManagerActor.StartJob("demo", jobName, getCreateConfig(false, false), errorEvents ++ syncEvents) |
| 93 | + val JobResult(_, names2: Array[String]) = expectMsgClass(classOf[JobResult]) |
| 94 | + |
| 95 | + names2 should equal(names) |
| 96 | + |
| 97 | + //clean-up |
| 98 | + manager ! JobManagerActor.StartJob("demo", jobName, getDeleteConfig(List("rdd1", "df1")), errorEvents ++ syncEvents) |
| 99 | + val JobResult(_, names3: Array[String]) = expectMsgClass(classOf[JobResult]) |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | +} |
0 commit comments