Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] - Fix Intermittent TestJBatchEndpoint.runJob #5567

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions examples/jbatch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<name>jbatch-example</name>

<properties>
<version.lib.jbatch-api>2.1.0-M2</version.lib.jbatch-api>
<version.lib.jbatch.container>2.1.0-M2</version.lib.jbatch.container>
<version.lib.jbatch-api>2.1.0</version.lib.jbatch-api>
<version.lib.jbatch.container>2.1.0</version.lib.jbatch.container>
<version.lib.derby>10.14.2.0</version.lib.derby>
<version.lib.jaxb-api>3.0.1</version.lib.jaxb-api>
</properties>
Expand Down Expand Up @@ -106,6 +106,11 @@
<artifactId>helidon-microprofile-tests-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,62 @@
* limitations under the License.
*/
package io.helidon.examples.jbatch;

import io.helidon.microprofile.tests.junit5.HelidonTest;
import jakarta.json.Json;
import jakarta.json.JsonBuilderFactory;
import org.junit.jupiter.api.Test;

import jakarta.inject.Inject;
import jakarta.json.JsonObject;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Collections;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;

@HelidonTest
public class TestJBatchEndpoint {

private static final JsonBuilderFactory JSON = Json.createBuilderFactory(Collections.emptyMap());

@Inject
private WebTarget webTarget;

@Test
public void runJob() throws InterruptedException {

JsonObject expectedJson = JSON.createObjectBuilder()
.add("Steps executed", "[step1, step2]")
.add("Status", "COMPLETED")
.build();

//Start the job
JsonObject jsonObject = webTarget
.path("/batch")
.request(MediaType.APPLICATION_JSON_TYPE)
.get(JsonObject.class);

Integer responseJobId = jsonObject.getInt("Started a job with Execution ID: ");
assertNotNull(responseJobId, "Response Job Id");

boolean result = false;
assertThat(responseJobId, is(notNullValue()));
JsonObject result = null;
for (int i = 1; i < 10; i++) {
//Wait a bit for it to complete
Thread.sleep(i*1000);

//Examine the results
jsonObject = webTarget
result = 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\"}");
if (result.equals(expectedJson)){
break;
}

if (result) break;
}

assertTrue(result, "Job Result string");
assertThat(result, equalTo(expectedJson));
}
}