Added HTTP over SPDY server connector, improved test case base class, improved pom.xml.

This commit is contained in:
Simone Bordet 2012-02-10 12:47:20 +01:00
parent d6ec06c5c3
commit ba25a485f2
11 changed files with 83 additions and 69 deletions

View File

@ -14,6 +14,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jetty.version>7.6.1-SNAPSHOT</jetty.version> <jetty.version>7.6.1-SNAPSHOT</jetty.version>
<jetty.npn.version>1.0.0-SNAPSHOT</jetty.npn.version> <jetty.npn.version>1.0.0-SNAPSHOT</jetty.npn.version>
<slf4j.version>1.6.4</slf4j.version>
</properties> </properties>
<build> <build>
@ -47,7 +48,7 @@
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version> <version>2.11</version>
<configuration> <configuration>
<argLine> <argLine>
-Xbootclasspath/a:${settings.localRepository}/org/eclipse/jetty/jetty-npn-boot/${jetty.npn.version}/jetty-npn-boot-${jetty.npn.version}.jar -Xbootclasspath/a:${settings.localRepository}/org/eclipse/jetty/jetty-npn-boot/${jetty.npn.version}/jetty-npn-boot-${jetty.npn.version}.jar
@ -72,7 +73,7 @@
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>1.6.4</version> <version>${slf4j.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
@ -83,7 +84,7 @@
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId> <artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version> <version>${slf4j.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2012 the original author or authors.
*
* Licensed 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.eclipse.jetty.spdy.nio.http;
import org.eclipse.jetty.spdy.nio.SPDYServerConnector;
public class HTTPSPDYServerConnector extends SPDYServerConnector
{
public HTTPSPDYServerConnector()
{
super(null);
putAsyncConnectionFactory("spdy/2", new HTTPOverSPDYAsyncConnectionFactory(this));
}
}

View File

@ -18,6 +18,7 @@ package org.eclipse.jetty.spdy;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.spdy.api.Session; import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
@ -49,7 +50,7 @@ public abstract class AbstractTest
protected SPDYClient.Factory clientFactory; protected SPDYClient.Factory clientFactory;
protected SPDYServerConnector connector; protected SPDYServerConnector connector;
protected InetSocketAddress startServer(ServerSessionFrameListener listener) throws Exception protected InetSocketAddress startSPDYServer(ServerSessionFrameListener listener) throws Exception
{ {
server = new Server(); server = new Server();
connector = newSPDYServerConnector(listener); connector = newSPDYServerConnector(listener);
@ -59,6 +60,17 @@ public abstract class AbstractTest
return new InetSocketAddress("localhost", connector.getLocalPort()); return new InetSocketAddress("localhost", connector.getLocalPort());
} }
protected InetSocketAddress startHTTPServer(Handler handler) throws Exception
{
server = new Server();
connector = newSPDYServerConnector(null);
connector.setPort(0);
server.addConnector(connector);
server.setHandler(handler);
server.start();
return new InetSocketAddress("localhost", connector.getLocalPort());
}
protected SPDYServerConnector newSPDYServerConnector(ServerSessionFrameListener listener) protected SPDYServerConnector newSPDYServerConnector(ServerSessionFrameListener listener)
{ {
return new SPDYServerConnector(listener); return new SPDYServerConnector(listener);

View File

@ -64,7 +64,7 @@ public class ConcurrentSynDataReplyDataTest extends AbstractTest
}; };
} }
}; };
final Session session = startClient(startServer(serverSessionFrameListener), null); final Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
final int iterations = 50; final int iterations = 50;
final int count = 50; final int count = 50;

View File

@ -61,7 +61,7 @@ public class GoAwayTest extends AbstractTest
latch.countDown(); latch.countDown();
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), null); Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
session.syn(SPDY.V2, new SynInfo(true), null); session.syn(SPDY.V2, new SynInfo(true), null);
@ -94,7 +94,7 @@ public class GoAwayTest extends AbstractTest
latch.countDown(); latch.countDown();
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), clientSessionFrameListener); Session session = startClient(startSPDYServer(serverSessionFrameListener), clientSessionFrameListener);
Stream stream1 = session.syn(SPDY.V2, new SynInfo(true), null); Stream stream1 = session.syn(SPDY.V2, new SynInfo(true), null);
@ -138,7 +138,7 @@ public class GoAwayTest extends AbstractTest
ref.get().syn(SPDY.V2, new SynInfo(true), null); ref.get().syn(SPDY.V2, new SynInfo(true), null);
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), clientSessionFrameListener); Session session = startClient(startSPDYServer(serverSessionFrameListener), clientSessionFrameListener);
ref.set(session); ref.set(session);
session.syn(SPDY.V2, new SynInfo(true), null); session.syn(SPDY.V2, new SynInfo(true), null);
@ -190,7 +190,7 @@ public class GoAwayTest extends AbstractTest
goAwayLatch.countDown(); goAwayLatch.countDown();
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), clientSessionFrameListener); Session session = startClient(startSPDYServer(serverSessionFrameListener), clientSessionFrameListener);
// First stream is processed ok // First stream is processed ok
final CountDownLatch reply1Latch = new CountDownLatch(1); final CountDownLatch reply1Latch = new CountDownLatch(1);

