feat: Implement external job import logging functionality with independent log files
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package com.ruoyi.cms.externalimport;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class ExternalJobImportRunLogTest {
|
||||
@Test
|
||||
void createsIndependentUtf8LogForEachRun() throws Exception {
|
||||
Path directory = Files.createTempDirectory("external-job-import-run-log-");
|
||||
Path firstFile = null;
|
||||
Path secondFile = null;
|
||||
try {
|
||||
try (ExternalJobImportRunLog first = ExternalJobImportRunLog.open(directory.toString())) {
|
||||
first.info("第一份任务日志");
|
||||
firstFile = first.getFile();
|
||||
}
|
||||
try (ExternalJobImportRunLog second = ExternalJobImportRunLog.open(directory.toString())) {
|
||||
second.error("第二份任务日志异常", new IllegalStateException("test failure"));
|
||||
secondFile = second.getFile();
|
||||
}
|
||||
|
||||
assertTrue(Files.exists(firstFile));
|
||||
assertTrue(Files.exists(secondFile));
|
||||
assertNotEquals(firstFile, secondFile);
|
||||
assertTrue(new String(Files.readAllBytes(firstFile), StandardCharsets.UTF_8).contains("第一份任务日志"));
|
||||
assertTrue(new String(Files.readAllBytes(secondFile), StandardCharsets.UTF_8).contains("test failure"));
|
||||
} finally {
|
||||
if (firstFile != null) {
|
||||
Files.deleteIfExists(firstFile);
|
||||
}
|
||||
if (secondFile != null) {
|
||||
Files.deleteIfExists(secondFile);
|
||||
}
|
||||
Files.deleteIfExists(directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user