Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

<properties>
<jib.from.image>powsybl/java-dynawo:2.1.0</jib.from.image>
<gridsuite-dependencies.version>31</gridsuite-dependencies.version>
<gridsuite-dependencies.version>32</gridsuite-dependencies.version>
<liquibase-hibernate-package>org.gridsuite.securityanalysis.server</liquibase-hibernate-package>
<db-util.version>1.0.5</db-util.version>
<powsybl-network-store.version>1.16.0</powsybl-network-store.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ public ResponseEntity<Void> invalidateStatus(@Parameter(description = "Result uu
@Operation(summary = "Stop a security analysis computation")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis has been stopped")})
public ResponseEntity<Void> stop(@Parameter(description = "Result UUID") @PathVariable("resultUuid") UUID resultUuid,
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver) {
securityAnalysisService.stop(resultUuid, receiver);
@Parameter(description = "Result receiver") @RequestParam(name = "receiver", required = false) String receiver,
@RequestHeader(HEADER_USER_ID) String userId) {
securityAnalysisService.stop(resultUuid, receiver, userId);
return ResponseEntity.ok().build();
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ spring:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}sa.stopped
publishFailed-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}sa.failed
output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0;publishFailed-out-0
publishCancelFailed-out-0:
destination: ${powsybl-ws.rabbitmq.destination.prefix:}sa.cancelfailed
output-bindings: publishRun-out-0;publishResult-out-0;publishCancel-out-0;publishStopped-out-0;publishFailed-out-;publishCancelFailed-out-0

powsybl-ws:
database:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ public void stopTest() throws Exception {
// wait for security analysis to actually run before trying to stop it
countDownLatch.await();

mockMvc.perform(put("/" + VERSION + "/results/" + RESULT_UUID + "/stop"
+ "?receiver=me"))
mockMvc.perform(put("/" + VERSION + "/results/" + RESULT_UUID + "/stop" + "?receiver=me")
.header(HEADER_USER_ID, "testUserId"))
Comment on lines -651 to +652
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems here we manage to get the stopped notification and not the cancelfailed notification. Why ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think because we running in different thread and we wait

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// wait for security analysis to actually run before trying to stop it
countDownLatch.await();

And because in this service we have a SecurityAnalysisProviderMock which make:

// creating a long completable future which is here to be canceled
return new CompletableFuture<SecurityAnalysisReport>().completeOnTimeout(REPORT, 3, TimeUnit.SECONDS);

then we have the time to cancel the computation and obtain a clean sa.stopped

Both of those code parts seems absent of other computation services (LF, SE,Dy, CC etc...)
Should add it

.andExpect(status().isOk());

Message<byte[]> message = output.receive(TIMEOUT * 3, "sa.stopped");
Expand All @@ -658,6 +658,19 @@ public void stopTest() throws Exception {
assertEquals(getCancelMessage(COMPUTATION_TYPE), message.getHeaders().get("message"));
}

@Test
public void testStopAndFail() throws Exception {
UUID randomUuid = UUID.randomUUID();
mockMvc.perform(put("/" + VERSION + "/results/" + randomUuid + "/stop" + "?receiver=me")
.header(HEADER_USER_ID, "testUserId"))
.andExpect(status().isOk());

Message<byte[]> message = output.receive(TIMEOUT * 3, "sa.cancelfailed");
assertEquals(randomUuid.toString(), message.getHeaders().get("resultUuid"));
assertEquals("me", message.getHeaders().get("receiver"));
assertEquals(getCancelFailedMessage(COMPUTATION_TYPE), message.getHeaders().get("message"));
}

@Test
public void runTestWithError() throws Exception {
MvcResult mvcResult;
Expand Down
Loading