1. opensymphony
  2. xwork

Commits

tm_jee  committed 2d5ebfd

XW-439
- clean up of ConfigurationManager is incomplete

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@1218e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits 89b96db
  • Branches master

Comments (0)

Files changed (3)

File src/java/com/opensymphony/xwork2/config/ConfigurationManager.java

View file
      */
     public void clearConfigurationProviders() {
         for (ConfigurationProvider configurationProvider : configurationProviders) {
-            configurationProvider.destroy();
+        	try {
+        		configurationProvider.destroy();
+        	}
+        	catch(Exception e) {
+        		LOG.warn("error while destroying configuration provider ["+configurationProvider+"]", e);
+        	}
         }
-
         configurationProviders.clear();
     }
 
+    /**
+     * Destroy its managing Configuration instance
+     */
     public synchronized void destroyConfiguration() {
         clearConfigurationProviders(); // let's destroy the ConfigurationProvider first
         setConfigurationProviders(new CopyOnWriteArrayList<ConfigurationProvider>());
             }
 
             if (reload) {
+            	for (ConfigurationProvider configurationProvider : configurationProviders) {
+                	try {
+                		configurationProvider.destroy();
+                	}
+                	catch(Exception e) {
+                		LOG.warn("error while destroying configuration provider ["+configurationProvider+"]", e);
+                	}
+                }
                 configuration.reload(providers);
             }
         }

File src/java/com/opensymphony/xwork2/config/impl/DefaultConfiguration.java

View file
      */
     public void destroy() {
         packageContexts.clear();
+        loadedFileNames.clear();
     }
 
     public void rebuildRuntimeConfiguration() {

File src/test/com/opensymphony/xwork2/config/ConfigurationManagerTest.java

View file
 
 //import org.easymock.MockControl;
 
+import java.util.Properties;
+
 import com.mockobjects.dynamic.C;
 import com.mockobjects.dynamic.Mock;
+import com.opensymphony.xwork2.inject.ContainerBuilder;
 import com.opensymphony.xwork2.util.FileManager;
+import com.opensymphony.xwork2.util.location.LocatableProperties;
 import com.opensymphony.xwork2.XWorkTestCase;
 
 
         configProviderMock.expect("init", C.isA(Configuration.class));
         configProviderMock.expect("register", C.ANY_ARGS);
         configProviderMock.expect("loadPackages", C.ANY_ARGS);
+        configProviderMock.expect("destroy", C.ANY_ARGS);
         configProviderMock.matchAndReturn("toString", "mock");
         configurationManager.getConfiguration();
         configProviderMock.verify();
         configProviderMock.expect("destroy");
     }
 
-//    public void testDestroyConfiguration() throws Exception {
-//    	MockControl control = MockControl.createControl(Configuration.class);
-//    	Configuration configuration = (Configuration) control.getMock();
-//    	ConfigurationManager.setConfiguration(configuration);
-//
-//    	configuration.destroy();		// EasyMock
-//    	configProviderMock.expect("destroy");  // MockObject
-//    	control.replay();
-//    	ConfigurationManager.destroyConfiguration();
-//    	configProviderMock.verify();
-//    	control.verify();
-//    }
+    public void testDestroyConfiguration() throws Exception {
+    	class State {
+    		public boolean isDestroyed1 =false;
+    		public boolean isDestroyed2 =false;
+    	};
+    	
+    	final State state = new State();
+    	ConfigurationManager configurationManager = new ConfigurationManager();
+    	configurationManager.addConfigurationProvider(new ConfigurationProvider() {
+			public void destroy() { 
+				throw new RuntimeException("testing testing 123");
+			}
+			public void init(Configuration configuration) throws ConfigurationException {
+			}
+			public void loadPackages() throws ConfigurationException {
+			}
+			public boolean needsReload() { return false;
+			}
+			public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
+			}
+			public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
+			}
+    	});
+    	configurationManager.addConfigurationProvider(new ConfigurationProvider() {
+			public void destroy() { 
+				state.isDestroyed1 = true;
+			}
+			public void init(Configuration configuration) throws ConfigurationException {
+			}
+			public void loadPackages() throws ConfigurationException {
+			}
+			public boolean needsReload() { return false;
+			}
+			public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
+			}
+			public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
+			}
+    	});
+    	configurationManager.addConfigurationProvider(new ConfigurationProvider() {
+			public void destroy() { 
+				throw new RuntimeException("testing testing 123");
+			}
+			public void init(Configuration configuration) throws ConfigurationException {
+			}
+			public void loadPackages() throws ConfigurationException {
+			}
+			public boolean needsReload() { return false;
+			}
+			public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
+			}
+			public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
+			}
+    	});
+    	configurationManager.addConfigurationProvider(new ConfigurationProvider() {
+			public void destroy() { 
+				state.isDestroyed2 = true;
+			}
+			public void init(Configuration configuration) throws ConfigurationException {
+			}
+			public void loadPackages() throws ConfigurationException {
+			}
+			public boolean needsReload() { return false;
+			}
+			public void register(ContainerBuilder builder, Properties props) throws ConfigurationException {
+			}
+			public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
+			}
+    	});
+    	
+    	assertFalse(state.isDestroyed1);
+    	assertFalse(state.isDestroyed2);
+    	
+    	configurationManager.clearConfigurationProviders();
+    	
+    	assertTrue(state.isDestroyed1);
+    	assertTrue(state.isDestroyed2);
+    }
 
     public void testClearConfigurationProviders() throws Exception {
         configProviderMock.expect("destroy");