cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r952752 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/ itests/cayenne-di-stack/sr...
Date Tue, 08 Jun 2010 17:51:07 GMT
Author: aadamchik
Date: Tue Jun  8 17:51:07 2010
New Revision: 952752

URL: http://svn.apache.org/viewvc?rev=952752&view=rev
Log:
 CAY-1421 CayenneRuntime shutdown functionality

* shutdown integration tests
* a more robust EM shutdown method

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/EventManager.java
    cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=952752&r1=952751&r2=952752&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Tue Jun  8 17:51:07 2010
@@ -37,6 +37,7 @@ CAY-1414 Remove org.apache.cayenne.conf 
 CAY-1415 Replace WebApplicationContextFilter with a DI-enabled filter
 CAY-1419 File-based ResourceLocator to replace legacy FileConfiguration
 CAY-1420 Migrate ROP server-side components to DI-based stack
+CAY-1421 CayenneRuntime shutdown functionality
 CAY-1422 Convert EventManager to an interface, make it injectable
 CAY-1424 DI: support for named service injection and flexible map/list binding
 CAY-1425 Remove Configuration sharedConfiguration singleton affecting DataContext deserialization,
CayenneDataObject XML deserialization, DataContext static factory method. 

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorTest.java?rev=952752&r1=952751&r2=952752&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/test/java/org/apache/cayenne/di/spi/DefaultInjectorTest.java
Tue Jun  8 17:51:07 2010
@@ -22,6 +22,9 @@ import junit.framework.TestCase;
 
 import org.apache.cayenne.di.Binder;
 import org.apache.cayenne.di.Module;
+import org.apache.cayenne.di.OnScopeEnd;
+import org.apache.cayenne.di.mock.MockImplementation1_EventAnnotations;
+import org.apache.cayenne.di.mock.MockInterface1;
 
 public class DefaultInjectorTest extends TestCase {
 
@@ -66,5 +69,33 @@ public class DefaultInjectorTest extends
         assertTrue(configureCalled[0]);
         assertTrue(configureCalled[1]);
     }
+    
+    public void testShutdown() {
+
+        MockImplementation1_EventAnnotations.reset();
+
+        Module module = new Module() {
+
+            public void configure(Binder binder) {
+                binder.bind(MockInterface1.class).to(
+                        MockImplementation1_EventAnnotations.class).inSingletonScope();
+            }
+        };
+
+        DefaultInjector injector = new DefaultInjector(module);
+
+        MockInterface1 instance1 = injector.getInstance(MockInterface1.class);
+        assertEquals("XuI", instance1.getName());
+
+        assertFalse(MockImplementation1_EventAnnotations.shutdown1);
+        assertFalse(MockImplementation1_EventAnnotations.shutdown2);
+        assertFalse(MockImplementation1_EventAnnotations.shutdown3);
+
+        injector.shutdown();
+
+        assertTrue(MockImplementation1_EventAnnotations.shutdown1);
+        assertTrue(MockImplementation1_EventAnnotations.shutdown2);
+        assertTrue(MockImplementation1_EventAnnotations.shutdown3);
+    }
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java?rev=952752&r1=952751&r2=952752&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java
Tue Jun  8 17:51:07 2010
@@ -82,6 +82,15 @@ public class DefaultEventManager impleme
     }
 
     /**
+     * Returns true if the EventManager was stopped via {@link #shutdown()} method.
+     * 
+     * @since 3.1
+     */
+    public boolean isStopped() {
+        return stopped;
+    }
+
+    /**
      * Returns true if this EventManager is single-threaded. If so it will throw an
      * exception on any attempt to register an unblocking listener or dispatch a
      * non-blocking event.
@@ -100,10 +109,15 @@ public class DefaultEventManager impleme
      */
     @OnScopeEnd
     public void shutdown() {
-        this.stopped = true;
 
-        for (DispatchThread thread : dispatchThreads) {
-            thread.interrupt();
+        if (!stopped) {
+
+            for (DispatchThread thread : dispatchThreads) {
+                thread.interrupt();
+            }
+
+            dispatchThreads.clear();
+            this.stopped = true;
         }
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/EventManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/EventManager.java?rev=952752&r1=952751&r2=952752&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/EventManager.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/EventManager.java
Tue Jun  8 17:51:07 2010
@@ -40,14 +40,6 @@ public interface EventManager {
     boolean isSingleThreaded();
 
     /**
-     * Stops event threads. After the EventManager is stopped, it can not be restarted and
-     * should be discarded.
-     * 
-     * @since 3.0
-     */
-    void shutdown();
-
-    /**
      * Register an <code>EventListener</code> for events sent by any sender.
      * 
      * @throws RuntimeException if <code>methodName</code> is not found.

Modified: cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java?rev=952752&r1=952751&r2=952752&view=diff
==============================================================================
--- cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java
(original)
+++ cayenne/main/trunk/itests/cayenne-di-stack/src/test/java/org/apache/cayenne/runtime/CayenneServerRuntimeIntegrationTest.java
Tue Jun  8 17:51:07 2010
@@ -23,6 +23,8 @@ import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.configuration.server.CayenneServerRuntimeCase;
 import org.apache.cayenne.configuration.server.RuntimeName;
+import org.apache.cayenne.event.DefaultEventManager;
+import org.apache.cayenne.event.EventManager;
 import org.apache.cayenne.itest.di_stack.Table1;
 import org.apache.cayenne.query.SelectQuery;
 import org.apache.cayenne.test.DBHelper;
@@ -78,4 +80,25 @@ public class CayenneServerRuntimeIntegra
 		assertEquals(o1.getObjectId(), o2.getObjectId());
 
 	}
+
+	public void testShutdown() throws Exception {
+
+		// create a context and save some objects to warm up the stack...
+		ObjectContext context1 = runtime.getContext();
+
+		Table1 t1 = context1.newObject(Table1.class);
+		t1.setName("XmKK");
+		context1.commitChanges();
+
+		// ensure that some of the services that require shutdown are
+		// instantiated and check their state before and after
+		EventManager em = runtime.getInjector().getInstance(EventManager.class);
+		assertNotNull(em);
+		assertTrue(em instanceof DefaultEventManager);
+		assertFalse(((DefaultEventManager) em).isStopped());
+
+		runtime.getInjector().shutdown();
+
+		assertTrue(((DefaultEventManager) em).isStopped());
+	}
 }



Mime
View raw message