You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2007/08/22 14:40:58 UTC

svn commit: r568590 - in /mina/trunk/core/src: main/java/org/apache/mina/common/ main/java/org/apache/mina/filter/codec/ test/java/org/apache/mina/filter/stream/ test/java/org/apache/mina/filter/util/ test/java/org/apache/mina/util/

Author: trustin
Date: Wed Aug 22 05:40:57 2007
New Revision: 568590

URL: http://svn.apache.org/viewvc?rev=568590&view=rev
Log:
* Added DummySession
* Changed ProtocolCodecSession to extend DummySession



Added:
    mina/trunk/core/src/main/java/org/apache/mina/common/DummySession.java   (with props)
Removed:
    mina/trunk/core/src/test/java/org/apache/mina/util/DummySession.java
Modified:
    mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecSession.java
    mina/trunk/core/src/test/java/org/apache/mina/filter/stream/StreamWriteFilterTest.java
    mina/trunk/core/src/test/java/org/apache/mina/filter/util/WrappingFilterTest.java

Added: mina/trunk/core/src/main/java/org/apache/mina/common/DummySession.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/common/DummySession.java?rev=568590&view=auto
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/common/DummySession.java (added)
+++ mina/trunk/core/src/main/java/org/apache/mina/common/DummySession.java Wed Aug 22 05:40:57 2007
@@ -0,0 +1,205 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.mina.common;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+/**
+ * A dummy {@link IoSession} for unit-testing or non-network-use of
+ * the classes that depends on {@link IoSession}.
+ * 
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
+ */
+public class DummySession extends AbstractIoSession {
+    
+    private static final TransportMetadata TRANSPORT_METADATA =
+        new DefaultTransportMetadata(
+                "dummy", false, false,
+                SocketAddress.class, IoSessionConfig.class, Object.class);
+    
+    private static final SocketAddress ANONYMOUS_ADDRESS = new SocketAddress() {
+        private static final long serialVersionUID = -496112902353454179L;
+
+        @Override
+        public String toString() {
+            return "?";
+        }
+    };
+    
+    private volatile IoService service;
+
+    private final IoSessionConfig config = new AbstractIoSessionConfig() {
+        @Override
+        protected void doSetAll(IoSessionConfig config) {
+        }
+    };
+    
+    private final IoFilterChain filterChain = new AbstractIoFilterChain(this) {
+        @Override
+        protected void doClose(IoSession session) throws Exception {
+        }
+
+        @Override
+        protected void doWrite(IoSession session, WriteRequest writeRequest)
+                throws Exception {
+        }
+    };
+    
+    private volatile IoHandler handler = new IoHandlerAdapter();
+    private volatile SocketAddress localAddress = ANONYMOUS_ADDRESS;
+    private volatile SocketAddress remoteAddress = ANONYMOUS_ADDRESS;
+    private volatile TransportMetadata transportMetadata = TRANSPORT_METADATA;
+
+    /**
+     * Creates a new instance.
+     */
+    public DummySession() {
+        // Initialize dumy service.
+        IoAcceptor acceptor = new AbstractIoAcceptor(
+                new AbstractIoSessionConfig() {
+                    @Override
+                    protected void doSetAll(IoSessionConfig config) {
+                    }
+                }) {
+
+            @Override
+            protected void doBind() throws IOException {
+                throw new UnsupportedOperationException();
+            }
+
+            @Override
+            protected void doUnbind() {
+                throw new UnsupportedOperationException();
+            }
+
+            public IoSession newSession(SocketAddress remoteAddress) {
+                throw new UnsupportedOperationException();
+            }
+
+            public TransportMetadata getTransportMetadata() {
+                return TRANSPORT_METADATA;
+            }
+        };
+        
+        // Set meaningless default values.
+        acceptor.setHandler(new IoHandlerAdapter());
+        acceptor.setLocalAddress(ANONYMOUS_ADDRESS);
+
+        this.service = acceptor;
+    }
+    
+    @Override
+    protected void updateTrafficMask() {
+    }
+
+    public IoSessionConfig getConfig() {
+        return config;
+    }
+
+    public IoFilterChain getFilterChain() {
+        return filterChain;
+    }
+
+    public IoHandler getHandler() {
+        return handler;
+    }
+    
+    /**
+     * Sets the {@link IoHandler} which handles this session.
+     */
+    public void setHandler(IoHandler handler) {
+        if (handler == null) {
+            throw new NullPointerException("handler");
+        }
+        
+        this.handler = handler;
+    }
+
+    public SocketAddress getLocalAddress() {
+        return localAddress;
+    }
+
+    public SocketAddress getRemoteAddress() {
+        return remoteAddress;
+    }
+    
+    /**
+     * Sets the socket address of local machine which is associated with
+     * this session.
+     */
+    public void setLocalAddress(SocketAddress localAddress) {
+        if (localAddress == null) {
+            throw new NullPointerException("localAddress");
+        }
+        
+        this.localAddress = localAddress;
+    }
+    
+    /**
+     * Sets the socket address of remote peer. 
+     */
+    public void setRemoteAddress(SocketAddress remoteAddress) {
+        if (remoteAddress == null) {
+            throw new NullPointerException("remoteAddress");
+        }
+        
+        this.remoteAddress = remoteAddress;
+    }
+
+    public int getScheduledWriteBytes() {
+        return 0;
+    }
+
+    public int getScheduledWriteMessages() {
+        return 0;
+    }
+
+    public IoService getService() {
+        return service;
+    }
+    
+    /**
+     * Sets the {@link IoService} which provides I/O service to this session.
+     */
+    public void setService(IoService service) {
+        if (service == null) {
+            throw new NullPointerException("service");
+        }
+        
+        this.service = service;
+    }
+
+    public TransportMetadata getTransportMetadata() {
+        return transportMetadata;
+    }
+    
+    /**
+     * Sets the {@link TransportMetadata} that this session runs on.
+     */
+    public void setTransportMetadata(TransportMetadata transportMetadata) {
+        if (transportMetadata == null) {
+            throw new NullPointerException("transportMetadata");
+        }
+        
+        this.transportMetadata = transportMetadata;
+    }
+}

