Replaced usage of hardcoded protocol versions with constant.

This commit is contained in:
Simone Bordet 2012-02-07 16:36:17 +01:00
parent cf5db008de
commit 3ca69de16a
30 changed files with 148 additions and 117 deletions

View File

@ -31,6 +31,7 @@ import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.GoAwayInfo;
import org.eclipse.jetty.spdy.api.PingInfo;
import org.eclipse.jetty.spdy.api.RstInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.SPDYException;
import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.SessionStatus;
@ -307,8 +308,7 @@ public class StandardSession implements ISession, Parser.Listener, ISession.Cont
if (stream == null)
{
// There is no stream, therefore no version, so we hardcode version 2.
short version = (short)2;
rst(version, new RstInfo(streamId, StreamStatus.INVALID_STREAM));
rst(SPDY.V2, new RstInfo(streamId, StreamStatus.INVALID_STREAM));
}
else
{

View File

@ -0,0 +1,27 @@
/*
* 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.api;
public class SPDY
{
public static final short V2 = 2;
public static final short V3 = 3;
private SPDY()
{
}
}

View File

@ -24,9 +24,8 @@ import java.util.List;
* <p>Once a {@link Session} has been obtained, it can be used to open SPDY streams:</p>
* <pre>
* Session session = ...;
* short spdyVersion = 2;
* SynInfo synInfo = new SynInfo(spdyVersion, true);
* session.syn(synInfo, new Stream.FrameListener.Adapter()
* SynInfo synInfo = new SynInfo(true);
* session.syn(SPDY.V2, synInfo, new Stream.FrameListener.Adapter()
* {
* public void onReply(Stream stream, ReplyInfo replyInfo)
* {

View File

@ -35,9 +35,9 @@ public enum StreamStatus
{
switch (version)
{
case 2:
case SPDY.V2:
return Mapper.v2Codes.get(code);
case 3:
case SPDY.V3:
return Mapper.v3Codes.get(code);
default:
throw new IllegalStateException();
@ -61,9 +61,9 @@ public enum StreamStatus
{
switch (version)
{
case 2:
case SPDY.V2:
return v2Code;
case 3:
case SPDY.V3:
return v3Code;
default:
throw new IllegalStateException();

View File

@ -16,10 +16,12 @@
package org.eclipse.jetty.spdy.frames;
import org.eclipse.jetty.spdy.api.SPDY;
public class NoOpFrame extends ControlFrame
{
public NoOpFrame()
{
super((short)2, ControlFrameType.NOOP, (byte)0);
super(SPDY.V2, ControlFrameType.NOOP, (byte)0);
}
}

View File

@ -23,6 +23,7 @@ import java.nio.charset.Charset;
import org.eclipse.jetty.spdy.CompressionFactory;
import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY;
public class HeadersBlockGenerator
{
@ -103,13 +104,13 @@ public class HeadersBlockGenerator
{
switch (version)
{
case 2:
case SPDY.V2:
{
buffer.write((value & 0xFF_00) >>> 8);
buffer.write(value & 0x00_FF);
break;
}
case 3:
case SPDY.V3:
{
buffer.write((value & 0xFF_00_00_00) >>> 24);
buffer.write((value & 0x00_FF_00_00) >>> 16);

View File

@ -19,6 +19,7 @@ package org.eclipse.jetty.spdy.generator;
import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.StreamStatus;
import org.eclipse.jetty.spdy.frames.ControlFrame;
import org.eclipse.jetty.spdy.frames.SynReplyFrame;
@ -64,9 +65,9 @@ public class SynReplyGenerator extends ControlFrameGenerator
{
switch (version)
{
case 2:
case SPDY.V2:
return 6;
case 3:
case SPDY.V3:
return 4;
default:
// Here the version is trusted to be correct; if it's not
@ -79,10 +80,10 @@ public class SynReplyGenerator extends ControlFrameGenerator
{
switch (version)
{
case 2:
case SPDY.V2:
buffer.putShort((short)0);
break;
case 3:
case SPDY.V3:
break;
default:
// Here the version is trusted to be correct; if it's not

View File

@ -19,6 +19,7 @@ package org.eclipse.jetty.spdy.generator;
import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.StreamStatus;
import org.eclipse.jetty.spdy.frames.ControlFrame;
import org.eclipse.jetty.spdy.frames.SynStreamFrame;
@ -65,10 +66,10 @@ public class SynStreamGenerator extends ControlFrameGenerator
{
switch (version)
{
case 2:
case SPDY.V2:
priority <<= 6;
break;
case 3:
case SPDY.V3:
priority <<= 5;
break;
default:

View File

@ -47,11 +47,11 @@ import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.eclipse.jetty.spdy.nio.EmptyAsyncEndPoint;
public class ServerHTTP11OverSPDY2AsyncConnectionFactory extends ServerSPDY2AsyncConnectionFactory
public class HTTP11OverSPDY2AsyncConnectionFactory extends ServerSPDY2AsyncConnectionFactory
{
private final Connector connector;
public ServerHTTP11OverSPDY2AsyncConnectionFactory(Connector connector)
public HTTP11OverSPDY2AsyncConnectionFactory(Connector connector)
{
this.connector = connector;
}

View File

@ -22,6 +22,7 @@ import java.util.EnumMap;
import org.eclipse.jetty.spdy.CompressionFactory;
import org.eclipse.jetty.spdy.SessionException;
import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.SessionStatus;
import org.eclipse.jetty.spdy.frames.ControlFrame;
import org.eclipse.jetty.spdy.frames.ControlFrameType;
@ -173,7 +174,7 @@ public abstract class ControlFrameParser
private void checkVersion(short version) throws SessionException
{
if (version != 2 && version != 3)
if (version != SPDY.V2 && version != SPDY.V3)
throw new SessionException(SessionStatus.PROTOCOL_ERROR, "Unrecognized version " + version);
}

View File

@ -23,6 +23,7 @@ import java.util.zip.ZipException;
import org.eclipse.jetty.spdy.CompressionFactory;
import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.StreamStatus;
public abstract class HeadersBlockParser
@ -127,12 +128,15 @@ public abstract class HeadersBlockParser
private int readCount(int version, ByteBuffer buffer) throws StreamException
{
if (version == 2)
return buffer.getShort();
else if (version == 3)
return buffer.getInt();
else
throw new IllegalStateException();
switch (version)
{
case SPDY.V2:
return buffer.getShort();
case SPDY.V3:
return buffer.getInt();
default:
throw new IllegalStateException();
}
}
private int readNameLength(int version, ByteBuffer buffer) throws StreamException

View File

@ -22,6 +22,7 @@ import org.eclipse.jetty.spdy.CompressionFactory;
import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.frames.ControlFrameType;
import org.eclipse.jetty.spdy.frames.SynReplyFrame;
@ -77,7 +78,7 @@ public class SynReplyBodyParser extends ControlFrameBodyParser
{
switch (controlFrameParser.getVersion())
{
case 2:
case SPDY.V2:
{
if (buffer.remaining() >= 2)
{
@ -91,7 +92,7 @@ public class SynReplyBodyParser extends ControlFrameBodyParser
}
break;
}
case 3:
case SPDY.V3:
{
state = State.HEADERS;
break;
@ -105,7 +106,7 @@ public class SynReplyBodyParser extends ControlFrameBodyParser
}
case ADDITIONAL_BYTES:
{
assert controlFrameParser.getVersion() == 2;
assert controlFrameParser.getVersion() == SPDY.V2;
buffer.get();
--cursor;
if (cursor == 0)

View File

@ -21,6 +21,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.CompressionFactory;
import org.eclipse.jetty.spdy.StreamException;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.frames.ControlFrameType;
import org.eclipse.jetty.spdy.frames.SynStreamFrame;
@ -151,11 +152,11 @@ public class SynStreamBodyParser extends ControlFrameBodyParser
// so we use an int to perform the shifts
switch (version)
{
case 2:
case SPDY.V2:
int p2 = currByte & 0b1100_0000;
p2 >>>= 6;
return (byte)p2;
case 3:
case SPDY.V3:
int p3 = currByte & 0b1110_0000;
p3 >>>= 5;
return (byte)p3;

View File

@ -30,6 +30,7 @@ import org.eclipse.jetty.spdy.api.ByteBufferDataInfo;
import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StringDataInfo;
@ -68,7 +69,6 @@ public class SPDYConcurrentSynDataReplyDataTest extends SPDYTest
final int iterations = 50;
final int count = 50;
final short version = 2;
final Headers headers = new Headers();
headers.put("method", "get");
headers.put("path", "/");
@ -94,7 +94,7 @@ public class SPDYConcurrentSynDataReplyDataTest extends SPDYTest
@Override
public Object call() throws Exception
{
process(session, version, headers, iterations);
process(session, SPDY.V2, headers, iterations);
return null;
}
});

View File

@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.GoAwayInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.SPDYException;
import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.SessionStatus;
@ -62,10 +63,9 @@ public class SPDYGoAwayTest extends SPDYTest
};
Session session = startClient(startServer(serverSessionFrameListener), null);
short version = (short)2;
session.syn(version, new SynInfo(true), null);
session.syn(SPDY.V2, new SynInfo(true), null);
session.goAway(version);
session.goAway(SPDY.V2);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
@ -73,14 +73,13 @@ public class SPDYGoAwayTest extends SPDYTest
@Test
public void testGoAwayOnServerClose() throws Exception
{
final short version = (short)2;
ServerSessionFrameListener serverSessionFrameListener = new ServerSessionFrameListener.Adapter()
{
@Override
public Stream.FrameListener onSyn(Stream stream, SynInfo synInfo)
{
stream.reply(new ReplyInfo(true));
stream.getSession().goAway(version);
stream.getSession().goAway(SPDY.V2);
return null;
}
};
@ -97,7 +96,7 @@ public class SPDYGoAwayTest extends SPDYTest
};
Session session = startClient(startServer(serverSessionFrameListener), clientSessionFrameListener);
Stream stream1 = session.syn(version, new SynInfo(true), null);
Stream stream1 = session.syn(SPDY.V2, new SynInfo(true), null);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
GoAwayInfo goAwayInfo = ref.get();
@ -109,7 +108,6 @@ public class SPDYGoAwayTest extends SPDYTest
@Test
public void testSynStreamIgnoredAfterGoAway() throws Exception
{
final short version = (short)2;
final CountDownLatch latch = new CountDownLatch(1);
ServerSessionFrameListener serverSessionFrameListener = new ServerSessionFrameListener.Adapter()
{
@ -122,7 +120,7 @@ public class SPDYGoAwayTest extends SPDYTest
if (synCount == 1)
{
stream.reply(new ReplyInfo(true));
stream.getSession().goAway(version);
stream.getSession().goAway(SPDY.V2);
}
else
{
@ -137,13 +135,13 @@ public class SPDYGoAwayTest extends SPDYTest
@Override
public void onGoAway(Session session, GoAwayInfo goAwayInfo)
{
ref.get().syn(version, new SynInfo(true), null);
ref.get().syn(SPDY.V2, new SynInfo(true), null);
}
};
Session session = startClient(startServer(serverSessionFrameListener), clientSessionFrameListener);
ref.set(session);
session.syn(version, new SynInfo(true), null);
session.syn(SPDY.V2, new SynInfo(true), null);
Assert.assertFalse(latch.await(1, TimeUnit.SECONDS));
}
@ -151,7 +149,6 @@ public class SPDYGoAwayTest extends SPDYTest
@Test
public void testDataNotProcessedAfterGoAway() throws Exception
{
final short version = (short)2;
final CountDownLatch closeLatch = new CountDownLatch(1);
final CountDownLatch dataLatch = new CountDownLatch(1);
ServerSessionFrameListener serverSessionFrameListener = new ServerSessionFrameListener.Adapter()
@ -169,7 +166,7 @@ public class SPDYGoAwayTest extends SPDYTest
}
else
{
stream.getSession().goAway(version);
stream.getSession().goAway(SPDY.V2);
closeLatch.countDown();
return new Stream.FrameListener.Adapter()
{
@ -197,7 +194,7 @@ public class SPDYGoAwayTest extends SPDYTest
// First stream is processed ok
final CountDownLatch reply1Latch = new CountDownLatch(1);
Stream stream1 = session.syn(version, new SynInfo(true), new Stream.FrameListener.Adapter()
Stream stream1 = session.syn(SPDY.V2, new SynInfo(true), new Stream.FrameListener.Adapter()
{
@Override
public void onReply(Stream stream, ReplyInfo replyInfo)
@ -208,7 +205,7 @@ public class SPDYGoAwayTest extends SPDYTest
Assert.assertTrue(reply1Latch.await(5, TimeUnit.SECONDS));
// Second stream is closed in the middle
Stream stream2 = session.syn(version, new SynInfo(false), null);
Stream stream2 = session.syn(SPDY.V2, new SynInfo(false), null);
Assert.assertTrue(closeLatch.await(5, TimeUnit.SECONDS));
// There is a race between the data we want to send, and the client

View File

@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.SynInfo;
@ -56,8 +57,7 @@ public class SPDYHeadersTest extends SPDYTest
Session session = startClient(startServer(serverSessionFrameListener), null);
final CountDownLatch latch = new CountDownLatch(1);
short version = 2;
session.syn(version, new SynInfo(false), new Stream.FrameListener.Adapter()
session.syn(SPDY.V2, new SynInfo(false), new Stream.FrameListener.Adapter()
{
@Override
public void onReply(Stream stream, ReplyInfo replyInfo)

View File

@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.jetty.spdy.api.PingInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
import org.junit.Assert;
@ -43,7 +44,7 @@ public class SPDYPingTest extends SPDYTest
}
};
Session session = startClient(startServer(null), clientSessionFrameListener);
PingInfo pingInfo = session.ping((short)2);
PingInfo pingInfo = session.ping(SPDY.V2);
Assert.assertEquals(1, pingInfo.getPingId() % 2);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
@ -63,7 +64,7 @@ public class SPDYPingTest extends SPDYTest
@Override
public void onConnect(Session session)
{
PingInfo pingInfo = session.ping((short)2);
PingInfo pingInfo = session.ping(SPDY.V2);
this.pingId = pingInfo.getPingId();
}

View File

@ -21,6 +21,7 @@ import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.SettingsInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;
@ -49,7 +50,7 @@ public class SPDYSettingsTest extends SPDYTest
};
Session session = startClient(startServer(serverSessionFrameListener), null);
session.settings((short)2, clientSettingsInfo);
session.settings(SPDY.V2, clientSettingsInfo);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
@ -67,7 +68,7 @@ public class SPDYSettingsTest extends SPDYTest
@Override
public void onConnect(Session session)
{
session.settings((short)2, serverSettingsInfo);
session.settings(SPDY.V2, serverSettingsInfo);
}
};

View File

@ -30,6 +30,7 @@ import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.RstInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamStatus;
@ -84,7 +85,7 @@ public class SPDYSynReplyTest extends SPDYTest
});
final CountDownLatch replyLatch = new CountDownLatch(1);
Stream stream = session.syn((short)2, new SynInfo(new Headers(), true), new Stream.FrameListener.Adapter()
Stream stream = session.syn(SPDY.V2, new SynInfo(new Headers(), true), new Stream.FrameListener.Adapter()
{
@Override
public void onReply(Stream stream, ReplyInfo replyInfo)
@ -166,7 +167,7 @@ public class SPDYSynReplyTest extends SPDYTest
});
final CountDownLatch replyLatch = new CountDownLatch(1);
Stream stream = session.syn((short)2, new SynInfo(new Headers(), false), new Stream.FrameListener.Adapter()
Stream stream = session.syn(SPDY.V2, new SynInfo(new Headers(), false), new Stream.FrameListener.Adapter()
{
@Override
public void onReply(Stream stream, ReplyInfo replyInfo)
@ -214,7 +215,7 @@ public class SPDYSynReplyTest extends SPDYTest
final CountDownLatch replyLatch = new CountDownLatch(1);
final CountDownLatch dataLatch1 = new CountDownLatch(1);
final CountDownLatch dataLatch2 = new CountDownLatch(1);
session.syn((short)2, new SynInfo(true), new Stream.FrameListener.Adapter()
session.syn(SPDY.V2, new SynInfo(true), new Stream.FrameListener.Adapter()
{
private AtomicInteger dataCount = new AtomicInteger();
@ -265,7 +266,7 @@ public class SPDYSynReplyTest extends SPDYTest
@Override
public void onConnect(Session session)
{
Stream stream = session.syn((short)2, new SynInfo(false), new Stream.FrameListener.Adapter()
Stream stream = session.syn(SPDY.V2, new SynInfo(false), new Stream.FrameListener.Adapter()
{
@Override
public void onReply(Stream stream, ReplyInfo replyInfo)
@ -349,7 +350,7 @@ public class SPDYSynReplyTest extends SPDYTest
};
Session session = startClient(startServer(serverSessionFrameListener), null);
Stream stream = session.syn((short)2, new SynInfo(true), null);
Stream stream = session.syn(SPDY.V2, new SynInfo(true), null);
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
RstInfo rstInfo = ref.get();

View File

@ -30,7 +30,7 @@ public class ClientUsageTest
{
Session session = new StandardSession(null, 1, null, null);
session.syn((short)2, new SynInfo(false), new Stream.FrameListener.Adapter()
session.syn(SPDY.V2, new SynInfo(false), new Stream.FrameListener.Adapter()
{
@Override
public void onReply(Stream stream, ReplyInfo replyInfo)
@ -39,7 +39,7 @@ public class ClientUsageTest
replyInfo.getHeaders().get("host");
// Then issue another similar request
stream.getSession().syn((short)2, new SynInfo(true), this);
stream.getSession().syn(SPDY.V2, new SynInfo(true), this);
}
});
}
@ -49,7 +49,7 @@ public class ClientUsageTest
{
Session session = new StandardSession(null, 1, null, null);
Stream stream = session.syn((short)2, new SynInfo(false), new Stream.FrameListener.Adapter()
Stream stream = session.syn(SPDY.V2, new SynInfo(false), new Stream.FrameListener.Adapter()
{
// The good of passing the listener here is that you can safely accumulate info
// from the headers to be used in the data, e.g. content-type, charset
@ -66,7 +66,7 @@ public class ClientUsageTest
// stream.setAttribute("content-length", contentLength);
// Then issue another similar request
stream.getSession().syn((short)2, new SynInfo(true), this);
stream.getSession().syn(SPDY.V2, new SynInfo(true), this);
}
@Override

View File

@ -71,7 +71,7 @@ public class ServerUsageTest
// However, the API may allow to initiate the stream like in bwtp
SynInfo synInfo = new SynInfo(new Headers(), false, true, 0, (byte)0);
Stream stream = session.syn((short)2, synInfo, null);
Stream stream = session.syn(SPDY.V2, synInfo, null);
// The point here is that we have no idea if the client accepted our stream
// So we return a stream, we may be able to send the headers frame, but later
// the client sends a rst frame.

View File

@ -19,6 +19,7 @@ package org.eclipse.jetty.spdy.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser;
import org.junit.Assert;
@ -29,10 +30,9 @@ public class GoAwayGenerateParseTest
@Test
public void testGenerateParse() throws Exception
{
short version = 2;
int lastStreamId = 13;
int statusCode = 1;
GoAwayFrame frame1 = new GoAwayFrame(version, lastStreamId, statusCode);
GoAwayFrame frame1 = new GoAwayFrame(SPDY.V2, lastStreamId, statusCode);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -47,7 +47,7 @@ public class GoAwayGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.GO_AWAY, frame2.getType());
GoAwayFrame goAway = (GoAwayFrame)frame2;
Assert.assertEquals(version, goAway.getVersion());
Assert.assertEquals(SPDY.V2, goAway.getVersion());
Assert.assertEquals(lastStreamId, goAway.getLastStreamId());
Assert.assertEquals(0, goAway.getFlags());
Assert.assertEquals(statusCode, goAway.getStatusCode());
@ -56,10 +56,9 @@ public class GoAwayGenerateParseTest
@Test
public void testGenerateParseOneByteAtATime() throws Exception
{
short version = 2;
int lastStreamId = 13;
int statusCode = 1;
GoAwayFrame frame1 = new GoAwayFrame(version, lastStreamId, statusCode);
GoAwayFrame frame1 = new GoAwayFrame(SPDY.V2, lastStreamId, statusCode);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -75,7 +74,7 @@ public class GoAwayGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.GO_AWAY, frame2.getType());
GoAwayFrame goAway = (GoAwayFrame)frame2;
Assert.assertEquals(version, goAway.getVersion());
Assert.assertEquals(SPDY.V2, goAway.getVersion());
Assert.assertEquals(lastStreamId, goAway.getLastStreamId());
Assert.assertEquals(0, goAway.getFlags());
Assert.assertEquals(statusCode, goAway.getStatusCode());

View File

@ -21,6 +21,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.HeadersInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser;
import org.junit.Assert;
@ -31,12 +32,11 @@ public class HeadersGenerateParseTest
@Test
public void testGenerateParse() throws Exception
{
short version = 2;
byte flags = HeadersInfo.FLAG_RESET_COMPRESSION;
int streamId = 13;
Headers headers = new Headers();
headers.put("a", "b");
HeadersFrame frame1 = new HeadersFrame(version, flags, streamId, headers);
HeadersFrame frame1 = new HeadersFrame(SPDY.V2, flags, streamId, headers);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -51,7 +51,7 @@ public class HeadersGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.HEADERS, frame2.getType());
HeadersFrame headersFrame = (HeadersFrame)frame2;
Assert.assertEquals(version, headersFrame.getVersion());
Assert.assertEquals(SPDY.V2, headersFrame.getVersion());
Assert.assertEquals(streamId, headersFrame.getStreamId());
Assert.assertEquals(flags, headersFrame.getFlags());
Assert.assertEquals(headers, headersFrame.getHeaders());
@ -60,12 +60,11 @@ public class HeadersGenerateParseTest
@Test
public void testGenerateParseOneByteAtATime() throws Exception
{
short version = 2;
byte flags = HeadersInfo.FLAG_RESET_COMPRESSION;
int streamId = 13;
Headers headers = new Headers();
headers.put("a", "b");
HeadersFrame frame1 = new HeadersFrame(version, flags, streamId, headers);
HeadersFrame frame1 = new HeadersFrame(SPDY.V2, flags, streamId, headers);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -81,7 +80,7 @@ public class HeadersGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.HEADERS, frame2.getType());
HeadersFrame headersFrame = (HeadersFrame)frame2;
Assert.assertEquals(version, headersFrame.getVersion());
Assert.assertEquals(SPDY.V2, headersFrame.getVersion());
Assert.assertEquals(streamId, headersFrame.getStreamId());
Assert.assertEquals(flags, headersFrame.getFlags());
Assert.assertEquals(headers, headersFrame.getHeaders());

View File

@ -19,6 +19,7 @@ package org.eclipse.jetty.spdy.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser;
import org.junit.Assert;
@ -29,9 +30,8 @@ public class PingGenerateParseTest
@Test
public void testGenerateParse() throws Exception
{
short version = 2;
int pingId = 13;
PingFrame frame1 = new PingFrame(version, pingId);
PingFrame frame1 = new PingFrame(SPDY.V2, pingId);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -46,7 +46,7 @@ public class PingGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.PING, frame2.getType());
PingFrame ping = (PingFrame)frame2;
Assert.assertEquals(version, ping.getVersion());
Assert.assertEquals(SPDY.V2, ping.getVersion());
Assert.assertEquals(pingId, ping.getPingId());
Assert.assertEquals(0, ping.getFlags());
}
@ -54,9 +54,8 @@ public class PingGenerateParseTest
@Test
public void testGenerateParseOneByteAtATime() throws Exception
{
short version = 2;
int pingId = 13;
PingFrame frame1 = new PingFrame(version, pingId);
PingFrame frame1 = new PingFrame(SPDY.V2, pingId);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -72,7 +71,7 @@ public class PingGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.PING, frame2.getType());
PingFrame ping = (PingFrame)frame2;
Assert.assertEquals(version, ping.getVersion());
Assert.assertEquals(SPDY.V2, ping.getVersion());
Assert.assertEquals(pingId, ping.getPingId());
Assert.assertEquals(0, ping.getFlags());
}

View File

@ -19,6 +19,7 @@ package org.eclipse.jetty.spdy.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.StreamStatus;
import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser;
@ -30,10 +31,9 @@ public class RstStreamGenerateParseTest
@Test
public void testGenerateParse() throws Exception
{
short version = 2;
int streamId = 13;
int streamStatus = StreamStatus.UNSUPPORTED_VERSION.getCode(version);
RstStreamFrame frame1 = new RstStreamFrame(version, streamId, streamStatus);
int streamStatus = StreamStatus.UNSUPPORTED_VERSION.getCode(SPDY.V2);
RstStreamFrame frame1 = new RstStreamFrame(SPDY.V2, streamId, streamStatus);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -48,7 +48,7 @@ public class RstStreamGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.RST_STREAM, frame2.getType());
RstStreamFrame rstStream = (RstStreamFrame)frame2;
Assert.assertEquals(version, rstStream.getVersion());
Assert.assertEquals(SPDY.V2, rstStream.getVersion());
Assert.assertEquals(streamId, rstStream.getStreamId());
Assert.assertEquals(0, rstStream.getFlags());
Assert.assertEquals(streamStatus, rstStream.getStatusCode());
@ -57,10 +57,9 @@ public class RstStreamGenerateParseTest
@Test
public void testGenerateParseOneByteAtATime() throws Exception
{
short version = 2;
int streamId = 13;
int streamStatus = StreamStatus.UNSUPPORTED_VERSION.getCode(version);
RstStreamFrame frame1 = new RstStreamFrame(version, streamId, streamStatus);
int streamStatus = StreamStatus.UNSUPPORTED_VERSION.getCode(SPDY.V2);
RstStreamFrame frame1 = new RstStreamFrame(SPDY.V2, streamId, streamStatus);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -76,7 +75,7 @@ public class RstStreamGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.RST_STREAM, frame2.getType());
RstStreamFrame rstStream = (RstStreamFrame)frame2;
Assert.assertEquals(version, rstStream.getVersion());
Assert.assertEquals(SPDY.V2, rstStream.getVersion());
Assert.assertEquals(streamId, rstStream.getStreamId());
Assert.assertEquals(0, rstStream.getFlags());
Assert.assertEquals(streamStatus, rstStream.getStatusCode());

View File

@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.SettingsInfo;
import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser;
@ -32,12 +33,11 @@ public class SettingsGenerateParseTest
@Test
public void testGenerateParse() throws Exception
{
short version = 2;
byte flags = SettingsInfo.CLEAR_PERSISTED;
Map<SettingsInfo.Key, Integer> pairs = new HashMap<>();
pairs.put(new SettingsInfo.Key(SettingsInfo.Key.FLAG_PERSIST | SettingsInfo.Key.MAX_STREAMS), 100);
pairs.put(new SettingsInfo.Key(SettingsInfo.Key.FLAG_PERSISTED | SettingsInfo.Key.ROUND_TRIP_TIME), 500);
SettingsFrame frame1 = new SettingsFrame(version, flags, pairs);
SettingsFrame frame1 = new SettingsFrame(SPDY.V2, flags, pairs);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -52,7 +52,7 @@ public class SettingsGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.SETTINGS, frame2.getType());
SettingsFrame settings = (SettingsFrame)frame2;
Assert.assertEquals(version, settings.getVersion());
Assert.assertEquals(SPDY.V2, settings.getVersion());
Assert.assertEquals(flags, settings.getFlags());
Assert.assertEquals(pairs, settings.getSettings());
}
@ -60,12 +60,11 @@ public class SettingsGenerateParseTest
@Test
public void testGenerateParseOneByteAtATime() throws Exception
{
short version = 2;
byte flags = SettingsInfo.CLEAR_PERSISTED;
Map<SettingsInfo.Key, Integer> pairs = new HashMap<>();
pairs.put(new SettingsInfo.Key(SettingsInfo.Key.FLAG_PERSIST | SettingsInfo.Key.MAX_STREAMS), 100);
pairs.put(new SettingsInfo.Key(SettingsInfo.Key.FLAG_PERSISTED | SettingsInfo.Key.ROUND_TRIP_TIME), 500);
SettingsFrame frame1 = new SettingsFrame(version, flags, pairs);
SettingsFrame frame1 = new SettingsFrame(SPDY.V2, flags, pairs);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -81,7 +80,7 @@ public class SettingsGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.SETTINGS, frame2.getType());
SettingsFrame settings = (SettingsFrame)frame2;
Assert.assertEquals(version, settings.getVersion());
Assert.assertEquals(SPDY.V2, settings.getVersion());
Assert.assertEquals(flags, settings.getFlags());
Assert.assertEquals(pairs, settings.getSettings());
}

View File

@ -21,6 +21,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser;
import org.junit.Assert;
@ -31,12 +32,11 @@ public class SynReplyGenerateParseTest
@Test
public void testGenerateParse() throws Exception
{
short version = 2;
byte flags = ReplyInfo.FLAG_FIN;
int streamId = 13;
Headers headers = new Headers();
headers.put("a", "b");
SynReplyFrame frame1 = new SynReplyFrame(version, flags, streamId, headers);
SynReplyFrame frame1 = new SynReplyFrame(SPDY.V2, flags, streamId, headers);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -51,7 +51,7 @@ public class SynReplyGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.SYN_REPLY, frame2.getType());
SynReplyFrame synReply = (SynReplyFrame)frame2;
Assert.assertEquals(version, synReply.getVersion());
Assert.assertEquals(SPDY.V2, synReply.getVersion());
Assert.assertEquals(flags, synReply.getFlags());
Assert.assertEquals(streamId, synReply.getStreamId());
Assert.assertEquals(headers, synReply.getHeaders());
@ -60,12 +60,11 @@ public class SynReplyGenerateParseTest
@Test
public void testGenerateParseOneByteAtATime() throws Exception
{
short version = 2;
byte flags = ReplyInfo.FLAG_FIN;
int streamId = 13;
Headers headers = new Headers();
headers.put("a", "b");
SynReplyFrame frame1 = new SynReplyFrame(version, flags, streamId, headers);
SynReplyFrame frame1 = new SynReplyFrame(SPDY.V2, flags, streamId, headers);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -81,7 +80,7 @@ public class SynReplyGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.SYN_REPLY, frame2.getType());
SynReplyFrame synReply = (SynReplyFrame)frame2;
Assert.assertEquals(version, synReply.getVersion());
Assert.assertEquals(SPDY.V2, synReply.getVersion());
Assert.assertEquals(flags, synReply.getFlags());
Assert.assertEquals(streamId, synReply.getStreamId());
Assert.assertEquals(headers, synReply.getHeaders());

View File

@ -20,6 +20,7 @@ import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser;
@ -31,7 +32,6 @@ public class SynStreamGenerateParseTest
@Test
public void testGenerateParse() throws Exception
{
short version = 2;
byte flags = SynInfo.FLAG_FIN;
int streamId = 13;
int associatedStreamId = 11;
@ -39,7 +39,7 @@ public class SynStreamGenerateParseTest
Headers headers = new Headers();
headers.put("a", "b");
headers.put("c", "d");
SynStreamFrame frame1 = new SynStreamFrame(version, flags, streamId, associatedStreamId, priority, headers);
SynStreamFrame frame1 = new SynStreamFrame(SPDY.V2, flags, streamId, associatedStreamId, priority, headers);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -54,7 +54,7 @@ public class SynStreamGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.SYN_STREAM, frame2.getType());
SynStreamFrame synStream = (SynStreamFrame)frame2;
Assert.assertEquals(version, synStream.getVersion());
Assert.assertEquals(SPDY.V2, synStream.getVersion());
Assert.assertEquals(streamId, synStream.getStreamId());
Assert.assertEquals(associatedStreamId, synStream.getAssociatedStreamId());
Assert.assertEquals(flags, synStream.getFlags());
@ -65,7 +65,6 @@ public class SynStreamGenerateParseTest
@Test
public void testGenerateParseOneByteAtATime() throws Exception
{
short version = 2;
byte flags = SynInfo.FLAG_FIN;
int streamId = 13;
int associatedStreamId = 11;
@ -73,7 +72,7 @@ public class SynStreamGenerateParseTest
Headers headers = new Headers();
headers.put("a", "b");
headers.put("c", "d");
SynStreamFrame frame1 = new SynStreamFrame(version, flags, streamId, associatedStreamId, priority, headers);
SynStreamFrame frame1 = new SynStreamFrame(SPDY.V2, flags, streamId, associatedStreamId, priority, headers);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -89,7 +88,7 @@ public class SynStreamGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.SYN_STREAM, frame2.getType());
SynStreamFrame synStream = (SynStreamFrame)frame2;
Assert.assertEquals(version, synStream.getVersion());
Assert.assertEquals(SPDY.V2, synStream.getVersion());
Assert.assertEquals(streamId, synStream.getStreamId());
Assert.assertEquals(associatedStreamId, synStream.getAssociatedStreamId());
Assert.assertEquals(flags, synStream.getFlags());

View File

@ -19,6 +19,7 @@ package org.eclipse.jetty.spdy.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.spdy.StandardCompressionFactory;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.generator.Generator;
import org.eclipse.jetty.spdy.parser.Parser;
import org.junit.Assert;
@ -29,10 +30,9 @@ public class WindowUpdateGenerateParseTest
@Test
public void testGenerateParse() throws Exception
{
short version = 2;
int streamId = 13;
int windowDelta = 17;
WindowUpdateFrame frame1 = new WindowUpdateFrame(version, streamId, windowDelta);
WindowUpdateFrame frame1 = new WindowUpdateFrame(SPDY.V2, streamId, windowDelta);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -47,7 +47,7 @@ public class WindowUpdateGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.WINDOW_UPDATE, frame2.getType());
WindowUpdateFrame windowUpdate = (WindowUpdateFrame)frame2;
Assert.assertEquals(version, windowUpdate.getVersion());
Assert.assertEquals(SPDY.V2, windowUpdate.getVersion());
Assert.assertEquals(streamId, windowUpdate.getStreamId());
Assert.assertEquals(0, windowUpdate.getFlags());
Assert.assertEquals(windowDelta, windowUpdate.getWindowDelta());
@ -56,10 +56,9 @@ public class WindowUpdateGenerateParseTest
@Test
public void testGenerateParseOneByteAtATime() throws Exception
{
short version = 2;
int streamId = 13;
int windowDelta = 17;
WindowUpdateFrame frame1 = new WindowUpdateFrame(version, streamId, windowDelta);
WindowUpdateFrame frame1 = new WindowUpdateFrame(SPDY.V2, streamId, windowDelta);
Generator generator = new Generator(new StandardCompressionFactory().newCompressor());
ByteBuffer buffer = generator.control(frame1);
@ -75,7 +74,7 @@ public class WindowUpdateGenerateParseTest
Assert.assertNotNull(frame2);
Assert.assertEquals(ControlFrameType.WINDOW_UPDATE, frame2.getType());
WindowUpdateFrame windowUpdate = (WindowUpdateFrame)frame2;
Assert.assertEquals(version, windowUpdate.getVersion());
Assert.assertEquals(SPDY.V2, windowUpdate.getVersion());
Assert.assertEquals(streamId, windowUpdate.getStreamId());
Assert.assertEquals(0, windowUpdate.getFlags());
Assert.assertEquals(windowDelta, windowUpdate.getWindowDelta());

View File

@ -30,6 +30,7 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.spdy.api.Headers;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.SynInfo;
@ -51,7 +52,7 @@ public class HTTPOverSPDYTest
server = new Server();
connector = new SPDYServerConnector(null);
server.addConnector(connector);
connector.putAsyncConnectionFactory("spdy/2", new ServerHTTP11OverSPDY2AsyncConnectionFactory(connector));
connector.putAsyncConnectionFactory("spdy/2", new HTTP11OverSPDY2AsyncConnectionFactory(connector));
server.setHandler(handler);
server.start();
@ -64,7 +65,7 @@ public class HTTPOverSPDYTest
@After
public void stop() throws Exception
{
session.goAway((short)2);
session.goAway(SPDY.V2);
clientFactory.stop();
clientFactory.join();
server.stop();
@ -95,7 +96,7 @@ public class HTTPOverSPDYTest
headers.put("url", "http://localhost:" + connector.getLocalPort() + path);
headers.put("version", "HTTP/1.1");
final CountDownLatch replyLatch = new CountDownLatch(1);
session.syn((short)2, new SynInfo(headers, true), new Stream.FrameListener.Adapter()
session.syn(SPDY.V2, new SynInfo(headers, true), new Stream.FrameListener.Adapter()
{
@Override
public void onReply(Stream stream, ReplyInfo replyInfo)