Skip to content

Commit

Permalink
fix: added a scenario for the new getStatus method on jobExecution class
Browse files Browse the repository at this point in the history
  • Loading branch information
angelo.andreussi authored and Coduz committed Feb 11, 2025
1 parent 21f315b commit d05c3f5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Feature: Job Execution service CRUD tests
| integer | maxNumberChildEntities | 5 |
Given I create a job with the name "TestJob"
And A regular job execution item
When I update the end time of the execution item
When I update the end time of the execution item as if the job finished now
Then No exception was thrown
When I search for the last job execution in the database
Then The job execution items match
Expand Down Expand Up @@ -156,6 +156,24 @@ Feature: Job Execution service CRUD tests

And I test the sanity of the job execution factory

Scenario: Update the end time of an existing execution item and see if status is computed correctly

Given I login as user with name "kapua-sys" and password "kapua-password"
And I configure the job service
| type | name | value |
| boolean | infiniteChildEntities | true |
| integer | maxNumberChildEntities | 5 |
Given I create a job with the name "TestJob"
And A regular job execution item
When I update the end time of the execution item as if the job finished now
Then No exception was thrown
When I search for the last job execution in the database
Then The job execution status is "TERMINATED"
When I update the end time of the execution item as if the job never finished
Then No exception was thrown
When I search for the last job execution in the database
Then The job execution status is "RUNNING"

@teardown
Scenario: Tear down test resources
Given Stop Docker environment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* @since 2.1.0
*/
public enum JobStatus {
public enum JobExecutionStatus {

/**
* @since 2.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.eclipse.kapua.service.job.execution.JobExecutionListResult;
import org.eclipse.kapua.service.job.execution.JobExecutionQuery;
import org.eclipse.kapua.service.job.execution.JobExecutionService;
import org.eclipse.kapua.service.job.execution.JobExecutionStatus;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.slf4j.Logger;
Expand Down Expand Up @@ -107,7 +108,7 @@ public void updateJobIdForExecution() throws Exception {
}
}

@When("I update the end time of the execution item")
@When("I update the end time of the execution item as if the job finished now")
public void updateJobExecutionEndTime() throws Exception {
JobExecution execution = (JobExecution) stepData.get(JOB_EXECUTION);
primeException();
Expand All @@ -120,6 +121,19 @@ public void updateJobExecutionEndTime() throws Exception {
}
}

@When("I update the end time of the execution item as if the job never finished")
public void updateJobExecutionEndTimeWithNull() throws Exception {
JobExecution execution = (JobExecution) stepData.get(JOB_EXECUTION);
primeException();
try {
execution.setEndedOn(null);
execution = jobExecutionService.update(execution);
stepData.put(JOB_EXECUTION, execution);
} catch (KapuaException ex) {
verifyException(ex);
}
}

@When("I search for the last job execution in the database")
public void findLastJobExecution() throws Exception {
JobExecution execution = (JobExecution) stepData.get(JOB_EXECUTION);
Expand Down Expand Up @@ -419,7 +433,6 @@ private void logJobInfo(JobExecutionListResult jobExecutionList, Job job, int ex
}
}


@Then("The job execution matches the creator")
public void checkJobExecutionItemAgainstCreator() {
JobExecutionCreator executionCreator = (JobExecutionCreator) stepData.get("JobExecutionCreator");
Expand All @@ -430,7 +443,7 @@ public void checkJobExecutionItemAgainstCreator() {
}

@Then("The job execution items match")
public void checkJobExecutionItems() {
public void checkJobExecutionItemsRunning() {
JobExecution execution = (JobExecution) stepData.get(JOB_EXECUTION);
JobExecution foundExecution = (JobExecution) stepData.get("JobExecutionFound");
Assert.assertEquals(execution.getScopeId(), foundExecution.getScopeId());
Expand All @@ -439,6 +452,12 @@ public void checkJobExecutionItems() {
Assert.assertEquals(execution.getEndedOn(), foundExecution.getEndedOn());
}

@Then("The job execution status is {string}")
public void checkJobExecutionItems(String status) {
JobExecution foundExecution = (JobExecution) stepData.get("JobExecutionFound");
Assert.assertEquals(foundExecution.getStatus(), JobExecutionStatus.valueOf(status));
}

@Then("There is no such job execution item in the database")
public void checkThatNoExecutionWasFound() {
Assert.assertNull("Unexpected job execution item found!", stepData.get("JobExecutionFound"));
Expand Down

0 comments on commit d05c3f5

Please sign in to comment.