diff --git a/common/source/java/ch/systemsx/cisd/common/test/Retry10.java b/common/source/java/ch/systemsx/cisd/common/test/Retry10.java new file mode 100644 index 0000000000000000000000000000000000000000..5582dd1f6f626d44c692cfe3b55d33db73461843 --- /dev/null +++ b/common/source/java/ch/systemsx/cisd/common/test/Retry10.java @@ -0,0 +1,50 @@ +/* + * Copyright 2008 ETH Zuerich, CISD + * + * Licensed 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 ch.systemsx.cisd.common.test; + +import org.testng.IRetryAnalyzer; +import org.testng.ITestResult; +import org.testng.util.RetryAnalyzerCount; + +/** + * An {@link RetryAnalyzerCount} extension which sets the count to <code>10</code>. + * <p> + * This {@link IRetryAnalyzer} should only be applied to methods we know they should run + * successfully but do not for some reason. The retry analyzer exits as soon as it made a successful + * call. + * </p> + * + * @author Christian Ribeaud + */ +public final class Retry10 extends RetryAnalyzerCount +{ + public Retry10() + { + setCount(10); + } + + // + // RetryAnalyzerCount + // + + @Override + public final boolean retryMethod(final ITestResult result) + { + return true; + } + +} diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/concurrent/ConcurrencyUtilitiesTest.java b/common/sourceTest/java/ch/systemsx/cisd/common/concurrent/ConcurrencyUtilitiesTest.java index 047ed6bd15af76e96fc8a01b78107118d9718a58..4c4af5884d7f0e007192f3799bbd208badf06eba 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/concurrent/ConcurrencyUtilitiesTest.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/concurrent/ConcurrencyUtilitiesTest.java @@ -16,7 +16,11 @@ package ch.systemsx.cisd.common.concurrent; -import static org.testng.AssertJUnit.*; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertNull; +import static org.testng.AssertJUnit.assertTrue; +import static org.testng.AssertJUnit.fail; import java.util.ArrayList; import java.util.List; @@ -37,6 +41,7 @@ import ch.systemsx.cisd.common.exceptions.StopException; import ch.systemsx.cisd.common.logging.ISimpleLogger; import ch.systemsx.cisd.common.logging.LogInitializer; import ch.systemsx.cisd.common.logging.LogLevel; +import ch.systemsx.cisd.common.test.Retry10; /** * Test cases for {@link ConcurrencyUtilities}. @@ -54,7 +59,7 @@ public class ConcurrencyUtilitiesTest final String message; - LogRecord(LogLevel level, String message) + LogRecord(final LogLevel level, final String message) { this.level = level; this.message = message; @@ -65,17 +70,17 @@ public class ConcurrencyUtilitiesTest { private final List<LogRecord> records = new ArrayList<LogRecord>(); - public void log(LogLevel level, String message) + public void log(final LogLevel level, final String message) { records.add(new LogRecord(level, message)); } - public void assertNumberOfMessage(int expectedNumberOfMessages) + public void assertNumberOfMessage(final int expectedNumberOfMessages) { assertEquals(expectedNumberOfMessages, records.size()); } - public void assertEq(int i, LogLevel expectedLevel, String expectedMessage) + public void assertEq(final int i, final LogLevel expectedLevel, final String expectedMessage) { assertEquals(expectedLevel, records.get(i).level); assertEquals(expectedMessage, records.get(i).message); @@ -246,7 +251,7 @@ public class ConcurrencyUtilitiesTest logger.assertEq(0, LogLevel.WARN, name + ": timeout of 0.02 s exceeded, cancelled."); } - @Test(groups = "slow") + @Test(groups = "slow", retryAnalyzer = Retry10.class) public void testGetExecutionResultNoTimeoutDueToSensor() { final RecordingActivityObserverSensor sensor = new RecordingActivityObserverSensor(); @@ -446,7 +451,7 @@ public class ConcurrencyUtilitiesTest { } - public TaggedException(String msg) + public TaggedException(final String msg) { super(msg); } @@ -492,7 +497,7 @@ public class ConcurrencyUtilitiesTest { ConcurrencyUtilities.tryGetResult(future, 100L, logSettings, true); fail("Should have been a TaggedException"); - } catch (TaggedException ex) + } catch (final TaggedException ex) { // Good } @@ -519,7 +524,7 @@ public class ConcurrencyUtilitiesTest { ConcurrencyUtilities.tryGetResult(future, 100L); fail("Should have been a TaggedException"); - } catch (TaggedException ex) + } catch (final TaggedException ex) { // Good }