View File

@ -54,7 +54,7 @@ public class HeadersTest extends AbstractTest
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), null); Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
session.syn(SPDY.V2, new SynInfo(false), new Stream.FrameListener.Adapter() session.syn(SPDY.V2, new SynInfo(false), new Stream.FrameListener.Adapter()

View File

@ -43,7 +43,7 @@ public class PingTest extends AbstractTest
latch.countDown(); latch.countDown();
} }
}; };
Session session = startClient(startServer(null), clientSessionFrameListener); Session session = startClient(startSPDYServer(null), clientSessionFrameListener);
PingInfo pingInfo = session.ping(SPDY.V2); PingInfo pingInfo = session.ping(SPDY.V2);
Assert.assertEquals(1, pingInfo.getPingId() % 2); Assert.assertEquals(1, pingInfo.getPingId() % 2);
@ -76,7 +76,7 @@ public class PingTest extends AbstractTest
pingLatch.countDown(); pingLatch.countDown();
} }
}; };
startClient(startServer(serverSessionFrameListener), null); startClient(startSPDYServer(serverSessionFrameListener), null);
Assert.assertTrue(pingLatch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(pingLatch.await(5, TimeUnit.SECONDS));
} }

View File

@ -48,7 +48,7 @@ public class SettingsTest extends AbstractTest
latch.countDown(); latch.countDown();
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), null); Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
session.settings(SPDY.V2, clientSettingsInfo); session.settings(SPDY.V2, clientSettingsInfo);
@ -83,7 +83,7 @@ public class SettingsTest extends AbstractTest
} }
}; };
startClient(startServer(serverSessionFrameListener), clientSessionFrameListener); startClient(startSPDYServer(serverSessionFrameListener), clientSessionFrameListener);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
} }

View File

@ -65,7 +65,7 @@ public class SynReplyTest extends AbstractTest
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), null); Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
final CountDownLatch streamCreatedLatch = new CountDownLatch(1); final CountDownLatch streamCreatedLatch = new CountDownLatch(1);
final CountDownLatch streamRemovedLatch = new CountDownLatch(1); final CountDownLatch streamRemovedLatch = new CountDownLatch(1);
@ -154,7 +154,7 @@ public class SynReplyTest extends AbstractTest
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), null); Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
final CountDownLatch streamRemovedLatch = new CountDownLatch(1); final CountDownLatch streamRemovedLatch = new CountDownLatch(1);
session.addListener(new Session.StreamListener.Adapter() session.addListener(new Session.StreamListener.Adapter()
@ -210,7 +210,7 @@ public class SynReplyTest extends AbstractTest
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), null); Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
final CountDownLatch replyLatch = new CountDownLatch(1); final CountDownLatch replyLatch = new CountDownLatch(1);
final CountDownLatch dataLatch1 = new CountDownLatch(1); final CountDownLatch dataLatch1 = new CountDownLatch(1);
@ -318,7 +318,7 @@ public class SynReplyTest extends AbstractTest
} }
}; };
startClient(startServer(serverSessionFrameListener), clientSessionFrameListener); startClient(startSPDYServer(serverSessionFrameListener), clientSessionFrameListener);
Assert.assertTrue(synLatch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(synLatch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(replyLatch.await(5, TimeUnit.SECONDS)); Assert.assertTrue(replyLatch.await(5, TimeUnit.SECONDS));
@ -348,7 +348,7 @@ public class SynReplyTest extends AbstractTest
latch.countDown(); latch.countDown();
} }
}; };
Session session = startClient(startServer(serverSessionFrameListener), null); Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
Stream stream = session.syn(SPDY.V2, new SynInfo(true), null); Stream stream = session.syn(SPDY.V2, new SynInfo(true), null);

View File

