You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ja...@apache.org on 2016/01/28 15:16:09 UTC
svn commit: r1727361 - in /ace/trunk/org.apache.ace.agent:
src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
Author: jawi
Date: Thu Jan 28 14:16:09 2016
New Revision: 1727361
URL: http://svn.apache.org/viewvc?rev=1727361&view=rev
Log:
ACE-520 - do not blacklist servers when there is only one:
- only blacklist servers if there more than one server is supplied.
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
Modified: ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java?rev=1727361&r1=1727360&r2=1727361&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java (original)
+++ ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DiscoveryHandlerImpl.java Thu Jan 28 14:16:09 2016
@@ -100,13 +100,17 @@ public class DiscoveryHandlerImpl extend
DiscoveryHandlerImpl(String[] serverURLs, boolean checkServerURLs) {
super("discovery");
m_defaultServerURLs = m_serverURLs = Arrays.asList(serverURLs);
- m_defaultCheckURLs = m_checkURLs = checkServerURLs;
+ // ACE-520 - checking URLs only makes sense if there is more than one URL available...
+ m_defaultCheckURLs = m_checkURLs = checkServerURLs && m_defaultServerURLs.size() > 1;
}
@Override
protected void onInit() throws Exception {
String urls = getConfigurationHandler().get(CONFIG_DISCOVERY_SERVERURLS, mergeUrls(m_defaultServerURLs));
+ boolean checkServerURLs = getConfigurationHandler().getBoolean(CONFIG_DISCOVERY_CHECKING, DEFAULT_CHECK_SERVER_URLS);
m_defaultServerURLs = m_serverURLs = splitUrls(urls);
+ // ACE-520 - checking URLs only makes sense if there is more than one URL available...
+ m_defaultCheckURLs = m_checkURLs = checkServerURLs && m_defaultServerURLs.size() > 1;
getEventsHandler().addListener(this);
}
@@ -139,6 +143,8 @@ public class DiscoveryHandlerImpl extend
else {
checkURLs = m_defaultCheckURLs;
}
+ // ACE-520 - checking URLs only makes sense if there is more than one URL available...
+ checkURLs &= serverURLs.size() > 1;
List<String> oldServerURLs = m_serverURLs;
boolean oldCheckURLs = m_checkURLs;
Modified: ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java?rev=1727361&r1=1727360&r2=1727361&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java (original)
+++ ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java Thu Jan 28 14:16:09 2016
@@ -45,8 +45,10 @@ public class DiscoveryHandlerImplTest ex
private static final int PORT = 8882;
private TestWebServer m_webServer;
- private URL m_availableURL;
- private URL m_unavailableURL;
+ private URL m_availableURL1;
+ private URL m_availableURL2;
+ private URL m_unavailableURL1;
+ private URL m_unavailableURL2;
private AgentContext m_agentContext;
private AgentContextImpl m_agentContextImpl;
@@ -55,15 +57,17 @@ public class DiscoveryHandlerImplTest ex
public void setUpOnceAgain() throws Exception {
m_webServer = new TestWebServer(PORT, "/", "generated");
m_webServer.start();
- m_availableURL = new URL("http://localhost:" + PORT);
- m_unavailableURL = new URL("http://localhost:9999");
+ m_availableURL1 = new URL("http://localhost:" + PORT);
+ m_availableURL2 = new URL("http://127.0.0.1:" + PORT);
+ m_unavailableURL1 = new URL("http://localhost:19999");
+ m_unavailableURL2 = new URL("http://127.0.0.1:19999");
BundleContext bc = mockBundleContext();
m_agentContextImpl = mockAgentContext();
m_agentContext = m_agentContextImpl;
// Make sure the default server URL is not reachable, as used for this test...
- m_agentContextImpl.setHandler(DiscoveryHandler.class, new DiscoveryHandlerImpl("http://localhost:9999", true));
+ m_agentContextImpl.setHandler(DiscoveryHandler.class, new DiscoveryHandlerImpl(m_unavailableURL1.toExternalForm(), true));
m_agentContextImpl.setHandler(EventsHandler.class, new EventsHandlerImpl(bc));
m_agentContextImpl.setHandler(ConfigurationHandler.class, new ConfigurationHandlerImpl(bc));
m_agentContextImpl.setHandler(ConnectionHandler.class, new ConnectionHandlerImpl());
@@ -80,21 +84,36 @@ public class DiscoveryHandlerImplTest ex
clearTestMocks();
}
+ private String concat(URL... urls) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < urls.length; i++) {
+ if (i > 0) {
+ sb.append(",");
+ }
+ sb.append(urls[i].toExternalForm());
+ }
+ return sb.toString();
+ }
+
@Test
public void testAvailableURL() throws Exception {
ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class);
- configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_availableURL.toExternalForm(), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
+ 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_availableURL);
+ 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, m_unavailableURL.toExternalForm(), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
+ 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());
@@ -104,12 +123,15 @@ public class DiscoveryHandlerImplTest ex
public void testUnavailableAfterConfigUpdate() throws Exception {
ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class);
- configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_availableURL.toExternalForm(), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
+ 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_availableURL);
+ assertEquals(discoveryHandler.getServerUrl(), m_availableURL1);
- configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_unavailableURL.toExternalForm());
+ configureAgent(configurationHandler,
+ AgentConstants.CONFIG_DISCOVERY_SERVERURLS, concat(m_unavailableURL1, m_unavailableURL2));
assertNull(discoveryHandler.getServerUrl());
}
@@ -118,44 +140,53 @@ public class DiscoveryHandlerImplTest ex
public void testAvailableAfterConfigUpdate() throws Exception {
ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class);
- configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_unavailableURL.toExternalForm(), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
+ 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, m_availableURL.toExternalForm());
+ configureAgent(configurationHandler,
+ AgentConstants.CONFIG_DISCOVERY_SERVERURLS, concat(m_availableURL1));
- assertEquals(discoveryHandler.getServerUrl(), m_availableURL);
+ assertEquals(discoveryHandler.getServerUrl(), m_availableURL1);
}
@Test
public void testAvailableAfterUnavailableURL() throws Exception {
ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class);
- configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_unavailableURL.toExternalForm() + "," + m_availableURL.toExternalForm(), AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
+ 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_availableURL);
+ assertEquals(discoveryHandler.getServerUrl(), m_availableURL1);
}
@Test
public void testEmptyURLConfig() throws Exception {
ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class);
- configureAgent(configurationHandler, AgentConstants.CONFIG_DISCOVERY_SERVERURLS, "", AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
+ configureAgent(configurationHandler,
+ AgentConstants.CONFIG_DISCOVERY_SERVERURLS, "",
+ AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class);
- assertNull(discoveryHandler.getServerUrl());
+ assertEquals(discoveryHandler.getServerUrl(), m_unavailableURL1);
}
@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");
+ configureAgent(configurationHandler,
+ AgentConstants.CONFIG_DISCOVERY_SERVERURLS, "invalidURL",
+ AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
DiscoveryHandler discoveryHandler = m_agentContext.getHandler(DiscoveryHandler.class);
- assertNull(discoveryHandler.getServerUrl());
+ assertNull(discoveryHandler.getServerUrl()); // we cannot resolve this during the configuration change...
}
@Test