From 42116530951f11981adc9db323f63b6864f696f8 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 18 Jun 2014 15:24:16 +0200 Subject: [PATCH] Fixed tests. --- .../jetty/http2/client/IdleTimeoutTest.java | 77 +++++++++++++++++-- .../test/resources/jetty-logging.properties | 10 +-- .../jetty/http2/server/HTTP2ServerTest.java | 15 +--- .../test/resources/jetty-logging.properties | 1 - 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/IdleTimeoutTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/IdleTimeoutTest.java index d229967214e..857e50190d2 100644 --- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/IdleTimeoutTest.java +++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/IdleTimeoutTest.java @@ -59,6 +59,7 @@ public class IdleTimeoutTest extends AbstractTest @Override public Stream.Listener onNewStream(Stream stream, HeadersFrame requestFrame) { + stream.setIdleTimeout(10 * idleTimeout); MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields()); HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true); stream.headers(responseFrame, Callback.Adapter.INSTANCE); @@ -79,7 +80,14 @@ public class IdleTimeoutTest extends AbstractTest MetaData.Request metaData = newRequest("GET", new HttpFields()); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); - session.newStream(requestFrame, new Promise.Adapter(), new Stream.Listener.Adapter()); + session.newStream(requestFrame, new Promise.Adapter() + { + @Override + public void succeeded(Stream stream) + { + stream.setIdleTimeout(10 * idleTimeout); + } + }, new Stream.Listener.Adapter()); Assert.assertTrue(latch.await(2 * idleTimeout, TimeUnit.MILLISECONDS)); } @@ -87,7 +95,15 @@ public class IdleTimeoutTest extends AbstractTest @Test public void testServerEnforcingIdleTimeoutWithUnrespondedStream() throws Exception { - startServer(new ServerSessionListener.Adapter()); + startServer(new ServerSessionListener.Adapter() + { + @Override + public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) + { + stream.setIdleTimeout(10 * idleTimeout); + return null; + } + }); connector.setIdleTimeout(idleTimeout); final CountDownLatch latch = new CountDownLatch(1); @@ -103,7 +119,14 @@ public class IdleTimeoutTest extends AbstractTest // The request is not replied, and the server should idle timeout. MetaData.Request metaData = newRequest("GET", new HttpFields()); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); - session.newStream(requestFrame, new Promise.Adapter(), new Stream.Listener.Adapter()); + session.newStream(requestFrame, new Promise.Adapter() + { + @Override + public void succeeded(Stream stream) + { + stream.setIdleTimeout(10 * idleTimeout); + } + }, new Stream.Listener.Adapter()); Assert.assertTrue(latch.await(2 * idleTimeout, TimeUnit.MILLISECONDS)); } @@ -118,6 +141,7 @@ public class IdleTimeoutTest extends AbstractTest { try { + stream.setIdleTimeout(10 * idleTimeout); Thread.sleep(2 * idleTimeout); MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields()); HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true); @@ -146,7 +170,14 @@ public class IdleTimeoutTest extends AbstractTest final CountDownLatch replyLatch = new CountDownLatch(1); MetaData.Request metaData = newRequest("GET", new HttpFields()); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); - session.newStream(requestFrame, new Promise.Adapter(), new Stream.Listener.Adapter() + session.newStream(requestFrame, new Promise.Adapter() + { + @Override + public void succeeded(Stream stream) + { + stream.setIdleTimeout(10 * idleTimeout); + } + }, new Stream.Listener.Adapter() { @Override public void onHeaders(Stream stream, HeadersFrame frame) @@ -170,6 +201,7 @@ public class IdleTimeoutTest extends AbstractTest @Override public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) { + stream.setIdleTimeout(10 * idleTimeout); MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields()); HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true); stream.headers(responseFrame, Callback.Adapter.INSTANCE); @@ -187,7 +219,14 @@ public class IdleTimeoutTest extends AbstractTest Session session = newClient(new Session.Listener.Adapter()); MetaData.Request metaData = newRequest("GET", new HttpFields()); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); - session.newStream(requestFrame, new Promise.Adapter(), new Stream.Listener.Adapter()); + session.newStream(requestFrame, new Promise.Adapter() + { + @Override + public void succeeded(Stream stream) + { + stream.setIdleTimeout(10 * idleTimeout); + } + }, new Stream.Listener.Adapter()); Assert.assertTrue(closeLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS)); } @@ -198,6 +237,13 @@ public class IdleTimeoutTest extends AbstractTest final CountDownLatch closeLatch = new CountDownLatch(1); startServer(new ServerSessionListener.Adapter() { + @Override + public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) + { + stream.setIdleTimeout(10 * idleTimeout); + return null; + } + @Override public void onClose(Session session, GoAwayFrame frame) { @@ -209,7 +255,14 @@ public class IdleTimeoutTest extends AbstractTest Session session = newClient(new Session.Listener.Adapter()); MetaData.Request metaData = newRequest("GET", new HttpFields()); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); - session.newStream(requestFrame, new Promise.Adapter(), new Stream.Listener.Adapter()); + session.newStream(requestFrame, new Promise.Adapter() + { + @Override + public void succeeded(Stream stream) + { + stream.setIdleTimeout(10 * idleTimeout); + } + }, new Stream.Listener.Adapter()); Assert.assertTrue(closeLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS)); } @@ -223,6 +276,7 @@ public class IdleTimeoutTest extends AbstractTest @Override public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) { + stream.setIdleTimeout(10 * idleTimeout); MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields()); HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true); stream.headers(responseFrame, Callback.Adapter.INSTANCE); @@ -242,7 +296,14 @@ public class IdleTimeoutTest extends AbstractTest final CountDownLatch replyLatch = new CountDownLatch(1); MetaData.Request metaData = newRequest("GET", new HttpFields()); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); - session.newStream(requestFrame, new Promise.Adapter(), new Stream.Listener.Adapter() + session.newStream(requestFrame, new Promise.Adapter() + { + @Override + public void succeeded(Stream stream) + { + stream.setIdleTimeout(10 * idleTimeout); + } + }, new Stream.Listener.Adapter() { @Override public void onHeaders(Stream stream, HeadersFrame frame) @@ -361,7 +422,7 @@ public class IdleTimeoutTest extends AbstractTest } @Test - public void testIdleTimeoutIsInterruptedWhenReceiving() throws Exception + public void testStreamIdleTimeoutIsNotEnforcedWhenReceiving() throws Exception { final CountDownLatch timeoutLatch = new CountDownLatch(1); startServer(new ServerSessionListener.Adapter() diff --git a/jetty-http2/http2-common/src/test/resources/jetty-logging.properties b/jetty-http2/http2-common/src/test/resources/jetty-logging.properties index 31b37987e9a..b4e43807801 100644 --- a/jetty-http2/http2-common/src/test/resources/jetty-logging.properties +++ b/jetty-http2/http2-common/src/test/resources/jetty-logging.properties @@ -1,10 +1,2 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -org.eclipse.jetty.LEVEL=INFO -org.eclipse.jetty.STACKS=true -org.eclipse.jetty.SOURCE=false -org.eclipse.jetty.http2.hpack.LEVEL=debug -#org.eclipse.jetty.spdy.LEVEL=DEBUG -#org.eclipse.jetty.server.LEVEL=DEBUG -#org.eclipse.jetty.io.LEVEL=DEBUG -#org.eclipse.jetty.io.ssl.LEVEL=DEBUG -#org.eclipse.jetty.spdy.server.LEVEL=DEBUG +org.eclipse.jetty.http2.LEVEL=INFO diff --git a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java index 68afb37a915..92a45734bb8 100644 --- a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java +++ b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2ServerTest.java @@ -18,7 +18,6 @@ package org.eclipse.jetty.http2.server; -import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -46,9 +45,6 @@ import org.eclipse.jetty.http2.frames.HeadersFrame; import org.eclipse.jetty.http2.frames.PingFrame; import org.eclipse.jetty.http2.frames.SettingsFrame; import org.eclipse.jetty.http2.generator.Generator; -import org.eclipse.jetty.http2.hpack.HpackContext; -import org.eclipse.jetty.http2.hpack.HpackDecoder; -import org.eclipse.jetty.http2.hpack.HpackEncoder; import org.eclipse.jetty.http2.parser.ErrorCode; import org.eclipse.jetty.http2.parser.Parser; import org.eclipse.jetty.http2.parser.PrefaceParser; @@ -86,9 +82,6 @@ public class HTTP2ServerTest generator = new Generator(byteBufferPool); server.start(); - HpackContext.LOG.setDebugEnabled(true); - HpackEncoder.LOG.setDebugEnabled(true); - HpackDecoder.LOG.setDebugEnabled(true); } @After @@ -355,7 +348,7 @@ public class HTTP2ServerTest } } - private void parseResponse(Socket client, Parser parser) throws IOException + private boolean parseResponse(Socket client, Parser parser) throws IOException { byte[] buffer = new byte[2048]; InputStream input = client.getInputStream(); @@ -365,13 +358,13 @@ public class HTTP2ServerTest try { int read = input.read(buffer); - if (read <= 0) - throw new EOFException(); + if (read < 0) + return true; parser.parse(ByteBuffer.wrap(buffer, 0, read)); } catch (SocketTimeoutException x) { - break; + return false; } } } diff --git a/jetty-http2/http2-server/src/test/resources/jetty-logging.properties b/jetty-http2/http2-server/src/test/resources/jetty-logging.properties index 1a5ad20f950..3d1e404e15a 100644 --- a/jetty-http2/http2-server/src/test/resources/jetty-logging.properties +++ b/jetty-http2/http2-server/src/test/resources/jetty-logging.properties @@ -1,4 +1,3 @@ org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog org.eclipse.jetty.http2.LEVEL=INFO -org.eclipse.jetty.http2.hpack.LEVEL=DEBUG