@ -149,7 +149,7 @@ public class IdleTimeoutTest extends AbstractTest
public void testClientEnforcingIdleTimeout() throws Exception public void testClientEnforcingIdleTimeout() throws Exception
{ {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
InetSocketAddress address = startServer(new ServerSessionFrameListener.Adapter() InetSocketAddress address = startSPDYServer(new ServerSessionFrameListener.Adapter()
{ {
@Override @Override
public Stream.FrameListener onSyn(Stream stream, SynInfo synInfo) public Stream.FrameListener onSyn(Stream stream, SynInfo synInfo)
@ -183,7 +183,7 @@ public class IdleTimeoutTest extends AbstractTest
public void testClientEnforcingIdleTimeoutWithUnrespondedStream() throws Exception public void testClientEnforcingIdleTimeoutWithUnrespondedStream() throws Exception
{ {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
InetSocketAddress address = startServer(new ServerSessionFrameListener.Adapter() InetSocketAddress address = startSPDYServer(new ServerSessionFrameListener.Adapter()
{ {
@Override @Override
public void onGoAway(Session session, GoAwayInfo goAwayInfo) public void onGoAway(Session session, GoAwayInfo goAwayInfo)
@ -211,7 +211,7 @@ public class IdleTimeoutTest extends AbstractTest
{ {
final long maxIdleTime = 1000; final long maxIdleTime = 1000;
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
InetSocketAddress address = startServer(new ServerSessionFrameListener.Adapter() InetSocketAddress address = startSPDYServer(new ServerSessionFrameListener.Adapter()
{ {
@Override @Override
public Stream.FrameListener onSyn(Stream stream, SynInfo synInfo) public Stream.FrameListener onSyn(Stream stream, SynInfo synInfo)

View File

@ -18,17 +18,15 @@ package org.eclipse.jetty.spdy.nio.http;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.spdy.AbstractTest;
import org.eclipse.jetty.spdy.api.Headers; import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo; import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY; import org.eclipse.jetty.spdy.api.SPDY;
@ -36,43 +34,18 @@ import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream; import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StringDataInfo; import org.eclipse.jetty.spdy.api.StringDataInfo;
import org.eclipse.jetty.spdy.api.SynInfo; import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.nio.SPDYClient; import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.spdy.nio.SPDYServerConnector; import org.eclipse.jetty.spdy.nio.SPDYServerConnector;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
public class HTTPOverSPDYTest public class HTTPOverSPDYTest extends AbstractTest
{ {
private Server server; @Override
private SPDYServerConnector connector; protected SPDYServerConnector newSPDYServerConnector(ServerSessionFrameListener listener)
private SPDYClient.Factory clientFactory;
private Session session;
public void start(Handler handler, Session.FrameListener listener) throws Exception
{ {
server = new Server(); return new HTTPSPDYServerConnector();
connector = new SPDYServerConnector(null);
server.addConnector(connector);
connector.putAsyncConnectionFactory("spdy/2", new HTTPOverSPDYAsyncConnectionFactory(connector));
server.setHandler(handler);
server.start();
clientFactory = new SPDYClient.Factory();
clientFactory.start();
SPDYClient client = clientFactory.newSPDYClient();
session = client.connect(new InetSocketAddress("localhost", connector.getLocalPort()), listener).get(5, TimeUnit.SECONDS);
}
@After
public void stop() throws Exception
{
session.goAway(SPDY.V2);
clientFactory.stop();
clientFactory.join();
server.stop();
server.join();
} }
@Ignore @Ignore
@ -80,7 +53,7 @@ public class HTTPOverSPDYTest
public void test100Continue() throws Exception public void test100Continue() throws Exception
{ {
final String data = "data"; final String data = "data";
start(new AbstractHandler() Session session = startClient(startHTTPServer(new AbstractHandler()
{ {
@Override @Override
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
@ -95,7 +68,7 @@ public class HTTPOverSPDYTest
httpResponse.setStatus(200); httpResponse.setStatus(200);
} }
}, null); }), null);
Headers headers = new Headers(); Headers headers = new Headers();
headers.put("method", "POST"); headers.put("method", "POST");
@ -127,7 +100,7 @@ public class HTTPOverSPDYTest
{ {
final String path = "/foo"; final String path = "/foo";
final CountDownLatch handlerLatch = new CountDownLatch(1); final CountDownLatch handlerLatch = new CountDownLatch(1);
start(new AbstractHandler() Session session = startClient(startHTTPServer(new AbstractHandler()
{ {
@Override @Override
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
@ -140,7 +113,7 @@ public class HTTPOverSPDYTest
Assert.assertEquals("localhost:" + connector.getLocalPort(), httpRequest.getHeader("host")); Assert.assertEquals("localhost:" + connector.getLocalPort(), httpRequest.getHeader("host"));
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, null); }), null);
Headers headers = new Headers(); Headers headers = new Headers();
headers.put("method", "GET"); headers.put("method", "GET");
@ -169,7 +142,7 @@ public class HTTPOverSPDYTest
final String query = "p=1"; final String query = "p=1";
final String uri = path + "?" + query; final String uri = path + "?" + query;
final CountDownLatch handlerLatch = new CountDownLatch(1); final CountDownLatch handlerLatch = new CountDownLatch(1);
start(new AbstractHandler() Session session = startClient(startHTTPServer(new AbstractHandler()
{ {
@Override @Override
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
@ -182,7 +155,7 @@ public class HTTPOverSPDYTest
Assert.assertEquals(query, httpRequest.getQueryString()); Assert.assertEquals(query, httpRequest.getQueryString());
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, null); }), null);
Headers headers = new Headers(); Headers headers = new Headers();
headers.put("method", "GET"); headers.put("method", "GET");
@ -209,7 +182,7 @@ public class HTTPOverSPDYTest
{ {
final String path = "/foo"; final String path = "/foo";
final CountDownLatch handlerLatch = new CountDownLatch(1); final CountDownLatch handlerLatch = new CountDownLatch(1);
start(new AbstractHandler() Session session = startClient(startHTTPServer(new AbstractHandler()
{ {
@Override @Override
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
@ -221,7 +194,7 @@ public class HTTPOverSPDYTest
Assert.assertEquals(path, httpRequest.getRequestURI()); Assert.assertEquals(path, httpRequest.getRequestURI());
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, null); }), null);
Headers headers = new Headers(); Headers headers = new Headers();
headers.put("method", "HEAD"); headers.put("method", "HEAD");
@ -249,7 +222,7 @@ public class HTTPOverSPDYTest
final String path = "/foo"; final String path = "/foo";
final String data = "a=1&b=2"; final String data = "a=1&b=2";
final CountDownLatch handlerLatch = new CountDownLatch(1); final CountDownLatch handlerLatch = new CountDownLatch(1);
start(new AbstractHandler() Session session = startClient(startHTTPServer(new AbstractHandler()
{ {
@Override @Override
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
@ -261,7 +234,7 @@ public class HTTPOverSPDYTest
Assert.assertEquals("2", httpRequest.getParameter("b")); Assert.assertEquals("2", httpRequest.getParameter("b"));
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, null); }), null);
Headers headers = new Headers(); Headers headers = new Headers();
headers.put("method", "POST"); headers.put("method", "POST");
@ -293,7 +266,7 @@ public class HTTPOverSPDYTest
final String data1 = "a=1&"; final String data1 = "a=1&";
final String data2 = "b=2"; final String data2 = "b=2";
final CountDownLatch handlerLatch = new CountDownLatch(1); final CountDownLatch handlerLatch = new CountDownLatch(1);
start(new AbstractHandler() Session session = startClient(startHTTPServer(new AbstractHandler()
{ {
@Override @Override
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
@ -305,7 +278,7 @@ public class HTTPOverSPDYTest
Assert.assertEquals("2", httpRequest.getParameter("b")); Assert.assertEquals("2", httpRequest.getParameter("b"));
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, null); }), null);
Headers headers = new Headers(); Headers headers = new Headers();
headers.put("method", "POST"); headers.put("method", "POST");
@ -340,7 +313,7 @@ public class HTTPOverSPDYTest
final String data1 = "a=1&"; final String data1 = "a=1&";
final String data2 = "b=2"; final String data2 = "b=2";
final CountDownLatch handlerLatch = new CountDownLatch(1); final CountDownLatch handlerLatch = new CountDownLatch(1);
start(new AbstractHandler() Session session = startClient(startHTTPServer(new AbstractHandler()
{ {
@Override @Override
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
@ -352,7 +325,7 @@ public class HTTPOverSPDYTest
Assert.assertEquals("2", httpRequest.getParameter("b")); Assert.assertEquals("2", httpRequest.getParameter("b"));
handlerLatch.countDown(); handlerLatch.countDown();
} }
}, null); }), null);
Headers headers = new Headers(); Headers headers = new Headers();
headers.put("method", "POST"); headers.put("method", "POST");