/** * Wait for the assertions to pass for the duration of the timeout period * * Validation will be attempted and errors handled silently until the timeout period expires after which assertion * errors will be propagated and will cause test failure */ public int await() { return await(getTimeoutSeconds()); }
/** * check that the assertions pass for the whole duration of the timeout period */ public int check() { return check(getTimeoutSeconds()); }
protected int doTest(PolledAssertion p, TimeUnit timeUnit, long length) { return p.check(timeUnit, length); } }
public void waitForMatch(String pattern, boolean searchWithinLines, TimeUnit timeUnit, long length) { throw new ChorusException("Process " + streamDescription + " mode cannot be INLINE when pattern matching"); }
private Properties getConfig(String configName) { Properties p = new HandlerConfigLoader().loadPropertiesForSubGroup(configurationManager, "selenium", configName); new ScopeUtils().setScopeForContextIfNotConfigured(scenarioToken, p); return p; } }
protected int doTest(PolledAssertion p, TimeUnit timeUnit, long length) { return p.await(timeUnit, length); }
protected void validate() { throw new FailImmediatelyException("Fail Immediately"); } }.check(10);
public ChorusException(String message, Throwable cause) { super(getMessage(message, cause), cause); }
@Test public void testCheckedConditionPasses() throws Exception { final boolean[] condition = {true}; final AtomicLong count = new AtomicLong(); new PolledAssertion() { protected void validate() { count.incrementAndGet(); assertTrue(condition[0]); } }.check(0.3f); assertTrue("Expect count > 2", count.get() > 2); }
@Test public void testICanFailImmediatelyWhileAwaiting() throws Exception { long timeStart = System.currentTimeMillis(); try { new PolledAssertion() { protected void validate() { throw new FailImmediatelyException("Fail Immediately"); } }.check(10); } catch (AssertionError ae) { } assertTrue("Expect time < 1s", ((System.currentTimeMillis() - timeStart) / 1000) < 1); }
private URL getRemoteWebDriverURL(String url) { try { return new URL(url); } catch (MalformedURLException e) { throw new ChorusException("Invalid URL for Selenium RemoteWebDriver [" + url + "]", e); } }
private Properties getConfig(String configName) { Properties p = new HandlerConfigLoader().loadPropertiesForSubGroup(configurationManager, "processes", configName); new ScopeUtils().setScopeForContextIfNotConfigured(scenarioToken, p); return p; }
public int await(float seconds) { return await(TimeUnit.MILLISECONDS, (int)(seconds * 1000)); }
public int check(float seconds) { return check(TimeUnit.MILLISECONDS, (int) (seconds * 1000)); }
protected void validate() throws InvocationTargetException { FailImmediatelyException f = new FailImmediatelyException("Fail Immediately"); throw new InvocationTargetException(f); } }.check(10);
private Tuple2<Connection, SqlConfig> getConnectionDetails(String configName) { Tuple2<Connection, SqlConfig> connectionDetails = configNameToConnectionDetails.get(configName); if ( connectionDetails == null) { throw new ChorusException("Could not find a database connection for database " + configName); } return connectionDetails; }
protected boolean parseBooleanProperty(String value, String propertyKey) { try { return Boolean.parseBoolean(value); } catch (Exception e) { throw new ChorusException("Failed to parse property " + propertyKey + " with value '" + value + "' as boolean"); } }
@Override protected void validate() throws Exception { if ( ! alignedClients.contains(clientName)) { boolean connected = connectedClients.contains(clientName); String message = connected ? "connect" : "finish publishing steps (send steps aligned)"; throw new ChorusException("Client " + clientName + " did not " + message); } } };
@Step(value = ".* call a step with a step retry and the step is polled until it passes", retryDuration = 1, retryIntervalMillis = 100) public int stepWhichFailsAtFirst() throws InterruptedException { tryCount ++; if ( tryCount < 10) { throw new ChorusException("Simulate Failure"); } return tryCount; }