directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r209435 - in /directory/network: branches/0.7/src/java/org/apache/mina/util/ trunk/ trunk/src/java/org/apache/mina/filter/ trunk/src/test/org/apache/mina/filter/
Date Wed, 06 Jul 2005 09:01:14 GMT
Author: trustin
Date: Wed Jul  6 02:01:12 2005
New Revision: 209435

URL: http://svn.apache.org/viewcvs?rev=209435&view=rev
Log:
Fix for DIRMINA-72 
* Call on ThreadPoolFilter.getSessionBuffer() was not synchronized properly.
* Added a regression test for this issue.


Added:
    directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
  (with props)
Modified:
    directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java
    directory/network/trunk/project.xml
    directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java

Modified: directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java?rev=209435&r1=209434&r2=209435&view=diff
==============================================================================
--- directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java (original)
+++ directory/network/branches/0.7/src/java/org/apache/mina/util/BaseThreadPool.java Wed Jul
 6 02:01:12 2005
@@ -175,17 +175,18 @@
     {
         final BlockingSet readySessionBuffers = this.readySessionBuffers;
         final Set busySessionBuffers = this.busySessionBuffers;
-        final SessionBuffer buf = getSessionBuffer( session );
-        final Queue eventQueue = buf.eventQueue;
         final Event event = new Event( type, nextFilter, data );
 
-        synchronized( buf )
-        {
-            eventQueue.push( event );
-        }
-
         synchronized( readySessionBuffers )
         {
+            final SessionBuffer buf = getSessionBuffer( session );
+            final Queue eventQueue = buf.eventQueue;
+
+            synchronized( buf )
+            {
+                eventQueue.push( event );
+            }
+
             if( !busySessionBuffers.contains( buf ) )
             {
                 busySessionBuffers.add( buf );

Modified: directory/network/trunk/project.xml
URL: http://svn.apache.org/viewcvs/directory/network/trunk/project.xml?rev=209435&r1=209434&r2=209435&view=diff
==============================================================================
--- directory/network/trunk/project.xml (original)
+++ directory/network/trunk/project.xml Wed Jul  6 02:01:12 2005
@@ -133,6 +133,7 @@
       <excludes>
         <exclude>**/Abstract*</exclude>
         <exclude>**/DatagramBindTest*</exclude>
+        <exclude>**/*RegressionTest*</exclude>
       </excludes>
     </unitTest>
 

Modified: directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java?rev=209435&r1=209434&r2=209435&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/filter/ThreadPoolFilter.java Wed Jul
 6 02:01:12 2005
@@ -133,17 +133,18 @@
     {
         final BlockingSet readySessionBuffers = this.readySessionBuffers;
         final Set busySessionBuffers = this.busySessionBuffers;
-        final SessionBuffer buf = getSessionBuffer( session );
-        final Queue eventQueue = buf.eventQueue;
         final Event event = new Event( type, nextFilter, data );
 
-        synchronized( buf )
-        {
-            eventQueue.push( event );
-        }
-
         synchronized( readySessionBuffers )
         {
+            final SessionBuffer buf = getSessionBuffer( session );
+            final Queue eventQueue = buf.eventQueue;
+
+            synchronized( buf )
+            {
+                eventQueue.push( event );
+            }
+
             if( !busySessionBuffers.contains( buf ) )
             {
                 busySessionBuffers.add( buf );

Added: directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java?rev=209435&view=auto
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
(added)
+++ directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
Wed Jul  6 02:01:12 2005
@@ -0,0 +1,182 @@
+package org.apache.mina.filter;
+
+import java.net.SocketAddress;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.mina.common.BaseIoSession;
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.common.IoFilter.NextFilter;
+import org.apache.mina.common.IoFilter.WriteRequest;
+
+public class ThreadPoolFilterRegressionTest extends TestCase
+{
+    private static final Object FILTER_PARENT = new Object();
+
+    private ThreadPoolFilter filter;
+    
+    public ThreadPoolFilterRegressionTest()
+    {
+    }
+    
+    public void setUp()
+    {
+        filter = new ThreadPoolFilter();
+        filter.filterAdded( FILTER_PARENT );
+    }
+    
+    public void tearDown()
+    {
+        filter.filterRemoved( FILTER_PARENT );
+        filter = null;
+    }
+    
+    public void testEventOrder() throws Throwable
+    {
+        final EventOrderChecker nextFilter = new EventOrderChecker();
+        final IoSession[] sessions = new IoSession[]
+        {
+            new EventOrderCounter(),
+            new EventOrderCounter(),
+            new EventOrderCounter(),
+            new EventOrderCounter(),
+            new EventOrderCounter(),
+            new EventOrderCounter(),
+            new EventOrderCounter(),
+            new EventOrderCounter(),
+            new EventOrderCounter(),
+            new EventOrderCounter(),
+        };
+        final int end = sessions.length - 1;
+        final ThreadPoolFilter filter = this.filter;
+        
+        for( int i = 0; i < 1000000; i++ )
+        {
+            Integer objI = new Integer( i );
+
+            for( int j = 0; j <= end; j++ )
+            {
+                filter.messageReceived( nextFilter, sessions[ j ], objI );
+            }
+
+            if( nextFilter.throwable != null )
+            {
+                throw nextFilter.throwable;
+            }
+        }
+    }
+    
+    private static class EventOrderCounter extends BaseIoSession
+    {
+        private Integer lastCount = null;
+
+        public synchronized void setLastCount( Integer newCount )
+        {
+            if( lastCount != null )
+            {
+                Assert.assertEquals( lastCount.intValue() + 1, newCount.intValue() );
+            }
+            
+            lastCount = newCount;
+        }
+
+        public IoHandler getHandler()
+        {
+            return null;
+        }
+
+        public IoFilterChain getFilterChain()
+        {
+            return null;
+        }
+
+        public WriteFuture write( Object message )
+        {
+            return null;
+        }
+
+        public CloseFuture close()
+        {
+            return null;
+        }
+
+        public TransportType getTransportType()
+        {
+            return null;
+        }
+
+        public boolean isConnected()
+        {
+            return false;
+        }
+
+        public IoSessionConfig getConfig()
+        {
+            return null;
+        }
+
+        public SocketAddress getRemoteAddress()
+        {
+            return null;
+        }
+
+        public SocketAddress getLocalAddress()
+        {
+            return null;
+        }
+
+        public int getScheduledWriteRequests()
+        {
+            return 0;
+        }
+    }
+    
+    private static class EventOrderChecker implements NextFilter
+    {
+        private Throwable throwable;
+
+        public void sessionOpened( IoSession session )
+        {
+        }
+
+        public void sessionClosed( IoSession session )
+        {
+        }
+
+        public void sessionIdle( IoSession session, IdleStatus status )
+        {
+        }
+
+        public void exceptionCaught( IoSession session, Throwable cause )
+        {
+        }
+
+        public void messageReceived( IoSession session, Object message )
+        {
+            try
+            {
+                ( ( EventOrderCounter ) session ).setLastCount( ( Integer ) message );
+            }
+            catch( Throwable t )
+            {
+                this.throwable = t;
+            }
+        }
+
+        public void messageSent( IoSession session, Object message )
+        {
+        }
+
+        public void filterWrite( IoSession session, WriteRequest writeRequest )
+        {
+        }
+    }
+}

Propchange: directory/network/trunk/src/test/org/apache/mina/filter/ThreadPoolFilterRegressionTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message