Skip to content

Commit

Permalink
Refactor TestParameterLoader. (#30876)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhucong authored Apr 13, 2024
1 parent 136ca67 commit 1c47a97
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.test.env.EnvironmentContext;
import org.apache.shardingsphere.test.loader.strategy.TestParameterLoadStrategy;
import org.apache.shardingsphere.test.loader.summary.FileSummary;
Expand Down Expand Up @@ -65,11 +66,26 @@ public final class TestParameterLoader {
*/
@SneakyThrows
public Stream<ExternalSQLTestParameter> load(final URI sqlCaseURI, final URI resultURI, final String databaseType, final String reportType) {
return load(sqlCaseURI, resultURI, databaseType, reportType, null);
}

/**
* Load test parameters.
*
* @param sqlCaseURI SQL case URI
* @param resultURI result URI
* @param databaseType database type
* @param reportType report type
* @param caseRegex case regex
* @return loaded test parameters
*/
@SneakyThrows
public Stream<ExternalSQLTestParameter> load(final URI sqlCaseURI, final URI resultURI, final String databaseType, final String reportType, final String caseRegex) {
Collection<FileSummary> sqlCaseFileSummaries = loadStrategy.loadSQLCaseFileSummaries(sqlCaseURI);
Collection<FileSummary> resultFileSummaries = loadStrategy.loadSQLCaseFileSummaries(resultURI);
Map<String, FileSummary> resultFileSummaryMap =
resultFileSummaries.stream().collect(Collectors.toMap(fileSummary -> Files.getNameWithoutExtension(fileSummary.getFileName()), Function.identity()));
return sqlCaseFileSummaries.stream().flatMap(each -> {
return sqlCaseFileSummaries.stream().filter(each -> StringUtils.isEmpty(caseRegex) || each.getFileName().matches(caseRegex)).flatMap(each -> {
List<String> sqlCaseFileContent = loadContent(URI.create(each.getAccessURI()));
String fileName = Files.getNameWithoutExtension(each.getFileName());
Optional<FileSummary> resultFileSummary = Optional.ofNullable(resultFileSummaryMap.get(fileName));
Expand Down

0 comments on commit 1c47a97

Please sign in to comment.