Mercurial > stress-tester
changeset 757:46e165392894
NcDataBlockReader bugfix
author | Devel 2 |
---|---|
date | Fri, 15 Dec 2017 10:04:12 +0100 |
parents | 2042253e3dab |
children | d87032f02b94 |
files | stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataReader.java stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataWriter.java stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java stress-tester/src/test/resources/pcap/http/http_get_png.pcap |
diffstat | 5 files changed, 25 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataReader.java Thu Dec 14 11:24:10 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataReader.java Fri Dec 15 10:04:12 2017 +0100 @@ -96,7 +96,6 @@ public HttpHeaders decodeHeaders(ByteBuff buffer) throws IOException { long headerSize = ncDataHelper.readLongVLC(buffer); - HttpHeaders headers; if (HttpHeadersDecoder.isDefaultEnableCachedHeaders()) { headers = new HttpHeadersImpl();
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataWriter.java Thu Dec 14 11:24:10 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/HttpSessionPayloadEventDataWriter.java Fri Dec 15 10:04:12 2017 +0100 @@ -166,18 +166,17 @@ ByteBuff reqBuffer = new HeapByteBuff(); ByteBuff respBuffer = new HeapByteBuff(); byte flags = 0; - long size = 1; HttpRequest req = messages.getRequest(); DataSource reqContent = null; if (req != null) { flags |= FLAG_REQUEST; - size += encodeRequest(req, reqBuffer); + encodeRequest(req, reqBuffer); reqContent = req.getContent(); if (reqContent != null) { - size += reqContent.available(); - size += ncDataHelper.writeLongVLC(reqBuffer, reqContent.available()); + reqContent.available(); + ncDataHelper.writeLongVLC(reqBuffer, reqContent.available()); } else { - size += ncDataHelper.writeLongVLC(reqBuffer, 0); + ncDataHelper.writeLongVLC(reqBuffer, 0); } } @@ -188,13 +187,13 @@ || mode == HttpWriteMode.REQUEST_FULL_RESPONSE_HEADERS); if (encodeResponse && resp != null) { flags |= FLAG_RESPONSE; - size += encodeResponse(resp, respBuffer); + encodeResponse(resp, respBuffer); respContent = resp.getContent(); if (respContent != null) { - size += respContent.available(); - size += ncDataHelper.writeLongVLC(respBuffer, respContent.available()); + respContent.available(); + ncDataHelper.writeLongVLC(respBuffer, respContent.available()); } else { - size += ncDataHelper.writeLongVLC(respBuffer, 0); + ncDataHelper.writeLongVLC(respBuffer, 0); } } @@ -210,8 +209,6 @@ writer.writeSessionPayloadData(respContent); } writer.closeSessionPayloadBlock(); - - size++; } public void write(HttpSessionPayloadEvent event, NcDataBlockWriter writer) throws IOException {
--- a/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java Thu Dec 14 11:24:10 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/reader/nc/NcDataBlockReader.java Fri Dec 15 10:04:12 2017 +0100 @@ -76,6 +76,15 @@ return header; } + public int getBufferSize() { + return bufferSize; + } + + public void setBufferSize(int bufferSize) { + Assert.greaterThanZero(bufferSize, "bufferSize"); + this.bufferSize = bufferSize; + } + @Override public void open() throws IOException { if (!Files.exists(path)) { @@ -136,7 +145,7 @@ } if (buffer.readableBytes() >= requiredBytes) { - return -1; + return 0; } if (buffer.isEmpty() && buffer.readedBytes() > 0) { @@ -152,8 +161,8 @@ } nioBuffer.flip(); - readed += nioBuffer.remaining(); - buffer.append(nioBuffer); + readed += res; + buffer.append(nioBuffer, res); nioBuffer.clear(); } @@ -202,7 +211,6 @@ buffer.skipBytes(8); //reserved bytes header = new NcHeader(verMajor, verMinor); - nioBuffer.position(NcHeader.PREAMBULE.length - 1); } private void checkBlockType(byte type, byte requiredType) throws IOException { @@ -301,7 +309,7 @@ int readed = buffer.read(data, length); while (readed < length) { int res = read(bufferSize); - if (res == -1) { + if (res == -1 && buffer.isEmpty()) { throw new IOException("Unable to read full content. EOF reached."); } @@ -313,7 +321,6 @@ private NcSessionPayloadBlock readSessionPayloadBlock(boolean skipBlockType, boolean skipData, boolean skipOptions) throws IOException { NcSessionPayloadBlock payloadBlock = readSessionPayloadBlockHeader(skipBlockType); - if (!skipData) { if (payloadBlock.dataSize() <= Integer.MAX_VALUE) { int dataSize = (int) payloadBlock.dataSize();
--- a/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java Thu Dec 14 11:24:10 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java Fri Dec 15 10:04:12 2017 +0100 @@ -1,6 +1,7 @@ package com.passus.st.source; import static com.passus.commons.utils.ResourceUtils.createTmpFile; +import com.passus.st.Log4jConfigurationFactory; import com.passus.st.client.ArrayListEventHandler; import com.passus.st.client.DataEvents; import com.passus.st.client.Event; @@ -49,12 +50,14 @@ return new Object[][]{ {"pcap/http/http_req_resp.pcap"}, {"pcap/http/http_ndiag_tcp_conn.pcap"}, - {"pcap/http/basic_digest.pcap"} + {"pcap/http/basic_digest.pcap"}, + {"pcap/http/http_get_png.pcap"} }; } @Test(dataProvider = "pcapFiles") public void testRead(String pcapFile) throws Exception { + Log4jConfigurationFactory.enableFactory("debug"); FileEvents fileEvents = writeEvents(pcapFile); try { ArrayListEventHandler handler = new ArrayListEventHandler(); @@ -80,7 +83,6 @@ assertMessagesContent(expectedPayloadEvent.getResponse(), payloadEvent.getResponse()); } } - } finally { FileUtils.copyFile(fileEvents.ncFile, new File("c:\\tmp\\a")); fileEvents.ncFile.delete();