You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2014/07/22 22:08:09 UTC
svn commit: r1612682 - in /commons/proper/configuration/trunk/src:
main/java/org/apache/commons/configuration/builder/
main/java/org/apache/commons/configuration/builder/combined/
test/java/org/apache/commons/configuration/builder/combined/
Author: oheger
Date: Tue Jul 22 20:08:09 2014
New Revision: 1612682
URL: http://svn.apache.org/r1612682
Log:
Fixed failing test cases.
MultiFileConfigurationBuilder now keeps a separate list of the event listeners
which have to be passed to managed builders. It is filled with event listeners
not related to builder events.
Modified:
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java?rev=1612682&r1=1612681&r2=1612682&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/BasicConfigurationBuilder.java Tue Jul 22 20:08:09 2014
@@ -606,11 +606,10 @@ public class BasicConfigurationBuilder<T
}
/**
- * Copies all {@code ConfigurationListener} and
- * {@code ConfigurationErrorListener} objects to the specified target
- * configuration builder. This method is intended to be used by derived
- * classes which support inheritance of their properties to other builder
- * objects.
+ * Copies all {@code EventListener} objects registered at this builder to
+ * the specified target configuration builder. This method is intended to be
+ * used by derived classes which support inheritance of their properties to
+ * other builder objects.
*
* @param target the target configuration builder (must not be <b>null</b>)
* @throws NullPointerException if the target builder is <b>null</b>
@@ -618,7 +617,23 @@ public class BasicConfigurationBuilder<T
protected synchronized void copyEventListeners(
BasicConfigurationBuilder<?> target)
{
- target.eventListeners.addAll(eventListeners);
+ copyEventListeners(target, eventListeners);
+ }
+
+ /**
+ * Copies all event listeners in the specified list to the specified target
+ * configuration builder. This method is intended to be used by derived
+ * classes which have to deal with managed configuration builders that need
+ * to be initialized with event listeners.
+ *
+ * @param target the target configuration builder (must not be <b>null</b>)
+ * @param listeners the event listeners to be copied over
+ * @throws NullPointerException if the target builder is <b>null</b>
+ */
+ protected void copyEventListeners(BasicConfigurationBuilder<?> target,
+ EventListenerList listeners)
+ {
+ target.eventListeners.addAll(listeners);
}
/**
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java?rev=1612682&r1=1612681&r2=1612682&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/combined/MultiFileConfigurationBuilder.java Tue Jul 22 20:08:09 2014
@@ -31,6 +31,7 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration.event.Event;
import org.apache.commons.configuration.event.EventListener;
+import org.apache.commons.configuration.event.EventListenerList;
import org.apache.commons.configuration.event.EventType;
import org.apache.commons.configuration.ex.ConfigurationException;
import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
@@ -99,6 +100,9 @@ public class MultiFileConfigurationBuild
private final ThreadLocal<Boolean> inInterpolation =
new ThreadLocal<Boolean>();
+ /** A list for the event listeners to be passed to managed builders. */
+ private final EventListenerList configurationListeners = new EventListenerList();
+
/**
* A specialized event listener which gets registered at all managed
* builders. This listener just propagates notifications from managed
@@ -227,31 +231,43 @@ public class MultiFileConfigurationBuild
/**
* {@inheritDoc} This implementation ensures that the listener is also added
- * at managed configuration builders.
+ * to managed configuration builders if necessary. Listeners for the builder-related
+ * event types are excluded because otherwise they would be triggered by the
+ * internally used configuration builders.
*/
@Override
public synchronized <E extends Event> void addEventListener(
EventType<E> eventType, EventListener<? super E> l)
{
super.addEventListener(eventType, l);
- for (FileBasedConfigurationBuilder<T> b : getManagedBuilders().values())
+ if (isEventTypeForManagedBuilders(eventType))
{
- b.addEventListener(eventType, l);
+ for (FileBasedConfigurationBuilder<T> b : getManagedBuilders()
+ .values())
+ {
+ b.addEventListener(eventType, l);
+ }
+ configurationListeners.addEventListener(eventType, l);
}
}
/**
* {@inheritDoc} This implementation ensures that the listener is also
- * removed from managed configuration builders.
+ * removed from managed configuration builders if necessary.
*/
@Override
public synchronized <E extends Event> boolean removeEventListener(
EventType<E> eventType, EventListener<? super E> l)
{
boolean result = super.removeEventListener(eventType, l);
- for (FileBasedConfigurationBuilder<T> b : getManagedBuilders().values())
+ if (isEventTypeForManagedBuilders(eventType))
{
- b.removeEventListener(eventType, l);
+ for (FileBasedConfigurationBuilder<T> b : getManagedBuilders()
+ .values())
+ {
+ b.removeEventListener(eventType, l);
+ }
+ configurationListeners.removeEventListener(eventType, l);
}
return result;
}
@@ -407,7 +423,7 @@ public class MultiFileConfigurationBuild
*/
private void initListeners(FileBasedConfigurationBuilder<T> newBuilder)
{
- copyEventListeners(newBuilder);
+ copyEventListeners(newBuilder, configurationListeners);
newBuilder.addEventListener(ConfigurationBuilderEvent.RESET,
managedBuilderDelegationListener);
}
@@ -472,4 +488,20 @@ public class MultiFileConfigurationBuild
}
return newParams;
}
+
+ /**
+ * Checks whether the given event type is of interest for the managed
+ * configuration builders. This method is called by the methods for managing
+ * event listeners to find out whether a listener should be passed to the
+ * managed builders, too.
+ *
+ * @param eventType the event type object
+ * @return a flag whether this event type is of interest for managed
+ * builders
+ */
+ private static boolean isEventTypeForManagedBuilders(EventType<?> eventType)
+ {
+ return !EventType
+ .isInstanceOf(eventType, ConfigurationBuilderEvent.ANY);
+ }
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java?rev=1612682&r1=1612681&r2=1612682&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java Tue Jul 22 20:08:09 2014
@@ -79,7 +79,6 @@ import org.apache.commons.configuration.
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -1223,7 +1222,7 @@ public class TestCombinedConfigurationBu
/**
* Tests whether reloading support works for MultiFileConfigurationBuilder.
*/
- @Test @Ignore
+ @Test
public void testMultiTenentConfigurationReloading()
throws ConfigurationException, InterruptedException
{
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java?rev=1612682&r1=1612681&r2=1612682&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestMultiFileConfigurationBuilder.java Tue Jul 22 20:08:09 2014
@@ -43,13 +43,13 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.event.ConfigurationEvent;
import org.apache.commons.configuration.event.Event;
import org.apache.commons.configuration.event.EventListener;
+import org.apache.commons.configuration.event.EventListenerTestImpl;
import org.apache.commons.configuration.ex.ConfigurationException;
import org.apache.commons.configuration.interpol.ConfigurationInterpolator;
import org.apache.commons.configuration.interpol.DefaultLookups;
import org.apache.commons.configuration.tree.ExpressionEngine;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.easymock.EasyMock;
-import org.junit.Ignore;
import org.junit.Test;
import org.xml.sax.SAXParseException;
@@ -257,26 +257,24 @@ public class TestMultiFileConfigurationB
@Test
public void testAddConfigurationListener() throws ConfigurationException
{
- @SuppressWarnings("unchecked")
- EventListener<ConfigurationEvent> l1 =
- EasyMock.createMock(EventListener.class);
+ EventListener<ConfigurationEvent> l1 = new EventListenerTestImpl(null);
@SuppressWarnings("unchecked")
EventListener<Event> l2 =
EasyMock.createMock(EventListener.class);
- EasyMock.replay(l1, l2);
+ EasyMock.replay(l2);
MultiFileConfigurationBuilder<XMLConfiguration> builder =
createTestBuilder(null);
- builder.addConfigurationListener(ConfigurationEvent.ANY, l1);
+ builder.addEventListener(ConfigurationEvent.ANY, l1);
switchToConfig(1);
XMLConfiguration config = builder.getConfiguration();
assertTrue("Listener not added", config.getEventListeners(ConfigurationEvent.ANY)
.contains(l1));
- builder.addConfigurationListener(Event.ANY, l2);
+ builder.addEventListener(Event.ANY, l2);
assertTrue("Listener 2 not added", config.getEventListeners(Event.ANY)
.contains(l2));
- assertTrue("Wrong result", builder.removeConfigurationListener(Event.ANY, l2));
+ assertTrue("Wrong result", builder.removeEventListener(Event.ANY, l2));
assertFalse("Wrong result after removal",
- builder.removeConfigurationListener(Event.ANY, l2));
+ builder.removeEventListener(Event.ANY, l2));
assertFalse("Listener not removed", config.getEventListeners(Event.ANY)
.contains(l2));
switchToConfig(2);
@@ -350,7 +348,7 @@ public class TestMultiFileConfigurationB
/**
* Tests whether builder listeners are handled correctly.
*/
- @Test @Ignore
+ @Test
public void testBuilderListener() throws ConfigurationException
{
BuilderEventListenerImpl listener = new BuilderEventListenerImpl();
@@ -371,7 +369,7 @@ public class TestMultiFileConfigurationB
* Tests whether listeners at managed builders are removed when the cache is
* cleared.
*/
- @Test @Ignore
+ @Test
public void testRemoveBuilderListenerOnReset()
throws ConfigurationException
{