From 65539f740c4558d44e1c6b958cdafe0d8e4269d6 Mon Sep 17 00:00:00 2001 From: Dmitry Aleksandrov Date: Mon, 28 Nov 2022 11:20:54 +0200 Subject: [PATCH 1/2] Fix test for multiple try and errors. --- .../examples/jbatch/TestJBatchEndpoint.java | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/examples/jbatch/src/test/java/io/helidon/examples/jbatch/TestJBatchEndpoint.java b/examples/jbatch/src/test/java/io/helidon/examples/jbatch/TestJBatchEndpoint.java index 95a46f008a1..abfc22501d7 100644 --- a/examples/jbatch/src/test/java/io/helidon/examples/jbatch/TestJBatchEndpoint.java +++ b/examples/jbatch/src/test/java/io/helidon/examples/jbatch/TestJBatchEndpoint.java @@ -23,8 +23,7 @@ import jakarta.ws.rs.core.MediaType; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; @HelidonTest @@ -45,18 +44,23 @@ public void runJob() throws InterruptedException { Integer responseJobId = jsonObject.getInt("Started a job with Execution ID: "); assertNotNull(responseJobId, "Response Job Id"); - //Wait a bit for it to complete - Thread.sleep(3000); + boolean result = false; + for (int i = 1; i < 10; i++) { + //Wait a bit for it to complete + Thread.sleep(i*1000); - //Examine the results - jsonObject = webTarget - .path("batch/status/" + responseJobId) - .request(MediaType.APPLICATION_JSON_TYPE) - .get(JsonObject.class); + //Examine the results + jsonObject = webTarget + .path("batch/status/" + responseJobId) + .request(MediaType.APPLICATION_JSON_TYPE) + .get(JsonObject.class); + + String responseString = jsonObject.toString(); + result = responseString.equals("{\"Steps executed\":\"[step1, step2]\",\"Status\":\"COMPLETED\"}"); - String responseString = jsonObject.toString(); + if (result) break; + } - assertEquals("{\"Steps executed\":\"[step1, step2]\",\"Status\":\"COMPLETED\"}", - responseString, "Job Result string"); + assertTrue(result, "Job Result string"); } } From 1a7ceb6169118e432822b98fc5b4e71c983dea2e Mon Sep 17 00:00:00 2001 From: Dmitry Aleksandrov Date: Mon, 28 Nov 2022 11:28:25 +0200 Subject: [PATCH 2/2] Fix imports. --- .../java/io/helidon/examples/jbatch/TestJBatchEndpoint.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/jbatch/src/test/java/io/helidon/examples/jbatch/TestJBatchEndpoint.java b/examples/jbatch/src/test/java/io/helidon/examples/jbatch/TestJBatchEndpoint.java index abfc22501d7..ac3fa679e5c 100644 --- a/examples/jbatch/src/test/java/io/helidon/examples/jbatch/TestJBatchEndpoint.java +++ b/examples/jbatch/src/test/java/io/helidon/examples/jbatch/TestJBatchEndpoint.java @@ -23,7 +23,8 @@ import jakarta.ws.rs.core.MediaType; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; @HelidonTest