This is an automated email from the ASF dual-hosted git repository.
wmedvedeo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-kogito-apps.git
The following commit(s) were added to refs/heads/main by this push:
new ee3793841 incubator-kie-kogito-apps-2221: Improve Jobs Service Tests
(#2222)
ee3793841 is described below
commit ee3793841695715ae84253ab60d1368e7a42d1c0
Author: Walter Medvedeo <[email protected]>
AuthorDate: Fri May 23 11:58:14 2025 +0200
incubator-kie-kogito-apps-2221: Improve Jobs Service Tests (#2222)
---
.../main/java/org/kie/kogito/test/TestUtils.java | 64 +++++
.../pom.xml | 13 +
.../kie/kogito/it/jobs/BaseIndependentJobsIT.java | 268 +++++++++++++++++++++
.../org/kie/kogito/it/jobs/JobRecipientMock.java | 14 ++
.../org/kie/kogito/it/jobs/HttpJobExecutionIT.java | 61 +----
.../pom.xml | 5 +
.../org/kie/kogito/it/jobs/IndependentJobsIT.java | 31 +++
.../pom.xml | 6 +-
.../org/kie/kogito/it/jobs/IndependentJobsIT.java | 31 +++
9 files changed, 444 insertions(+), 49 deletions(-)
diff --git
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-common/src/main/java/org/kie/kogito/test/TestUtils.java
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-common/src/main/java/org/kie/kogito/test/TestUtils.java
index 98ffcbf58..2b3f5b3f6 100644
---
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-common/src/main/java/org/kie/kogito/test/TestUtils.java
+++
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-common/src/main/java/org/kie/kogito/test/TestUtils.java
@@ -19,16 +19,31 @@
package org.kie.kogito.test;
import java.time.Duration;
+import java.util.List;
+import java.util.Map;
import org.awaitility.Awaitility;
+import io.restassured.RestAssured;
import io.restassured.http.ContentType;
+import io.restassured.path.json.JsonPath;
import static io.restassured.RestAssured.given;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;
public class TestUtils {
+ public static final String JOB_RETRIES_FIELD = "retries";
+ public static final String JOB_STATUS_FIELD = "status";
+ public static final String JOB_EXECUTION_COUNTER_FIELD =
"executionCounter";
+
+ private static final String JOB_BY_ID_QUERY = "{ \"query\": " +
+ "\"{ Jobs (where: { id: { equal: \\\"%s\\\" } } ) " +
+ " { id, expirationTime, status, scheduledId, lastUpdate, retries,
repeatInterval, repeatLimit, executionCounter }" +
+ "}\" }";
+
private TestUtils() {
}
@@ -74,4 +89,53 @@ public class TestUtils {
.body("data.Jobs[0].status", is(jobStatus));
}
}
+
+ /**
+ * Asserts that information for a job exists in the Data Index and returns
the corresponding map representation.
+ *
+ * @param dataIndexUrl root url for the Data Index.
+ * @param jobId identifier of the job.
+ * @return the map representation of the job information stored in the
Data Index.
+ */
+ public static Map<String, Object> assertJobInDataIndexAndReturn(String
dataIndexUrl, String jobId) {
+ JsonPath result = RestAssured.given()
+ .contentType(ContentType.JSON)
+ .accept(ContentType.JSON)
+ .body(String.format(JOB_BY_ID_QUERY, jobId))
+ .post(dataIndexUrl + "/graphql")
+ .then()
+ .statusCode(200)
+ .extract()
+ .jsonPath();
+ List<Map<String, Object>> jobs = result.get("data.Jobs");
+ assertThat(jobs).hasSize(1);
+ return jobs.get(0);
+ }
+
+ /**
+ * Asserts that a job exists or not in the Jobs Service.
+ *
+ * @param jobServiceUrl root url for the Jobs Service.
+ * @param jobId identifier of the job.
+ * @param exists true if the assertion must validate that the job exists,
false for negative assertion.
+ * @param atMostTimeoutInSeconds @see {@link Awaitility#await()}.
+ */
+ public static void assertJobExists(String jobServiceUrl,
+ String jobId,
+ boolean exists,
+ long atMostTimeoutInSeconds) {
+
+ String query = jobServiceUrl + "/v2/jobs/" + jobId;
+ int expectedCode = exists ? 200 : 404;
+
+ Awaitility.await()
+ .atMost(atMostTimeoutInSeconds, SECONDS)
+ .with().pollInterval(1, SECONDS)
+ .untilAsserted(() -> RestAssured.given()
+ .contentType(ContentType.JSON)
+ .accept(ContentType.JSON)
+ .get(query)
+ .then()
+ .statusCode(expectedCode));
+ }
}
diff --git
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/pom.xml
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/pom.xml
index e7e822e47..bc63fa814 100644
---
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/pom.xml
+++
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/pom.xml
@@ -41,6 +41,14 @@
</properties>
<dependencies>
+ <dependency>
+ <groupId>jakarta.ws.rs</groupId>
+ <artifactId>jakarta.ws.rs-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.kie.kogito</groupId>
+ <artifactId>jobs-service-api</artifactId>
+ </dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>data-index-test-utils</artifactId>
@@ -69,6 +77,11 @@
<artifactId>junit-jupiter-api</artifactId>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>com.github.tomakehurst</groupId>
+ <artifactId>wiremock-jre8</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/src/test/java/org/kie/kogito/it/jobs/BaseIndependentJobsIT.java
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/src/test/java/org/kie/kogito/it/jobs/BaseIndependentJobsIT.java
new file mode 100644
index 000000000..9da83a429
--- /dev/null
+++
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/src/test/java/org/kie/kogito/it/jobs/BaseIndependentJobsIT.java
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.it.jobs;
+
+import java.time.OffsetDateTime;
+import java.time.temporal.ChronoUnit;
+import java.util.Map;
+import java.util.UUID;
+
+import org.awaitility.Awaitility;
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.jobs.service.api.Job;
+import org.kie.kogito.jobs.service.api.TemporalUnit;
+import org.kie.kogito.jobs.service.api.recipient.http.HttpRecipient;
+import
org.kie.kogito.jobs.service.api.recipient.http.HttpRecipientStringPayloadData;
+import org.kie.kogito.jobs.service.api.schedule.timer.TimerSchedule;
+import org.kie.kogito.jobs.service.api.serialization.SerializationUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.github.tomakehurst.wiremock.WireMockServer;
+
+import io.restassured.RestAssured;
+
+import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
+import static org.kie.kogito.it.jobs.JobRecipientMock.JOB_RECIPIENT_MOCK;
+import static
org.kie.kogito.it.jobs.JobRecipientMock.JOB_RECIPIENT_MOCK_URL_PROPERTY;
+import static org.kie.kogito.it.jobs.JobRecipientMock.verifyJobWasExecuted;
+import static org.kie.kogito.test.TestUtils.JOB_EXECUTION_COUNTER_FIELD;
+import static org.kie.kogito.test.TestUtils.JOB_RETRIES_FIELD;
+import static org.kie.kogito.test.TestUtils.JOB_STATUS_FIELD;
+import static org.kie.kogito.test.TestUtils.assertJobExists;
+import static org.kie.kogito.test.TestUtils.assertJobInDataIndexAndReturn;
+import static
org.kie.kogito.test.resources.JobServiceCompositeQuarkusTestResource.DATA_INDEX_SERVICE_URL;
+import static
org.kie.kogito.test.resources.JobServiceCompositeQuarkusTestResource.JOBS_SERVICE_URL;
+
+public abstract class BaseIndependentJobsIT implements
JobRecipientMock.JobRecipientMockAware, JobServiceHealthAware {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(BaseIndependentJobsIT.class);
+
+ protected WireMockServer jobRecipient;
+
+ private static OffsetDateTime getNowPlusSeconds(long seconds) {
+ return OffsetDateTime.now().plus(seconds, ChronoUnit.SECONDS);
+ }
+
+ @Override
+ public void setWireMockServer(WireMockServer jobRecipient) {
+ this.jobRecipient = jobRecipient;
+ }
+
+ @Test
+ void testFailingJob() throws Exception {
+ String jobId = UUID.randomUUID().toString();
+ Job job = Job.builder()
+ .id(jobId)
+ .correlationId(jobId)
+ .schedule(TimerSchedule.builder()
+ .startTime(getNowPlusSeconds(5))
+ .build())
+ .recipient(HttpRecipient.builder().forStringPayload()
+ .url("http://never.existing.kogito.service")
+ .method("POST")
+
.payload(HttpRecipientStringPayloadData.from("Irrelevant"))
+ .build())
+ .build();
+
+ String serializedJob =
SerializationUtils.DEFAULT_OBJECT_MAPPER.writeValueAsString(job);
+ LOGGER.debug("Creating failing job: {}", serializedJob);
+ // Create the job.
+ RestAssured.given()
+ .accept(APPLICATION_JSON)
+ .contentType(APPLICATION_JSON)
+ .body(serializedJob)
+ .post(jobServiceJobsUrl())
+ .then()
+ .statusCode(200);
+
+ LOGGER.debug("Verifying failing job retrials in Data Index, jobId:
{}", jobId);
+ // Ensure the job has been retrying for some time and properly
notifying the DI with the correct status while
+ // retrying.
+ Awaitility.await()
+ .atMost(60, SECONDS)
+ .with().pollInterval(1, SECONDS)
+ .untilAsserted(() -> {
+ Map<String, Object> dataIndexJob =
assertJobInDataIndexAndReturn(dataIndexUrl(), jobId);
+ int retries = (Integer)
dataIndexJob.get(JOB_RETRIES_FIELD);
+ assertThat(retries).isGreaterThan(10);
+
assertThat(dataIndexJob).hasFieldOrPropertyWithValue(JOB_STATUS_FIELD,
Job.State.RETRY.name());
+ });
+
+ LOGGER.debug("Verifying failing job reaches the ERROR state, jobId:
{}", jobId);
+ // Ensure the job finalizes the failing execution and properly
notifies the DI with the correct status.
+ Awaitility.await()
+ .atMost(60, SECONDS)
+ .with().pollInterval(1, SECONDS)
+ .untilAsserted(() -> {
+ Map<String, Object> dataIndexJob =
assertJobInDataIndexAndReturn(dataIndexUrl(), jobId);
+
assertThat(dataIndexJob).hasFieldOrPropertyWithValue(JOB_STATUS_FIELD,
Job.State.ERROR.name());
+ });
+
+ LOGGER.debug("Verifying failing job is removed from the Job Service,
jobId: {}", jobId);
+ // Ensure the job as removed from the jobs service.
+ assertJobExists(jobServiceUrl(), jobId, false, 60);
+ }
+
+ @Test
+ void testSimpleJob() throws Exception {
+ String jobRecipientUrl = jobRecipientMockUrl() + "/" +
JOB_RECIPIENT_MOCK;
+ String jobId = UUID.randomUUID().toString();
+ Job job = Job.builder()
+ .id(jobId)
+ .correlationId(jobId)
+ .schedule(TimerSchedule.builder()
+ .startTime(getNowPlusSeconds(50))
+ .build())
+ .recipient(HttpRecipient.builder().forStringPayload()
+ .url(jobRecipientUrl)
+ .method("POST")
+
.payload(HttpRecipientStringPayloadData.from("Irrelevant"))
+ .header("Content-type", APPLICATION_JSON)
+ .header("jobId", jobId)
+ .build())
+ .build();
+
+ String serializedJob =
SerializationUtils.DEFAULT_OBJECT_MAPPER.writeValueAsString(job);
+ LOGGER.debug("Creating simple job: {}", serializedJob);
+ // Create the job.
+ RestAssured.given()
+ .accept(APPLICATION_JSON)
+ .contentType(APPLICATION_JSON)
+ .body(serializedJob)
+ .post(jobServiceJobsUrl())
+ .then()
+ .statusCode(200);
+
+ LOGGER.debug("Verifying the simple job was scheduled in the Data
Index, jobId: {}", jobId);
+ // Verify the job is registered as scheduled in the Data Index.
+ Awaitility.await()
+ .atMost(120, SECONDS)
+ .with().pollInterval(1, SECONDS)
+ .untilAsserted(() -> {
+ Map<String, Object> dataIndexJob =
assertJobInDataIndexAndReturn(dataIndexUrl(), jobId);
+
assertThat(dataIndexJob).hasFieldOrPropertyWithValue(JOB_STATUS_FIELD,
Job.State.SCHEDULED.name());
+ });
+
+ // Verify the job was executed.
+ verifyJobWasExecuted(jobRecipient, jobId, 0);
+
+ LOGGER.debug("Verifying simple job reaches the EXECUTED state jobId:
{}", jobId);
+ // Verify the job is registered as executed in the Data Index.
+ Awaitility.await()
+ .atMost(60, SECONDS)
+ .with().pollInterval(1, SECONDS)
+ .untilAsserted(() -> {
+ Map<String, Object> dataIndexJob =
assertJobInDataIndexAndReturn(dataIndexUrl(), jobId);
+
assertThat(dataIndexJob).hasFieldOrPropertyWithValue(JOB_STATUS_FIELD,
Job.State.EXECUTED.name());
+ });
+
+ // Ensure the job as removed from the jobs service.
+ assertJobExists(jobServiceUrl(), jobId, false, 60);
+ }
+
+ @Test
+ void testRepetitiveJob() throws Exception {
+ String jobRecipientUrl = jobRecipientMockUrl() + "/" +
JOB_RECIPIENT_MOCK;
+ String jobId = UUID.randomUUID().toString();
+ int repeatCount = 2;
+ // initial execution + 2 repetitions
+ int expectedExecutions = repeatCount + 1;
+ Job job = Job.builder()
+ .id(jobId)
+ .correlationId(jobId)
+ .schedule(TimerSchedule.builder()
+ .startTime(getNowPlusSeconds(30))
+ .repeatCount(2)
+ .delay(30L)
+ .delayUnit(TemporalUnit.SECONDS)
+ .build())
+ .recipient(HttpRecipient.builder().forStringPayload()
+ .url(jobRecipientUrl)
+ .method("POST")
+
.payload(HttpRecipientStringPayloadData.from("Irrelevant"))
+ .header("Content-type", APPLICATION_JSON)
+ .header("jobId", jobId)
+ .build())
+ .build();
+
+ String serializedJob =
SerializationUtils.DEFAULT_OBJECT_MAPPER.writeValueAsString(job);
+ LOGGER.debug("Creating repetitive job: {}", serializedJob);
+ // Create the job.
+ RestAssured.given()
+ .accept(APPLICATION_JSON)
+ .contentType(APPLICATION_JSON)
+ .body(serializedJob)
+ .post(jobServiceJobsUrl())
+ .then()
+ .statusCode(200);
+
+ // Verify the job is registered as scheduled in the Data Index.
+ Awaitility.await()
+ .atMost(60, SECONDS)
+ .with().pollInterval(1, SECONDS)
+ .untilAsserted(() -> {
+ Map<String, Object> dataIndexJob =
assertJobInDataIndexAndReturn(dataIndexUrl(), jobId);
+
assertThat(dataIndexJob).hasFieldOrPropertyWithValue(JOB_STATUS_FIELD,
Job.State.SCHEDULED.name());
+ });
+
+ LOGGER.debug("Verifying the repetitive job programmed executions are
produced jobId: {}", jobId);
+ for (int i = 1; i <= expectedExecutions; i++) {
+ // executions goes 1,2,3
+ final int execution = i;
+ // limit goes 2,1,0
+ int limit = expectedExecutions - execution;
+ // Verify the job was executed.
+ verifyJobWasExecuted(jobRecipient, jobId, limit);
+ // Verify the given execution was produced, and the expected
status registered in the DI.
+ Awaitility.await()
+ .atMost(60, SECONDS)
+ .with().pollInterval(1, SECONDS)
+ .untilAsserted(() -> {
+ Map<String, Object> dataIndexJob =
assertJobInDataIndexAndReturn(dataIndexUrl(), jobId);
+
assertThat(dataIndexJob).hasFieldOrPropertyWithValue(JOB_EXECUTION_COUNTER_FIELD,
execution);
+ if (execution < expectedExecutions) {
+
assertThat(dataIndexJob).hasFieldOrPropertyWithValue(JOB_STATUS_FIELD,
Job.State.SCHEDULED.name());
+ } else {
+
assertThat(dataIndexJob).hasFieldOrPropertyWithValue(JOB_STATUS_FIELD,
Job.State.EXECUTED.name());
+ }
+ });
+ }
+ // Ensure the job as removed from the jobs service.
+ assertJobExists(jobServiceUrl(), jobId, false, 60);
+ }
+
+ public String jobServiceJobsUrl() {
+ return jobServiceUrl() + "/v2/jobs";
+ }
+
+ public String jobServiceUrl() {
+ return System.getProperty(JOBS_SERVICE_URL);
+ }
+
+ public String dataIndexUrl() {
+ return System.getProperty(DATA_INDEX_SERVICE_URL);
+ }
+
+ public String jobRecipientMockUrl() {
+ return System.getProperty(JOB_RECIPIENT_MOCK_URL_PROPERTY);
+ }
+}
diff --git
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-knative-eventing/src/test/java/org/kie/kogito/it/jobs/JobRecipientMock.java
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/src/test/java/org/kie/kogito/it/jobs/JobRecipientMock.java
similarity index 81%
rename from
apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-knative-eventing/src/test/java/org/kie/kogito/it/jobs/JobRecipientMock.java
rename to
apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/src/test/java/org/kie/kogito/it/jobs/JobRecipientMock.java
index a0218df73..b8d265ece 100644
---
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-knative-eventing/src/test/java/org/kie/kogito/it/jobs/JobRecipientMock.java
+++
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-common-quarkus/src/test/java/org/kie/kogito/it/jobs/JobRecipientMock.java
@@ -33,7 +33,12 @@ import com.github.tomakehurst.wiremock.matching.UrlPattern;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
+import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
+import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
import static com.github.tomakehurst.wiremock.client.WireMock.request;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.awaitility.Awaitility.await;
/**
* Mock an external JobRecipient to verify the proper execution of jobs
service api over http.
@@ -79,4 +84,13 @@ public class JobRecipientMock implements
QuarkusTestResourceLifecycleManager {
((JobRecipientMockAware)
testInstance).setWireMockServer(wireMockServer);
}
}
+
+ public static void verifyJobWasExecuted(WireMockServer jobRecipient,
String jobId, int limit) {
+ await()
+ .atMost(600, SECONDS)
+ .with().pollInterval(1, SECONDS)
+ .untilAsserted(() -> jobRecipient.verify(1,
+ postRequestedFor(urlEqualTo("/" + JOB_RECIPIENT_MOCK +
"?limit=" + limit))
+ .withHeader("jobId", equalTo(jobId))));
+ }
}
diff --git
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-knative-eventing/src/test/java/org/kie/kogito/it/jobs/HttpJobExecutionIT.java
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-knative-eventing/src/test/java/org/kie/kogito/it/jobs/HttpJobExecutionIT.java
index c89667c35..bcdfb2152 100644
---
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-knative-eventing/src/test/java/org/kie/kogito/it/jobs/HttpJobExecutionIT.java
+++
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-knative-eventing/src/test/java/org/kie/kogito/it/jobs/HttpJobExecutionIT.java
@@ -26,8 +26,6 @@ import org.junit.jupiter.api.Test;
import org.kie.kogito.jobs.service.api.event.CreateJobEvent;
import org.kie.kogito.jobs.service.api.event.DeleteJobEvent;
import org.kie.kogito.test.resources.JobServiceTestResource;
-import org.kie.kogito.testcontainers.quarkus.KafkaQuarkusTestResource;
-import org.testcontainers.shaded.org.awaitility.Awaitility;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -37,23 +35,18 @@ import io.cloudevents.SpecVersion;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.RestAssured;
-import io.restassured.http.ContentType;
-import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
-import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static org.awaitility.Awaitility.await;
import static org.kie.kogito.it.jobs.JobRecipientMock.JOB_RECIPIENT_MOCK;
import static
org.kie.kogito.it.jobs.JobRecipientMock.JOB_RECIPIENT_MOCK_URL_PROPERTY;
+import static org.kie.kogito.it.jobs.JobRecipientMock.verifyJobWasExecuted;
+import static org.kie.kogito.test.TestUtils.assertJobExists;
import static
org.kie.kogito.test.resources.JobServiceCompositeQuarkusTestResource.JOBS_SERVICE_URL;
@QuarkusIntegrationTest
-@QuarkusTestResource(KafkaQuarkusTestResource.class)
@QuarkusTestResource(JobRecipientMock.class)
@JobServiceTestResource(knativeEventingEnabled = true)
-public class HttpJobExecutionIT implements
JobRecipientMock.JobRecipientMockAware {
+class HttpJobExecutionIT implements JobRecipientMock.JobRecipientMockAware,
JobServiceHealthAware {
private static final String APPLICATION_CLOUD_EVENTS =
"application/cloudevents+json";
private static final String SPECVERSION = "specversion";
@@ -99,8 +92,8 @@ public class HttpJobExecutionIT implements
JobRecipientMock.JobRecipientMockAwar
.then()
.statusCode(202);
- verifyJobWasExecuted(jobId, 0);
- assertJobExists(jobId, false, 1, 60);
+ verifyJobWasExecuted(jobRecipient, jobId, 0);
+ assertJobExists(jobServiceUrl(), jobId, false, 60);
}
@Test
@@ -127,7 +120,7 @@ public class HttpJobExecutionIT implements
JobRecipientMock.JobRecipientMockAwar
.then()
.statusCode(202);
- assertJobExists(jobId, true, 1, 60);
+ assertJobExists(jobServiceUrl(), jobId, true, 60);
ObjectNode delete = objectMapper.createObjectNode()
.put("id", jobId);
@@ -146,7 +139,7 @@ public class HttpJobExecutionIT implements
JobRecipientMock.JobRecipientMockAwar
.then()
.statusCode(202);
- assertJobExists(jobId, false, 1, 60);
+ assertJobExists(jobServiceUrl(), jobId, false, 60);
}
@Test
@@ -177,7 +170,7 @@ public class HttpJobExecutionIT implements
JobRecipientMock.JobRecipientMockAwar
.then()
.statusCode(202);
- verifyJobWasExecuted(jobId, 0);
+ verifyJobWasExecuted(jobRecipient, jobId, 0);
}
@Test
@@ -208,7 +201,7 @@ public class HttpJobExecutionIT implements
JobRecipientMock.JobRecipientMockAwar
.then()
.statusCode(202);
- assertJobExists(jobId, true, 1, 60);
+ assertJobExists(jobServiceUrl(), jobId, true, 60);
ObjectNode deleteCloudEvent = objectMapper.createObjectNode()
.put(ID, UUID.randomUUID().toString())
@@ -231,36 +224,7 @@ public class HttpJobExecutionIT implements
JobRecipientMock.JobRecipientMockAwar
.then()
.statusCode(202);
- assertJobExists(jobId, false, 1, 60);
- }
-
- private void verifyJobWasExecuted(String jobId, int limit) {
- await()
- .atMost(600, SECONDS)
- .with().pollInterval(1, SECONDS)
- .untilAsserted(() -> jobRecipient.verify(1,
- postRequestedFor(urlEqualTo("/" + JOB_RECIPIENT_MOCK +
"?limit=" + limit))
- .withHeader("jobId", equalTo(jobId))));
- }
-
- private static void assertJobExists(String jobId,
- boolean exists,
- long atLeastTimeoutInSeconds,
- long atMostTimeoutInSeconds) {
-
- String query = jobServiceUrl() + "/v2/jobs/" + jobId;
- int expectedCode = exists ? 200 : 404;
-
- Awaitility.await()
- .atLeast(atLeastTimeoutInSeconds, SECONDS)
- .atMost(atMostTimeoutInSeconds, SECONDS)
- .with().pollInterval(1, SECONDS)
- .untilAsserted(() -> RestAssured.given()
- .contentType(ContentType.JSON)
- .accept(ContentType.JSON)
- .get(query)
- .then()
- .statusCode(expectedCode));
+ assertJobExists(jobServiceUrl(), jobId, false, 60);
}
private ObjectNode createJob(String jobId, String startTimeStr, String
jobRecipientUrl) {
@@ -279,11 +243,12 @@ public class HttpJobExecutionIT implements
JobRecipientMock.JobRecipientMockAwar
return job;
}
- private static String jobServiceEventsUrl() {
+ public String jobServiceEventsUrl() {
return jobServiceUrl() + "/v2/jobs/events";
}
- private static String jobServiceUrl() {
+ @Override
+ public String jobServiceUrl() {
return System.getProperty(JOBS_SERVICE_URL);
}
diff --git
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-management/pom.xml
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-management/pom.xml
index c873c7fbc..3a5f01aef 100644
---
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-management/pom.xml
+++
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-management/pom.xml
@@ -76,6 +76,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.github.tomakehurst</groupId>
+ <artifactId>wiremock-jre8</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-management/src/test/java/org/kie/kogito/it/jobs/IndependentJobsIT.java
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-management/src/test/java/org/kie/kogito/it/jobs/IndependentJobsIT.java
new file mode 100644
index 000000000..15da870e7
--- /dev/null
+++
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-management/src/test/java/org/kie/kogito/it/jobs/IndependentJobsIT.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.it.jobs;
+
+import org.kie.kogito.test.resources.JobServiceTestResource;
+
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+
+@QuarkusIntegrationTest
+@QuarkusTestResource(JobRecipientMock.class)
+@JobServiceTestResource(kafkaEnabled = true, dataIndexEnabled = true)
+class IndependentJobsIT extends BaseIndependentJobsIT {
+
+}
diff --git
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-messaging/pom.xml
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-messaging/pom.xml
index bb0e24b2c..bc3386be7 100644
---
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-messaging/pom.xml
+++
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-messaging/pom.xml
@@ -94,7 +94,11 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
-
+ <dependency>
+ <groupId>com.github.tomakehurst</groupId>
+ <artifactId>wiremock-jre8</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-messaging/src/test/java/org/kie/kogito/it/jobs/IndependentJobsIT.java
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-messaging/src/test/java/org/kie/kogito/it/jobs/IndependentJobsIT.java
new file mode 100644
index 000000000..15da870e7
--- /dev/null
+++
b/apps-integration-tests/integration-tests-jobs-service/integration-tests-jobs-service-quarkus/integration-tests-jobs-service-quarkus-messaging/src/test/java/org/kie/kogito/it/jobs/IndependentJobsIT.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.it.jobs;
+
+import org.kie.kogito.test.resources.JobServiceTestResource;
+
+import io.quarkus.test.common.QuarkusTestResource;
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+
+@QuarkusIntegrationTest
+@QuarkusTestResource(JobRecipientMock.class)
+@JobServiceTestResource(kafkaEnabled = true, dataIndexEnabled = true)
+class IndependentJobsIT extends BaseIndependentJobsIT {
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]