26
26
import lombok .extern .slf4j .Slf4j ;
27
27
import org .assertj .core .api .WithAssertions ;
28
28
import org .gridsuite .computation .dto .ReportInfos ;
29
+ import org .gridsuite .computation .s3 .ComputationS3Service ;
29
30
import org .gridsuite .computation .s3 .S3InputStreamInfos ;
30
- import org .gridsuite .computation .s3 .S3Service ;
31
31
import org .gridsuite .computation .service .*;
32
32
import org .junit .jupiter .api .AfterEach ;
33
33
import org .junit .jupiter .api .BeforeEach ;
60
60
import java .util .concurrent .CompletableFuture ;
61
61
import java .util .concurrent .ForkJoinPool ;
62
62
63
- import static org .gridsuite .computation .s3 .S3Service .S3_DELIMITER ;
64
- import static org .gridsuite .computation .s3 .S3Service .S3_SERVICE_NOT_AVAILABLE_MESSAGE ;
63
+ import static org .gridsuite .computation .s3 .ComputationS3Service .S3_DELIMITER ;
64
+ import static org .gridsuite .computation .s3 .ComputationS3Service .S3_SERVICE_NOT_AVAILABLE_MESSAGE ;
65
65
import static org .gridsuite .computation .service .NotificationService .*;
66
66
import static org .junit .jupiter .api .Assertions .*;
67
67
import static org .mockito .ArgumentMatchers .*;
@@ -97,7 +97,7 @@ class ComputationTest implements WithAssertions {
97
97
@ Mock
98
98
private Network network ;
99
99
@ Mock
100
- private S3Service s3Service ;
100
+ private ComputationS3Service computationS3Service ;
101
101
102
102
private enum MockComputationStatus {
103
103
NOT_DONE ,
@@ -164,8 +164,8 @@ protected MockComputationResultContext(UUID resultUuid, MockComputationRunContex
164
164
}
165
165
166
166
private static class MockComputationService extends AbstractComputationService <MockComputationRunContext , MockComputationResultService , MockComputationStatus > {
167
- protected MockComputationService (NotificationService notificationService , MockComputationResultService resultService , S3Service s3Service , ObjectMapper objectMapper , UuidGeneratorService uuidGeneratorService , String defaultProvider ) {
168
- super (notificationService , resultService , s3Service , objectMapper , uuidGeneratorService , defaultProvider );
167
+ protected MockComputationService (NotificationService notificationService , MockComputationResultService resultService , ComputationS3Service computationS3Service , ObjectMapper objectMapper , UuidGeneratorService uuidGeneratorService , String defaultProvider ) {
168
+ super (notificationService , resultService , computationS3Service , objectMapper , uuidGeneratorService , defaultProvider );
169
169
}
170
170
171
171
@ Override
@@ -187,8 +187,8 @@ private enum ComputationResultWanted {
187
187
}
188
188
189
189
private static class MockComputationWorkerService extends AbstractWorkerService <Object , MockComputationRunContext , Object , MockComputationResultService > {
190
- protected MockComputationWorkerService (NetworkStoreService networkStoreService , NotificationService notificationService , ReportService reportService , MockComputationResultService resultService , S3Service s3Service , ExecutionService executionService , AbstractComputationObserver <Object , Object > observer , ObjectMapper objectMapper ) {
191
- super (networkStoreService , notificationService , reportService , resultService , s3Service , executionService , observer , objectMapper );
190
+ protected MockComputationWorkerService (NetworkStoreService networkStoreService , NotificationService notificationService , ReportService reportService , MockComputationResultService resultService , ComputationS3Service computationS3Service , ExecutionService executionService , AbstractComputationObserver <Object , Object > observer , ObjectMapper objectMapper ) {
191
+ super (networkStoreService , notificationService , reportService , resultService , computationS3Service , executionService , observer , objectMapper );
192
192
}
193
193
194
194
@ Override
@@ -257,12 +257,12 @@ void init() throws IOException {
257
257
notificationService ,
258
258
reportService ,
259
259
resultService ,
260
- s3Service ,
260
+ computationS3Service ,
261
261
executionService ,
262
262
new MockComputationObserver (ObservationRegistry .create (), new SimpleMeterRegistry ()),
263
263
objectMapper
264
264
);
265
- computationService = new MockComputationService (notificationService , resultService , s3Service , objectMapper , uuidGeneratorService , provider );
265
+ computationService = new MockComputationService (notificationService , resultService , computationS3Service , objectMapper , uuidGeneratorService , provider );
266
266
267
267
MessageBuilder <String > builder = MessageBuilder
268
268
.withPayload ("" )
@@ -392,7 +392,7 @@ void testProcessDebugWithS3Service() throws IOException {
392
392
393
393
// Verify interactions
394
394
verify (resultService ).saveDebugFileLocation (eq (RESULT_UUID ), anyString ());
395
- verify (s3Service ).uploadFile (any (Path .class ), anyString (), anyString (), eq (30 ));
395
+ verify (computationS3Service ).uploadFile (any (Path .class ), anyString (), anyString (), eq (30 ));
396
396
verify (notificationService .getPublisher (), times (1 /* for result message */ ))
397
397
.send (eq ("publishResult-out-0" ), isA (Message .class ));
398
398
verify (notificationService .getPublisher (), times (1 /* for debug message */ ))
@@ -411,7 +411,7 @@ void testConsumeRunWithoutDebug() {
411
411
workerService .consumeRun ().accept (message );
412
412
413
413
// Verify interactions
414
- verifyNoInteractions (s3Service , resultService );
414
+ verifyNoInteractions (computationS3Service , resultService );
415
415
verify (notificationService .getPublisher (), times (1 /* only result */ ))
416
416
.send (eq ("publishResult-out-0" ), isA (Message .class ));
417
417
verify (notificationService .getPublisher (), times (0 /* no debug */ ))
@@ -420,7 +420,7 @@ void testConsumeRunWithoutDebug() {
420
420
421
421
@ Test
422
422
void testProcessDebugWithoutS3Service () {
423
- // Setup worker service without S3Service
423
+ // Setup worker service without ComputationS3Service
424
424
workerService = new MockComputationWorkerService (
425
425
networkStoreService ,
426
426
notificationService ,
@@ -441,7 +441,7 @@ void testProcessDebugWithoutS3Service() {
441
441
// Verify
442
442
verify (notificationService .getPublisher ()).send (eq ("publishDebug-out-0" ), argThat ((Message <String > msg ) ->
443
443
msg .getHeaders ().get (HEADER_ERROR_MESSAGE ).equals (S3_SERVICE_NOT_AVAILABLE_MESSAGE )));
444
- verifyNoInteractions (s3Service , resultService );
444
+ verifyNoInteractions (computationS3Service , resultService );
445
445
}
446
446
447
447
@ Test
@@ -459,7 +459,7 @@ void testProcessDebugWithIOException() throws IOException {
459
459
workerService .consumeRun ().accept (message );
460
460
461
461
// Verify interactions
462
- verify (s3Service , never ()).uploadFile (any (), any (), any (), anyInt ());
462
+ verify (computationS3Service , never ()).uploadFile (any (), any (), any (), anyInt ());
463
463
verify (resultService , never ()).saveDebugFileLocation (any (), any ());
464
464
verify (notificationService .getPublisher ()).send (eq ("publishDebug-out-0" ), argThat ((Message <String > msg ) ->
465
465
msg .getHeaders ().get (HEADER_ERROR_MESSAGE ).equals ("Zip error" )));
@@ -478,7 +478,7 @@ void testDownloadDebugFileSuccess() throws IOException {
478
478
.fileLength (fileLength )
479
479
.build ();
480
480
when (resultService .findDebugFileLocation (RESULT_UUID )).thenReturn (S3_KEY );
481
- when (s3Service .downloadFile (S3_KEY )).thenReturn (s3InputStreamInfos );
481
+ when (computationS3Service .downloadFile (S3_KEY )).thenReturn (s3InputStreamInfos );
482
482
483
483
// Execute
484
484
ResponseEntity <?> response = computationService .downloadDebugFile (RESULT_UUID );
@@ -489,7 +489,7 @@ void testDownloadDebugFileSuccess() throws IOException {
489
489
assertThat (response .getHeaders ().getContentType ()).isEqualTo (MediaType .APPLICATION_OCTET_STREAM );
490
490
assertThat (response .getHeaders ().getContentLength ()).isEqualTo (fileLength );
491
491
assertThat (response .getHeaders ().get (HttpHeaders .CONTENT_DISPOSITION )).contains ("attachment; filename=\" " + fileName + "\" " );
492
- verify (s3Service ).downloadFile (S3_KEY );
492
+ verify (computationS3Service ).downloadFile (S3_KEY );
493
493
}
494
494
495
495
@ Test
@@ -499,7 +499,7 @@ void testDownloadDebugFileS3NotAvailable() throws IOException {
499
499
500
500
// Execute & Check
501
501
assertThrows (PowsyblException .class , () -> computationService .downloadDebugFile (RESULT_UUID ), "S3 service not available" );
502
- verify (s3Service , never ()).downloadFile (any ());
502
+ verify (computationS3Service , never ()).downloadFile (any ());
503
503
}
504
504
505
505
@ Test
@@ -512,21 +512,21 @@ void testDownloadDebugFileNotFound() throws IOException {
512
512
513
513
// Check
514
514
assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .NOT_FOUND );
515
- verify (s3Service , never ()).downloadFile (any ());
515
+ verify (computationS3Service , never ()).downloadFile (any ());
516
516
}
517
517
518
518
@ Test
519
519
void testDownloadDebugFileIOException () throws IOException {
520
520
// Setup
521
521
when (resultService .findDebugFileLocation (RESULT_UUID )).thenReturn (S3_KEY );
522
- when (s3Service .downloadFile (S3_KEY )).thenThrow (new IOException ("S3 error" ));
522
+ when (computationS3Service .downloadFile (S3_KEY )).thenThrow (new IOException ("S3 error" ));
523
523
524
524
// Act
525
525
ResponseEntity <?> response = computationService .downloadDebugFile (RESULT_UUID );
526
526
527
527
// Assert
528
528
assertThat (response .getStatusCode ()).isEqualTo (HttpStatus .NOT_FOUND );
529
- verify (s3Service ).downloadFile (S3_KEY );
529
+ verify (computationS3Service ).downloadFile (S3_KEY );
530
530
}
531
531
532
532
}
0 commit comments