diff --git a/core/src/test/java/com/netflix/conductor/core/events/TestSimpleActionProcessor.java b/core/src/test/java/com/netflix/conductor/core/events/TestSimpleActionProcessor.java index bed7801290..e86ef79225 100644 --- a/core/src/test/java/com/netflix/conductor/core/events/TestSimpleActionProcessor.java +++ b/core/src/test/java/com/netflix/conductor/core/events/TestSimpleActionProcessor.java @@ -16,12 +16,13 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.stubbing.Answer; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Configuration; import org.springframework.retry.annotation.EnableRetry; import org.springframework.test.context.ContextConfiguration; @@ -49,6 +50,7 @@ import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; +@SpringBootTest @ContextConfiguration( classes = { TestObjectMapperConfiguration.class, @@ -57,9 +59,8 @@ @RunWith(SpringRunner.class) public class TestSimpleActionProcessor { - private WorkflowExecutor workflowExecutor; - private ExternalPayloadStorageUtils externalPayloadStorageUtils; - private SimpleActionProcessor actionProcessor; + @MockBean private WorkflowExecutor workflowExecutor; + @MockBean private ExternalPayloadStorageUtils externalPayloadStorageUtils; @Autowired private ObjectMapper objectMapper; @@ -67,19 +68,6 @@ public class TestSimpleActionProcessor { @Configuration public static class TestConfiguration {} - @Before - public void setup() { - externalPayloadStorageUtils = mock(ExternalPayloadStorageUtils.class); - - workflowExecutor = mock(WorkflowExecutor.class); - - actionProcessor = - new SimpleActionProcessor( - workflowExecutor, - new ParametersUtils(objectMapper), - new JsonUtils(objectMapper)); - } - @SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testStartWorkflow_correlationId() throws Exception { @@ -114,6 +102,11 @@ public void testStartWorkflow_correlationId() throws Exception { anyMap())) .thenReturn("workflow_1"); + SimpleActionProcessor actionProcessor = + new SimpleActionProcessor( + workflowExecutor, + new ParametersUtils(objectMapper), + new JsonUtils(objectMapper)); Map output = actionProcessor.execute(action, payload, "testEvent", "testMessage"); @@ -170,6 +163,11 @@ public void testStartWorkflow() throws Exception { anyMap())) .thenReturn("workflow_1"); + SimpleActionProcessor actionProcessor = + new SimpleActionProcessor( + workflowExecutor, + new ParametersUtils(objectMapper), + new JsonUtils(objectMapper)); Map output = actionProcessor.execute(action, payload, "testEvent", "testMessage"); @@ -220,6 +218,11 @@ public void testCompleteTask() throws Exception { when(workflowExecutor.getWorkflow(eq("workflow_1"), anyBoolean())).thenReturn(workflow); doNothing().when(externalPayloadStorageUtils).verifyAndUpload(any(), any()); + SimpleActionProcessor actionProcessor = + new SimpleActionProcessor( + workflowExecutor, + new ParametersUtils(objectMapper), + new JsonUtils(objectMapper)); actionProcessor.execute(action, payload, "testEvent", "testMessage"); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(TaskResult.class); @@ -267,6 +270,11 @@ public void testCompleteLoopOverTask() throws Exception { when(workflowExecutor.getWorkflow(eq("workflow_1"), anyBoolean())).thenReturn(workflow); doNothing().when(externalPayloadStorageUtils).verifyAndUpload(any(), any()); + SimpleActionProcessor actionProcessor = + new SimpleActionProcessor( + workflowExecutor, + new ParametersUtils(objectMapper), + new JsonUtils(objectMapper)); actionProcessor.execute(action, payload, "testEvent", "testMessage"); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(TaskResult.class); @@ -309,6 +317,11 @@ public void testCompleteTaskByTaskId() throws Exception { when(workflowExecutor.getTask(eq("task_1"))).thenReturn(task); doNothing().when(externalPayloadStorageUtils).verifyAndUpload(any(), any()); + SimpleActionProcessor actionProcessor = + new SimpleActionProcessor( + workflowExecutor, + new ParametersUtils(objectMapper), + new JsonUtils(objectMapper)); actionProcessor.execute(action, payload, "testEvent", "testMessage"); ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(TaskResult.class); @@ -326,7 +339,6 @@ public void testCompleteTaskByTaskId() throws Exception { @Test public void testExecuteTransientException() { - WorkflowExecutor workflowExec = mock(WorkflowExecutor.class); AtomicInteger executeInvoked = new AtomicInteger(0); doAnswer( (Answer) @@ -334,7 +346,7 @@ public void testExecuteTransientException() { executeInvoked.incrementAndGet(); throw new TransientException("some retriable error"); }) - .when(workflowExec) + .when(workflowExecutor) .startWorkflow( anyString(), anyInt(), @@ -344,9 +356,9 @@ public void testExecuteTransientException() { anyString(), anyMap()); - SimpleActionProcessor actionProc = + SimpleActionProcessor actionProcessor = new SimpleActionProcessor( - workflowExec, + workflowExecutor, new ParametersUtils(objectMapper), new JsonUtils(objectMapper)); @@ -358,7 +370,7 @@ public void testExecuteTransientException() { action.setAction(Type.start_workflow); action.setStart_workflow(startWorkflow); - actionProc.execute(action, "{\"key\": \"value\"}", "testEvent", "testMessage"); + actionProcessor.execute(action, "{\"key\": \"value\"}", "testEvent", "testMessage"); assertEquals(3, executeInvoked.get()); } } diff --git a/server/src/main/java/com/netflix/conductor/Conductor.java b/server/src/main/java/com/netflix/conductor/Conductor.java index de253a7e20..bc0ef741ed 100644 --- a/server/src/main/java/com/netflix/conductor/Conductor.java +++ b/server/src/main/java/com/netflix/conductor/Conductor.java @@ -22,10 +22,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.core.io.FileSystemResource; +import org.springframework.retry.annotation.EnableRetry; // Prevents from the datasource beans to be loaded, AS they are needed only for specific databases. // In case that SQL database is selected this class will be imported back in the appropriate // database persistence module. +@EnableRetry @SpringBootApplication(exclude = DataSourceAutoConfiguration.class) public class Conductor {