Mercurial > stress-tester
changeset 789:595f1081548e
NcEventSource bugfix
author | Devel 2 |
---|---|
date | Wed, 20 Dec 2017 14:15:02 +0100 |
parents | c237fae692f1 |
children | bd1d28b5a096 |
files | stress-tester/src/main/java/com/passus/st/source/NcEventSource.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java |
diffstat | 3 files changed, 22 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java Wed Dec 20 13:24:56 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java Wed Dec 20 14:15:02 2017 +0100 @@ -3,10 +3,14 @@ import com.passus.commons.Assert; import com.passus.commons.annotations.Plugin; import com.passus.commons.service.ServiceException; +import com.passus.commons.utils.UniqueIdGenerator; import com.passus.data.Allocator; import com.passus.data.ByteBuff; import com.passus.data.ByteBuffDataSource; import com.passus.data.DefaultAllocator; +import com.passus.st.client.DataEvents; +import com.passus.st.client.DataEvents.DataEnd; +import com.passus.st.client.DataEvents.DataLoopEnd; import com.passus.st.client.EventHandler; import com.passus.st.client.SessionStatusEvent; import com.passus.st.client.http.HttpReqResp; @@ -43,7 +47,7 @@ private HttpSessionPayloadEventDataReader httpReader = new HttpSessionPayloadEventDataReader(); - private String name; + private String name = UniqueIdGenerator.generate(); private ReaderThread readerThread; @@ -56,14 +60,14 @@ public NcEventSource() { } + public NcEventSource(File file) { + this(file.getAbsolutePath()); + } + public NcEventSource(String ncFile) { this.ncFile = ncFile; } - public NcEventSource(File file) { - this.ncFile = file.getAbsolutePath(); - } - @Override public String getType() { return TYPE; @@ -188,8 +192,11 @@ read(); } + handler.handle(new DataLoopEnd(getName(), i)); reader.reset(); } + + handler.handle(new DataEnd(getName())); } catch (Exception e) { LOGGER.debug(e.getMessage(), e); } @@ -200,15 +207,17 @@ switch (blockType) { case NcSessionStatusBlock.TYPE: NcSessionStatusBlock statusBlock = (NcSessionStatusBlock) reader.read(); + statusBlock.sessionInfo().setSourceName(getName()); SessionStatusEvent event = new SessionStatusEvent(statusBlock.sessionInfo(), statusBlock.status()); handler.handle(event); break; case NcSessionPayloadBlock.TYPE: NcSessionPayloadBlock payloadBlock = (NcSessionPayloadBlock) reader.read(); SessionInfo sessionInfo = payloadBlock.sessionInfo(); + sessionInfo.setSourceName(getName()); ByteBuff payload = readPayload(payloadBlock.data()); HttpReqResp messages = httpReader.decodeMessages(payload); - handler.handle(new HttpSessionPayloadEvent(sessionInfo, messages, sessionInfo.getSourceName())); + handler.handle(new HttpSessionPayloadEvent(sessionInfo, messages, getName())); break; default: reader.read(); @@ -249,15 +258,19 @@ public void run() { working = true; try { + String sourceName = NcEventSource.this.getName(); for (int i = 0; i < loops; i++) { while (working && !reader.eof()) { read(); } + handler.handle(new DataLoopEnd(sourceName, i)); if (working) { reader.reset(); } } + + handler.handle(new DataEvents.DataEnd(sourceName)); } catch (Exception e) { LOGGER.debug(e.getMessage(), e); }
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Wed Dec 20 13:24:56 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Wed Dec 20 14:15:02 2017 +0100 @@ -155,10 +155,12 @@ } } + @Override public int getLoops() { return loops; } + @Override public void setLoops(int loops) { Assert.greaterOrEqualZero(loops, "loop"); this.loops = loops;
--- a/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java Wed Dec 20 13:24:56 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java Wed Dec 20 14:15:02 2017 +0100 @@ -1,10 +1,8 @@ package com.passus.st.source; import static com.passus.commons.utils.ResourceUtils.createTmpFile; -import com.passus.data.Allocator; import com.passus.data.PooledAllocator; import com.passus.st.client.ArrayListEventHandler; -import com.passus.st.client.DataEvents; import com.passus.st.client.Event; import com.passus.st.client.http.HttpSessionPayloadEvent; import com.passus.st.utils.EventUtils; @@ -14,8 +12,6 @@ import java.io.IOException; import java.util.List; import java.util.Properties; -import java.util.stream.Collectors; -import org.apache.commons.io.FileUtils; import static org.testng.AssertJUnit.*; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -38,11 +34,6 @@ events.forEach(eventDst::handle); eventDst.stop(); - events = events.stream().filter((event) -> { - return (event.getType() != DataEvents.DataEnd.TYPE - && event.getType() != DataEvents.DataLoopEnd.TYPE); - }).collect(Collectors.toList()); - return new FileEvents(tmpFile, events); } @@ -125,7 +116,7 @@ eventSource.start(); List<Event> events = handler.getEvents(); - assertEquals(fileEvents.events.size() * 2, events.size()); + assertEquals((fileEvents.events.size() * 2) - 1, events.size()); } finally { fileEvents.ncFile.delete(); }