|
@@ -19,14 +19,15 @@ package org.apache.dolphinscheduler.plugin.task.api.parser;
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
|
-import java.io.IOException;
|
|
|
import java.net.URI;
|
|
|
-import java.net.URISyntaxException;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Paths;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import lombok.SneakyThrows;
|
|
|
+
|
|
|
import org.junit.jupiter.api.Assertions;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
@@ -35,7 +36,7 @@ import com.google.common.collect.ImmutableMap;
|
|
|
class TaskOutputParameterParserTest {
|
|
|
|
|
|
@Test
|
|
|
- void testEmptyLog() throws IOException, URISyntaxException {
|
|
|
+ void testEmptyLog() {
|
|
|
List<String> varPools = getLogs("/outputParam/emptyVarPoolLog.txt");
|
|
|
TaskOutputParameterParser taskOutputParameterParser = new TaskOutputParameterParser();
|
|
|
varPools.forEach(taskOutputParameterParser::appendParseLog);
|
|
@@ -43,7 +44,7 @@ class TaskOutputParameterParserTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- void testOneLineLog() throws IOException, URISyntaxException {
|
|
|
+ void testOneLineLog() {
|
|
|
List<String> varPools = getLogs("/outputParam/onelineVarPoolLog.txt");
|
|
|
TaskOutputParameterParser taskOutputParameterParser = new TaskOutputParameterParser();
|
|
|
varPools.forEach(taskOutputParameterParser::appendParseLog);
|
|
@@ -51,7 +52,7 @@ class TaskOutputParameterParserTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- void testOneVarPollInMultiLineLog() throws IOException, URISyntaxException {
|
|
|
+ void testOneVarPoolInMultiLineLog() {
|
|
|
List<String> varPools = getLogs("/outputParam/oneVarPollInMultiLineLog.txt");
|
|
|
TaskOutputParameterParser taskOutputParameterParser = new TaskOutputParameterParser();
|
|
|
varPools.forEach(taskOutputParameterParser::appendParseLog);
|
|
@@ -63,14 +64,46 @@ class TaskOutputParameterParserTest {
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- void testVarPollInMultiLineLog() throws IOException, URISyntaxException {
|
|
|
- List<String> varPools = getLogs("/outputParam/multipleVarPoll.txt");
|
|
|
+ void testVarPoolInMultiLineLog() {
|
|
|
+ List<String> varPools = getLogs("/outputParam/multipleVarPool.txt");
|
|
|
TaskOutputParameterParser taskOutputParameterParser = new TaskOutputParameterParser();
|
|
|
varPools.forEach(taskOutputParameterParser::appendParseLog);
|
|
|
assertEquals(ImmutableMap.of("name", "tom", "age", "1"), taskOutputParameterParser.getTaskOutputParams());
|
|
|
}
|
|
|
|
|
|
- private List<String> getLogs(String file) throws IOException, URISyntaxException {
|
|
|
+ @Test
|
|
|
+ void textVarPoolExceedMaxRows() {
|
|
|
+ List<String> varPools = getLogs("/outputParam/maxRowsVarPool.txt");
|
|
|
+ TaskOutputParameterParser taskOutputParameterParser = new TaskOutputParameterParser(2, Integer.MAX_VALUE);
|
|
|
+ varPools.forEach(taskOutputParameterParser::appendParseLog);
|
|
|
+ assertEquals(Collections.emptyMap(), taskOutputParameterParser.getTaskOutputParams());
|
|
|
+
|
|
|
+ taskOutputParameterParser = new TaskOutputParameterParser();
|
|
|
+ varPools.forEach(taskOutputParameterParser::appendParseLog);
|
|
|
+ assertEquals(ImmutableMap.of("name", "name=tom\n" +
|
|
|
+ "name=name=tom\n" +
|
|
|
+ "name=name=tom\n" +
|
|
|
+ "name=name=tom\n" +
|
|
|
+ "name=name=tom"), taskOutputParameterParser.getTaskOutputParams());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void textVarPoolExceedMaxLength() {
|
|
|
+ List<String> varPools = getLogs("/outputParam/maxLengthVarPool.txt");
|
|
|
+ TaskOutputParameterParser taskOutputParameterParser = new TaskOutputParameterParser(2, 10);
|
|
|
+ varPools.forEach(taskOutputParameterParser::appendParseLog);
|
|
|
+ assertEquals(Collections.emptyMap(), taskOutputParameterParser.getTaskOutputParams());
|
|
|
+
|
|
|
+ taskOutputParameterParser = new TaskOutputParameterParser();
|
|
|
+ varPools.forEach(taskOutputParameterParser::appendParseLog);
|
|
|
+ assertEquals(ImmutableMap.of("name", "123456789\n" +
|
|
|
+ "12345\n"), taskOutputParameterParser.getTaskOutputParams());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @SneakyThrows
|
|
|
+ private List<String> getLogs(String file) {
|
|
|
URI uri = TaskOutputParameterParserTest.class.getResource(file).toURI();
|
|
|
return Files.lines(Paths.get(uri)).collect(Collectors.toList());
|
|
|
}
|