Author: rdonkin
Date: Tue Mar 17 11:32:25 2009
New Revision: 755195

URL: http://svn.apache.org/viewvc?rev=755195&view=rev
Log:
Ensure that connection is abandoned when line cannot be consumed. IMAP-69 
https://issues.apache.org/jira/browse/IMAP-69

Added:
    
james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
   (with props)
Modified:
    
james/protocols/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java

Modified: 
james/protocols/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java?rev=755195&r1=755194&r2=755195&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java
 (original)
+++ 
james/protocols/imap/trunk/seda/src/main/java/org/apache/james/imap/main/ImapRequestHandler.java
 Tue Mar 17 11:32:25 2009
@@ -125,6 +125,7 @@
                     }
                     logger.debug("Abandoning after fault in clean up", e);
                     abandon(output, session);
+                    return false;
                 }
 
                 result = !(ImapSessionState.LOGOUT == session.getState());

Added: 
james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java?rev=755195&view=auto
==============================================================================
--- 
james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
 (added)
+++ 
james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
 Tue Mar 17 11:32:25 2009
@@ -0,0 +1,88 @@
+/****************************************************************
+ * 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.james.imap.main;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.apache.james.api.imap.process.ImapProcessor;
+import org.apache.james.api.imap.process.ImapSession;
+import org.apache.james.imap.decode.ImapDecoder;
+import org.apache.james.imap.encode.ImapEncoder;
+import org.jmock.Expectations;
+import org.jmock.integration.junit3.MockObjectTestCase;
+
+public class ImapRequestHandlerAdandonConnectionTest extends 
MockObjectTestCase {
+
+    /** System under test */
+    ImapRequestHandler subject;
+    
+    // Fakes
+    /** Stores output */
+    ByteArrayOutputStream fakeOutput;
+    
+    // Stubs
+    ImapDecoder decoderStub;
+    ImapProcessor processorStub;
+    ImapEncoder encoderStub;
+    ImapSession sessionStub;    
+
+    @Override
+    protected void setUp() throws Exception {
+        // Fakes
+        fakeOutput = new ByteArrayOutputStream();
+        // Stubs
+        decoderStub = mock(ImapDecoder.class);
+        processorStub = mock(ImapProcessor.class);
+        encoderStub = mock(ImapEncoder.class);
+        sessionStub = mock(ImapSession.class);
+        // System under test
+        subject = new ImapRequestHandler(decoderStub, processorStub, 
encoderStub);
+        super.setUp();
+    }
+    
+    public void testWhenConsumeLineFailsShouldAbandonConnection() throws 
Exception {        
+        //
+        // Setup
+        //
+        
+        // Setup stubs
+        checking(new Expectations() {{
+            ignoring(decoderStub);
+            ignoring(processorStub);
+            ignoring(encoderStub);
+            ignoring(sessionStub);
+        }});
+        
+        // Create input stream that will throw IOException after first read
+        byte[] endOfStreamAfterOneCharacter = {'0'};
+        ByteArrayInputStream fakeInput = new 
ByteArrayInputStream(endOfStreamAfterOneCharacter);
+        
+        
+        // 
+        // Exercise
+        //
+        boolean result = subject.handleRequest(fakeInput, fakeOutput, 
sessionStub);
+        
+        //
+        // Verify output
+        //
+        assertFalse("Connection should be abandoned", result);
+    }
+}

Propchange: 
james/protocols/imap/trunk/seda/src/test/java/org/apache/james/imap/main/ImapRequestHandlerAdandonConnectionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to