Mercurial > stress-tester
changeset 767:68147f3215dd
NcEventSource.allocator
author | Devel 2 |
---|---|
date | Mon, 18 Dec 2017 09:13:40 +0100 |
parents | 3931dbbb20f4 |
children | 6300f55ac52b |
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, 53 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java Mon Dec 18 08:55:14 2017 +0100 +++ b/stress-tester/src/main/java/com/passus/st/source/NcEventSource.java Mon Dec 18 09:13:40 2017 +0100 @@ -3,8 +3,10 @@ import com.passus.commons.Assert; import com.passus.commons.annotations.Plugin; import com.passus.commons.service.ServiceException; +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.EventHandler; import com.passus.st.client.SessionStatusEvent; import com.passus.st.client.http.HttpReqResp; @@ -17,7 +19,6 @@ import com.passus.st.reader.nc.NcSessionStatusBlock; import java.io.File; import java.io.IOException; -import java.util.Objects; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -48,6 +49,8 @@ private boolean parallel = true; + private Allocator allocator = new DefaultAllocator(); + public NcEventSource() { } @@ -74,6 +77,15 @@ this.name = name; } + public Allocator getAllocator() { + return allocator; + } + + public void setAllocator(Allocator allocator) { + Assert.notNull(allocator, "allocator"); + this.allocator = allocator; + } + @Override public int getLoops() { throw new UnsupportedOperationException("Not supported yet."); @@ -116,6 +128,7 @@ try { reader = new NcDataBlockReader(ncFile); + reader.setAllocator(allocator); reader.open(); if (parallel) {
--- a/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java Mon Dec 18 08:55:14 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/source/NcEventSourceTest.java Mon Dec 18 09:13:40 2017 +0100 @@ -1,6 +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; @@ -55,6 +57,25 @@ }; } + private void assertEvents(FileEvents expectedEvents, List<Event> events) { + assertEquals(expectedEvents.events.size(), events.size()); + for (int i = 0; i < events.size(); i++) { + Event expectedEvent = expectedEvents.events.get(i); + Event event = events.get(i); + + assertEquals(expectedEvent.getType(), event.getType()); + if (event.getType() == HttpSessionPayloadEvent.TYPE) { + HttpSessionPayloadEvent expectedPayloadEvent = (HttpSessionPayloadEvent) expectedEvent; + HttpSessionPayloadEvent payloadEvent = (HttpSessionPayloadEvent) event; + + assertMessages(expectedPayloadEvent.getRequest(), payloadEvent.getRequest()); + assertMessagesContent(expectedPayloadEvent.getRequest(), payloadEvent.getRequest()); + assertMessages(expectedPayloadEvent.getResponse(), payloadEvent.getResponse()); + assertMessagesContent(expectedPayloadEvent.getResponse(), payloadEvent.getResponse()); + } + } + } + @Test(dataProvider = "pcapFiles") public void testRead(String pcapFile) throws Exception { FileEvents fileEvents = writeEvents(pcapFile); @@ -66,24 +87,27 @@ eventSource.start(); List<Event> events = handler.getEvents(); - assertEquals(fileEvents.events.size(), events.size()); - for (int i = 0; i < events.size(); i++) { - Event expectedEvent = fileEvents.events.get(i); - Event event = events.get(i); + assertEvents(fileEvents, events); + } finally { + fileEvents.ncFile.delete(); + } + } - assertEquals(expectedEvent.getType(), event.getType()); - if (event.getType() == HttpSessionPayloadEvent.TYPE) { - HttpSessionPayloadEvent expectedPayloadEvent = (HttpSessionPayloadEvent) expectedEvent; - HttpSessionPayloadEvent payloadEvent = (HttpSessionPayloadEvent) event; + public void testRead_PooledAllocator() throws Exception { + FileEvents fileEvents = writeEvents("pcap/http/http_req_resp.pcap"); + try { + PooledAllocator allocator = new PooledAllocator(); + ArrayListEventHandler handler = new ArrayListEventHandler(); + NcEventSource eventSource = new NcEventSource(fileEvents.ncFile); + eventSource.setAllocator(allocator); + eventSource.setHandler(handler); + eventSource.setParallel(false); + eventSource.start(); - assertMessages(expectedPayloadEvent.getRequest(), payloadEvent.getRequest()); - assertMessagesContent(expectedPayloadEvent.getRequest(), payloadEvent.getRequest()); - assertMessages(expectedPayloadEvent.getResponse(), payloadEvent.getResponse()); - assertMessagesContent(expectedPayloadEvent.getResponse(), payloadEvent.getResponse()); - } - } + List<Event> events = handler.getEvents(); + assertEvents(fileEvents, events); + assertEquals(2, allocator.usedSize()); } finally { - FileUtils.copyFile(fileEvents.ncFile, new File("c:\\tmp\\a")); fileEvents.ncFile.delete(); } }