Skip to content
Closed
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 @@ -132,6 +132,8 @@ public Boolean startReplicationTask() {
public Boolean checkFinishedReplicationTask() {
log.info("checkFinishedReplicationTask ......");
awaitReplicationTaskStatus(STATUS.STOPPED);
// shutdown client
client.shutdown();
String stopReason = describeReplicationTasks().getStopReason();
return stopReason.endsWith(STATUS.FINISH_END_TOKEN);
}
Expand All @@ -145,6 +147,8 @@ public void stopReplicationTask() {
.withReplicationTaskArn(replicationTaskArn);
client.stopReplicationTask(request);
awaitReplicationTaskStatus(STATUS.STOPPED);
// shutdown client
client.shutdown();
}

public Boolean deleteReplicationTask() {
Expand All @@ -158,6 +162,8 @@ public Boolean deleteReplicationTask() {
} catch (ResourceNotFoundException e) {
isDeleteSuccessfully = true;
}
// shutdown client
client.shutdown();
return isDeleteSuccessfully;
}

Expand Down Expand Up @@ -268,8 +274,8 @@ public String replaceFileParameters(String parameter) throws IOException {
}
if (parameter.startsWith("file://")) {
String filePath = parameter.substring(7);
try {
return IOUtils.toString(new FileInputStream(filePath), StandardCharsets.UTF_8);
try (FileInputStream fis = new FileInputStream(filePath)) {
return IOUtils.toString(fis, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new IOException("Error reading file: " + filePath, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Arrays;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -238,4 +242,61 @@ public void testAwaitReplicationTaskStatus() {
}
});
}

@Test
public void replaceFileParameters_NullParameter_ReturnsNull() throws IOException {
Assertions.assertTimeout(Duration.ofMillis(60000), () -> {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
mockHook.when(DmsHook::createClient).thenReturn(client);
DmsHook dmsHook = spy(new DmsHook());
String parameter = null;
String result = dmsHook.replaceFileParameters(parameter);
Assertions.assertEquals(null, result);
}
});
}

@Test
public void replaceFileParameters_NormalString_ReturnsSameString() throws IOException {
Assertions.assertTimeout(Duration.ofMillis(60000), () -> {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
mockHook.when(DmsHook::createClient).thenReturn(client);
DmsHook dmsHook = spy(new DmsHook());
String parameter = "normal string";
String result = dmsHook.replaceFileParameters(parameter);
Assertions.assertEquals(parameter, result);
}
});
}

@Test
public void replaceFileParameters_FileExists_ReturnsFileContent() throws IOException {
Assertions.assertTimeout(Duration.ofMillis(60000), () -> {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
mockHook.when(DmsHook::createClient).thenReturn(client);
DmsHook dmsHook = spy(new DmsHook());
File tempFile = new File("tempFile.txt");
String fileContent = "content of the file";
FileUtils.writeStringToFile(tempFile, fileContent, StandardCharsets.UTF_8);
String parameter = "file://" + tempFile.getAbsolutePath();
String result = dmsHook.replaceFileParameters(parameter);
Assertions.assertEquals(fileContent, result);
}
});
}

@Test
public void replaceFileParameters_FileNotExists_ThrowsIOException() {
Assertions.assertTimeout(Duration.ofMillis(60000), () -> {
try (MockedStatic<DmsHook> mockHook = Mockito.mockStatic(DmsHook.class)) {
mockHook.when(DmsHook::createClient).thenReturn(client);
DmsHook dmsHook = spy(new DmsHook());
String parameter = "file://nonexistentfile.txt";
Assertions.assertThrows(IOException.class, () -> {
dmsHook.replaceFileParameters(parameter);
});
}
});
}

}
Loading