From 7067cf44911996a03fcaa9547997610f3eb984a5 Mon Sep 17 00:00:00 2001 From: Michael Buckley Date: Mon, 18 Mar 2024 13:29:41 -0400 Subject: [PATCH] sketch out test cases --- .../docs/server_jpa_batch/batch2_states.md | 4 +- .../pom.xml | 6 + .../batch2/test/IJobMaintenenaceActions.java | 111 ++++++++++++++++++ .../batch2/test/IWorkChunkStorageTests.java | 5 + .../maintenance/JobInstanceProcessor.java | 4 + 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-storage-batch2-test-utilities/src/main/java/ca/uhn/hapi/fhir/batch2/test/IJobMaintenenaceActions.java diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_batch/batch2_states.md b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_batch/batch2_states.md index b586e7c55bc..9d1afea884b 100644 --- a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_batch/batch2_states.md +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/docs/server_jpa_batch/batch2_states.md @@ -56,7 +56,9 @@ stateDiagram-v2 state FAILED state COMPLETED direction LR - [*] --> READY : on create - normal or step + [*] --> READY : on create - normal + [*] --> GATED : on create - gated + GATED --> READY : on create - gated READY --> QUEUED : placed on kafka (maint.) %% worker processing states diff --git a/hapi-fhir-storage-batch2-test-utilities/pom.xml b/hapi-fhir-storage-batch2-test-utilities/pom.xml index 774fb6c0233..fc56dda9e44 100644 --- a/hapi-fhir-storage-batch2-test-utilities/pom.xml +++ b/hapi-fhir-storage-batch2-test-utilities/pom.xml @@ -17,6 +17,12 @@ HAPI FHIR JPA Server - Batch2 specification tests Batch2 is a framework for managing and executing long running "batch" jobs + + 17 + 17 + 17 + + ca.uhn.hapi.fhir diff --git a/hapi-fhir-storage-batch2-test-utilities/src/main/java/ca/uhn/hapi/fhir/batch2/test/IJobMaintenenaceActions.java b/hapi-fhir-storage-batch2-test-utilities/src/main/java/ca/uhn/hapi/fhir/batch2/test/IJobMaintenenaceActions.java new file mode 100644 index 00000000000..625b13691da --- /dev/null +++ b/hapi-fhir-storage-batch2-test-utilities/src/main/java/ca/uhn/hapi/fhir/batch2/test/IJobMaintenenaceActions.java @@ -0,0 +1,111 @@ +package ca.uhn.hapi.fhir.batch2.test; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +import static org.junit.jupiter.api.Assertions.fail; + +public interface IJobMaintenenaceActions extends IWorkChunkCommon, WorkChunkTestConstants { + + // fixme step 1 is special - only 1 chunk. + // fixme cover step 1 to step 2 and step 2->3 + @ParameterizedTest + @ValueSource(strings={ + """ + 1|COMPLETE + 2|GATED + """, + """ + 1|COMPLETE + 2|QUEUED + """, + """ + 1|COMPLETE + 2|COMPLETE + 2|ERRORED + 2|IN_PROGRESS + """, + """ + 1|COMPLETE + 2|READY + 2|QUEUED + 2|COMPLETE + 2|ERRORED + 2|FAILED + 2|IN_PROGRESS + 3|GATED + 3|GATED + """, + """ + 1|COMPLETE + 2|READY + 2|QUEUED + 2|COMPLETE + 2|ERRORED + 2|FAILED + 2|IN_PROGRESS + 3|QUEUED # a lie + 3|GATED + """ + + } + ) + default void testGatedStep2NotReady_notAdvance(String theChunkState) { + // given + // need job instance definition + // step 1 + // step 2 + // step 3 + // IN STEP 2 + + // chunks + setupChunksInStates(theChunkState); + // when + // run job maintenance + + // then + // step not changed. + fail(); + } + + @ParameterizedTest + @ValueSource(strings={ + """ + # new code only + 1|COMPLETE + 2|COMPLETE + 2|COMPLETE + 3|GATED|READY + 3|GATED|READY + """, + """ + # OLD code only + 1|COMPLETE + 2|COMPLETE + 2|COMPLETE + 3|QUEUED|READY + 3|QUEUED|READY + """, + """ + # mixed code only + 1|COMPLETE + 2|COMPLETE + 2|COMPLETE + 3|GATED|READY + 3|QUEUED|READY + """ + + }) + default void testGatedStep2ReadyToAdvance_advanceToStep3(String theTestStates) { + // given + + // when + // then + fail(); + } + + + void setupChunksInStates(String theChunkState); + +} diff --git a/hapi-fhir-storage-batch2-test-utilities/src/main/java/ca/uhn/hapi/fhir/batch2/test/IWorkChunkStorageTests.java b/hapi-fhir-storage-batch2-test-utilities/src/main/java/ca/uhn/hapi/fhir/batch2/test/IWorkChunkStorageTests.java index 344ab2c4d96..dd4c98c584a 100644 --- a/hapi-fhir-storage-batch2-test-utilities/src/main/java/ca/uhn/hapi/fhir/batch2/test/IWorkChunkStorageTests.java +++ b/hapi-fhir-storage-batch2-test-utilities/src/main/java/ca/uhn/hapi/fhir/batch2/test/IWorkChunkStorageTests.java @@ -32,6 +32,10 @@ public interface IWorkChunkStorageTests extends IWorkChunkCommon, WorkChunkTestC assertNull(chunk.getData()); } + // fixme add test - testWorkChunkCreate_inReady + + // fixme add test - testNonGatedWorkChunkInReady_IsQueuedDuringMaintentaince + @Test default void testStoreAndFetchWorkChunk_WithData() { JobInstance instance = createInstance(); @@ -39,6 +43,7 @@ public interface IWorkChunkStorageTests extends IWorkChunkCommon, WorkChunkTestC String id = storeWorkChunk(JOB_DEFINITION_ID, TARGET_STEP_ID, instanceId, 0, CHUNK_DATA); assertNotNull(id); + // fixme drop this verify against READY state. runMaintenancePass(); runInTransaction(() -> assertEquals(WorkChunkStatusEnum.QUEUED, freshFetchWorkChunk(id).getStatus())); diff --git a/hapi-fhir-storage-batch2/src/main/java/ca/uhn/fhir/batch2/maintenance/JobInstanceProcessor.java b/hapi-fhir-storage-batch2/src/main/java/ca/uhn/fhir/batch2/maintenance/JobInstanceProcessor.java index 47ee0365bed..1c21747eeb8 100644 --- a/hapi-fhir-storage-batch2/src/main/java/ca/uhn/fhir/batch2/maintenance/JobInstanceProcessor.java +++ b/hapi-fhir-storage-batch2/src/main/java/ca/uhn/fhir/batch2/maintenance/JobInstanceProcessor.java @@ -391,6 +391,10 @@ public class JobInstanceProcessor { readyChunksForNextStep.size()); } + // fixme create a new persistence transition for state advance + // fixme update stepId to next step AND update all chunks in this step to READY (from GATED or QUEUED ;-P) + // fixme so we can queue them safely. + // update the job step so the workers will process them. // if it's the last (gated) step, there will be no change - but we should // queue up the chunks anyways