This is an automated email from the ASF dual-hosted git repository. erans pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-math.git
commit bf1c2c214c67fb3ce513fc8241d711e91cc81be9 Author: Gilles Sadowski <gillese...@gmail.com> AuthorDate: Fri Aug 27 19:16:03 2021 +0200 Remove obsolete helper class for unit testing. Retries are handled by the "surefire" plugin. --- .../apache/commons/math4/legacy/RetryRunner.java | 81 ---------------------- .../commons/math4/legacy/RetryRunnerTest.java | 54 --------------- .../scalar/noderiv/CMAESOptimizerTest.java | 5 -- 3 files changed, 140 deletions(-) diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunner.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunner.java deleted file mode 100644 index 7505c9f..0000000 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunner.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.math4.legacy; - -import org.junit.runners.BlockJUnit4ClassRunner; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; -import org.junit.runners.model.Statement; - - -/** - * A test runner that retries tests when assertions fail. - */ -public class RetryRunner extends BlockJUnit4ClassRunner { - /** - * Simple constructor. - * - * @param testClass Class to test. - * @throws InitializationError if default runner cannot be built. - */ - public RetryRunner(final Class<?> testClass) - throws InitializationError { - super(testClass); - } - - @Override - public Statement methodInvoker(final FrameworkMethod method, - Object test) { - final Statement singleTryStatement = super.methodInvoker(method, test); - return new Statement() { - /** - * Evaluate the statement. - * We attempt several runs for the test, at most MAX_ATTEMPTS. - * if one attempt succeeds, we succeed, if all attempts fail, we - * fail with the reason corresponding to the last attempt - */ - @Override - public void evaluate() throws Throwable { - Throwable failureReason = null; - - final Retry retry = method.getAnnotation(Retry.class); - if (retry == null) { - // Do a single test run attempt. - singleTryStatement.evaluate(); - } else { - final int numRetries = retry.value(); - - for (int i = 0; i < numRetries; ++i) { - try { - // Do a single test run attempt. - singleTryStatement.evaluate(); - // Attempt succeeded, stop evaluation here. - return; - } catch (Throwable t) { - // Attempt failed, store the reason. - failureReason = t; - } - } - - // All attempts failed. - throw failureReason; - } - } - }; - } -} diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunnerTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunnerTest.java deleted file mode 100644 index 51718e4..0000000 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/RetryRunnerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.math4.legacy; - -import java.util.Random; - -import org.apache.commons.math4.legacy.exception.MathIllegalStateException; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Test for the "Retry" functionality (retrying Junit test methods). - */ -@RunWith(RetryRunner.class) -public class RetryRunnerTest { - private final Random rng = new Random(); - - /** - * Shows that an always failing test will fail even if it is retried. - */ - @Test(expected=MathIllegalStateException.class) - @Retry - public void testRetryFailAlways() { - throw new MathIllegalStateException(); - } - - /** - * Shows that a test that sometimes fail might succeed if it is retried. - * In this case the high number of retries makes it quite unlikely that - * the exception will be thrown by all of the calls. - */ - @Test - @Retry(100) - public void testRetryFailSometimes() { - if (rng.nextBoolean()) { - throw new MathIllegalStateException(); - } - } -} diff --git a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java index c0f356b..3c23414 100644 --- a/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java +++ b/commons-math-legacy/src/test/java/org/apache/commons/math4/legacy/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java @@ -16,8 +16,6 @@ */ package org.apache.commons.math4.legacy.optim.nonlinear.scalar.noderiv; -import org.apache.commons.math4.legacy.Retry; -import org.apache.commons.math4.legacy.RetryRunner; import org.apache.commons.math4.legacy.analysis.MultivariateFunction; import org.apache.commons.math4.legacy.exception.DimensionMismatchException; import org.apache.commons.math4.legacy.exception.NotPositiveException; @@ -41,7 +39,6 @@ import org.junit.runner.RunWith; /** * Test for {@link CMAESOptimizer}. */ -@RunWith(RetryRunner.class) public class CMAESOptimizerTest { static final int DIM = 13; @@ -125,7 +122,6 @@ public class CMAESOptimizerTest { } @Test - @Retry(3) public void testRosen() { final int dim = 12; double[] startPoint = OptimTestUtils.point(dim, 0.1); @@ -142,7 +138,6 @@ public class CMAESOptimizerTest { } @Test - @Retry(3) public void testMaximize() { double[] startPoint = OptimTestUtils.point(DIM,1.0); double[] insigma = OptimTestUtils.point(DIM,0.1);