Added HTTP over SPDY server connector, improved test case base class, improved pom.xml.
This commit is contained in:
parent
d6ec06c5c3
commit
ba25a485f2
7
pom.xml
7
pom.xml
|
@ -14,6 +14,7 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<jetty.version>7.6.1-SNAPSHOT</jetty.version>
|
||||
<jetty.npn.version>1.0.0-SNAPSHOT</jetty.npn.version>
|
||||
<slf4j.version>1.6.4</slf4j.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -47,7 +48,7 @@
|
|||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.9</version>
|
||||
<version>2.11</version>
|
||||
<configuration>
|
||||
<argLine>
|
||||
-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>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.6.4</version>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -83,7 +84,7 @@
|
|||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.1</version>
|
||||
<version>${slf4j.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ package org.eclipse.jetty.spdy;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.spdy.api.Session;
|
||||
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
|
||||
|
@ -49,7 +50,7 @@ public abstract class AbstractTest
|
|||
protected SPDYClient.Factory clientFactory;
|
||||
protected SPDYServerConnector connector;
|
||||
|
||||
protected InetSocketAddress startServer(ServerSessionFrameListener listener) throws Exception
|
||||
protected InetSocketAddress startSPDYServer(ServerSessionFrameListener listener) throws Exception
|
||||
{
|
||||
server = new Server();
|
||||
connector = newSPDYServerConnector(listener);
|
||||
|
@ -59,6 +60,17 @@ public abstract class AbstractTest
|
|||
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)
|
||||
{
|
||||
return new SPDYServerConnector(listener);
|
||||
|
|
|
@ -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 count = 50;
|
||||
|
|
|
@ -61,7 +61,7 @@ public class GoAwayTest extends AbstractTest
|
|||
latch.countDown();
|
||||
}
|
||||
};
|
||||
Session session = startClient(startServer(serverSessionFrameListener), null);
|
||||
Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
|
||||
|
||||
session.syn(SPDY.V2, new SynInfo(true), null);
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class GoAwayTest extends AbstractTest
|
|||
latch.countDown();
|
||||
}
|
||||
};
|
||||
Session session = startClient(startServer(serverSessionFrameListener), clientSessionFrameListener);
|
||||
Session session = startClient(startSPDYServer(serverSessionFrameListener), clientSessionFrameListener);
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
Session session = startClient(startServer(serverSessionFrameListener), clientSessionFrameListener);
|
||||
Session session = startClient(startSPDYServer(serverSessionFrameListener), clientSessionFrameListener);
|
||||
ref.set(session);
|
||||
|
||||
session.syn(SPDY.V2, new SynInfo(true), null);
|
||||
|
@ -190,7 +190,7 @@ public class GoAwayTest extends AbstractTest
|
|||
goAwayLatch.countDown();
|
||||
}
|
||||
};
|
||||
Session session = startClient(startServer(serverSessionFrameListener), clientSessionFrameListener);
|
||||
Session session = startClient(startSPDYServer(serverSessionFrameListener), clientSessionFrameListener);
|
||||
|
||||
// First stream is processed ok
|
||||
final CountDownLatch reply1Latch = new CountDownLatch(1);
|
||||
|
|
|
@ -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);
|
||||
session.syn(SPDY.V2, new SynInfo(false), new Stream.FrameListener.Adapter()
|
||||
|
|
|
@ -43,7 +43,7 @@ public class PingTest extends AbstractTest
|
|||
latch.countDown();
|
||||
}
|
||||
};
|
||||
Session session = startClient(startServer(null), clientSessionFrameListener);
|
||||
Session session = startClient(startSPDYServer(null), clientSessionFrameListener);
|
||||
PingInfo pingInfo = session.ping(SPDY.V2);
|
||||
Assert.assertEquals(1, pingInfo.getPingId() % 2);
|
||||
|
||||
|
@ -76,7 +76,7 @@ public class PingTest extends AbstractTest
|
|||
pingLatch.countDown();
|
||||
}
|
||||
};
|
||||
startClient(startServer(serverSessionFrameListener), null);
|
||||
startClient(startSPDYServer(serverSessionFrameListener), null);
|
||||
|
||||
Assert.assertTrue(pingLatch.await(5, TimeUnit.SECONDS));
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class SettingsTest extends AbstractTest
|
|||
latch.countDown();
|
||||
}
|
||||
};
|
||||
Session session = startClient(startServer(serverSessionFrameListener), null);
|
||||
Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -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 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);
|
||||
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 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(replyLatch.await(5, TimeUnit.SECONDS));
|
||||
|
@ -348,7 +348,7 @@ public class SynReplyTest extends AbstractTest
|
|||
latch.countDown();
|
||||
}
|
||||
};
|
||||
Session session = startClient(startServer(serverSessionFrameListener), null);
|
||||
Session session = startClient(startSPDYServer(serverSessionFrameListener), null);
|
||||
|
||||
Stream stream = session.syn(SPDY.V2, new SynInfo(true), null);
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ public class IdleTimeoutTest extends AbstractTest
|
|||
public void testClientEnforcingIdleTimeout() throws Exception
|
||||
{
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
InetSocketAddress address = startServer(new ServerSessionFrameListener.Adapter()
|
||||
InetSocketAddress address = startSPDYServer(new ServerSessionFrameListener.Adapter()
|
||||
{
|
||||
@Override
|
||||
public Stream.FrameListener onSyn(Stream stream, SynInfo synInfo)
|
||||
|
@ -183,7 +183,7 @@ public class IdleTimeoutTest extends AbstractTest
|
|||
public void testClientEnforcingIdleTimeoutWithUnrespondedStream() throws Exception
|
||||
{
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
InetSocketAddress address = startServer(new ServerSessionFrameListener.Adapter()
|
||||
InetSocketAddress address = startSPDYServer(new ServerSessionFrameListener.Adapter()
|
||||
{
|
||||
@Override
|
||||
public void onGoAway(Session session, GoAwayInfo goAwayInfo)
|
||||
|
@ -211,7 +211,7 @@ public class IdleTimeoutTest extends AbstractTest
|
|||
{
|
||||
final long maxIdleTime = 1000;
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
InetSocketAddress address = startServer(new ServerSessionFrameListener.Adapter()
|
||||
InetSocketAddress address = startSPDYServer(new ServerSessionFrameListener.Adapter()
|
||||
{
|
||||
@Override
|
||||
public Stream.FrameListener onSyn(Stream stream, SynInfo synInfo)
|
||||
|
|
|
@ -18,17 +18,15 @@ package org.eclipse.jetty.spdy.nio.http;
|
|||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
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.ReplyInfo;
|
||||
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.StringDataInfo;
|
||||
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.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HTTPOverSPDYTest
|
||||
public class HTTPOverSPDYTest extends AbstractTest
|
||||
{
|
||||
private Server server;
|
||||
private SPDYServerConnector connector;
|
||||
private SPDYClient.Factory clientFactory;
|
||||
private Session session;
|
||||
|
||||
public void start(Handler handler, Session.FrameListener listener) throws Exception
|
||||
@Override
|
||||
protected SPDYServerConnector newSPDYServerConnector(ServerSessionFrameListener listener)
|
||||
{
|
||||
server = new Server();
|
||||
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();
|
||||
return new HTTPSPDYServerConnector();
|
||||
}
|
||||
|
||||
@Ignore
|
||||
|
@ -80,7 +53,7 @@ public class HTTPOverSPDYTest
|
|||
public void test100Continue() throws Exception
|
||||
{
|
||||
final String data = "data";
|
||||
start(new AbstractHandler()
|
||||
Session session = startClient(startHTTPServer(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
|
||||
|
@ -95,7 +68,7 @@ public class HTTPOverSPDYTest
|
|||
|
||||
httpResponse.setStatus(200);
|
||||
}
|
||||
}, null);
|
||||
}), null);
|
||||
|
||||
Headers headers = new Headers();
|
||||
headers.put("method", "POST");
|
||||
|
@ -127,7 +100,7 @@ public class HTTPOverSPDYTest
|
|||
{
|
||||
final String path = "/foo";
|
||||
final CountDownLatch handlerLatch = new CountDownLatch(1);
|
||||
start(new AbstractHandler()
|
||||
Session session = startClient(startHTTPServer(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
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"));
|
||||
handlerLatch.countDown();
|
||||
}
|
||||
}, null);
|
||||
}), null);
|
||||
|
||||
Headers headers = new Headers();
|
||||
headers.put("method", "GET");
|
||||
|
@ -169,7 +142,7 @@ public class HTTPOverSPDYTest
|
|||
final String query = "p=1";
|
||||
final String uri = path + "?" + query;
|
||||
final CountDownLatch handlerLatch = new CountDownLatch(1);
|
||||
start(new AbstractHandler()
|
||||
Session session = startClient(startHTTPServer(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
|
||||
|
@ -182,7 +155,7 @@ public class HTTPOverSPDYTest
|
|||
Assert.assertEquals(query, httpRequest.getQueryString());
|
||||
handlerLatch.countDown();
|
||||
}
|
||||
}, null);
|
||||
}), null);
|
||||
|
||||
Headers headers = new Headers();
|
||||
headers.put("method", "GET");
|
||||
|
@ -209,7 +182,7 @@ public class HTTPOverSPDYTest
|
|||
{
|
||||
final String path = "/foo";
|
||||
final CountDownLatch handlerLatch = new CountDownLatch(1);
|
||||
start(new AbstractHandler()
|
||||
Session session = startClient(startHTTPServer(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
|
||||
|
@ -221,7 +194,7 @@ public class HTTPOverSPDYTest
|
|||
Assert.assertEquals(path, httpRequest.getRequestURI());
|
||||
handlerLatch.countDown();
|
||||
}
|
||||
}, null);
|
||||
}), null);
|
||||
|
||||
Headers headers = new Headers();
|
||||
headers.put("method", "HEAD");
|
||||
|
@ -249,7 +222,7 @@ public class HTTPOverSPDYTest
|
|||
final String path = "/foo";
|
||||
final String data = "a=1&b=2";
|
||||
final CountDownLatch handlerLatch = new CountDownLatch(1);
|
||||
start(new AbstractHandler()
|
||||
Session session = startClient(startHTTPServer(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
|
||||
|
@ -261,7 +234,7 @@ public class HTTPOverSPDYTest
|
|||
Assert.assertEquals("2", httpRequest.getParameter("b"));
|
||||
handlerLatch.countDown();
|
||||
}
|
||||
}, null);
|
||||
}), null);
|
||||
|
||||
Headers headers = new Headers();
|
||||
headers.put("method", "POST");
|
||||
|
@ -293,7 +266,7 @@ public class HTTPOverSPDYTest
|
|||
final String data1 = "a=1&";
|
||||
final String data2 = "b=2";
|
||||
final CountDownLatch handlerLatch = new CountDownLatch(1);
|
||||
start(new AbstractHandler()
|
||||
Session session = startClient(startHTTPServer(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
|
||||
|
@ -305,7 +278,7 @@ public class HTTPOverSPDYTest
|
|||
Assert.assertEquals("2", httpRequest.getParameter("b"));
|
||||
handlerLatch.countDown();
|
||||
}
|
||||
}, null);
|
||||
}), null);
|
||||
|
||||
Headers headers = new Headers();
|
||||
headers.put("method", "POST");
|
||||
|
@ -340,7 +313,7 @@ public class HTTPOverSPDYTest
|
|||
final String data1 = "a=1&";
|
||||
final String data2 = "b=2";
|
||||
final CountDownLatch handlerLatch = new CountDownLatch(1);
|
||||
start(new AbstractHandler()
|
||||
Session session = startClient(startHTTPServer(new AbstractHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse)
|
||||
|
@ -352,7 +325,7 @@ public class HTTPOverSPDYTest
|
|||
Assert.assertEquals("2", httpRequest.getParameter("b"));
|
||||
handlerLatch.countDown();
|
||||
}
|
||||
}, null);
|
||||
}), null);
|
||||
|
||||
Headers headers = new Headers();
|
||||
headers.put("method", "POST");
|
||||
|
|
Loading…
Reference in New Issue