Skip to content

Commit

Permalink
LIVY-125. Refactor existing test jobs into a new library.
Browse files Browse the repository at this point in the history
This will help with writing integration tests, by avoiding
having to create new versions of these simple jobs. It also
serves as a nice cleanup of the existing code.

I also removed the async job from the rsc tests, since the
support code for dealing with async Spark jobs has been
removed from Livy.

Closes apache#115
  • Loading branch information
Marcelo Vanzin committed Apr 25, 2016
1 parent 55faccd commit af28e7b
Show file tree
Hide file tree
Showing 16 changed files with 440 additions and 225 deletions.
7 changes: 7 additions & 0 deletions client-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.cloudera.livy</groupId>
<artifactId>livy-test-lib</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.cloudera.livy.client.common.HttpMessages._
import com.cloudera.livy.server.WebServer
import com.cloudera.livy.server.client.{ClientSession, ClientSessionServlet}
import com.cloudera.livy.sessions.SessionState
import com.cloudera.livy.test.jobs.Echo

/**
* The test for the HTTP client is written in Scala so we can reuse the code in the livy-server
Expand Down Expand Up @@ -213,7 +214,7 @@ class HttpClientSpec extends FunSpecLike with BeforeAndAfterAll {
assert(expectedStr === new String(b))
}

private def runJob(sync: Boolean, genStatusFn: Long => Seq[JobStatus]): (Long, JFuture[Long]) = {
private def runJob(sync: Boolean, genStatusFn: Long => Seq[JobStatus]): (Long, JFuture[Int]) = {
val jobId = java.lang.Long.valueOf(ID_GENERATOR.incrementAndGet())
when(session.submitJob(any(classOf[Array[Byte]]))).thenReturn(jobId)

Expand All @@ -222,7 +223,8 @@ class HttpClientSpec extends FunSpecLike with BeforeAndAfterAll {
val remaining = statuses.drop(1)
when(session.jobStatus(meq(jobId))).thenReturn(first, remaining: _*)

val handle = if (sync) client.run(new DummyJob()) else client.submit(new DummyJob())
val job = new Echo(42)
val handle = if (sync) client.run(job) else client.submit(job)
(jobId, handle)
}

Expand All @@ -248,13 +250,6 @@ class HttpClientSpec extends FunSpecLike with BeforeAndAfterAll {

}

// Won't really get called, here just so we can use the API.
class DummyJob extends Job[Long] {

override def call(jc: JobContext): Long = 42L

}

private object HttpClientSpec {

// Hack warning: keep the session object available so that individual tests can mock
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<module>repl</module>
<module>rsc</module>
<module>server</module>
<module>test-lib</module>
<module>integration-test</module>
</modules>

Expand Down
6 changes: 6 additions & 0 deletions rsc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
<artifactId>livy-client-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.cloudera.livy</groupId>
<artifactId>livy-test-lib</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.esotericsoftware.kryo</groupId>
Expand Down
5 changes: 1 addition & 4 deletions rsc/src/main/java/com/cloudera/livy/rsc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@ public static String stackTraceAsString(Throwable t) {
StringBuilder sb = new StringBuilder();
sb.append(t.getClass().getName()).append(": ").append(t.getMessage());
for (StackTraceElement e : t.getStackTrace()) {
sb.append(e.toString());
sb.append("\n");
}
if (sb.length() > 0) {
sb.setLength(sb.length() - 1);
sb.append(e.toString());
}
return sb.toString();
}
Expand Down
Loading

0 comments on commit af28e7b

Please sign in to comment.