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..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,8 +23,8 @@ 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.assertTrue; @HelidonTest @@ -45,18 +45,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"); } }