gpt4 book ai didi

junit - Java GC 开销限制错误使用 JUnit 5 TestFactory 和大量的 dynamicTest (DynamicContainer/DynamicNode)

转载 作者:行者123 更新时间:2023-12-05 07:33:22 25 4
gpt4 key购买 nike

我在尝试使用 maven-surefire-plugin 2.21.0 创建和运行大量 JUnit 5 动态测试时遇到以下问题

[ERROR] GC overhead limit exceeded [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process [ERROR] GC overhead limit exceeded [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:673) [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:535) [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:280) [ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:245) [ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1124) [ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:954) [ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:832) [ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154) [ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146) [ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117) [ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81) [ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) [ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)

下面是我的代码,它是一个数据库比较工具。基本上我在做的是,从两个数据库流式传输数据并比较记录,如果两个记录中的任何一个存在差异,则测试失败,因此将创建与数据库中记录一样多的动态测试(~14M),相当大,不确定动态测试是否打算在这种规模下使用。非常感谢这方面的任何帮助:)

 @TestFactory
Stream<DynamicNode> dynamicTestsWithContainers() throws SQLException {
return tableNameProvider()//List of db tables ~100
.map(tableName -> dynamicContainer(tableName, dynamicNodeStream(tableName)));
}

private Stream<DynamicNode> dynamicNodeStream(String tableName) {

try {
System.out.println("Testing " + tableName);
Stream<Row> rows = sourceRepo.rows(tableName);
Stream<List<Row>> batchRows = batch(rows, 10000);
Optional<TableSchema> tableInfo = sourceRepo.getTableSchema(tableName);


final Stream<DynamicNode> dynamicNodeStream = batchRows
.flatMap(batch -> {

Map<String, Row> sourceRowsMap = buildRowMap(batch, tableInfo.get());//HashMap with 10000 Objects
Map<String, Row> targetRowsMap = targetRepo.getTargetDBRows(sourceRowsMap, tableInfo.get());//HashMap with 10000 Objects
Set<String> commonKeys = Sets.intersection(sourceRowsMap.keySet(), targetRowsMap.keySet());

final Stream<DynamicTest> dynamicTestStream = Streams.concat(
Stream.of(
dynamicTest("All source records should be present in target DB", () -> assertThat(targetRowsMap.keySet())
.as("Comparing " + sourceRepo.getServerName() + " against " + targetRepo.getServerName())
.hasSameElementsAs(sourceRowsMap.keySet()))
),
commonKeys
.stream()
.map(rowKey -> dynamicTest(tableName + " Row with #" + rowKey + " should be same in target DB",
() -> assertThat(targetRowsMap.get(rowKey).getRowData())
.isEqualToComparingFieldByFieldRecursively(sourceRowsMap.get(rowKey).getRowData())
))

);

return dynamicTestStream;
});

return dynamicNodeStream;
} catch (Exception e) {
throw new RuntimeException("Error running tests on table " + tableName, e);
}
}

最佳答案

尝试:

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-XX:+UseConcMarkSweepGC</argLine>
</configuration>
</plugin>

在您的构建配置文件中允许并发垃圾回收。

关于junit - Java GC 开销限制错误使用 JUnit 5 TestFactory 和大量的 dynamicTest (DynamicContainer/DynamicNode),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50629005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com