Allow Batch2 transition from ERRORED to COMPLETE (#4242)

* Allow Batch2 transition from ERRORED to COMPLETE

* Add changelog

* Test fix

Co-authored-by: James Agnew <james@jamess-mbp.lan>
This commit is contained in:
James Agnew 2022-11-04 07:21:06 -04:00 committed by GitHub
parent 3199728024
commit b965347b8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 17 deletions

View File

@ -0,0 +1,4 @@
---
type: fix
issue: 4242
title: "Batch2 jobs were incorrectly prevented from transitioning from ERRORED to COMPLETE status."

View File

@ -146,7 +146,7 @@ public enum StatusEnum {
case IN_PROGRESS:
return theNewStatus != QUEUED;
case ERRORED:
return theNewStatus == FAILED;
return theNewStatus == FAILED || theNewStatus == COMPLETED || theNewStatus == CANCELLED;
case COMPLETED:
case CANCELLED:
case FAILED:

View File

@ -87,10 +87,10 @@ public class JobInstanceStatusUpdater {
invokeCompletionHandler(theJobInstance, definition, definition.getCompletionHandler());
break;
case FAILED:
case ERRORED:
case CANCELLED:
invokeCompletionHandler(theJobInstance, definition, definition.getErrorHandler());
break;
case ERRORED:
case QUEUED:
case IN_PROGRESS:
default:

View File

@ -50,8 +50,8 @@ class StatusEnumTest {
"ERRORED, QUEUED, false",
"ERRORED, IN_PROGRESS, false",
"ERRORED, COMPLETED, false",
"ERRORED, CANCELLED, false",
"ERRORED, COMPLETED, true",
"ERRORED, CANCELLED, true",
"ERRORED, ERRORED, true",
"ERRORED, FAILED, true",

View File

@ -20,6 +20,7 @@ import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@ -28,7 +29,7 @@ class JobInstanceStatusUpdaterTest {
private static final String TEST_NAME = "test name";
private static final String TEST_ERROR_MESSAGE = "test error message";
private static final int TEST_ERROR_COUNT = 729;
private final JobInstance ourQueuedInstance = new JobInstance().setStatus(StatusEnum.QUEUED);
private final JobInstance myQueuedInstance = new JobInstance().setStatus(StatusEnum.QUEUED);
@Mock
IJobPersistence myJobPersistence;
@ -51,36 +52,58 @@ class JobInstanceStatusUpdaterTest {
myInstance.setParameters(myTestParameters);
myInstance.setErrorMessage(TEST_ERROR_MESSAGE);
myInstance.setErrorCount(TEST_ERROR_COUNT);
when(myJobDefinition.getParametersType()).thenReturn(TestParameters.class);
}
@Test
public void testCompletionHandler() {
AtomicReference<JobCompletionDetails> calledDetails = new AtomicReference<>();
// setup
when(myJobPersistence.fetchInstance(TEST_INSTANCE_ID)).thenReturn(Optional.of(ourQueuedInstance));
when(myJobPersistence.updateInstance(myInstance)).thenReturn(true);
IJobCompletionHandler<TestParameters> completionHandler = details -> calledDetails.set(details);
when(myJobDefinition.getCompletionHandler()).thenReturn(completionHandler);
setupCompleteCallback();
// execute
mySvc.updateInstanceStatus(myInstance, StatusEnum.COMPLETED);
JobCompletionDetails<TestParameters> receivedDetails = calledDetails.get();
assertCompleteCallbackCalled();
}
@Test
public void testCompletionHandler_ERROR_to_COMPLETED() {
setupCompleteCallback();
myInstance.setStatus(StatusEnum.ERRORED);
myQueuedInstance.setStatus(StatusEnum.ERRORED);
when(myJobDefinition.getParametersType()).thenReturn(TestParameters.class);
// execute
mySvc.updateInstanceStatus(myInstance, StatusEnum.COMPLETED);
assertCompleteCallbackCalled();
}
private void assertCompleteCallbackCalled() {
JobCompletionDetails<TestParameters> receivedDetails = myDetails.get();
assertEquals(TEST_INSTANCE_ID, receivedDetails.getInstance().getInstanceId());
assertEquals(TEST_NAME, receivedDetails.getParameters().name);
}
private void setupCompleteCallback() {
myDetails = new AtomicReference<>();
when(myJobPersistence.fetchInstance(TEST_INSTANCE_ID)).thenReturn(Optional.of(myQueuedInstance));
when(myJobPersistence.updateInstance(myInstance)).thenReturn(true);
IJobCompletionHandler<TestParameters> completionHandler = details -> myDetails.set(details);
when(myJobDefinition.getCompletionHandler()).thenReturn(completionHandler);
when(myJobDefinition.getParametersType()).thenReturn(TestParameters.class);
}
@Test
public void testErrorHandler_ERROR() {
setupErrorCallback();
// setup
myDetails = new AtomicReference<>();
when(myJobPersistence.fetchInstance(TEST_INSTANCE_ID)).thenReturn(Optional.of(myQueuedInstance));
when(myJobPersistence.updateInstance(myInstance)).thenReturn(true);
// execute
mySvc.updateInstanceStatus(myInstance, StatusEnum.ERRORED);
assertErrorCallbackCalled(StatusEnum.ERRORED);
assertNull(myDetails.get());
}
@Test
@ -117,10 +140,11 @@ class JobInstanceStatusUpdaterTest {
myDetails = new AtomicReference<>();
// setup
when(myJobPersistence.fetchInstance(TEST_INSTANCE_ID)).thenReturn(Optional.of(ourQueuedInstance));
when(myJobPersistence.fetchInstance(TEST_INSTANCE_ID)).thenReturn(Optional.of(myQueuedInstance));
when(myJobPersistence.updateInstance(myInstance)).thenReturn(true);
IJobCompletionHandler<TestParameters> errorHandler = details -> myDetails.set(details);
when(myJobDefinition.getErrorHandler()).thenReturn(errorHandler);
when(myJobDefinition.getParametersType()).thenReturn(TestParameters.class);
}