geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r607542 [6/6] - in /geronimo/sandbox/async-http-client-mina2: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/ahc/ src/main/java/org/apache/ahc/auth/ src/main/java/org/apache/ahc/codec/...
Date Sun, 30 Dec 2007 11:37:00 GMT
Added: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AuthTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AuthTest.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AuthTest.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AuthTest.java Sun
Dec 30 03:36:47 2007
@@ -0,0 +1,89 @@
+/*
+ *  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.ahc;
+
+import java.net.URL;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.ahc.auth.AuthScope;
+import org.apache.ahc.auth.UsernamePasswordCredentials;
+import org.apache.ahc.codec.HttpRequestMessage;
+
+public class AuthTest extends AbstractTest {
+
+    AsyncHttpClient ahc;
+
+    public void testBasicAuth() throws Exception {
+        TestCallback callback = new TestCallback();
+        HttpRequestMessage request = new HttpRequestMessage(
+            new URL("http://localhost:8282/authbasic/secure.jsp"), callback);
+
+        UsernamePasswordCredentials creds = new UsernamePasswordCredentials("test","password");
+        request.addCredentials(AuthScope.ANY, creds);
+        ahc.sendRequest(request);
+
+        callback.await(5, TimeUnit.SECONDS);
+
+        assertEquals(200, callback.getMessage().getStatusCode());
+        assertEquals("Hello World!\n", callback.getMessage().getStringContent());
+    }
+
+    public void testBasicAuthFailure() throws Exception {
+
+        TestCallback callback = new TestCallback();
+        HttpRequestMessage request = new HttpRequestMessage(
+            new URL("http://localhost:8282/authbasic/secure.jsp"), callback);
+
+        UsernamePasswordCredentials creds = new UsernamePasswordCredentials("test","badpassword");
+        request.addCredentials(AuthScope.ANY, creds);
+        ahc.sendRequest(request);
+
+        callback.await(5, TimeUnit.SECONDS);
+
+        //Should be an auth failure
+        assertEquals(401, callback.getMessage().getStatusCode());
+    }
+
+    public void testDigestAuth() throws Exception {
+        TestCallback callback = new TestCallback();
+        HttpRequestMessage request = new HttpRequestMessage(
+            new URL("http://localhost:8282/authdigest/secure.jsp"), callback);
+
+        UsernamePasswordCredentials creds = new UsernamePasswordCredentials("test","password");
+        request.addCredentials(AuthScope.ANY, creds);
+        ahc.sendRequest(request);
+
+        callback.await(5, TimeUnit.SECONDS);
+
+        assertEquals(200, callback.getMessage().getStatusCode());
+        assertEquals("Hello World!\n", callback.getMessage().getStringContent());
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        ahc = new AsyncHttpClient();
+        ahc.setTcpNoDelay(true);
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        ahc.destroyAll();
+    }
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AuthTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AuthTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AuthTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ChunkedTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ChunkedTest.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ChunkedTest.java
(added)
+++ geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ChunkedTest.java
Sun Dec 30 03:36:47 2007
@@ -0,0 +1,83 @@
+/*
+ *  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.ahc;
+
+import junit.framework.TestCase;
+import org.apache.ahc.codec.HttpResponseDecoder;
+import org.apache.ahc.codec.HttpResponseMessage;
+import org.apache.mina.common.IoBuffer;
+import org.apache.mina.common.IoSession;
+
+import java.util.Arrays;
+
+public class ChunkedTest extends TestCase {
+
+    private static final String FAKE_HTTP =
+        "HTTP/1.1 200 OK\r\n" 
+            + "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n"
+            + "Content-Type: text/plain\r\n"
+            + "Transfer-Encoding: chunked\r\n"
+            + "\r\n"
+            + "1a; ignore-stuff-here\r\n"
+            + "abcdefghijklmnopqrstuvwxyz\r\n"
+            + "10\r\n"
+            + "1234567890abcdef\r\n"
+            + "0\r\n"
+            + "some-footer: some-value\r\n"
+            + "another-footer: another-value\r\n\r\n";
+
+
+    private static final String  FAKE_HTTP_CONTINUE =
+        "HTTP/1.1 100 Continue\r\n" 
+            + "Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n" 
+            + "Content-Type: text/plain\r\n"
+            + "\r\n" + FAKE_HTTP;
+
+    public void testChunking() throws Exception {
+        IoBuffer buffer = IoBuffer.allocate(FAKE_HTTP.length());
+        buffer.put(FAKE_HTTP.getBytes());
+        buffer.flip();
+
+        IoSession session = new FakeIoSession();
+        HttpResponseDecoder decoder = new HttpResponseDecoder();
+        FakeProtocolDecoderOutput out = new FakeProtocolDecoderOutput();
+        decoder.decode(session, buffer, out);
+
+        HttpResponseMessage response = (HttpResponseMessage)out.getObject();
+        assertTrue(
+            Arrays.equals(response.getContent(), "abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes()));
+    }
+
+    public void testChunkingContinue() throws Exception {
+        IoBuffer buffer = IoBuffer.allocate(FAKE_HTTP_CONTINUE.length());
+        buffer.put(FAKE_HTTP.getBytes());
+        buffer.flip();
+
+        IoSession session = new FakeIoSession();
+        HttpResponseDecoder decoder = new HttpResponseDecoder();
+        FakeProtocolDecoderOutput out = new FakeProtocolDecoderOutput();
+        decoder.decode(session, buffer, out);
+
+        HttpResponseMessage response = (HttpResponseMessage)out.getObject();
+        assertTrue(
+            Arrays.equals(response.getContent(), "abcdefghijklmnopqrstuvwxyz1234567890abcdef".getBytes()));
+    }
+
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ChunkedTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ChunkedTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ChunkedTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ConnectionReuseTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ConnectionReuseTest.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ConnectionReuseTest.java
(added)
+++ geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ConnectionReuseTest.java
Sun Dec 30 03:36:47 2007
@@ -0,0 +1,126 @@
+/*
+ *  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.ahc;
+
+import java.net.URL;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.ahc.codec.HttpRequestMessage;
+import org.apache.ahc.codec.HttpResponseMessage;
+
+public class ConnectionReuseTest extends AbstractTest {
+    // variable that keeps count of session close's
+    private final AtomicInteger closeCount = new AtomicInteger(0);
+    
+    // It is important that this test case contains these methods in this order.
+    // It is because to test connection reuse we need to keep the embedded 
+    // server running while connections are reused.  However, AbstractTest 
+    // starts and tears down the server around each test method.
+    public void testConnectionReuse() throws Exception {
+        // reset the count
+        closeCount.set(0);
+        Future<HttpResponseMessage> future = 
+                submitRequest("http://localhost:8282/", true, new SessionCloseCounter());
+
+        HttpResponseMessage msg = future.get();
+        assertEquals("\nHello World!", msg.getStringContent());
+        
+        // do another request for the same host
+        future = submitRequest("http://localhost:8282/params.jsp", true, 
+                new SessionCloseCounter());
+
+        msg = future.get();
+        assertEquals("Test One Test Two", msg.getStringContent());
+        
+        // check that I got zero close at this point
+        assertEquals(0, closeCount.get());
+    }
+    
+    
+    public void testSSLConnectionReuse() throws Exception {
+        // reset the count
+        closeCount.set(0);
+        Future<HttpResponseMessage> future = 
+                submitRequest("https://localhost:8383/", true, new SessionCloseCounter());
+
+        HttpResponseMessage msg = future.get();
+        assertEquals("\nHello World!", msg.getStringContent());
+        
+        // do another request for the same host
+        future = submitRequest("https://localhost:8383/", true, new SessionCloseCounter());
+
+        msg = future.get();
+        assertEquals("\nHello World!", msg.getStringContent());
+        
+        // check that I got zero close at this point
+        assertEquals(0, closeCount.get());
+    }
+    
+    
+    public void testConnectionClose() throws Exception {
+        // reset the count
+        closeCount.set(0);
+        Future<HttpResponseMessage> future = 
+                submitRequest("http://localhost:8282/", false, new SessionCloseCounter());
+
+        HttpResponseMessage msg = future.get();
+        assertEquals("\nHello World!", msg.getStringContent());
+        
+        // do another request for the same host
+        future = submitRequest("http://localhost:8282/params.jsp", false, 
+                new SessionCloseCounter());
+
+        msg = future.get();
+        assertEquals("Test One Test Two", msg.getStringContent());
+        
+        // give it a bit of time to catch up
+        Thread.sleep(500L);
+        
+        // check that I got close count of 2 at this point
+        assertEquals(2, closeCount.get());
+    }
+    
+    private Future<HttpResponseMessage> submitRequest(String url, 
+                                                      boolean reuseConnection,
+                                                      AsyncHttpClientCallback cb) 
+            throws Exception {
+        HttpRequestMessage request = new HttpRequestMessage(new URL(url), cb);
+
+        request.setParameter("TEST1", "Test One");
+        request.setParameter("TEST2", "Test Two");
+        AsyncHttpClient ahc = new AsyncHttpClient();
+        ahc.setReuseConnection(reuseConnection);
+        ahc.setTcpNoDelay(true);
+        return ahc.sendRequest(request);
+    }
+    
+    private class SessionCloseCounter implements AsyncHttpClientCallback {
+        public void onClosed() {
+            System.out.println("onClosed()");
+            // increment the counter on every close
+            closeCount.incrementAndGet();
+        }
+
+        public void onException(Throwable cause) {}
+        public void onResponse(HttpResponseMessage message) {}
+        public void onTimeout() {}
+    }
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ConnectionReuseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ConnectionReuseTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ConnectionReuseTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeIoSession.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeIoSession.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeIoSession.java
(added)
+++ geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeIoSession.java
Sun Dec 30 03:36:47 2007
@@ -0,0 +1,342 @@
+/*
+ * 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.ahc;
+
+import java.net.SocketAddress;
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.mina.common.*;
+import org.apache.mina.transport.socket.SocketSessionConfig;
+
+public class FakeIoSession implements IoSession {
+
+    private Map<Object, Object> attributes = new HashMap<Object, Object>();
+    private TransportMetadata META = new DefaultTransportMetadata(
+                    "nio", "socket", false, true,
+                    InetSocketAddress.class,
+                    SocketSessionConfig.class,
+                    IoBuffer.class, FileRegion.class);
+
+    public long getId() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public IoService getService() {
+        return null;
+    }
+
+    public IoHandler getHandler() {
+        return null;
+    }
+
+    public IoSessionConfig getConfig() {
+        return null;
+    }
+
+    public IoFilterChain getFilterChain() {
+        return null;
+    }
+
+    public TransportMetadata getTransportMetadata() {
+        return META;
+    }
+
+    public ReadFuture read() {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public WriteFuture write(Object object) {
+        return null;
+    }
+
+    public WriteFuture write(Object o, SocketAddress socketAddress) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public CloseFuture close() {
+        return null;
+    }
+
+    public CloseFuture closeOnFlush() {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public CloseFuture close(boolean b) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object getAttachment() {
+        return null;
+    }
+
+    public Object setAttachment(Object object) {
+        return null;
+    }
+
+    public Object getAttribute(Object o) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object getAttribute(Object o, Object o1) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object setAttribute(Object o, Object o1) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object setAttribute(Object o) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object setAttributeIfAbsent(Object o, Object o1) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object setAttributeIfAbsent(Object o) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object removeAttribute(Object o) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public boolean removeAttribute(Object o, Object o1) {
+        return false;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public boolean replaceAttribute(Object o, Object o1, Object o2) {
+        return false;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public boolean containsAttribute(Object o) {
+        return false;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object getAttribute(String string) {
+        return attributes.get(string);
+    }
+
+    public Object getAttribute(String key, Object defaultValue) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object setAttribute(String string, Object object) {
+        return attributes.put(string, object);
+    }
+
+    public Object setAttribute(String string) {
+        return attributes.put(string, null);
+    }
+
+    public Object setAttributeIfAbsent(String key, Object value) {
+        return null;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public Object removeAttribute(String string) {
+        return attributes.remove(string);
+    }
+
+    public boolean removeAttribute(String key, Object value) {
+        return false;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public boolean replaceAttribute(String key, Object oldValue, Object newValue) {
+        return false;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+
+    public boolean containsAttribute(String string) {
+        return attributes.containsKey(string);
+    }
+
+    public Set<Object> getAttributeKeys() {
+        return attributes.keySet();
+    }
+
+    public boolean isConnected() {
+        return false;
+    }
+
+    public boolean isClosing() {
+        return false;
+    }
+
+    public CloseFuture getCloseFuture() {
+        return null;
+    }
+
+    public SocketAddress getRemoteAddress() {
+        return null;
+    }
+
+    public SocketAddress getLocalAddress() {
+        return null;
+    }
+
+    public SocketAddress getServiceAddress() {
+        return null;
+    }
+
+    public int getIdleTime(IdleStatus idleStatus) {
+        return 0;
+    }
+
+    public long getIdleTimeInMillis(IdleStatus idleStatus) {
+        return 0;
+    }
+
+    public void setIdleTime(IdleStatus idleStatus, int i) {
+    }
+
+    public int getWriteTimeout() {
+        return 0;
+    }
+
+    public long getWriteTimeoutInMillis() {
+        return 0;
+    }
+
+    public void setWriteTimeout(int i) {
+    }
+
+    public TrafficMask getTrafficMask() {
+        return null;
+    }
+
+    public void setTrafficMask(TrafficMask trafficMask) {
+    }
+
+    public void suspendRead() {
+    }
+
+    public void suspendWrite() {
+    }
+
+    public void resumeRead() {
+    }
+
+    public void resumeWrite() {
+    }
+
+    public long getReadBytes() {
+        return 0;
+    }
+
+    public long getWrittenBytes() {
+        return 0;
+    }
+
+    public long getReadMessages() {
+        return 0;
+    }
+
+    public long getWrittenMessages() {
+        return 0;
+    }
+
+    public double getReadBytesThroughput() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public double getWrittenBytesThroughput() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public double getReadMessagesThroughput() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public double getWrittenMessagesThroughput() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public int getScheduledWriteMessages() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public long getWrittenWriteRequests() {
+        return 0;
+    }
+
+    public int getScheduledWriteRequests() {
+        return 0;
+    }
+
+    public long getScheduledWriteBytes() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public long getCreationTime() {
+        return 0;
+    }
+
+    public long getLastIoTime() {
+        return 0;
+    }
+
+    public long getLastReadTime() {
+        return 0;
+    }
+
+    public long getLastWriteTime() {
+        return 0;
+    }
+
+    public boolean isIdle(IdleStatus idleStatus) {
+        return false;
+    }
+
+    public int getIdleCount(IdleStatus idleStatus) {
+        return 0;
+    }
+
+    public int getReaderIdleCount() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public int getWriterIdleCount() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public int getBothIdleCount() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public long getLastIdleTime(IdleStatus idleStatus) {
+        return 0;
+    }
+
+    public long getLastReaderIdleTime() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public long getLastWriterIdleTime() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public long getLastBothIdleTime() {
+        return 0;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeIoSession.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeIoSession.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeIoSession.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java
(added)
+++ geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java
Sun Dec 30 03:36:47 2007
@@ -0,0 +1,41 @@
+/*
+ * 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.ahc;
+
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+
+public class FakeProtocolDecoderOutput implements ProtocolDecoderOutput {
+    
+    private Object object;
+
+    public void write(Object obj) {
+        this.object = obj;
+    }
+
+    public void flush() {
+    }
+
+
+    public Object getObject() {
+        return object;
+    }
+
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeRealm.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeRealm.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeRealm.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeRealm.java Sun
Dec 30 03:36:47 2007
@@ -0,0 +1,57 @@
+/*
+ *  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.ahc;
+
+import java.security.Principal;
+import java.util.ArrayList;
+
+import org.apache.catalina.realm.GenericPrincipal;
+import org.apache.catalina.realm.RealmBase;
+
+public class FakeRealm extends RealmBase {
+    protected String getName() {
+        return "test";
+    }
+
+    protected String getPassword(String string) {
+        return "password";
+    }
+
+    protected Principal getPrincipal(String user) {
+        if (user.equals("test")) {
+            ArrayList roles = new ArrayList();
+            roles.add("test");
+            Principal principal = new GenericPrincipal(this, user, "password", roles);
+            return principal;
+        }
+
+        return null;
+    }
+
+
+    public Principal authenticate(String user, String password) {
+        if (user.equals("test") && password.equals("password")) {
+            return getPrincipal(user);
+        }
+
+        return null;
+    }
+
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeRealm.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeRealm.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeRealm.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/RetryTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/RetryTest.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/RetryTest.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/RetryTest.java Sun
Dec 30 03:36:47 2007
@@ -0,0 +1,74 @@
+/*
+ *  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.ahc;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.ahc.codec.HttpRequestMessage;
+import org.apache.ahc.codec.HttpResponseMessage;
+
+public class RetryTest extends AbstractTest {
+
+
+    public void testHtmlConnection() throws Exception {
+        TestCallback callback = new TestCallback();
+        doGetConnection(callback, "http://localhost:8284/");
+        Thread.sleep(5000); 
+        assertTrue(callback.isException());
+    }
+
+    public void testSSLHtmlConnection() throws Exception {
+        TestCallback callback = new TestCallback();
+        doGetConnection(callback, "https://localhost:8385/");
+        
+        Thread.sleep(5000); 
+        assertTrue(callback.isException());
+    }
+
+    private void doGetConnection(TestCallback callback, String url)
+        throws Exception {
+        HttpRequestMessage request = new HttpRequestMessage(new URL(url), callback);
+
+        request.setParameter("TEST1", "Test One");
+        request.setParameter("TEST2", "Test Two");
+        doConnection(request, callback);
+    }
+
+    private void doConnection(HttpRequestMessage request,
+                              TestCallback callback) throws Exception {
+        AsyncHttpClient ahc = new AsyncHttpClient();
+        ahc.setTcpNoDelay(true);
+        ahc.setConnectionRetries(3); 
+        // set a short timeout 
+        request.setTimeOut(200); 
+
+        ahc.sendRequest(request);
+
+        //We are done...Thread would normally end...
+        //So this little wait simulates the thread going back in the pool
+        //5 second timeout due to no response
+        callback.await(5, TimeUnit.SECONDS);
+    }
+}
+

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/RetryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/RetryTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/RetryTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/TimeoutTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/TimeoutTest.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/TimeoutTest.java
(added)
+++ geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/TimeoutTest.java
Sun Dec 30 03:36:47 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.ahc;
+
+import java.net.URL;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.ahc.codec.HttpRequestMessage;
+
+public class TimeoutTest extends AbstractTest {
+
+    public void testTimeout() throws Exception {
+
+        TestCallback callback = new TestCallback();
+
+        AsyncHttpClient ahc = new AsyncHttpClient();
+        ahc.setTcpNoDelay(true);
+
+        HttpRequestMessage request = new HttpRequestMessage(new URL("http://localhost:8282/timeout.jsp"),
callback);
+
+        //Create a client with a one second timeout
+        request.setTimeOut(1000);
+
+        ahc.sendRequest(request);
+
+        //We are done...Thread would normally end...
+        //So this little wait simulates the thread going back in the pool
+        //5 second timeout due to no response
+        callback.await(5, TimeUnit.SECONDS);
+
+        assertTrue(callback.isTimeout());
+
+        ahc.destroyAll();
+    }
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/TimeoutTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/TimeoutTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/TimeoutTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java



Mime
View raw message