Mercurial > stress-tester
changeset 787:e400b2e6d698
NcEventSource.loops support
author | Devel 2 |
---|---|
date | Wed, 20 Dec 2017 12:53:30 +0100 |
parents | 527625f63b80 |
children | c237fae692f1 |
files | stress-tester/src/main/java/com/passus/st/source/NcEventSource.java stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java |
diffstat | 2 files changed, 46 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java Wed Dec 20 12:53:13 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java Wed Dec 20 12:53:30 2017 +0100 @@ -51,6 +51,8 @@ private Allocator allocator = new DefaultAllocator(); + private int loops = 1; + public NcEventSource() { } @@ -88,12 +90,13 @@ @Override public int getLoops() { - throw new UnsupportedOperationException("Not supported yet."); + return loops; } @Override public void setLoops(int loops) { - throw new UnsupportedOperationException("Not supported yet."); + Assert.greaterOrEqualZero(loops, "loops"); + this.loops = loops; } public boolean isParallel() { @@ -132,9 +135,9 @@ reader.open(); httpReader.setAllocator(allocator); - + if (parallel) { - readerThread = new ReaderThread(); + readerThread = new ReaderThread(loops); readerThread.start(); } @@ -180,8 +183,12 @@ private void readAll() { try { - while (!reader.eof()) { - read(); + for (int i = 0; i < loops; i++) { + while (!reader.eof()) { + read(); + } + + reader.reset(); } } catch (Exception e) { LOGGER.debug(e.getMessage(), e); @@ -232,12 +239,24 @@ private boolean working = false; + private final int loops; + + public ReaderThread(int loops) { + this.loops = loops; + } + @Override public void run() { working = true; try { - while (working && !reader.eof()) { - read(); + for (int i = 0; i < loops; i++) { + while (working && !reader.eof()) { + read(); + } + + if (working) { + reader.reset(); + } } } catch (Exception e) { LOGGER.debug(e.getMessage(), e);
--- a/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java Wed Dec 20 12:53:13 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java Wed Dec 20 12:53:30 2017 +0100 @@ -93,6 +93,7 @@ } } + @Test public void testRead_PooledAllocator() throws Exception { FileEvents fileEvents = writeEvents("pcap/http/http_req_resp.pcap"); try { @@ -112,6 +113,24 @@ } } + @Test + public void testRead_2loops() throws Exception { + FileEvents fileEvents = writeEvents("pcap/http/http_req_resp.pcap"); + try { + ArrayListEventHandler handler = new ArrayListEventHandler(); + NcEventSource eventSource = new NcEventSource(fileEvents.ncFile); + eventSource.setLoops(2); + eventSource.setHandler(handler); + eventSource.setParallel(false); + eventSource.start(); + + List<Event> events = handler.getEvents(); + assertEquals(fileEvents.events.size() * 2, events.size()); + } finally { + fileEvents.ncFile.delete(); + } + } + private class FileEvents { public final File ncFile;