@Override protected void setUp() throws Exception { m_backEnd = m_mock.createMock(PollerBackEnd.class); m_settings = m_mock.createMock(PollerSettings.class); m_pollService = m_mock.createMock(PollService.class); m_registrationListener = m_mock.createMock(PropertyChangeListener.class); m_polledServiceListener = m_mock.createMock(ServicePollStateChangedListener.class); m_configChangeListener = m_mock.createMock(ConfigurationChangedListener.class); setPollConfig(new DemoPollerConfiguration()); m_oldPollerConfiguration = null; m_frontEnd = new DefaultPollerFrontEnd(); m_frontEnd.setTimeAdjustment(new DefaultTimeAdjustment()); // ServerUnreachableAdaptor adaptor = new ServerUnreachableAdaptor(); // adaptor.setRemoteBackEnd(m_backEnd); // m_frontEnd.setPollerBackEnd(adaptor); m_frontEnd.setPollerBackEnd(m_backEnd); m_frontEnd.setPollerSettings(m_settings); m_frontEnd.setPollService(m_pollService); m_frontEnd.addConfigurationChangedListener(m_configChangeListener); m_frontEnd.addPropertyChangeListener(m_registrationListener); m_frontEnd.addServicePollStateChangedListener(m_polledServiceListener); m_serviceStatus = PollStatus.available(1234.0); }
@Override public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { PollStatus serviceStatus = PollStatus.unavailable("Poll not completed yet"); TimeoutTracker tracker = new TimeoutTracker(parameters, DEFAULT_SEQUENCE_RETRY, DEFAULT_TIMEOUT); for (tracker.reset(); tracker.shouldRetry() && !serviceStatus.isAvailable(); tracker.nextAttempt()) { String seleniumTestFilename = getGroovyFilename(parameters); try { Map<String, Number> responseTimes = new HashMap<String, Number>(); responseTimes.put(PollStatus.PROPERTY_RESPONSE_TIME, Double.NaN); tracker.startAttempt(); Result result = runTest( getBaseUrl(parameters, svc), getTimeout(parameters), createGroovyClass(seleniumTestFilename)); double responseTime = tracker.elapsedTimeInMillis(); responseTimes.put(PollStatus.PROPERTY_RESPONSE_TIME, responseTime); if (result.wasSuccessful()) { serviceStatus = PollStatus.available(); serviceStatus.setProperties(responseTimes); } else { serviceStatus = PollStatus.unavailable(getFailureMessage(result, svc)); } } catch (CompilationFailedException e) { serviceStatus = PollStatus.unavailable( "Selenium page sequence attempt on:" + svc.getIpAddr() + " failed : selenium-test compilation error " + e.getMessage()); String reason = "Selenium sequence failed: CompilationFailedException" + e.getMessage(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); } catch (IOException e) { serviceStatus = PollStatus.unavailable( "Selenium page sequence attempt on " + svc.getIpAddr() + " failed: IOException occurred, failed to find selenium-test: " + seleniumTestFilename); String reason = "Selenium sequence failed: IOException: " + e.getMessage(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); } catch (Exception e) { serviceStatus = PollStatus.unavailable( "Selenium page sequence attempt on " + svc.getIpAddr() + " failed:\n" + e.getMessage()); String reason = "Selenium sequence failed: Exception: " + e.getMessage(); SeleniumMonitor.LOG.debug(reason); PollStatus.unavailable(reason); } } return serviceStatus; }