directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r190252 - in /directory/network/branches/dirmina-39/src: java/org/apache/mina/common/ConnectFuture.java test/org/apache/mina/common/FutureTest.java
Date Sun, 12 Jun 2005 11:39:00 GMT
Author: trustin
Date: Sun Jun 12 04:38:59 2005
New Revision: 190252

URL: http://svn.apache.org/viewcvs?rev=190252&view=rev
Log:
Added: FutureTest

Added:
    directory/network/branches/dirmina-39/src/test/org/apache/mina/common/FutureTest.java
  (with props)
Modified:
    directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java

Modified: directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java?rev=190252&r1=190251&r2=190252&view=diff
==============================================================================
--- directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java
(original)
+++ directory/network/branches/dirmina-39/src/java/org/apache/mina/common/ConnectFuture.java
Sun Jun 12 04:38:59 2005
@@ -20,6 +20,11 @@
         }
     }
     
+    public boolean isConnected()
+    {
+        return getValue() instanceof IoSession;
+    }
+    
     public void setSession( IoSession session )
     {
         setValue( session );

Added: directory/network/branches/dirmina-39/src/test/org/apache/mina/common/FutureTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/dirmina-39/src/test/org/apache/mina/common/FutureTest.java?rev=190252&view=auto
==============================================================================
--- directory/network/branches/dirmina-39/src/test/org/apache/mina/common/FutureTest.java
(added)
+++ directory/network/branches/dirmina-39/src/test/org/apache/mina/common/FutureTest.java
Sun Jun 12 04:38:59 2005
@@ -0,0 +1,127 @@
+package org.apache.mina.common;
+
+import java.net.SocketAddress;
+
+import junit.framework.TestCase;
+
+public class FutureTest extends TestCase
+{
+    
+    public void testCloseFuture() throws Exception
+    {
+        CloseFuture future = new CloseFuture();
+        assertFalse( future.isReady() );
+        assertFalse( future.isClosed() );
+        
+        TestThread thread = new TestThread( future );
+        thread.start();
+        
+        future.setClosed( true );
+        thread.join();
+        
+        assertTrue( thread.success );
+        assertTrue( future.isReady() );
+        assertTrue( future.isClosed() );
+        
+    }
+    
+    public void testConnectFuture() throws Exception
+    {
+        ConnectFuture future = new ConnectFuture();
+        assertFalse( future.isReady() );
+        assertFalse( future.isConnected() );
+        assertNull( future.getSession() );
+
+        TestThread thread = new TestThread( future );
+        thread.start();
+        
+        IoSession session = new BaseIoSession()
+        {
+            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;
+            }
+        };
+        
+        future.setSession( session );
+        thread.join();
+        
+        assertTrue( thread.success );
+        assertTrue( future.isReady() );
+        assertTrue( future.isConnected() );
+        assertEquals( session, future.getSession() );
+    }
+    
+    public void testWriteFuture() throws Exception
+    {
+        WriteFuture future = new WriteFuture();
+        assertFalse( future.isReady() );
+        assertFalse( future.isWritten() );
+        
+        TestThread thread = new TestThread( future );
+        thread.start();
+        
+        future.setWritten( true );
+        thread.join();
+        
+        assertTrue( thread.success );
+        assertTrue( future.isReady() );
+        assertTrue( future.isWritten() );
+    }
+    
+    private static class TestThread extends Thread
+    {
+        private final IoFuture future;
+        private boolean success;
+        
+        public TestThread( IoFuture future )
+        {
+            this.future = future;
+        }
+        
+        public void run()
+        {
+            success = future.join( 10000 );
+        }
+    }
+}

Propchange: directory/network/branches/dirmina-39/src/test/org/apache/mina/common/FutureTest.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message