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
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ public ComputationS3Service(S3Client s3Client, String bucketName) {
this.bucketName = bucketName;
}

public void uploadFile(Path filePath, String s3Key, String fileName, Integer expireAfterMinutes) throws IOException {
public void uploadFile(Path filePath, String s3Key, String fileName) throws IOException {
try {
PutObjectRequest putRequest = PutObjectRequest.builder()
.bucket(bucketName)
.key(s3Key)
.metadata(Map.of(METADATA_FILE_NAME, fileName))
.tagging(expireAfterMinutes != null ? "expire-after-minutes=" + expireAfterMinutes : null)
.build();
s3Client.putObject(putRequest, RequestBody.fromFile(filePath));
} catch (SdkException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected void processDebug(AbstractResultContext<C> resultContext) {
resultService.saveDebugFileLocation(resultContext.getResultUuid(), s3Key);

// upload zip file to s3 storage
computationS3Service.uploadFile(debugFilePath, s3Key, fileName, 30);
computationS3Service.uploadFile(debugFilePath, s3Key, fileName);

// notify to study-server
sendDebugMessage(resultContext, null);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/gridsuite/computation/ComputationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ void testProcessDebugWithS3Service() throws IOException {

// Verify interactions
verify(resultService).saveDebugFileLocation(eq(RESULT_UUID), anyString());
verify(computationS3Service).uploadFile(any(Path.class), anyString(), anyString(), eq(30));
verify(computationS3Service).uploadFile(any(Path.class), anyString(), anyString());
verify(notificationService.getPublisher(), times(1 /* for result message */))
.send(eq("publishResult-out-0"), isA(Message.class));
verify(notificationService.getPublisher(), times(1 /* for debug message */))
Expand Down Expand Up @@ -459,7 +459,7 @@ void testProcessDebugWithIOException() throws IOException {
workerService.consumeRun().accept(message);

// Verify interactions
verify(computationS3Service, never()).uploadFile(any(), any(), any(), anyInt());
verify(computationS3Service, never()).uploadFile(any(), any(), any());
verify(resultService, never()).saveDebugFileLocation(any(), any());
verify(notificationService.getPublisher()).send(eq("publishDebug-out-0"), argThat((Message<String> msg) ->
msg.getHeaders().get(HEADER_ERROR_MESSAGE).equals("Zip error")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void uploadFileShouldSendSuccessful() throws IOException {
Files.writeString(tempFile, "Normal case");

// perform test
computationS3Service.uploadFile(tempFile, PATH_IN_S3, "test.txt", 30);
computationS3Service.uploadFile(tempFile, PATH_IN_S3, "test.txt");

// check result
ArgumentCaptor<PutObjectRequest> requestCaptor = ArgumentCaptor.forClass(PutObjectRequest.class);
Expand All @@ -63,7 +63,6 @@ void uploadFileShouldSendSuccessful() throws IOException {
assertThat(actualRequest.bucket()).isEqualTo("ws-bucket");
assertThat(actualRequest.key()).isEqualTo(PATH_IN_S3);
assertThat(actualRequest.metadata()).containsEntry(ComputationS3Service.METADATA_FILE_NAME, "test.txt");
assertThat(actualRequest.tagging()).isEqualTo("expire-after-minutes=30");
}

@Test
Expand All @@ -77,7 +76,7 @@ void uploadFileShouldThrowException() throws IOException {
.thenThrow(S3Exception.builder().message(UPLOAD_FAILED_MESSAGE).build());

// perform test and check
assertThatThrownBy(() -> computationS3Service.uploadFile(tempFile, "key", "name.txt", null))
assertThatThrownBy(() -> computationS3Service.uploadFile(tempFile, "key", "name.txt"))
.isInstanceOf(IOException.class)
.hasMessageContaining(UPLOAD_FAILED_MESSAGE);
}
Expand Down