Author: jawi
Date: Tue Nov 19 11:03:31 2013
New Revision: 1543375
URL: http://svn.apache.org/r1543375
Log:
ACE-431 - configuration not always supplied before start of controller:
- changes in the configuration always caused an asynchronous event, which
could lead to the fact that the DefaultController was already started
before its configuration was supplied;
- when starting the ConfigurationHandler, a synchronous event is sent to
all listeners to ensure they have the configuration;
- another issue is that the order in which components were started is not
deterministic causing problems when the ConfigurationHandler was started
as last handler. Changed this to make the starting of handlers
deterministic;
- lastly, when the controller gets a new configuration, it will cancel any
pending tasks (leaving those that are already running, running) ensuring
that is will use the new configuration as soon as possible.
Modified:
ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BaseAgentTest.java
ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/CustomAgentControllerTest.java
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/DiscoveryHandlerImplTest.java
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java
Modified:
ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BaseAgentTest.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BaseAgentTest.java?rev=1543375&r1=1543374&r2=1543375&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BaseAgentTest.java
(original)
+++
ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/BaseAgentTest.java
Tue Nov 19 11:03:31 2013
@@ -3,11 +3,14 @@ package org.apache.ace.agent.itest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import org.apache.ace.agent.AgentConstants;
import org.apache.ace.agent.AgentControl;
+import org.apache.ace.agent.ConfigurationHandler;
import org.apache.ace.builder.DeploymentPackageBuilder;
import org.apache.ace.it.IntegrationTestBase;
import org.osgi.framework.Bundle;
@@ -45,7 +48,7 @@ public abstract class BaseAgentTest exte
}
m_file = createPackage(m_name, m_version, files);
}
-
+
public String getName() {
return m_name;
}
@@ -144,6 +147,14 @@ public abstract class BaseAgentTest exte
agentBundle.start();
}
+ protected void configureAgent(ConfigurationHandler handler, String...
configuration) {
+ Map<String, String> config = new HashMap<String, String>();
+ for (int i = 0; i < configuration.length; i += 2) {
+ config.put(configuration[i], configuration[i + 1]);
+ }
+ handler.putAll(config);
+ }
+
private void cleanDir(File dir) {
if (!dir.isDirectory()) {
throw new IllegalStateException();
Modified:
ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/CustomAgentControllerTest.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/CustomAgentControllerTest.java?rev=1543375&r1=1543374&r2=1543375&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/CustomAgentControllerTest.java
(original)
+++
ace/trunk/org.apache.ace.agent.itest/src/org/apache/ace/agent/itest/CustomAgentControllerTest.java
Tue Nov 19 11:03:31 2013
@@ -430,7 +430,7 @@ public class CustomAgentControllerTest e
@Override
protected void configureAdditionalServices() throws Exception {
-
m_control.getConfigurationHandler().put(AgentConstants.CONFIG_CONTROLLER_DISABLED,
"true");
+ configureAgent(m_control.getConfigurationHandler(),
AgentConstants.CONFIG_CONTROLLER_DISABLED, "true");
TestBundle bundle1v1 = new
TestBundle(TEST_BUNDLE_NAME_PREFIX.concat("1"), V1_0_0);
TestPackage package1 = new TestPackage(AGENT_ID, V1_0_0, bundle1v1);
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java?rev=1543375&r1=1543374&r2=1543375&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
(original)
+++
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/ConfigurationHandler.java
Tue Nov 19 11:03:31 2013
@@ -60,7 +60,10 @@ public interface ConfigurationHandler {
* The key, must not be <code>null</code>
* @param value
* The value, must not be <code>null</code>
+ * @deprecated use {@link #putAll(Map)} instead which allows the
configuration to be updated without partial
+ * visibility issues.
*/
+ @Deprecated
void put(String key, String value);
/**
@@ -76,7 +79,10 @@ public interface ConfigurationHandler {
*
* @param key
* The key, must not be <code>null</code>
+ * @deprecated use {@link #putAll(Map)} instead which allows the
configuration to be updated without partial
+ * visibility issues.
*/
+ @Deprecated
void remove(String key);
/**
@@ -97,7 +103,10 @@ public interface ConfigurationHandler {
* The key, must not be <code>null</code>
* @param value
* The value
+ * @deprecated use {@link #putAll(Map)} instead which allows the
configuration to be updated without partial
+ * visibility issues.
*/
+ @Deprecated
void putLong(String key, long value);
/**
@@ -118,6 +127,9 @@ public interface ConfigurationHandler {
* The key, must not be <code>null</code>
* @param value
* The value
+ * @deprecated use {@link #putAll(Map)} instead which allows the
configuration to be updated without partial
+ * visibility issues.
*/
+ @Deprecated
void putBoolean(String key, boolean Value);
}
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java?rev=1543375&r1=1543374&r2=1543375&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java
(original)
+++
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/AgentContextImpl.java
Tue Nov 19 11:03:31 2013
@@ -20,7 +20,7 @@ package org.apache.ace.agent.impl;
import java.io.File;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
@@ -60,7 +60,7 @@ public class AgentContextImpl implements
};
private final Map<Class<?>, Object> m_handlers = new HashMap<Class<?>,
Object>();
- private final Set<Object> m_components = new HashSet<Object>();
+ private final Set<Object> m_components = new LinkedHashSet<Object>();
private final File m_workDir;
public AgentContextImpl(File workDir) {
@@ -86,7 +86,9 @@ public class AgentContextImpl implements
for (Object component : m_components) {
initAgentContextAware(component);
}
- for (Object handler : m_handlers.values()) {
+ // Ensure the handlers are started in a deterministic order...
+ for (Class<?> handlerIface : KNOWN_HANDLERS) {
+ Object handler = m_handlers.get(handlerIface);
startAgentContextAware(handler);
}
for (Object component : m_components) {
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java?rev=1543375&r1=1543374&r2=1543375&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
(original)
+++
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/ConfigurationHandlerImpl.java
Tue Nov 19 11:03:31 2013
@@ -98,7 +98,7 @@ public class ConfigurationHandlerImpl ex
public void put(String key, String value) {
String previous = (String) m_configProps.put(key, value);
if (previous == null || !previous.equals(value)) {
- fireConfigChangeEvent();
+ fireConfigChangeEventAsynchronously();
// causes the config to be written eventually...
scheduleStore();
}
@@ -107,7 +107,7 @@ public class ConfigurationHandlerImpl ex
@Override
public void putAll(Map<String, String> props) {
m_configProps.putAll(props);
- fireConfigChangeEvent();
+ fireConfigChangeEventAsynchronously();
// causes the config to be written eventually...
scheduleStore();
}
@@ -126,7 +126,7 @@ public class ConfigurationHandlerImpl ex
public void remove(String key) {
Object value = m_configProps.remove(key);
if (value != null) {
- fireConfigChangeEvent();
+ fireConfigChangeEventAsynchronously();
// causes the config to be written eventually...
scheduleStore();
}
@@ -155,8 +155,8 @@ public class ConfigurationHandlerImpl ex
@Override
protected void onStart() throws Exception {
- // Notify all interested listeners about this...
- fireConfigChangeEvent();
+ // Notify all interested listeners about this, but do this the first
time synchronously, see ACE-431.
+ fireConfigChangeEventSynchronously();
}
@Override
@@ -165,12 +165,12 @@ public class ConfigurationHandlerImpl ex
storeConfig();
}
- private void fireConfigChangeEvent() {
- Map<String, String> props = new HashMap<String, String>();
- for (Map.Entry<Object, Object> entry : m_configProps.entrySet()) {
- props.put((String) entry.getKey(), (String) entry.getValue());
- }
- getEventsHandler().postEvent(EVENT_AGENT_CONFIG_CHANGED, props);
+ private void fireConfigChangeEventAsynchronously() {
+ getEventsHandler().postEvent(EVENT_AGENT_CONFIG_CHANGED,
getConfigurationSnapshot());
+ }
+
+ private void fireConfigChangeEventSynchronously() {
+ getEventsHandler().sendEvent(EVENT_AGENT_CONFIG_CHANGED,
getConfigurationSnapshot());
}
private File getConfigDir() throws IOException {
@@ -189,6 +189,17 @@ public class ConfigurationHandlerImpl ex
return file;
}
+ /**
+ * @return a new map instance with a snapshot of the current
configuration, never <code>null</code>.
+ */
+ private Map<String, String> getConfigurationSnapshot() {
+ Map<String, String> props = new HashMap<String, String>();
+ for (Map.Entry<Object, Object> entry : m_configProps.entrySet()) {
+ props.put((String) entry.getKey(), (String) entry.getValue());
+ }
+ return props;
+ }
+
private void loadConfig() throws IOException {
InputStream input = null;
try {
Modified:
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java?rev=1543375&r1=1543374&r2=1543375&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
(original)
+++
ace/trunk/org.apache.ace.agent/src/org/apache/ace/agent/impl/DefaultController.java
Tue Nov 19 11:03:31 2013
@@ -477,6 +477,8 @@ public class DefaultController extends C
}
logDebug("Config changed: disabled: %s, update: %s, fixPkg: %s,
syncDelay: %d, syncInterval: %d, maxRetries: %d", m_disabled.get(),
m_updateStreaming.get(), m_fixPackage.get(), m_syncDelay.get(),
m_interval.get(), m_maxRetries.get());
+
+ scheduleRunAfterDelay();
}
}
@@ -514,11 +516,7 @@ public class DefaultController extends C
@Override
protected void onStart() throws Exception {
- long delay = m_syncDelay.get();
-
- scheduleRun(delay);
-
- logDebug("Controller scheduled to run in %d seconds", delay);
+ scheduleRunAfterDelay();
}
@Override
@@ -531,6 +529,14 @@ public class DefaultController extends C
unscheduleRun();
}
+
+ protected void scheduleRunAfterDelay() {
+ long delay = m_syncDelay.get();
+
+ scheduleRun(delay);
+
+ logDebug("Controller scheduled to run in %d seconds", delay);
+ }
protected void scheduleRun(long seconds) {
unscheduleRun();
Modified:
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java?rev=1543375&r1=1543374&r2=1543375&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
(original)
+++
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/ConfigurationHandlerImplTest.java
Tue Nov 19 11:03:31 2013
@@ -117,8 +117,7 @@ public class ConfigurationHandlerImplTes
System.setProperty(systemKey1, "value1");
System.setProperty(systemKey2, "value2");
- configurationHandler.put(systemKey1, "newvalue1");
- configurationHandler.put(systemKey2, "newvalue2");
+ configureAgent(configurationHandler, systemKey1, "newvalue1",
systemKey2, "newvalue2");
m_agentContextImpl.stop();
m_agentContextImpl.setHandler(ConfigurationHandler.class, new
ConfigurationHandlerImpl());
@@ -157,8 +156,7 @@ public class ConfigurationHandlerImplTes
m_agentContextImpl.start();
configurationHandler =
m_agentContextImpl.getHandler(ConfigurationHandler.class);
- configurationHandler.putBoolean("boolean1", true);
- configurationHandler.putBoolean("boolean2", false);
+ configureAgent(configurationHandler, "boolean1", "true", "boolean2",
"false");
assertEquals(configurationHandler.getBoolean("boolean1", false), true);
assertEquals(configurationHandler.getBoolean("boolean2", true), false);
@@ -176,8 +174,7 @@ public class ConfigurationHandlerImplTes
m_agentContextImpl.start();
configurationHandler =
m_agentContextImpl.getHandler(ConfigurationHandler.class);
- configurationHandler.putLong("long1", 42);
- configurationHandler.putLong("long2", 4l);
+ configureAgent(configurationHandler, "long1", "42", "long2", "4");
assertEquals(configurationHandler.getLong("long1", 0l), 42);
assertEquals(configurationHandler.getLong("long2", 0l), 4l);
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=1543375&r1=1543374&r2=1543375&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
Tue Nov 19 11:03:31 2013
@@ -79,8 +79,7 @@ public class DiscoveryHandlerImplTest ex
public void testAvailableURL() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContext.getHandler(ConfigurationHandler.class);
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_SERVERURLS,
m_availableURL.toExternalForm());
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_CHECKING,
"true");
+ configureAgent(configurationHandler,
AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_availableURL.toExternalForm(),
AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
DiscoveryHandler discoveryHandler =
m_agentContext.getHandler(DiscoveryHandler.class);
assertEquals(discoveryHandler.getServerUrl(), m_availableURL);
@@ -90,8 +89,7 @@ public class DiscoveryHandlerImplTest ex
public void testUnavailableURL_unavailable() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContext.getHandler(ConfigurationHandler.class);
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_SERVERURLS,
m_unavailableURL.toExternalForm());
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_CHECKING,
"true");
+ configureAgent(configurationHandler,
AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_unavailableURL.toExternalForm(),
AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
DiscoveryHandler discoveryHandler =
m_agentContext.getHandler(DiscoveryHandler.class);
assertNull(discoveryHandler.getServerUrl());
@@ -101,13 +99,12 @@ public class DiscoveryHandlerImplTest ex
public void testUnavailableAfterConfigUpdate() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContext.getHandler(ConfigurationHandler.class);
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_SERVERURLS,
m_availableURL.toExternalForm());
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_CHECKING,
"true");
+ configureAgent(configurationHandler,
AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_availableURL.toExternalForm(),
AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
DiscoveryHandler discoveryHandler =
m_agentContext.getHandler(DiscoveryHandler.class);
assertEquals(discoveryHandler.getServerUrl(), m_availableURL);
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_SERVERURLS,
m_unavailableURL.toExternalForm());
+ configureAgent(configurationHandler,
AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_unavailableURL.toExternalForm());
assertNull(discoveryHandler.getServerUrl());
}
@@ -116,13 +113,12 @@ public class DiscoveryHandlerImplTest ex
public void testAvailableAfterConfigUpdate() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContext.getHandler(ConfigurationHandler.class);
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_SERVERURLS,
m_unavailableURL.toExternalForm());
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_CHECKING,
"true");
+ configureAgent(configurationHandler,
AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_unavailableURL.toExternalForm(),
AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
DiscoveryHandler discoveryHandler =
m_agentContext.getHandler(DiscoveryHandler.class);
assertNull(discoveryHandler.getServerUrl());
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_SERVERURLS,
m_availableURL.toExternalForm());
+ configureAgent(configurationHandler,
AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_availableURL.toExternalForm());
assertEquals(discoveryHandler.getServerUrl(), m_availableURL);
}
@@ -131,8 +127,7 @@ public class DiscoveryHandlerImplTest ex
public void testAvailableAfterUnavailableURL() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContext.getHandler(ConfigurationHandler.class);
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_SERVERURLS,
m_unavailableURL.toExternalForm() + "," + m_availableURL.toExternalForm());
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_CHECKING,
"true");
+ configureAgent(configurationHandler,
AgentConstants.CONFIG_DISCOVERY_SERVERURLS, m_unavailableURL.toExternalForm() +
"," + m_availableURL.toExternalForm(),
AgentConstants.CONFIG_DISCOVERY_CHECKING, "true");
DiscoveryHandler discoveryHandler =
m_agentContext.getHandler(DiscoveryHandler.class);
assertEquals(discoveryHandler.getServerUrl(), m_availableURL);
@@ -142,8 +137,7 @@ public class DiscoveryHandlerImplTest ex
public void testEmptyURLConfig() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContext.getHandler(ConfigurationHandler.class);
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_SERVERURLS,
"");
- configurationHandler.put(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());
@@ -153,8 +147,7 @@ public class DiscoveryHandlerImplTest ex
public void testBadURLConfig() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContext.getHandler(ConfigurationHandler.class);
- configurationHandler.put(AgentConstants.CONFIG_DISCOVERY_SERVERURLS,
"invalidURL");
- configurationHandler.put(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());
Modified:
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java?rev=1543375&r1=1543374&r2=1543375&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java
(original)
+++
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/impl/FeedbackHandlerImplTest.java
Tue Nov 19 11:03:31 2013
@@ -83,7 +83,7 @@ public class FeedbackHandlerImplTest ext
public void testSingleFeedbackChannelConfig() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContextImpl.getHandler(ConfigurationHandler.class);
- configurationHandler.put(CONFIG_FEEDBACK_CHANNELS, AUDITLOG);
+ configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS,
AUDITLOG);
FeedbackHandler feedbackHandler =
m_agentContextImpl.getHandler(FeedbackHandler.class);
@@ -95,7 +95,7 @@ public class FeedbackHandlerImplTest ext
public void testUpdateConfigAddFeedbackChannel() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContextImpl.getHandler(ConfigurationHandler.class);
- configurationHandler.put(CONFIG_FEEDBACK_CHANNELS, AUDITLOG);
+ configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS,
AUDITLOG);
FeedbackHandler feedbackHandler =
m_agentContextImpl.getHandler(FeedbackHandler.class);
@@ -104,7 +104,7 @@ public class FeedbackHandlerImplTest ext
assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG);
assertFeedbackChannelsNotPresent(feedbackHandler, CUSTOMCHANNEL);
- configurationHandler.put(CONFIG_FEEDBACK_CHANNELS,
AUDITLOG_AND_CUSTOMCHANNEL);
+ configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS,
AUDITLOG_AND_CUSTOMCHANNEL);
assertFeedbackChannelNames(feedbackHandler, AUDITLOG, CUSTOMCHANNEL);
@@ -115,14 +115,14 @@ public class FeedbackHandlerImplTest ext
public void testUpdateConfigRemoveFeedbackChannel() throws Exception {
ConfigurationHandler configurationHandler =
m_agentContextImpl.getHandler(ConfigurationHandler.class);
- configurationHandler.put(CONFIG_FEEDBACK_CHANNELS,
AUDITLOG_AND_CUSTOMCHANNEL);
+ configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS,
AUDITLOG_AND_CUSTOMCHANNEL);
FeedbackHandler feedbackHandler =
m_agentContextImpl.getHandler(FeedbackHandler.class);
assertFeedbackChannelNames(feedbackHandler, AUDITLOG, CUSTOMCHANNEL);
assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG,
CUSTOMCHANNEL);
- configurationHandler.put(CONFIG_FEEDBACK_CHANNELS, AUDITLOG);
+ configureAgent(configurationHandler, CONFIG_FEEDBACK_CHANNELS,
AUDITLOG);
assertFeedbackChannelNames(feedbackHandler, AUDITLOG);
assertFeedbackChannelsPresent(feedbackHandler, AUDITLOG);
Modified:
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java
URL:
http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java?rev=1543375&r1=1543374&r2=1543375&view=diff
==============================================================================
---
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java
(original)
+++
ace/trunk/org.apache.ace.agent/test/org/apache/ace/agent/testutil/BaseAgentTest.java
Tue Nov 19 11:03:31 2013
@@ -26,12 +26,15 @@ import static org.easymock.EasyMock.veri
import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.ace.agent.AgentContext;
import org.apache.ace.agent.AgentContextAware;
+import org.apache.ace.agent.ConfigurationHandler;
import org.apache.ace.agent.impl.AgentContextImpl;
import org.osgi.framework.BundleContext;
import org.testng.annotations.AfterClass;
@@ -59,6 +62,14 @@ public abstract class BaseAgentTest {
m_mocks.clear();
}
+ protected void configureAgent(ConfigurationHandler handler, String...
configuration) {
+ Map<String, String> config = new HashMap<String, String>();
+ for (int i = 0; i < configuration.length; i += 2) {
+ config.put(configuration[i], configuration[i + 1]);
+ }
+ handler.putAll(config);
+ }
+
protected File getWorkDir() {
return new File("generated");
}