Mercurial > stress-tester
changeset 693:3b6dbbe80eff
NC file in progress
author | Devel 2 |
---|---|
date | Mon, 27 Nov 2017 11:23:01 +0100 |
parents | a27658c9e2e3 |
children | 273721fe69d1 |
files | stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockWriter.java stress-tester/src/test/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataReaderTest.java |
diffstat | 3 files changed, 37 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java Mon Nov 27 10:55:36 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java Mon Nov 27 11:23:01 2017 +0100 @@ -112,6 +112,11 @@ opened = false; } + public boolean eof() { + checkOpened(); + return eof && buffer.isEmpty(); + } + private void checkOpened() { if (!opened) { throw new IllegalStateException("Reader is not opened."); @@ -142,7 +147,7 @@ eof = true; return -1; } - + nioBuffer.flip(); readed += nioBuffer.remaining(); buffer.append(nioBuffer); @@ -161,9 +166,22 @@ } public long position() throws IOException { + if (eof()) { + return -1; + } + return ch.position() - buffer.readedBytes(); } + public byte peekBlockType() throws IOException { + if (eof()) { + return -1; + } + + read(1); + return buffer.get(); + } + private void readHeader() throws IOException { read(NcHeader.SIZE); @@ -314,11 +332,6 @@ return payloadBlock; } - public int peekBlockType() throws IOException { - read(1); - return buffer.get(); - } - public NcSessionStatusBlock readSessionStatusBlock() throws IOException { return readSessionStatusBlock(false); }
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockWriter.java Mon Nov 27 10:55:36 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockWriter.java Mon Nov 27 11:23:01 2017 +0100 @@ -353,6 +353,8 @@ dsData.write(dataBuffer.array(), 0, length); dataBuffer.limit(length); return dataBuffer; + } else if (data instanceof ByteBuffer) { + return (ByteBuffer) data; } else if (data instanceof ByteBuff) { ByteBuff bbData = (ByteBuff) data; return bbData.toNioByteBuffer(false); @@ -361,7 +363,7 @@ } } - public void writeSessionPayloadContent(Object data) throws IOException { + public void writeSessionPayloadData(Object data) throws IOException { checkOpened(); if (currentBlockType != NcSessionPayloadBlock.TYPE) {
--- a/stress-tester/src/test/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataReaderTest.java Mon Nov 27 10:55:36 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataReaderTest.java Mon Nov 27 11:23:01 2017 +0100 @@ -5,6 +5,8 @@ import com.passus.net.http.HttpMessage; import com.passus.net.http.HttpRequest; import com.passus.net.http.HttpRequestBuilder; +import com.passus.net.http.HttpResponse; +import com.passus.net.http.HttpResponseBuilder; import java.io.IOException; import org.testng.annotations.Test; import static com.passus.st.utils.HttpMessageAssert.*; @@ -21,7 +23,7 @@ } @Test - public void testDecodeMessage() throws Exception { + public void testDecode_Request() throws Exception { ByteBuff buffer = new HeapByteBuff(); HttpRequest req = HttpRequestBuilder.get("http://test.com/test") .header("X-Header", "X-Header-Value") @@ -33,4 +35,16 @@ assertMessages(req, msgDecoded); } + @Test + public void testDecode_Response() throws Exception { + ByteBuff buffer = new HeapByteBuff(); + HttpResponse resp = HttpResponseBuilder.ok() + .header("X-Header", "X-Header-Value") + .build(); + encodeMessage(resp, buffer); + + HttpSessionPayloadEventDataReader reader = new HttpSessionPayloadEventDataReader(); + HttpMessage msgDecoded = reader.decodeMessage(buffer); + assertMessages(resp, msgDecoded); + } }