Skip to content

Commit

Permalink
Add test for init twice. (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbah authored and dgrove-oss committed Jul 6, 2018
1 parent 3657b38 commit d5caa45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
6 changes: 2 additions & 4 deletions java8/proxy/src/main/java/openwhisk/java/action/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ public void handle(HttpExchange t) throws IOException {
String base64Jar = message.getAsJsonPrimitive("code").getAsString();

// FIXME: this is obviously not very useful. The idea is that we
// will implement/use
// a streaming parser for the incoming JSON object so that we
// can stream the contents
// of the jar straight to a file.
// will implement/use a streaming parser for the incoming JSON object so that we
// can stream the contents of the jar straight to a file.
InputStream jarIs = new ByteArrayInputStream(base64Jar.getBytes(StandardCharsets.UTF_8));

// Save the bytes to a file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,34 @@ class JavaActionContainerTests extends FlatSpec with Matchers with WskActorSyste
err.trim shouldBe empty
}

it should "not allow initialization twice" in {
val (out, err) = withJavaContainer { c =>
val jar = JarBuilder.mkBase64Jar(
Seq("example", "HelloWhisk.java") ->
"""
| package example;
|
| import com.google.gson.JsonObject;
|
| public class HelloWhisk {
| public static JsonObject main(JsonObject args) {
| return args;
| }
| }
""".stripMargin.trim)

val (initCode, _) = c.init(initPayload("example.HelloWhisk", jar))
initCode should be(200)

val (initCode2, out2) = c.init(initPayload("example.HelloWhisk", jar))
initCode2 should (be < 200 or be > 299) // the code does not matter, just cannot be 20x
out2 should be(Some(JsObject("error" -> JsString("Cannot initialize the action more than once."))))
}

out.trim shouldBe empty
err.trim shouldBe empty
}

it should "support valid actions with non 'main' names" in {
val (out, err) = withJavaContainer { c =>
val jar = JarBuilder.mkBase64Jar(
Expand Down

0 comments on commit d5caa45

Please sign in to comment.