#java #spring-boot #gradle #gradle-tooling-api
#java #весенняя загрузка #gradle #gradle-tooling-api
Вопрос:
Переименовано из: LocationAwareException — org.gradle.инструментарий.Обработчик результатов получает уведомления об ошибках, но процесс тестирования работает
Я использую Gradle tooling API для запуска тестов через службу загрузки Java Spring. Я использую ScheduledFutures с Spring Framework ThreadPoolTaskScheduler для постановки тестов в очередь и одновременного запуска X из них в выполняемом классе. Кажется, все работает хорошо.
В основном в моем выполняемом классе я делаю следующее:
ProjectConnection connection = GradleConnector.newConnector()
.forProjectDirectory(new File(workingDir))
.connect();
...
TestLauncher tl = connection.newTestLauncher();
...
tl.withJvmTestClasses(testClass);
...
TestResultHandler handler = new TestResultHandler();
tl.run(handler);
...
connection.close();
Мой TestResultHandler просто выгружает информацию в OnFailure:
import org.gradle.tooling.GradleConnectionException;
import org.gradle.tooling.ResultHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestResultHandler implements ResultHandler<Object> {
private static final Logger logger = LoggerFactory.getLogger(TestResultHandler.class);
@Override
public void onFailure(GradleConnectionException e) {
logger.info("toString:");
logger.info(e.toString());
logger.info("getCause:");
logger.info(e.getCause().toString());
logger.info("getStackTrace:");
for (StackTraceElement elem : e.getStackTrace())
logger.info(elem.toString());
}
}
Мои тесты определенно работают, и я собираю результаты, но я вижу подобные вещи из TestResultHandler:
toString:
org.gradle.tooling.BuildException: Could not execute tests using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-6.8-bin.zip'.
getCause:
org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':test'.
getStackTrace:
org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:51)
org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:29)
org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:43)
org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:69)
org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
java.lang.Thread.run(Thread.java:748)
Кто-нибудь знает, что это значит, и должен ли я беспокоиться?
РЕДАКТИРОВАТЬ: вот пример вывода из .printStackTrace(). Спасибо, @ToYonos
Caused by: org.gradle.api.GradleException: Could not write XML test results for us.xxx.yyy.MiscTest to file /home/gradle/src/build/test-results/test/20210218-15_48_20_126/TEST-us.xxx.yyy.MiscTest.xml.
at org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator$JUnitXmlReportFileGenerator.run(Binary2JUnitXmlReportGenerator.java:125)
at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$QueueWorker.execute(DefaultBuildOperationExecutor.java:199)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runOperation(DefaultBuildOperationQueue.java:241)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.doRunBatch(DefaultBuildOperationQueue.java:222)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.lambda$runBatch$0(DefaultBuildOperationQueue.java:212)
at org.gradle.internal.resources.AbstractResourceLockRegistry.whileDisallowingLockChanges(AbstractResourceLockRegistry.java:70)
at org.gradle.internal.work.DefaultWorkerLeaseService.whileDisallowingProjectLockChanges(DefaultWorkerLeaseService.java:185)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.lambda$runBatch$1(DefaultBuildOperationQueue.java:212)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:213)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runBatch(DefaultBuildOperationQueue.java:200)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.run(DefaultBuildOperationQueue.java:172)
... 3 more
Caused by: org.gradle.api.UncheckedIOException: java.io.EOFException
at org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore$Reader.doRead(TestOutputStore.java:389)
at org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore$Reader.writeAllOutput(TestOutputStore.java:314)
at org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider$3.execute(InMemoryTestResultsProvider.java:61)
at org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider$3.execute(InMemoryTestResultsProvider.java:58)
at org.gradle.api.internal.tasks.testing.junit.result.TestOutputStoreBackedResultsProvider.withReader(TestOutputStoreBackedResultsProvider.java:36)
at org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider.writeAllOutput(InMemoryTestResultsProvider.java:58)
at org.gradle.api.internal.tasks.testing.junit.result.JUnitXmlResultWriter.writeOutputs(JUnitXmlResultWriter.java:94)
at org.gradle.api.internal.tasks.testing.junit.result.JUnitXmlResultWriter.write(JUnitXmlResultWriter.java:79)
at org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator$JUnitXmlReportFileGenerator.run(Binary2JUnitXmlReportGenerator.java:122)
... 17 more
Caused by: java.io.EOFException
at org.gradle.internal.serialize.kryo.KryoBackedDecoder.maybeEndOfStream(KryoBackedDecoder.java:74)
at org.gradle.internal.serialize.kryo.KryoBackedDecoder.readBoolean(KryoBackedDecoder.java:138)
at org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore$Reader.doRead(TestOutputStore.java:350)
... 25 more
Caused by: com.esotericsoftware.kryo.KryoException: Buffer underflow.
at com.esotericsoftware.kryo.io.Input.require(Input.java:181)
at com.esotericsoftware.kryo.io.Input.readBoolean(Input.java:783)
at org.gradle.internal.serialize.kryo.KryoBackedDecoder.readBoolean(KryoBackedDecoder.java:136)
... 26 more
На самом деле это немного усечено. Он был слишком большим, чтобы включить все это, но я думаю, что здесь самые важные части.
РЕДАКТИРОВАТЬ 2:
Здесь не хватило места … продолжение в ответе 1, который на самом деле не является ответом на вопрос.
Комментарии:
1.
onFailure
не могли бы вы добавить в метод для отладки,e.printStackTrace()
чтобы лучше понять проблему?2. Конечно. Я добавлю это. Я думаю, что он покажет то же самое, что и e.getStackTrace() .
3. Отключение отчетов HTML и XML исправило это. Я получаю свои результаты из класса, который реализует org.junit.platform.launcher. TestExecutionListener, так что без потери функциональности
4. Способа, которым вы зарегистрировали проблему, было недостаточно, потому что он пропустил дерево причинности.
e.printStackTrace()
это лучший способ получить полную картину проблемы.5. Путь
/home/gradle/src/build/test-results/test/20210218-15_48_20_126/TEST-us.xxx.yyy.MiscTest.xml
мне кажется неправильным. Т.е.src/build
выглядит неправильно. Существует ли оно вообще и подходит ли оно для результатов тестирования?
Ответ №1:
Хорошие глаза, @TobiasOtto. Это был пользовательский каталог. Я создавал это так:
def now = new Date()
def timestamp = now.format("yyyyMMdd-HH_mm_ss_SSS", TimeZone.getTimeZone('UTC'))
reports.junitXml.destination = file("$buildDir/test-results/test/$timestamp")
reports.html.destination = file("$testReportDir/test/$timestamp")
На самом деле я все еще сталкиваюсь с ошибкой и думал попробовать тот же трюк с каталогом test-results / test / binary
В моем вопросе не хватает места, но я хотел добавить еще одну трассировку стека:
org.gradle.tooling.TestExecutionException: Could not execute tests using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-6.8-bin.zip'.
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:49)
at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:29)
at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:43)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:69)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.gradle.api.tasks.testing.TestExecutionException: Test failed.
Failed tests:
Test UnknownClass#executionError (Task: :test)
at org.gradle.tooling.internal.provider.runner.TestExecutionResultEvaluator.evaluate(TestExecutionResultEvaluator.java:82)
at org.gradle.tooling.internal.provider.runner.TestExecutionRequestActionRunner.run(TestExecutionRequestActionRunner.java:58)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:63)
at org.gradle.tooling.internal.provider.ValidatingBuildActionRunner.run(ValidatingBuildActionRunner.java:32)
at org.gradle.tooling.internal.provider.FileSystemWatchingBuildActionRunner.run(FileSystemWatchingBuildActionRunner.java:77)
at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:41)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:49)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner$3.call(RunAsBuildOperationBuildActionRunner.java:44)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200)
at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195)
at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:75)
at org.gradle.internal.operations.DefaultBuildOperationRunner$3.execute(DefaultBuildOperationRunner.java:68)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:153)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:68)
at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:62)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.lambda$call$2(DefaultBuildOperationExecutor.java:76)
at org.gradle.internal.operations.UnmanagedBuildOperationWrapper.callWithUnmanagedSupport(UnmanagedBuildOperationWrapper.java:54)
at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:76)
at org.gradle.launcher.exec.RunAsBuildOperationBuildActionRunner.run(RunAsBuildOperationBuildActionRunner.java:44)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.lambda$execute$0(InProcessBuildActionExecuter.java:54)
at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:53)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:29)
at org.gradle.launcher.exec.BuildTreeScopeLifecycleBuildActionExecuter.lambda$execute$0(BuildTreeScopeLifecycleBuildActionExecuter.java:33)
at org.gradle.internal.buildtree.BuildTreeState.run(BuildTreeState.java:49)
at org.gradle.launcher.exec.BuildTreeScopeLifecycleBuildActionExecuter.execute(BuildTreeScopeLifecycleBuildActionExecuter.java:32)
at org.gradle.launcher.exec.BuildTreeScopeLifecycleBuildActionExecuter.execute(BuildTreeScopeLifecycleBuildActionExecuter.java:27)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:104)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:55)
at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:64)
at org.gradle.tooling.internal.provider.SubscribableBuildActionExecuter.execute(SubscribableBuildActionExecuter.java:37)
at org.gradle.tooling.internal.provider.SessionScopeLifecycleBuildActionExecuter.lambda$execute$0(SessionScopeLifecycleBuildActionExecuter.java:54)
at org.gradle.internal.session.BuildSessionState.run(BuildSessionState.java:67)
at org.gradle.tooling.internal.provider.SessionScopeLifecycleBuildActionExecuter.execute(SessionScopeLifecycleBuildActionExecuter.java:50)
at org.gradle.tooling.internal.provider.SessionScopeLifecycleBuildActionExecuter.execute(SessionScopeLifecycleBuildActionExecuter.java:36)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:36)
at org.gradle.tooling.internal.provider.GradleThreadBuildActionExecuter.execute(GradleThreadBuildActionExecuter.java:25)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:59)
at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:31)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:55)
at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:41)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:47)
at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:31)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:65)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:39)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:29)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:35)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:78)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:75)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:75)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:84)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
... 6 more
Я думал, что проблема решена, но, похоже, ее нет на 100%.
Я думаю, что полное исправление заключается в следующем … все еще тестируется, но будет обновляться, как только я проверю кучу раз:
test {
reports {
junitXml.enabled = false
html.enabled = false
}
def now = new Date()
def timestamp = now.format("yyyyMMdd-HH_mm_ss_SSS", TimeZone.getTimeZone('UTC'))
binaryResultsDirectory = file("$testReportDir/test/$timestamp")
}