You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by tm...@apache.org on 2006/11/18 07:59:28 UTC

svn commit: r476459 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/dispatcher/Dispatcher.java test/java/org/apache/struts2/dispatcher/DispatcherTest.java

Author: tmjee
Date: Fri Nov 17 22:59:27 2006
New Revision: 476459

URL: http://svn.apache.org/viewvc?view=rev&rev=476459
Log:
WW-1511
 - Dispatcher should cleaning up ConfigurationManager 


Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?view=diff&rev=476459&r1=476458&r2=476459
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java Fri Nov 17 22:59:27 2006
@@ -239,6 +239,8 @@
      * Release local threads and destroy any DispatchListeners.
      */
     public void cleanup() {
+    	
+    	// clean up ObjectFactory
         ObjectFactory objectFactory = ObjectFactory.getObjectFactory();
         if (objectFactory == null) {
             LOG.warn("Object Factory is null, something is seriously wrong, no clean up will be performed");
@@ -252,7 +254,11 @@
                 LOG.error("exception occurred while destroying ObjectFactory ["+objectFactory+"]", e);
             }
         }
+        
+        // clean up Dispatcher itself
         instance.set(null);
+        
+        // clean up DispatcherListeners
         synchronized(Dispatcher.class) {
             if (dispatcherListeners.size() > 0) {
                 for (DispatcherListener l : dispatcherListeners) {
@@ -260,6 +266,10 @@
                 }
             }
         }
+        
+        // clean up configuration 
+    	configurationManager.destroyConfiguration();
+    	configurationManager = null;
     }
 
     /**

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java?view=diff&rev=476459&r1=476458&r2=476459
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java (original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java Fri Nov 17 22:59:27 2006
@@ -30,7 +30,9 @@
 import org.apache.struts2.StrutsTestCase;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
+import org.springframework.mock.web.MockServletContext;
 
+import com.opensymphony.xwork2.config.ConfigurationManager;
 import com.opensymphony.xwork2.util.LocalizedTextUtil;
 
 /**
@@ -77,5 +79,71 @@
         du.prepare(req, res);
 
         assertEquals("utf-8", req.getCharacterEncoding());
+    }
+    
+    public void testDispatcherListener() throws Exception {
+    	
+    	final DispatcherListenerState state = new DispatcherListenerState();
+    	
+    	Dispatcher.addDispatcherListener(new DispatcherListener() {
+			public void dispatcherDestroyed(Dispatcher du) {
+				state.isDestroyed = true;
+			}
+			public void dispatcherInitialized(Dispatcher du) {
+				state.isInitialized = true;
+			}
+    	});
+    	
+    	
+    	assertFalse(state.isDestroyed);
+    	assertFalse(state.isInitialized);
+    	
+        Dispatcher du = initDispatcher(new HashMap<String, String>() );
+    	
+    	assertTrue(state.isInitialized);
+    	
+    	du.cleanup();
+    	
+    	assertTrue(state.isDestroyed);
+    }
+    
+    
+    public void testConfigurationManager() {
+    	Dispatcher du = null;
+    	final InternalConfigurationManager configurationManager = new InternalConfigurationManager();
+    	try {
+    		du = new Dispatcher(new MockServletContext(), new HashMap<String, String>()) {
+    			{
+    				setConfigurationManager(configurationManager);
+    			}
+    		};
+            Dispatcher.setInstance(du);
+            
+            assertFalse(configurationManager.destroyConfiguration);
+            
+            du.cleanup();
+            
+            assertTrue(configurationManager.destroyConfiguration);
+            
+    	}
+    	finally {
+    		du.setInstance(null);
+    	}
+    }
+    
+    class InternalConfigurationManager extends ConfigurationManager {
+    	public boolean destroyConfiguration = false;
+    	
+    	@Override
+    	public synchronized void destroyConfiguration() {
+    		super.destroyConfiguration();
+    		destroyConfiguration = true;
+    	}
+    }
+    
+    
+    class DispatcherListenerState {
+    	public boolean isInitialized = false;
+    	public boolean isDestroyed = false;
     }
 }