From 4d3b7fd91bcf316878b8482c7c540e61960198f7 Mon Sep 17 00:00:00 2001 From: Joanna Jeremicz Date: Wed, 16 Oct 2019 14:15:20 +0200 Subject: Fix El-alto staging job - Clean up scheduledTasksRunner after previous integration tests - Prevent race condition Change-Id: I2e112be27d736406b30ccfbfe0f762c164becb6c Issue-ID: DCAEGEN2-1853 Signed-off-by: Joanna Jeremicz --- .../PrhWorkflowSchedulingIntegrationTest.java | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'prh-app-server/src/test') diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/PrhWorkflowSchedulingIntegrationTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/PrhWorkflowSchedulingIntegrationTest.java index 44dcabfa..fffab218 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/PrhWorkflowSchedulingIntegrationTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/integration/PrhWorkflowSchedulingIntegrationTest.java @@ -20,22 +20,45 @@ package org.onap.dcaegen2.services.prh.integration; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.doAnswer; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; +import org.mockito.stubbing.Answer; import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; - -import static org.mockito.Mockito.verify; +import org.springframework.test.context.TestPropertySource; @SpringBootTest +@TestPropertySource(properties = {"prh.workflow-scheduling-interval=20ms"}) class PrhWorkflowSchedulingIntegrationTest { + private static final int EXPECTED_INVOCATIONS_NUMBER = 1; + private static final int REMAINING_INVOCATIONS_NUMBER = 0; @MockBean private ScheduledTasks scheduledTasks; + private CountDownLatch invocationLatch; @Test - void prhWorkflowShouldBeExecutedRightAfterApplicationStart() { - verify(scheduledTasks).scheduleMainPrhEventTask(); + void prhWorkflowShouldBeExecutedRightAfterApplicationStart() throws InterruptedException { + invocationLatch = new CountDownLatch(EXPECTED_INVOCATIONS_NUMBER); + doAnswer(registerInvocation(invocationLatch)).when(scheduledTasks).scheduleMainPrhEventTask(); + assertThatMethodWasInvokedOnce(); + } + + private void assertThatMethodWasInvokedOnce() throws InterruptedException { + invocationLatch.await(1, TimeUnit.SECONDS); + assertEquals(REMAINING_INVOCATIONS_NUMBER, invocationLatch.getCount()); + } + + private static Answer registerInvocation(CountDownLatch invocationLatch) { + return invocation -> { + invocationLatch.countDown(); + return null; + }; } } \ No newline at end of file -- cgit 1.2.3-korg