private URL getServerURL() { return m_agentContext.getHandler(DiscoveryHandler.class).getServerUrl(); }
protected URL getServerURL() throws RetryAfterException { // FIXME not sure if this is the proper place URL serverURL = getDiscoveryHandler().getServerUrl(); if (serverURL == null) { throw new RetryAfterException(10); } return serverURL; }
@Test public void testBadURLConfig() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, "invalidURL", AgentConstants.CONFIG_DISCOVERY_CHECKING, "true"); DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class); assertNull(discoveryHandler.getServerUrl()); // we cannot resolve this during the configuration change... }
@Test public void testEmptyURLConfig() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, "", AgentConstants.CONFIG_DISCOVERY_CHECKING, "true"); DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class); assertEquals(discoveryHandler.getServerUrl(), m_unavailableURL1); }
@Test public void testUnavailableAfterConfigUpdate() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, concat(m_availableURL1, m_availableURL2), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true"); DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class); assertEquals(discoveryHandler.getServerUrl(), m_availableURL1); configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, concat(m_unavailableURL1, m_unavailableURL2)); assertNull(discoveryHandler.getServerUrl()); }
@Test public void testAvailableAfterConfigUpdate() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, concat(m_unavailableURL1, m_unavailableURL2), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true"); DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class); assertNull(discoveryHandler.getServerUrl()); configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, concat(m_availableURL1)); assertEquals(discoveryHandler.getServerUrl(), m_availableURL1); }
@Test public void testUnavailableURL_unavailable() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, concat(m_unavailableURL1, m_unavailableURL2), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true"); DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class); assertNull(discoveryHandler.getServerUrl()); }
@Test public void testAvailableURL() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, concat(m_availableURL1, m_availableURL2), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true"); DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class); assertEquals(discoveryHandler.getServerUrl(), m_availableURL1); }
@Test public void testAvailableAfterUnavailableURL() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, concat(m_unavailableURL1, m_availableURL1), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true"); DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class); assertEquals(discoveryHandler.getServerUrl(), m_availableURL1); }
@BeforeMethod public void setUpAgain(Method method) throws Exception { // this setup is needed because a real Feedbackstore is initialized in the constructor. m_agentContext = mockAgentContext(); URL serverURL = new URL("http://localhost:" + PORT + "/"); m_webServer = new TestWebServer(PORT, "/", "generated"); m_webServer.start(); DiscoveryHandler discoveryHandler = addTestMock(DiscoveryHandler.class); expect(discoveryHandler.getServerUrl()).andReturn(serverURL).anyTimes(); IdentificationHandler identificationHandler = addTestMock(IdentificationHandler.class); expect(identificationHandler.getAgentId()).andReturn("identification").anyTimes(); replayTestMocks(); m_agentContext.setHandler(DiscoveryHandler.class, discoveryHandler); m_agentContext.setHandler(IdentificationHandler.class, identificationHandler); m_agentContext.setHandler(ConnectionHandler.class, new ConnectionHandlerImpl()); m_feedbackChannelImpl = new FeedbackChannelImpl(m_agentContext, "test"); m_agentContext.start(); }
expect(discoveryHandler.getServerUrl()).andReturn(serverURL).anyTimes();