From 1b3709e9803a5a3452efe5ef4349ccea43fe78c0 Mon Sep 17 00:00:00 2001 From: Knekylen Smith Date: Wed, 17 May 2023 12:17:12 -0400 Subject: [PATCH 1/4] Created a reporter that notifies when tests are not executed after max time is reached --- .../codice/itest/api/TestResultFactory.java | 6 ++ .../java/org/codice/itest/api/TestStatus.java | 2 +- .../itest/SkipAwareExecutorService.java | 48 ++++++++++++++ .../LoggingDiagnosticTestReporter.java | 1 + .../reporter/RemainingTestsReporter.java | 23 +++++++ .../reporter/TestReporterConfiguration.java | 13 ++++ .../result/NotExecutedTestResultImpl.java | 65 +++++++++++++++++++ .../itest/result/TestResultFactoryImpl.java | 8 +++ 8 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java create mode 100644 codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java create mode 100644 codice-itest-impl/src/main/java/org/codice/itest/result/NotExecutedTestResultImpl.java diff --git a/codice-itest-api/src/main/java/org/codice/itest/api/TestResultFactory.java b/codice-itest-api/src/main/java/org/codice/itest/api/TestResultFactory.java index 3eda0ea..882109b 100644 --- a/codice-itest-api/src/main/java/org/codice/itest/api/TestResultFactory.java +++ b/codice-itest-api/src/main/java/org/codice/itest/api/TestResultFactory.java @@ -40,4 +40,10 @@ public interface TestResultFactory { * @return an appropriate TestResult object. */ TestResult error(String testName, Throwable throwable, Instant startTime, Instant endTime); + + /** + * @param testName - the name of the test that did not run. + * @return an appropriate TestResult object. + */ + TestResult notExecuted(String testName); } diff --git a/codice-itest-api/src/main/java/org/codice/itest/api/TestStatus.java b/codice-itest-api/src/main/java/org/codice/itest/api/TestStatus.java index 74c42f1..6d2dcd5 100644 --- a/codice-itest-api/src/main/java/org/codice/itest/api/TestStatus.java +++ b/codice-itest-api/src/main/java/org/codice/itest/api/TestStatus.java @@ -15,7 +15,7 @@ */ public enum TestStatus { - PASS(0), FAIL(1), ERROR(2); + PASS(0), FAIL(1), ERROR(2), NOT_EXECUTED(3); private int returnCode; TestStatus(int returnCode) { diff --git a/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java b/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java new file mode 100644 index 0000000..99b3be4 --- /dev/null +++ b/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java @@ -0,0 +1,48 @@ +package org.codice.itest; + +import org.codice.itest.api.TestResult; +import org.codice.itest.api.TestResultFactory; +import org.codice.itest.reporter.RemainingTestsReporter; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import java.util.Collection; +import java.util.List; +import java.util.Arrays; +import java.util.concurrent.*; +import java.util.function.Consumer; + +import static org.codice.itest.api.TestStatus.NOT_EXECUTED; + +@Component("SkipAwareExecutorService") +public class SkipAwareExecutorService extends ThreadPoolExecutor { + + @Value("${itest.tests:#{null}}") + private String tests; + + private List> testResultListenerList; + + private List testNameList = Arrays.asList(tests.split(",")); + + private RemainingTestsReporter remainingTestsReporter; + + private TestResultFactory testResultFactory; + + public SkipAwareExecutorService(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, + BlockingQueue workQueue, List> testResultListenerList, RemainingTestsReporter remainingTestsReporter, TestResultFactory testResultFactory) { + super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); + this.testResultListenerList = testResultListenerList; + this.remainingTestsReporter = remainingTestsReporter; + this.testResultFactory = testResultFactory; + } + + @Override + public List shutdownNow() { + remainingTestsReporter.getRemainingList().forEach(testName -> { + TestResult testResult = testResultFactory.notExecuted(testName); + testResultListenerList.forEach(listener -> listener.accept(testResult)); + }); + + return super.shutdownNow(); + } +} diff --git a/codice-itest-impl/src/main/java/org/codice/itest/reporter/LoggingDiagnosticTestReporter.java b/codice-itest-impl/src/main/java/org/codice/itest/reporter/LoggingDiagnosticTestReporter.java index fa03bd9..0cdc8ea 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/reporter/LoggingDiagnosticTestReporter.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/reporter/LoggingDiagnosticTestReporter.java @@ -36,6 +36,7 @@ public void accept(TestResult testResult) { case FAIL: logger.warn(formattedResult); break; case ERROR: logger.error(formattedResult); + case NOT_EXECUTED: logger.error(formattedResult); } } } diff --git a/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java b/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java new file mode 100644 index 0000000..f7506d3 --- /dev/null +++ b/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java @@ -0,0 +1,23 @@ +package org.codice.itest.reporter; + +import org.codice.itest.api.TestResult; + +import java.util.List; +import java.util.function.Consumer; + +public class RemainingTestsReporter implements Consumer { + private List testNames; + public RemainingTestsReporter(List testNames){ + this.testNames = testNames; + } + + @Override + public void accept(TestResult testResult) { + if(testNames.contains(testResult.getTestName())){ + testNames.remove(testResult.getTestName()); + } + } + + public List getRemainingList(){return testNames;} + +} diff --git a/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java b/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java index d00dad5..73e4d8e 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java @@ -14,11 +14,14 @@ import org.codice.itest.config.ITestConfigurationProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; @Configuration @@ -34,6 +37,11 @@ public ExitCodeReporter exitCodeReporter(){ return new ExitCodeReporter(); } + @Value("${itest.tests:#{null}}") + private String tests; + + private List testNameList = Arrays.asList(tests.split(",")); + @Bean("testReporter") @ConditionalOnProperty(prefix="codice.itest", name="loggerName") public Consumer loggingDiagnosticTestReporter() { @@ -52,4 +60,9 @@ public Consumer defaultLoggingDiagnosticTestReporter() { public Consumer exitCodeReporterConsumer(ExitCodeReporter exitCodeReporter) { return (tr) -> exitCodeReporter.register(tr.getTestStatus()); } + + @Bean("remainingTestsConsumer") + public Consumer remainingTestsReporterConsumer() { + return new RemainingTestsReporter(testNameList); + } } diff --git a/codice-itest-impl/src/main/java/org/codice/itest/result/NotExecutedTestResultImpl.java b/codice-itest-impl/src/main/java/org/codice/itest/result/NotExecutedTestResultImpl.java new file mode 100644 index 0000000..fbf29a9 --- /dev/null +++ b/codice-itest-impl/src/main/java/org/codice/itest/result/NotExecutedTestResultImpl.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) Codice Foundation + + * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the License, or any later version. + + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. A copy of the GNU Lesser General Public License is distributed along with this program and can be found at + * http://www.gnu.org/licenses/lgpl.html. + */ +package org.codice.itest.result; + +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +import java.time.Instant; +import java.util.UUID; + +import static org.codice.itest.api.TestStatus.NOT_EXECUTED; + +final class NotExecutedTestResultImpl extends BaseTestResult{ + + NotExecutedTestResultImpl(UUID runId, String testName) { + super(runId, testName, NOT_EXECUTED, Instant.now(), Instant.now()); + } + + @Override + public String toString() { + return toStringCreator.append(super.getRunId()) + .append(super.getTestStatus()) + .append(super.getTestName()) + .append(NOT_EXECUTED) + .toString(); + } + + @Override + public boolean equals(Object other) { + if (other == null) { + return false; + } + + if (other == this) { + return true; + } + + if (!(other instanceof NotExecutedTestResultImpl)) { + return false; + } + + NotExecutedTestResultImpl testResult = (NotExecutedTestResultImpl) other; + + return new EqualsBuilder().append(super.getRunId(), testResult.getRunId()) + .append(super.getTestName(), testResult.getTestName()) + .append(super.getTestStatus(), testResult.getTestStatus()) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(1313, 4137).append(super.getRunId()) + .append(super.getTestName()) + .append(super.getTestStatus()) + .build(); + } +} diff --git a/codice-itest-impl/src/main/java/org/codice/itest/result/TestResultFactoryImpl.java b/codice-itest-impl/src/main/java/org/codice/itest/result/TestResultFactoryImpl.java index 244eb9b..dd1853a 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/result/TestResultFactoryImpl.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/result/TestResultFactoryImpl.java @@ -28,6 +28,7 @@ final class TestResultFactoryImpl implements TestResultFactory { private static final String START_TIME = "startTime"; private static final String END_TIME = "endTime"; private static final String EXCEPTION_MESSAGE = "exceptionMessage"; + //private static final String NOT_EXECUTED_MESSAGE = ""; private static final String STACK_TRACE = "stackTrace"; private static final String TEST_STATUS = "testStatus"; private final UUID runId; @@ -65,6 +66,13 @@ public TestResult error(String testName, Throwable throwable, Instant startTime, return new ErrorTestResultImpl(runId, testName, throwable, startTime, endTime); } + @Override + public TestResult notExecuted(String testName) { + MDC.put(STACK_TRACE, "Not Executed"); + MDC.put(TEST_STATUS, TestStatus.NOT_EXECUTED.name()); + return new NotExecutedTestResultImpl(runId, testName); + } + private void logTestResultCommonFields(String testName, Instant startTime, Instant endTime) { MDC.clear(); MDC.put(TEST_NAME, testName); From 21338fa2719adeea3f1bbd93d592f60af7294e6d Mon Sep 17 00:00:00 2001 From: Knekylen Smith Date: Thu, 18 May 2023 14:58:45 -0400 Subject: [PATCH 2/4] resolved threads --- .../org/codice/itest/SkipAwareExecutorService.java | 11 ++++++----- .../itest/reporter/LoggingDiagnosticTestReporter.java | 3 +-- .../codice/itest/reporter/RemainingTestsReporter.java | 7 +++++-- .../itest/reporter/TestReporterConfiguration.java | 7 ++----- .../codice/itest/result/TestResultFactoryImpl.java | 2 -- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java b/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java index 99b3be4..fc4e5b0 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java @@ -2,18 +2,16 @@ import org.codice.itest.api.TestResult; import org.codice.itest.api.TestResultFactory; +import org.codice.itest.config.ITestConfigurationProperties; import org.codice.itest.reporter.RemainingTestsReporter; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import java.util.Collection; import java.util.List; import java.util.Arrays; import java.util.concurrent.*; import java.util.function.Consumer; -import static org.codice.itest.api.TestStatus.NOT_EXECUTED; - @Component("SkipAwareExecutorService") public class SkipAwareExecutorService extends ThreadPoolExecutor { @@ -21,17 +19,20 @@ public class SkipAwareExecutorService extends ThreadPoolExecutor { private String tests; private List> testResultListenerList; + private final ITestConfigurationProperties iTestConfigurationProperties; - private List testNameList = Arrays.asList(tests.split(",")); + private List testNameList; private RemainingTestsReporter remainingTestsReporter; private TestResultFactory testResultFactory; public SkipAwareExecutorService(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, - BlockingQueue workQueue, List> testResultListenerList, RemainingTestsReporter remainingTestsReporter, TestResultFactory testResultFactory) { + BlockingQueue workQueue, List> testResultListenerList, ITestConfigurationProperties iTestConfigurationProperties, RemainingTestsReporter remainingTestsReporter, TestResultFactory testResultFactory) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); this.testResultListenerList = testResultListenerList; + this.iTestConfigurationProperties = iTestConfigurationProperties; + this.testNameList = iTestConfigurationProperties.tests(); this.remainingTestsReporter = remainingTestsReporter; this.testResultFactory = testResultFactory; } diff --git a/codice-itest-impl/src/main/java/org/codice/itest/reporter/LoggingDiagnosticTestReporter.java b/codice-itest-impl/src/main/java/org/codice/itest/reporter/LoggingDiagnosticTestReporter.java index 0cdc8ea..2475d40 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/reporter/LoggingDiagnosticTestReporter.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/reporter/LoggingDiagnosticTestReporter.java @@ -35,8 +35,7 @@ public void accept(TestResult testResult) { break; case FAIL: logger.warn(formattedResult); break; - case ERROR: logger.error(formattedResult); - case NOT_EXECUTED: logger.error(formattedResult); + case ERROR, NOT_EXECUTED: logger.error(formattedResult); } } } diff --git a/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java b/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java index f7506d3..8dd7864 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java @@ -7,17 +7,20 @@ public class RemainingTestsReporter implements Consumer { private List testNames; + private List remainingTestNames; + public RemainingTestsReporter(List testNames){ this.testNames = testNames; + this.remainingTestNames = testNames; } @Override public void accept(TestResult testResult) { if(testNames.contains(testResult.getTestName())){ - testNames.remove(testResult.getTestName()); + remainingTestNames.remove(testResult.getTestName()); } } - public List getRemainingList(){return testNames;} + public List getRemainingList(){return remainingTestNames;} } diff --git a/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java b/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java index 73e4d8e..627689a 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java @@ -27,9 +27,11 @@ @Configuration public class TestReporterConfiguration { private final ITestConfigurationProperties iTestConfigurationProperties; + private List testNameList; public TestReporterConfiguration(ITestConfigurationProperties iTestConfigurationProperties) { this.iTestConfigurationProperties = iTestConfigurationProperties; + this.testNameList = iTestConfigurationProperties.tests(); } @Bean @@ -37,11 +39,6 @@ public ExitCodeReporter exitCodeReporter(){ return new ExitCodeReporter(); } - @Value("${itest.tests:#{null}}") - private String tests; - - private List testNameList = Arrays.asList(tests.split(",")); - @Bean("testReporter") @ConditionalOnProperty(prefix="codice.itest", name="loggerName") public Consumer loggingDiagnosticTestReporter() { diff --git a/codice-itest-impl/src/main/java/org/codice/itest/result/TestResultFactoryImpl.java b/codice-itest-impl/src/main/java/org/codice/itest/result/TestResultFactoryImpl.java index dd1853a..944574b 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/result/TestResultFactoryImpl.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/result/TestResultFactoryImpl.java @@ -28,7 +28,6 @@ final class TestResultFactoryImpl implements TestResultFactory { private static final String START_TIME = "startTime"; private static final String END_TIME = "endTime"; private static final String EXCEPTION_MESSAGE = "exceptionMessage"; - //private static final String NOT_EXECUTED_MESSAGE = ""; private static final String STACK_TRACE = "stackTrace"; private static final String TEST_STATUS = "testStatus"; private final UUID runId; @@ -68,7 +67,6 @@ public TestResult error(String testName, Throwable throwable, Instant startTime, @Override public TestResult notExecuted(String testName) { - MDC.put(STACK_TRACE, "Not Executed"); MDC.put(TEST_STATUS, TestStatus.NOT_EXECUTED.name()); return new NotExecutedTestResultImpl(runId, testName); } From 5601fceb51beeec2a921fa373dfec34accf21201 Mon Sep 17 00:00:00 2001 From: Knekylen Smith Date: Fri, 19 May 2023 12:58:00 -0400 Subject: [PATCH 3/4] thread resolutions --- .../codice/itest/IntegrationTestService.java | 20 ++++++++++--------- .../itest/SkipAwareExecutorService.java | 15 ++++++++++++-- .../reporter/RemainingTestsReporter.java | 10 ++++++++++ .../result/NotExecutedTestResultImpl.java | 4 +--- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/codice-itest-impl/src/main/java/org/codice/itest/IntegrationTestService.java b/codice-itest-impl/src/main/java/org/codice/itest/IntegrationTestService.java index 89d198c..f69aca2 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/IntegrationTestService.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/IntegrationTestService.java @@ -14,7 +14,6 @@ import org.codice.itest.api.TestResult; import org.codice.itest.api.TestResultFactory; import org.codice.itest.config.ITestConfigurationProperties; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; @@ -43,22 +42,25 @@ final class IntegrationTestService implements CommandLineRunner { private ExecutorService executorService; + private SkipAwareExecutorService skipAwareExecutorService; + private TestResultFactory testResultFactory; private ITestConfigurationProperties iTestConfigurationProperties; /** - * - * @param tests - The set of all DiagnosticTest objects found in the Spring application context. - * @param testResultListenerList - A list of listeners to be notified upon test completion. - * @param executorService - Used to allow tests to be executed in parallel. + * @param tests - The set of all DiagnosticTest objects found in the Spring application context. + * @param testResultListenerList - A list of listeners to be notified upon test completion. + * @param executorService - Used to allow tests to be executed in parallel. + * @param skipAwareExecutorService - Used to allow tests to be executed in parallel while */ public IntegrationTestService(Stream tests, List> testResultListenerList, - TestResultFactory testResultFactory, + SkipAwareExecutorService skipAwareExecutorService, TestResultFactory testResultFactory, ExecutorService executorService, ITestConfigurationProperties iTestConfigurationProperties) { this.tests = tests; this.testResultListenerList = testResultListenerList; + this.skipAwareExecutorService = skipAwareExecutorService; this.testResultFactory = testResultFactory; this.executorService = executorService; this.iTestConfigurationProperties = iTestConfigurationProperties; @@ -71,9 +73,9 @@ public IntegrationTestService(Stream tests, * @throws InterruptedException - When interrupted while waiting for a test to complete. */ public void run(String[] args) throws InterruptedException { - this.tests.forEach(test -> executorService.execute(new TestExecutorTask(test, + this.tests.forEach(test -> skipAwareExecutorService.execute(new TestExecutorTask(test, testResultListenerList, testResultFactory))); - executorService.shutdown(); - executorService.awaitTermination(iTestConfigurationProperties.maxExecutionMinutes(), TimeUnit.MINUTES); + skipAwareExecutorService.shutdown(); + skipAwareExecutorService.awaitTermination(iTestConfigurationProperties.maxExecutionMinutes(), TimeUnit.MINUTES); } } diff --git a/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java b/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java index fc4e5b0..b4f648f 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java @@ -1,3 +1,13 @@ +/** + * Copyright (c) Codice Foundation + + * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the License, or any later version. + + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. A copy of the GNU Lesser General Public License is distributed along with this program and can be found at + * http://www.gnu.org/licenses/lgpl.html. + */ package org.codice.itest; import org.codice.itest.api.TestResult; @@ -8,8 +18,9 @@ import org.springframework.stereotype.Component; import java.util.List; -import java.util.Arrays; -import java.util.concurrent.*; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; @Component("SkipAwareExecutorService") diff --git a/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java b/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java index 8dd7864..b7207db 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/reporter/RemainingTestsReporter.java @@ -1,3 +1,13 @@ +/** + * Copyright (c) Codice Foundation + + * This is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of the License, or any later version. + + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. A copy of the GNU Lesser General Public License is distributed along with this program and can be found at + * http://www.gnu.org/licenses/lgpl.html. + */ package org.codice.itest.reporter; import org.codice.itest.api.TestResult; diff --git a/codice-itest-impl/src/main/java/org/codice/itest/result/NotExecutedTestResultImpl.java b/codice-itest-impl/src/main/java/org/codice/itest/result/NotExecutedTestResultImpl.java index fbf29a9..3916e19 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/result/NotExecutedTestResultImpl.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/result/NotExecutedTestResultImpl.java @@ -43,12 +43,10 @@ public boolean equals(Object other) { return true; } - if (!(other instanceof NotExecutedTestResultImpl)) { + if (!(other instanceof NotExecutedTestResultImpl testResult)) { return false; } - NotExecutedTestResultImpl testResult = (NotExecutedTestResultImpl) other; - return new EqualsBuilder().append(super.getRunId(), testResult.getRunId()) .append(super.getTestName(), testResult.getTestName()) .append(super.getTestStatus(), testResult.getTestStatus()) From d12d54ea8b61ebce8f19175af4897fdff3eb3385 Mon Sep 17 00:00:00 2001 From: Knekylen Smith Date: Mon, 5 Jun 2023 13:58:08 -0400 Subject: [PATCH 4/4] thread resolutions pt 2 --- ...Service.java => ITestExecutorService.java} | 8 ++++---- .../codice/itest/IntegrationTestService.java | 20 +++++++------------ .../reporter/TestReporterConfiguration.java | 2 -- 3 files changed, 11 insertions(+), 19 deletions(-) rename codice-itest-impl/src/main/java/org/codice/itest/{SkipAwareExecutorService.java => ITestExecutorService.java} (82%) diff --git a/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java b/codice-itest-impl/src/main/java/org/codice/itest/ITestExecutorService.java similarity index 82% rename from codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java rename to codice-itest-impl/src/main/java/org/codice/itest/ITestExecutorService.java index b4f648f..02056d4 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/SkipAwareExecutorService.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/ITestExecutorService.java @@ -23,8 +23,8 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -@Component("SkipAwareExecutorService") -public class SkipAwareExecutorService extends ThreadPoolExecutor { +@Component("ITestExecutorService") +public class ITestExecutorService extends ThreadPoolExecutor { @Value("${itest.tests:#{null}}") private String tests; @@ -38,8 +38,8 @@ public class SkipAwareExecutorService extends ThreadPoolExecutor { private TestResultFactory testResultFactory; - public SkipAwareExecutorService(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, - BlockingQueue workQueue, List> testResultListenerList, ITestConfigurationProperties iTestConfigurationProperties, RemainingTestsReporter remainingTestsReporter, TestResultFactory testResultFactory) { + public ITestExecutorService(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, + BlockingQueue workQueue, List> testResultListenerList, ITestConfigurationProperties iTestConfigurationProperties, RemainingTestsReporter remainingTestsReporter, TestResultFactory testResultFactory) { super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); this.testResultListenerList = testResultListenerList; this.iTestConfigurationProperties = iTestConfigurationProperties; diff --git a/codice-itest-impl/src/main/java/org/codice/itest/IntegrationTestService.java b/codice-itest-impl/src/main/java/org/codice/itest/IntegrationTestService.java index f69aca2..7e0ddde 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/IntegrationTestService.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/IntegrationTestService.java @@ -18,7 +18,6 @@ import org.springframework.stereotype.Component; import java.util.List; -import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.stream.Stream; @@ -40,9 +39,7 @@ final class IntegrationTestService implements CommandLineRunner { private List> testResultListenerList; - private ExecutorService executorService; - - private SkipAwareExecutorService skipAwareExecutorService; + private ITestExecutorService iTestExecutorService; private TestResultFactory testResultFactory; @@ -50,19 +47,16 @@ final class IntegrationTestService implements CommandLineRunner { /** * @param tests - The set of all DiagnosticTest objects found in the Spring application context. * @param testResultListenerList - A list of listeners to be notified upon test completion. - * @param executorService - Used to allow tests to be executed in parallel. - * @param skipAwareExecutorService - Used to allow tests to be executed in parallel while + * @param iTestExecutorService - Used to allow tests to be executed in parallel while checking for not executed test results */ public IntegrationTestService(Stream tests, List> testResultListenerList, - SkipAwareExecutorService skipAwareExecutorService, TestResultFactory testResultFactory, - ExecutorService executorService, + ITestExecutorService iTestExecutorService, TestResultFactory testResultFactory, ITestConfigurationProperties iTestConfigurationProperties) { this.tests = tests; this.testResultListenerList = testResultListenerList; - this.skipAwareExecutorService = skipAwareExecutorService; + this.iTestExecutorService = iTestExecutorService; this.testResultFactory = testResultFactory; - this.executorService = executorService; this.iTestConfigurationProperties = iTestConfigurationProperties; } @@ -73,9 +67,9 @@ public IntegrationTestService(Stream tests, * @throws InterruptedException - When interrupted while waiting for a test to complete. */ public void run(String[] args) throws InterruptedException { - this.tests.forEach(test -> skipAwareExecutorService.execute(new TestExecutorTask(test, + this.tests.forEach(test -> iTestExecutorService.execute(new TestExecutorTask(test, testResultListenerList, testResultFactory))); - skipAwareExecutorService.shutdown(); - skipAwareExecutorService.awaitTermination(iTestConfigurationProperties.maxExecutionMinutes(), TimeUnit.MINUTES); + iTestExecutorService.shutdown(); + iTestExecutorService.awaitTermination(iTestConfigurationProperties.maxExecutionMinutes(), TimeUnit.MINUTES); } } diff --git a/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java b/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java index 627689a..7fe88f2 100644 --- a/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java +++ b/codice-itest-impl/src/main/java/org/codice/itest/reporter/TestReporterConfiguration.java @@ -14,13 +14,11 @@ import org.codice.itest.config.ITestConfigurationProperties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import java.util.Arrays; import java.util.List; import java.util.function.Consumer;