From df8ba6be25f9d044e03aa68d9a68338bedf9b6ac Mon Sep 17 00:00:00 2001 From: Joris Mancini Date: Fri, 13 Dec 2024 16:17:08 +0100 Subject: [PATCH 1/3] feat: redirect build failures on rabbit dlq Signed-off-by: Joris Mancini --- pom.xml | 6 +++++- src/main/resources/config/application.yaml | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f3a4779a..bae1bba4 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,11 @@ - + + com.powsybl + powsybl-ws-commons + 1.18.0-SNAPSHOT + org.gridsuite diff --git a/src/main/resources/config/application.yaml b/src/main/resources/config/application.yaml index 0e4adfdb..632e73d0 100644 --- a/src/main/resources/config/application.yaml +++ b/src/main/resources/config/application.yaml @@ -20,6 +20,7 @@ spring: group: shortcircuitanalysisGroup consumer: concurrency: 2 + max-attempts: 1 publishRun-out-0: destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.run publishResult-out-0: @@ -30,11 +31,20 @@ spring: destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.cancel publishStopped-out-0: destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.stopped - publishFailed-out-0: - destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.failed publishCancelFailed-out-0: destination: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.cancelfailed - output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0;publishFailed-out-0:publishCancelFailed-out-0 + output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0:publishCancelFailed-out-0 + rabbit: + bindings: + consumeRun-in-0: + consumer: + auto-bind-dlq: true + dead-letter-exchange: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.run.dlx + dead-letter-queue-name: ${powsybl-ws.rabbitmq.destination.prefix:}shortcircuitanalysis.run.dlx.dlq + dead-letter-exchange-type: topic + quorum: + enabled: true + delivery-limit: 2 powsybl-ws: database: From 8c5d9ba8bc307eb4b39e9488ef28b20aa4d8982b Mon Sep 17 00:00:00 2001 From: Joris Mancini Date: Wed, 18 Dec 2024 14:43:15 +0100 Subject: [PATCH 2/3] fix: tests Signed-off-by: Joris Mancini --- pom.xml | 2 +- .../service/ShortCircuitWorkerService.java | 11 ---------- .../ShortCircuitAnalysisControllerTest.java | 20 +++++++------------ .../ShortCircuitWorkerServiceTest.java | 5 +++-- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index bae1bba4..ed5ecf92 100644 --- a/pom.xml +++ b/pom.xml @@ -87,7 +87,7 @@ com.powsybl powsybl-ws-commons - 1.18.0-SNAPSHOT + 1.19.0-SNAPSHOT diff --git a/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitWorkerService.java b/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitWorkerService.java index fe3125ed..a87c575d 100644 --- a/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitWorkerService.java +++ b/src/main/java/org/gridsuite/shortcircuit/server/service/ShortCircuitWorkerService.java @@ -101,17 +101,6 @@ protected void sendResultMessage(AbstractResultContext r resultContext.getRunContext().getUserId(), additionalHeaders); } - @Override - protected void publishFail(AbstractResultContext resultContext, String message) { - ShortCircuitRunContext context = resultContext.getRunContext(); - String busId = context.getBusId(); - Map additionalHeaders = new HashMap<>(); - additionalHeaders.put(HEADER_BUS_ID, busId); - - notificationService.publishFail(resultContext.getResultUuid(), resultContext.getRunContext().getReceiver(), - message, resultContext.getRunContext().getUserId(), getComputationType(), additionalHeaders); - } - @Override protected CompletableFuture getCompletableFuture(ShortCircuitRunContext runContext, String provider, UUID resultUuid) { List faults = runContext.getBusId() == null ? getAllBusfaultFromNetwork(runContext) : getBusFaultFromBusId(runContext); diff --git a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java index 4c9777c4..56bb4219 100644 --- a/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java +++ b/src/test/java/org/gridsuite/shortcircuit/server/ShortCircuitAnalysisControllerTest.java @@ -63,8 +63,7 @@ import static org.gridsuite.shortcircuit.server.TestUtils.unzip; import static org.gridsuite.shortcircuit.server.service.ShortCircuitResultContext.HEADER_BUS_ID; import static org.gridsuite.shortcircuit.server.service.ShortCircuitWorkerService.COMPUTATION_TYPE; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.doAnswer; @@ -197,7 +196,7 @@ public String getVersion() { private final String shortCircuitAnalysisRunDestination = "shortcircuitanalysis.run"; private final String shortCircuitAnalysisCancelDestination = "shortcircuitanalysis.cancel"; private final String shortCircuitAnalysisStoppedDestination = "shortcircuitanalysis.stopped"; - private final String shortCircuitAnalysisFailedDestination = "shortcircuitanalysis.failed"; + private final String shortCircuitAnalysisFailedDestination = "shortcircuitanalysis.run.dlx.dlq"; private final String shortCircuitAnalysisCancelFailedDestination = "shortcircuitanalysis.cancelfailed"; @Autowired @@ -665,11 +664,7 @@ void runWithBusBarSectionIdAndErrorTest() throws Exception { assertEquals("me", runMessage.getHeaders().get("receiver")); assertEquals("BUSBARSECTION_ID_NOT_EXISTING", runMessage.getHeaders().get(HEADER_BUS_ID)); - Message failedMessage = output.receive(TIMEOUT, shortCircuitAnalysisFailedDestination); - assertEquals(RESULT_UUID.toString(), failedMessage.getHeaders().get("resultUuid")); - assertEquals("me", failedMessage.getHeaders().get("receiver")); - assertEquals("BUSBARSECTION_ID_NOT_EXISTING", failedMessage.getHeaders().get(HEADER_BUS_ID)); - + assertNull(output.receive(TIMEOUT, shortCircuitAnalysisResultDestination)); mockMvc.perform(get( "/" + VERSION + "/results/{resultUuid}", RESULT_UUID)) .andExpect(status().isNotFound()); @@ -851,11 +846,10 @@ void runWithNoShortCircuitDataTest() throws Exception { assertEquals(RESULT_UUID.toString(), runMessage.getHeaders().get("resultUuid")); assertEquals("me", runMessage.getHeaders().get("receiver")); - //networkWithoutExtension has no shortcircuit data so the computation should fail - Message resultMessage = output.receive(TIMEOUT, shortCircuitAnalysisFailedDestination); - assertEquals("Short circuit analysis has failed : Missing short-circuit extension data", resultMessage.getHeaders().get("message")); - assertEquals(RESULT_UUID.toString(), resultMessage.getHeaders().get("resultUuid")); - assertEquals("me", resultMessage.getHeaders().get("receiver")); + assertNull(output.receive(TIMEOUT, shortCircuitAnalysisResultDestination)); + mockMvc.perform(get( + "/" + VERSION + "/results/{resultUuid}", RESULT_UUID)) + .andExpect(status().isNotFound()); } } diff --git a/src/test/java/org/gridsuite/shortcircuit/server/service/ShortCircuitWorkerServiceTest.java b/src/test/java/org/gridsuite/shortcircuit/server/service/ShortCircuitWorkerServiceTest.java index 338c8b25..8600eefa 100644 --- a/src/test/java/org/gridsuite/shortcircuit/server/service/ShortCircuitWorkerServiceTest.java +++ b/src/test/java/org/gridsuite/shortcircuit/server/service/ShortCircuitWorkerServiceTest.java @@ -17,6 +17,7 @@ import com.powsybl.network.store.client.NetworkStoreService; import com.powsybl.network.store.client.PreloadingStrategy; import com.powsybl.shortcircuit.*; +import com.powsybl.ws.commons.computation.ComputationException; import com.powsybl.ws.commons.computation.service.ExecutionService; import com.powsybl.ws.commons.computation.service.NotificationService; import com.powsybl.ws.commons.computation.service.ReportService; @@ -43,6 +44,7 @@ import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; @@ -148,8 +150,7 @@ void testGetBusFaultFromOutOfVoltageBus() throws Exception { try (var shortCircuitAnalysisMockedStatic = TestUtils.injectShortCircuitAnalysisProvider(analysisProvider); var shortCircuitResultContextMockedStatic = mockStatic(ShortCircuitResultContext.class)) { shortCircuitResultContextMockedStatic.when(() -> ShortCircuitResultContext.fromMessage(message, objectMapper)).thenReturn(resultContext); - workerService.consumeRun().accept(message); - verify(notificationService).publishFail(any(), any(), eq("Selected bus is out of voltage"), any(), any(), any()); + assertThrows(ComputationException.class, () -> workerService.consumeRun().accept(message)); } } From 34a7f56fe6ce392e4b46f428b84bd3f74f3e83ca Mon Sep 17 00:00:00 2001 From: Joris Mancini <53527338+TheMaskedTurtle@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:27:49 +0100 Subject: [PATCH 3/3] Bump powsybl-ws-commons to 1.19.0 Signed-off-by: Joris Mancini <53527338+TheMaskedTurtle@users.noreply.github.com> --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ed5ecf92..8b84dcc9 100644 --- a/pom.xml +++ b/pom.xml @@ -84,10 +84,10 @@ - + com.powsybl powsybl-ws-commons - 1.19.0-SNAPSHOT + 1.19.0