Propchange: mina/trunk/core/src/main/java/org/apache/mina/common/DummySession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: mina/trunk/core/src/main/java/org/apache/mina/common/DummySession.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecSession.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecSession.java?rev=568590&r1=568589&r2=568590&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecSession.java (original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/codec/ProtocolCodecSession.java Wed Aug 22 05:40:57 2007
@@ -19,122 +19,45 @@
  */
 package org.apache.mina.filter.codec;
 
-import java.io.IOException;
-import java.net.SocketAddress;
 import java.util.Queue;
 
-import org.apache.mina.common.AbstractIoAcceptor;
-import org.apache.mina.common.AbstractIoFilterChain;
-import org.apache.mina.common.AbstractIoSession;
-import org.apache.mina.common.AbstractIoSessionConfig;
 import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.DefaultTransportMetadata;
 import org.apache.mina.common.DefaultWriteFuture;
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.IoFilterChain;
-import org.apache.mina.common.IoHandler;
-import org.apache.mina.common.IoHandlerAdapter;
-import org.apache.mina.common.IoService;
+import org.apache.mina.common.DummySession;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.common.IoSessionConfig;
-import org.apache.mina.common.TransportMetadata;
 import org.apache.mina.common.WriteFuture;
-import org.apache.mina.common.WriteRequest;
 
 /**
  * A virtual {@link IoSession} that provides {@link ProtocolEncoderOutput}
- * and {@link ProtocolDecoderOutput}.  It is useful for unit testing
- * codec and reusing codec for non-network use (e.g. serialization).
+ * and {@link ProtocolDecoderOutput}.  It is useful for unit-testing
+ * codec and reusing codec for non-network-use (e.g. serialization).
  * 
- * <h2>Decoding</h2>
+ * <h2>Encoding</h2>
  * <pre>
  * ProtocolCodecSession session = new ProtocolCodecSession();
- * ProtocolDecoder decoder = ...;
- * ByteBuffer in = ...;
+ * ProtocolEncoder encoder = ...;
+ * MessageX in = ...;
  * 
- * decoder.decode(session, in, session.getProtocolDecoderOutput());
+ * encoder.encode(session, in, session.getProtocolEncoderOutput());
  * 
- * Object message = session.getProtocolDecoderOutputQueue().poll();
+ * ByteBuffer buffer = session.getProtocolDecoderOutputQueue().poll();
  * </pre>
  * 
- * <h2>Encoding</h2>
+ * <h2>Decoding</h2>
  * <pre>
  * ProtocolCodecSession session = new ProtocolCodecSession();
- * ProtocolEncoder encoder = ...;
- * MessageX in = ...;
+ * ProtocolDecoder decoder = ...;
+ * ByteBuffer in = ...;
  * 
- * encoder.encode(session, in, session.getProtocolEncoderOutput());
+ * decoder.decode(session, in, session.getProtocolDecoderOutput());
  * 
- * ByteBuffer buffer = session.getProtocolDecoderOutputQueue().poll();
+ * Object message = session.getProtocolDecoderOutputQueue().poll();
  * </pre>
  * 
  * @author The Apache MINA Project (dev@mina.apache.org)
  * @version $Rev$, $Date$
  */
-public class ProtocolCodecSession extends AbstractIoSession {
-    
-    private static final TransportMetadata METADATA =
-        new DefaultTransportMetadata(
-                "codec", false, false,
-                SocketAddress.class, IoSessionConfig.class, Object.class);
-    
-    private static final IoSessionConfig SERVICE_CONFIG = new AbstractIoSessionConfig() {
-        @Override
-        protected void doSetAll(IoSessionConfig config) {
-        }
-    };
-    
-    private static final SocketAddress ANONYMOUS_ADDRESS = new SocketAddress() {
-        private static final long serialVersionUID = -496112902353454179L;
-
-        @Override
-        public String toString() {
-            return "?";
-        }
-    };
-    
-    private static final IoAcceptor SERVICE = new AbstractIoAcceptor(SERVICE_CONFIG) {
-        @Override
-        protected void doBind() throws IOException {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        protected void doUnbind() {
-            throw new UnsupportedOperationException();
-        }
-
-        public IoSession newSession(SocketAddress remoteAddress) {
-            throw new UnsupportedOperationException();
-        }
-
-        public TransportMetadata getTransportMetadata() {
-            return METADATA;
-        }
-    };
-    
-    static {
-        // Set meaningless default values.
-        SERVICE.setHandler(new IoHandlerAdapter());
-        SERVICE.setLocalAddress(ANONYMOUS_ADDRESS);
-    }
-
-    private final IoSessionConfig config = new AbstractIoSessionConfig() {
-        @Override
-        protected void doSetAll(IoSessionConfig config) {
-        }
-    };
-    
-    private final IoFilterChain filterChain = new AbstractIoFilterChain(this) {
-        @Override
-        protected void doClose(IoSession session) throws Exception {
-        }
-
-        @Override
-        protected void doWrite(IoSession session, WriteRequest writeRequest)
-                throws Exception {
-        }
-    };
+public class ProtocolCodecSession extends DummySession {
     
     private final WriteFuture notWrittenFuture =
         DefaultWriteFuture.newNotWrittenFuture(this);
@@ -152,10 +75,6 @@
             }
     };
     
-    private volatile IoHandler handler = new IoHandlerAdapter();
-    private volatile SocketAddress localAddress = ANONYMOUS_ADDRESS;
-    private volatile SocketAddress remoteAddress = ANONYMOUS_ADDRESS;
-
     /**
      * Creates a new instance.
      */
@@ -190,79 +109,5 @@
      */
     public Queue<Object> getDecoderOutputQueue() {
         return decoderOutput.getMessageQueue();
-    }
-    
-    @Override
-    protected void updateTrafficMask() {
-    }
-
-    public IoSessionConfig getConfig() {
-        return config;
-    }
-
-    public IoFilterChain getFilterChain() {
-        return filterChain;
-    }
-
-    public IoHandler getHandler() {
-        return handler;
-    }
-    
-    /**
-     * Sets the {@link IoHandler} which handles this session.
-     */
-    public void setHandler(IoHandler handler) {
-        if (handler == null) {
-            throw new NullPointerException("handler");
-        }
-        
-        this.handler = handler;
-    }
-
-    public SocketAddress getLocalAddress() {
-        return localAddress;
-    }
-
-    public SocketAddress getRemoteAddress() {
-        return remoteAddress;
-    }
-    
-    /**
-     * Sets the socket address of local machine which is associated with
-     * this session.
-     */
-    public void setLocalAddress(SocketAddress localAddress) {
-        if (localAddress == null) {
-            throw new NullPointerException("localAddress");
-        }
-        
-        this.localAddress = localAddress;
-    }
-    
-    /**
-     * Sets the socket address of remote peer. 
-     */
-    public void setRemoteAddress(SocketAddress remoteAddress) {
-        if (remoteAddress == null) {
-            throw new NullPointerException("remoteAddress");
-        }
-        
-        this.remoteAddress = remoteAddress;
-    }
-
-    public int getScheduledWriteBytes() {
-        return 0;
-    }
-
-    public int getScheduledWriteMessages() {
-        return 0;
-    }
-
-    public IoService getService() {
-        return SERVICE;
-    }
-
-    public TransportMetadata getTransportMetadata() {
-        return METADATA;
     }
 }

Modified: mina/trunk/core/src/test/java/org/apache/mina/filter/stream/StreamWriteFilterTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/filter/stream/StreamWriteFilterTest.java?rev=568590&r1=568589&r2=568590&view=diff
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/filter/stream/StreamWriteFilterTest.java (original)
+++ mina/trunk/core/src/test/java/org/apache/mina/filter/stream/StreamWriteFilterTest.java Wed Aug 22 05:40:57 2007
@@ -34,6 +34,7 @@
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.DefaultWriteRequest;
+import org.apache.mina.common.DummySession;
 import org.apache.mina.common.IdleStatus;
 import org.apache.mina.common.IoFutureListener;
 import org.apache.mina.common.IoHandlerAdapter;
@@ -44,7 +45,6 @@
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
 import org.apache.mina.transport.socket.nio.SocketConnector;
 import org.apache.mina.util.AvailablePortFinder;
-import org.apache.mina.util.DummySession;
 import org.easymock.AbstractMatcher;
 import org.easymock.MockControl;
 

Modified: mina/trunk/core/src/test/java/org/apache/mina/filter/util/WrappingFilterTest.java
URL: http://svn.apache.org/viewvc/mina/trunk/core/src/test/java/org/apache/mina/filter/util/WrappingFilterTest.java?rev=568590&r1=568589&r2=568590&view=diff
==============================================================================
--- mina/trunk/core/src/test/java/org/apache/mina/filter/util/WrappingFilterTest.java (original)
+++ mina/trunk/core/src/test/java/org/apache/mina/filter/util/WrappingFilterTest.java Wed Aug 22 05:40:57 2007
@@ -1,12 +1,18 @@
 package org.apache.mina.filter.util;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import junit.framework.TestCase;
-import org.apache.mina.common.*;
-import org.apache.mina.util.DummySession;
-import org.easymock.MockControl;
 
-import java.util.List;
-import java.util.ArrayList;
+import org.apache.mina.common.DefaultWriteRequest;
+import org.apache.mina.common.DummySession;
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoEventType;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteRequest;
+import org.easymock.MockControl;
 
 /**
  * Tests {@link WrappingFilter}.