Skip to content
Snippets Groups Projects
Commit e62d3a94 authored by ribeaudc's avatar ribeaudc
Browse files

[SE-95] add: - 'Retry10', an 'IRetryAnalyzer' which tries to run a test until...

[SE-95] add: - 'Retry10', an 'IRetryAnalyzer' which tries to run a test until it becomes green (but maximum 10 times).

SVN: 7945
parent 56cb08f1
No related branches found
No related tags found
No related merge requests found
/*
* 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;
}
}
...@@ -16,7 +16,11 @@ ...@@ -16,7 +16,11 @@
package ch.systemsx.cisd.common.concurrent; 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.ArrayList;
import java.util.List; import java.util.List;
...@@ -37,6 +41,7 @@ import ch.systemsx.cisd.common.exceptions.StopException; ...@@ -37,6 +41,7 @@ import ch.systemsx.cisd.common.exceptions.StopException;
import ch.systemsx.cisd.common.logging.ISimpleLogger; import ch.systemsx.cisd.common.logging.ISimpleLogger;
import ch.systemsx.cisd.common.logging.LogInitializer; import ch.systemsx.cisd.common.logging.LogInitializer;
import ch.systemsx.cisd.common.logging.LogLevel; import ch.systemsx.cisd.common.logging.LogLevel;
import ch.systemsx.cisd.common.test.Retry10;
/** /**
* Test cases for {@link ConcurrencyUtilities}. * Test cases for {@link ConcurrencyUtilities}.
...@@ -54,7 +59,7 @@ public class ConcurrencyUtilitiesTest ...@@ -54,7 +59,7 @@ public class ConcurrencyUtilitiesTest
final String message; final String message;
LogRecord(LogLevel level, String message) LogRecord(final LogLevel level, final String message)
{ {
this.level = level; this.level = level;
this.message = message; this.message = message;
...@@ -65,17 +70,17 @@ public class ConcurrencyUtilitiesTest ...@@ -65,17 +70,17 @@ public class ConcurrencyUtilitiesTest
{ {
private final List<LogRecord> records = new ArrayList<LogRecord>(); 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)); records.add(new LogRecord(level, message));
} }
public void assertNumberOfMessage(int expectedNumberOfMessages) public void assertNumberOfMessage(final int expectedNumberOfMessages)
{ {
assertEquals(expectedNumberOfMessages, records.size()); 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(expectedLevel, records.get(i).level);
assertEquals(expectedMessage, records.get(i).message); assertEquals(expectedMessage, records.get(i).message);
...@@ -246,7 +251,7 @@ public class ConcurrencyUtilitiesTest ...@@ -246,7 +251,7 @@ public class ConcurrencyUtilitiesTest
logger.assertEq(0, LogLevel.WARN, name + ": timeout of 0.02 s exceeded, cancelled."); 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() public void testGetExecutionResultNoTimeoutDueToSensor()
{ {
final RecordingActivityObserverSensor sensor = new RecordingActivityObserverSensor(); final RecordingActivityObserverSensor sensor = new RecordingActivityObserverSensor();
...@@ -446,7 +451,7 @@ public class ConcurrencyUtilitiesTest ...@@ -446,7 +451,7 @@ public class ConcurrencyUtilitiesTest
{ {
} }
public TaggedException(String msg) public TaggedException(final String msg)
{ {
super(msg); super(msg);
} }
...@@ -492,7 +497,7 @@ public class ConcurrencyUtilitiesTest ...@@ -492,7 +497,7 @@ public class ConcurrencyUtilitiesTest
{ {
ConcurrencyUtilities.tryGetResult(future, 100L, logSettings, true); ConcurrencyUtilities.tryGetResult(future, 100L, logSettings, true);
fail("Should have been a TaggedException"); fail("Should have been a TaggedException");
} catch (TaggedException ex) } catch (final TaggedException ex)
{ {
// Good // Good
} }
...@@ -519,7 +524,7 @@ public class ConcurrencyUtilitiesTest ...@@ -519,7 +524,7 @@ public class ConcurrencyUtilitiesTest
{ {
ConcurrencyUtilities.tryGetResult(future, 100L); ConcurrencyUtilities.tryGetResult(future, 100L);
fail("Should have been a TaggedException"); fail("Should have been a TaggedException");
} catch (TaggedException ex) } catch (final TaggedException ex)
{ {
// Good // Good
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment