Search in sources :

Example 1 with PollingParameters

use of com.axway.ats.rbv.PollingParameters in project ats-framework by Axway.

the class Test_SimpleMonitorListener method evaluateMonitorsMultipleMonitorsEndOnFirstMatchExpectedFalseNegative.

@Test
public void evaluateMonitorsMultipleMonitorsEndOnFirstMatchExpectedFalseNegative() throws RbvException {
    final int pollingAttempts = 4;
    PollingParameters longPollingParams = new PollingParameters(0, POLLING_INTERVAL, pollingAttempts);
    DbStorage storage = new DbStorage(new MockDbProvider());
    Matchable matchable1 = storage.getFolder(new DbSearchTerm(""));
    Matchable matchable2 = storage.getFolder(new DbSearchTerm(""));
    Matchable matchable3 = storage.getFolder(new DbSearchTerm(""));
    DbFieldsRule dbRule = new DbStringFieldRule("", "key1", "value10", MatchRelation.EQUALS, "evaluateMonitorsMultipleMonitorsEndOnFirstMatchExpectedFalseNegative", true);
    Monitor monitor1 = new Monitor("monitor1", matchable1, dbRule, longPollingParams, false, true, false);
    Monitor monitor2 = new Monitor("monitor2", matchable2, dbRule, longPollingParams, false, true, false);
    Monitor monitor3 = new Monitor("monitor3", matchable3, dbRule, longPollingParams, false, true, false);
    List<Monitor> monitors = new ArrayList<Monitor>();
    monitors.add(monitor1);
    monitors.add(monitor2);
    monitors.add(monitor3);
    long timeBefore = System.currentTimeMillis();
    SimpleMonitorListener listener = new SimpleMonitorListener(monitors);
    assertFalse(listener.evaluateMonitors(pollingAttempts * POLLING_INTERVAL));
    long timeAfter = System.currentTimeMillis();
    //make sure more than (3 * poling interval) seconds have passed
    //this means that all iteration ware executed
    assertTrue(timeAfter - timeBefore > (pollingAttempts - 1) * POLLING_INTERVAL - 500);
}
Also used : DbSearchTerm(com.axway.ats.rbv.db.DbSearchTerm) ArrayList(java.util.ArrayList) DbFieldsRule(com.axway.ats.rbv.db.rules.DbFieldsRule) Matchable(com.axway.ats.rbv.storage.Matchable) Monitor(com.axway.ats.rbv.Monitor) DbStorage(com.axway.ats.rbv.db.DbStorage) SimpleMonitorListener(com.axway.ats.rbv.SimpleMonitorListener) PollingParameters(com.axway.ats.rbv.PollingParameters) MockDbProvider(com.axway.ats.rbv.db.MockDbProvider) DbStringFieldRule(com.axway.ats.rbv.db.rules.DbStringFieldRule) Test(org.junit.Test)

Example 2 with PollingParameters

use of com.axway.ats.rbv.PollingParameters in project ats-framework by Axway.

the class Test_SimpleMonitorListener method evaluateMonitorsMultipleMonitorsNegativeTimeoutExceeded.

@Test
public void evaluateMonitorsMultipleMonitorsNegativeTimeoutExceeded() throws RbvException {
    DbStorage storage = new DbStorage(new MockDbProvider());
    Matchable matchable1 = storage.getFolder(new DbSearchTerm(""));
    Matchable matchable2 = storage.getFolder(new DbSearchTerm(""));
    Matchable matchable3 = storage.getFolder(new DbSearchTerm(""));
    DbFieldsRule dbRule = new DbStringFieldRule("", "key1", "value10", MatchRelation.EQUALS, "evaluateMonitorsMultipleMonitorsNegativeTimeoutExceeded", true);
    PollingParameters longPolling = new PollingParameters(100, 1000, 5);
    Monitor monitor1 = new Monitor("monitor1", matchable1, dbRule, longPolling, true, false, false);
    Monitor monitor2 = new Monitor("monitor2", matchable2, dbRule, longPolling, true, false, false);
    Monitor monitor3 = new Monitor("monitor3", matchable3, dbRule, longPolling, true, false, false);
    List<Monitor> monitors = new ArrayList<Monitor>();
    monitors.add(monitor1);
    monitors.add(monitor2);
    monitors.add(monitor3);
    SimpleMonitorListener listener = new SimpleMonitorListener(monitors);
    assertFalse(listener.evaluateMonitors(1000));
}
Also used : Monitor(com.axway.ats.rbv.Monitor) DbStorage(com.axway.ats.rbv.db.DbStorage) SimpleMonitorListener(com.axway.ats.rbv.SimpleMonitorListener) DbSearchTerm(com.axway.ats.rbv.db.DbSearchTerm) ArrayList(java.util.ArrayList) DbFieldsRule(com.axway.ats.rbv.db.rules.DbFieldsRule) MockDbProvider(com.axway.ats.rbv.db.MockDbProvider) PollingParameters(com.axway.ats.rbv.PollingParameters) DbStringFieldRule(com.axway.ats.rbv.db.rules.DbStringFieldRule) Matchable(com.axway.ats.rbv.storage.Matchable) Test(org.junit.Test)

Example 3 with PollingParameters

use of com.axway.ats.rbv.PollingParameters in project ats-framework by Axway.

the class Test_SimpleMonitorListener method beforeMethod.

@Before
public void beforeMethod() throws RbvException {
    pollingParams = new PollingParameters(0, POLLING_INTERVAL, POLLING_ATTEMPTS);
    mockDbProvider = new MockDbProvider();
    DbStorage storage = new DbStorage(mockDbProvider);
    matchable = storage.getFolder(new DbSearchTerm(""));
}
Also used : DbStorage(com.axway.ats.rbv.db.DbStorage) DbSearchTerm(com.axway.ats.rbv.db.DbSearchTerm) PollingParameters(com.axway.ats.rbv.PollingParameters) MockDbProvider(com.axway.ats.rbv.db.MockDbProvider) Before(org.junit.Before)

Example 4 with PollingParameters

use of com.axway.ats.rbv.PollingParameters in project ats-framework by Axway.

the class VerificationSkeleton method verify.

/**
     * Verify that all rules match using the given expected result
     * 
     * @param expectedResult the expected result
     * @param endOnFirstMatch end on first match or keep testing until all polling attempts are exhausted
     * @param endOnFirstFailure end or first failure or keep testing until all polling attempts are exhausted
     * 
     * @return the matched meta data
     * @throws RbvException on error doing the verifications
     */
protected List<MetaData> verify(boolean expectedResult, boolean endOnFirstMatch, boolean endOnFirstFailure) throws RbvException {
    try {
        this.executor.setRootRule(this.rootRule);
        applyConfigurationSettings();
        Monitor monitor = new Monitor(getMonitorName(), this.folder, this.executor, new PollingParameters(pollingInitialDelay, pollingInterval, pollingAttempts), expectedResult, endOnFirstMatch, endOnFirstFailure);
        ArrayList<Monitor> monitors = new ArrayList<Monitor>();
        monitors.add(monitor);
        SimpleMonitorListener monitorListener = new SimpleMonitorListener(monitors);
        boolean evaluationPassed = monitorListener.evaluateMonitors(pollingTimeout);
        String lastRuleName = monitor.getLastRuleName();
        String classSimpleName = getClass().getSimpleName();
        if ("FileSystemVerification".equals(classSimpleName) && !expectedResult) {
            lastRuleName = "File do exist!";
        } else if (lastRuleName != null) {
            lastRuleName = "Rule failed '" + lastRuleName + "'!";
        } else {
            if ("DbVerification".equals(classSimpleName)) {
                lastRuleName = "Database connection problem!";
            } else if ("FileSystemVerification".equals(classSimpleName) && expectedResult) {
                lastRuleName = "File does not exist!";
            } else {
                lastRuleName = "Server connection problem!";
            }
        }
        if (evaluationPassed == false) {
            throw new RbvVerificationException("Verification failed. " + lastRuleName);
        }
        return monitor.getAllMatchedMetaData();
    } catch (ConfigurationException ce) {
        throw new RbvException("RBV configuration error", ce);
    }
}
Also used : Monitor(com.axway.ats.rbv.Monitor) RbvVerificationException(com.axway.ats.rbv.model.RbvVerificationException) SimpleMonitorListener(com.axway.ats.rbv.SimpleMonitorListener) ConfigurationException(com.axway.ats.config.exceptions.ConfigurationException) RbvException(com.axway.ats.rbv.model.RbvException) ArrayList(java.util.ArrayList) PollingParameters(com.axway.ats.rbv.PollingParameters)

Example 5 with PollingParameters

use of com.axway.ats.rbv.PollingParameters in project ats-framework by Axway.

the class Test_SimpleMonitorListener method evaluateMonitorsMultipleMonitorsEndOnFirstMatchExpectedFalsePositive.

@Test
public void evaluateMonitorsMultipleMonitorsEndOnFirstMatchExpectedFalsePositive() throws RbvException {
    PollingParameters longPollingParams = new PollingParameters(0, 5000, 10);
    DbStorage storage = new DbStorage(new MockDbProvider());
    Matchable matchable1 = storage.getFolder(new DbSearchTerm(""));
    Matchable matchable2 = storage.getFolder(new DbSearchTerm(""));
    Matchable matchable3 = storage.getFolder(new DbSearchTerm(""));
    DbFieldsRule dbRule = new DbStringFieldRule("", "key1", "value2345", MatchRelation.EQUALS, "evaluateMonitorsMultipleMonitorsEndOnFirstMatchPositive", true);
    Monitor monitor1 = new Monitor("monitor1", matchable1, dbRule, longPollingParams, false, true, false);
    Monitor monitor2 = new Monitor("monitor2", matchable2, dbRule, longPollingParams, false, true, false);
    Monitor monitor3 = new Monitor("monitor3", matchable3, dbRule, longPollingParams, false, true, false);
    List<Monitor> monitors = new ArrayList<Monitor>();
    monitors.add(monitor1);
    monitors.add(monitor2);
    monitors.add(monitor3);
    long timeBefore = Calendar.getInstance().getTimeInMillis();
    SimpleMonitorListener listener = new SimpleMonitorListener(monitors);
    listener.evaluateMonitors(TIME_END_POLL);
    long timeAfter = Calendar.getInstance().getTimeInMillis();
    //make sure less than (3 * poling interval) seconds have passed
    //this means that only one iteration was made
    assertTrue(timeAfter - timeBefore < 3 * POLLING_INTERVAL - 500);
}
Also used : Monitor(com.axway.ats.rbv.Monitor) DbStorage(com.axway.ats.rbv.db.DbStorage) SimpleMonitorListener(com.axway.ats.rbv.SimpleMonitorListener) DbSearchTerm(com.axway.ats.rbv.db.DbSearchTerm) ArrayList(java.util.ArrayList) DbFieldsRule(com.axway.ats.rbv.db.rules.DbFieldsRule) PollingParameters(com.axway.ats.rbv.PollingParameters) MockDbProvider(com.axway.ats.rbv.db.MockDbProvider) DbStringFieldRule(com.axway.ats.rbv.db.rules.DbStringFieldRule) Matchable(com.axway.ats.rbv.storage.Matchable) Test(org.junit.Test)

Aggregations

PollingParameters (com.axway.ats.rbv.PollingParameters)7 Test (org.junit.Test)5 Monitor (com.axway.ats.rbv.Monitor)4 SimpleMonitorListener (com.axway.ats.rbv.SimpleMonitorListener)4 DbSearchTerm (com.axway.ats.rbv.db.DbSearchTerm)4 DbStorage (com.axway.ats.rbv.db.DbStorage)4 MockDbProvider (com.axway.ats.rbv.db.MockDbProvider)4 ArrayList (java.util.ArrayList)4 DbFieldsRule (com.axway.ats.rbv.db.rules.DbFieldsRule)3 DbStringFieldRule (com.axway.ats.rbv.db.rules.DbStringFieldRule)3 Matchable (com.axway.ats.rbv.storage.Matchable)3 ConfigurationException (com.axway.ats.config.exceptions.ConfigurationException)1 RbvException (com.axway.ats.rbv.model.RbvException)1 RbvVerificationException (com.axway.ats.rbv.model.RbvVerificationException)1 Before (org.junit.Before)1