Fixed tests.

This commit is contained in:
Simone Bordet 2014-06-18 15:24:16 +02:00
parent 14dba64164
commit 4211653095
4 changed files with 74 additions and 29 deletions

View File

@ -59,6 +59,7 @@ public class IdleTimeoutTest extends AbstractTest
@Override @Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame requestFrame) public Stream.Listener onNewStream(Stream stream, HeadersFrame requestFrame)
{ {
stream.setIdleTimeout(10 * idleTimeout);
MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields()); MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true); HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true);
stream.headers(responseFrame, Callback.Adapter.INSTANCE); stream.headers(responseFrame, Callback.Adapter.INSTANCE);
@ -79,7 +80,14 @@ public class IdleTimeoutTest extends AbstractTest
MetaData.Request metaData = newRequest("GET", new HttpFields()); MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true);
session.newStream(requestFrame, new Promise.Adapter<Stream>(), new Stream.Listener.Adapter()); session.newStream(requestFrame, new Promise.Adapter<Stream>()
{
@Override
public void succeeded(Stream stream)
{
stream.setIdleTimeout(10 * idleTimeout);
}
}, new Stream.Listener.Adapter());
Assert.assertTrue(latch.await(2 * idleTimeout, TimeUnit.MILLISECONDS)); Assert.assertTrue(latch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
} }
@ -87,7 +95,15 @@ public class IdleTimeoutTest extends AbstractTest
@Test @Test
public void testServerEnforcingIdleTimeoutWithUnrespondedStream() throws Exception 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); connector.setIdleTimeout(idleTimeout);
final CountDownLatch latch = new CountDownLatch(1); 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. // The request is not replied, and the server should idle timeout.
MetaData.Request metaData = newRequest("GET", new HttpFields()); MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true);
session.newStream(requestFrame, new Promise.Adapter<Stream>(), new Stream.Listener.Adapter()); session.newStream(requestFrame, new Promise.Adapter<Stream>()
{
@Override
public void succeeded(Stream stream)
{
stream.setIdleTimeout(10 * idleTimeout);
}
}, new Stream.Listener.Adapter());
Assert.assertTrue(latch.await(2 * idleTimeout, TimeUnit.MILLISECONDS)); Assert.assertTrue(latch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
} }
@ -118,6 +141,7 @@ public class IdleTimeoutTest extends AbstractTest
{ {
try try
{ {
stream.setIdleTimeout(10 * idleTimeout);
Thread.sleep(2 * idleTimeout); Thread.sleep(2 * idleTimeout);
MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields()); MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true); HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true);
@ -146,7 +170,14 @@ public class IdleTimeoutTest extends AbstractTest
final CountDownLatch replyLatch = new CountDownLatch(1); final CountDownLatch replyLatch = new CountDownLatch(1);
MetaData.Request metaData = newRequest("GET", new HttpFields()); MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true);
session.newStream(requestFrame, new Promise.Adapter<Stream>(), new Stream.Listener.Adapter() session.newStream(requestFrame, new Promise.Adapter<Stream>()
{
@Override
public void succeeded(Stream stream)
{
stream.setIdleTimeout(10 * idleTimeout);
}
}, new Stream.Listener.Adapter()
{ {
@Override @Override
public void onHeaders(Stream stream, HeadersFrame frame) public void onHeaders(Stream stream, HeadersFrame frame)
@ -170,6 +201,7 @@ public class IdleTimeoutTest extends AbstractTest
@Override @Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
{ {
stream.setIdleTimeout(10 * idleTimeout);
MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields()); MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true); HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true);
stream.headers(responseFrame, Callback.Adapter.INSTANCE); stream.headers(responseFrame, Callback.Adapter.INSTANCE);
@ -187,7 +219,14 @@ public class IdleTimeoutTest extends AbstractTest
Session session = newClient(new Session.Listener.Adapter()); Session session = newClient(new Session.Listener.Adapter());
MetaData.Request metaData = newRequest("GET", new HttpFields()); MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true);
session.newStream(requestFrame, new Promise.Adapter<Stream>(), new Stream.Listener.Adapter()); session.newStream(requestFrame, new Promise.Adapter<Stream>()
{
@Override
public void succeeded(Stream stream)
{
stream.setIdleTimeout(10 * idleTimeout);
}
}, new Stream.Listener.Adapter());
Assert.assertTrue(closeLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS)); Assert.assertTrue(closeLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
} }
@ -198,6 +237,13 @@ public class IdleTimeoutTest extends AbstractTest
final CountDownLatch closeLatch = new CountDownLatch(1); final CountDownLatch closeLatch = new CountDownLatch(1);
startServer(new ServerSessionListener.Adapter() startServer(new ServerSessionListener.Adapter()
{ {
@Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
{
stream.setIdleTimeout(10 * idleTimeout);
return null;
}
@Override @Override
public void onClose(Session session, GoAwayFrame frame) public void onClose(Session session, GoAwayFrame frame)
{ {
@ -209,7 +255,14 @@ public class IdleTimeoutTest extends AbstractTest
Session session = newClient(new Session.Listener.Adapter()); Session session = newClient(new Session.Listener.Adapter());
MetaData.Request metaData = newRequest("GET", new HttpFields()); MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true);
session.newStream(requestFrame, new Promise.Adapter<Stream>(), new Stream.Listener.Adapter()); session.newStream(requestFrame, new Promise.Adapter<Stream>()
{
@Override
public void succeeded(Stream stream)
{
stream.setIdleTimeout(10 * idleTimeout);
}
}, new Stream.Listener.Adapter());
Assert.assertTrue(closeLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS)); Assert.assertTrue(closeLatch.await(2 * idleTimeout, TimeUnit.MILLISECONDS));
} }
@ -223,6 +276,7 @@ public class IdleTimeoutTest extends AbstractTest
@Override @Override
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame) public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
{ {
stream.setIdleTimeout(10 * idleTimeout);
MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields()); MetaData.Response metaData = new MetaData.Response(HttpVersion.HTTP_2, 200, new HttpFields());
HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true); HeadersFrame responseFrame = new HeadersFrame(stream.getId(), metaData, null, true);
stream.headers(responseFrame, Callback.Adapter.INSTANCE); stream.headers(responseFrame, Callback.Adapter.INSTANCE);
@ -242,7 +296,14 @@ public class IdleTimeoutTest extends AbstractTest
final CountDownLatch replyLatch = new CountDownLatch(1); final CountDownLatch replyLatch = new CountDownLatch(1);
MetaData.Request metaData = newRequest("GET", new HttpFields()); MetaData.Request metaData = newRequest("GET", new HttpFields());
HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true); HeadersFrame requestFrame = new HeadersFrame(0, metaData, null, true);
session.newStream(requestFrame, new Promise.Adapter<Stream>(), new Stream.Listener.Adapter() session.newStream(requestFrame, new Promise.Adapter<Stream>()
{
@Override
public void succeeded(Stream stream)
{
stream.setIdleTimeout(10 * idleTimeout);
}
}, new Stream.Listener.Adapter()
{ {
@Override @Override
public void onHeaders(Stream stream, HeadersFrame frame) public void onHeaders(Stream stream, HeadersFrame frame)
@ -361,7 +422,7 @@ public class IdleTimeoutTest extends AbstractTest
} }
@Test @Test
public void testIdleTimeoutIsInterruptedWhenReceiving() throws Exception public void testStreamIdleTimeoutIsNotEnforcedWhenReceiving() throws Exception
{ {
final CountDownLatch timeoutLatch = new CountDownLatch(1); final CountDownLatch timeoutLatch = new CountDownLatch(1);
startServer(new ServerSessionListener.Adapter() startServer(new ServerSessionListener.Adapter()

View File

@ -1,10 +1,2 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=INFO org.eclipse.jetty.http2.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

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.http2.server; package org.eclipse.jetty.http2.server;
import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; 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.PingFrame;
import org.eclipse.jetty.http2.frames.SettingsFrame; import org.eclipse.jetty.http2.frames.SettingsFrame;
import org.eclipse.jetty.http2.generator.Generator; 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.ErrorCode;
import org.eclipse.jetty.http2.parser.Parser; import org.eclipse.jetty.http2.parser.Parser;
import org.eclipse.jetty.http2.parser.PrefaceParser; import org.eclipse.jetty.http2.parser.PrefaceParser;
@ -86,9 +82,6 @@ public class HTTP2ServerTest
generator = new Generator(byteBufferPool); generator = new Generator(byteBufferPool);
server.start(); server.start();
HpackContext.LOG.setDebugEnabled(true);
HpackEncoder.LOG.setDebugEnabled(true);
HpackDecoder.LOG.setDebugEnabled(true);
} }
@After @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]; byte[] buffer = new byte[2048];
InputStream input = client.getInputStream(); InputStream input = client.getInputStream();
@ -365,13 +358,13 @@ public class HTTP2ServerTest
try try
{ {
int read = input.read(buffer); int read = input.read(buffer);
if (read <= 0) if (read < 0)
throw new EOFException(); return true;
parser.parse(ByteBuffer.wrap(buffer, 0, read)); parser.parse(ByteBuffer.wrap(buffer, 0, read));
} }
catch (SocketTimeoutException x) catch (SocketTimeoutException x)
{ {
break; return false;
} }
} }
} }

View File

@ -1,4 +1,3 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.http2.LEVEL=INFO org.eclipse.jetty.http2.LEVEL=INFO
org.eclipse.jetty.http2.hpack.LEVEL=DEBUG