Mercurial > stress-tester
changeset 799:4af45fd9b562
HttpSynchClientWorkerTest stub
author | Devel 1 |
---|---|
date | Wed, 03 Jan 2018 12:24:09 +0100 |
parents | 8a244bf83d7d |
children | 06bb0c4c4a5d |
files | stress-tester/src/test/java/com/passus/st/client/http/HttpAsynchClientWorkerTest.java stress-tester/src/test/java/com/passus/st/client/http/HttpClientTest.java stress-tester/src/test/java/com/passus/st/client/http/HttpSynchClientWorkerTest.java |
diffstat | 3 files changed, 164 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/test/java/com/passus/st/client/http/HttpAsynchClientWorkerTest.java Thu Dec 21 12:18:41 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/HttpAsynchClientWorkerTest.java Wed Jan 03 12:24:09 2018 +0100 @@ -70,9 +70,7 @@ statusEvent.setTimestamp(sessionEvent.getTimestamp()); worker.handle(statusEvent); - events.forEach((event) -> { - worker.handle(event); - }); + events.forEach(worker::handle); worker.join(); assertTrue(listner.size() > 0);
--- a/stress-tester/src/test/java/com/passus/st/client/http/HttpClientTest.java Thu Dec 21 12:18:41 2017 +0100 +++ b/stress-tester/src/test/java/com/passus/st/client/http/HttpClientTest.java Wed Jan 03 12:24:09 2018 +0100 @@ -65,9 +65,7 @@ SessionEvent sessionEvent = (SessionEvent) events.get(0); client.handle(new SessionStatusEvent(sessionEvent.getSessionInfo(), SessionStatusEvent.STATUS_ESTABLISHED)); - events.forEach((event) -> { - client.handle(event); - }); + events.forEach(client::handle); client.join(); assertTrue(listner.size() > 0); @@ -99,9 +97,7 @@ client.addListener(listner); client.start(); - events.forEach((event) -> { - client.handle(event); - }); + events.forEach(client::handle); client.join(); @@ -135,9 +131,7 @@ client.start(); for (int i = 0; i < 3; i++) { - events.forEach((event) -> { - client.handle(event); - }); + events.forEach(client::handle); } client.handle(dataEnd); client.join();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/test/java/com/passus/st/client/http/HttpSynchClientWorkerTest.java Wed Jan 03 12:24:09 2018 +0100 @@ -0,0 +1,160 @@ +package com.passus.st.client.http; + +import com.passus.config.Configuration; +import com.passus.st.Log4jConfigurationFactory; +import com.passus.st.client.Event; +import com.passus.st.client.SessionEvent; +import com.passus.st.client.SessionStatusEvent; +import com.passus.st.client.TestHttpClientListener; +import com.passus.st.emitter.ChannelContext; +import com.passus.st.emitter.Emitter; +import com.passus.st.emitter.EmitterHandler; +import com.passus.st.emitter.PassThroughSessionMapper; +import com.passus.st.emitter.SessionInfo; +import com.passus.st.emitter.SessionMapper; +import com.passus.st.emitter.nio.NioChannelContext; +import com.passus.st.metric.MetricsContainer; +import com.passus.st.utils.EventUtils; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import org.apache.logging.log4j.Level; +import static org.testng.AssertJUnit.*; +import org.testng.annotations.Test; + +/** + * + * @author mikolaj.podbielski + */ +public class HttpSynchClientWorkerTest { + + public HttpSynchClientWorkerTest() { + } + + @Test + public void testIsWorking() { + } + + @Test + public void testGetEventsQueueWaitTime() { + } + + @Test + public void testSetEventsQueueWaitTime() { + } + + @Test + public void testSessionInvalidated() throws Exception { + } + + @Test + public void testFlowStateChanged() { + } + + @Test + public void testHandle() { + } + + @Test + public void testCloseAllConnections() { + } + + @Test + public void testClose() { + } + + @Test + public void testRun() { + } + + private static class LocalEmitter implements Emitter { + + private SessionMapper sessionMapper = new PassThroughSessionMapper(); + private boolean started = false; + + @Override + public void setSessionMapper(SessionMapper sessionMapper) { + this.sessionMapper = sessionMapper; + } + + @Override + public SessionMapper getSessionMapper() { + return sessionMapper; + } + + @Override + public void connect(SessionInfo session, EmitterHandler handler, int workerIndex) throws IOException { + System.out.println("Emitter connect"); + System.out.println(session); + System.out.println(handler); + // doConnect -> channelRegistered + // selector + // doFinishConnect -> channelActive + ChannelContext context = new NioChannelContext(null, null, null, session); + try { + handler.channelRegistered(context); + handler.channelActive(context); + } catch (Exception ex) { + + } + } + + @Override + public boolean isStarted() { + return started; + } + + @Override + public void start() { + started = true; + } + + @Override + public void stop() { + started = false; + } + + @Override + public boolean isCollectMetrics() { + return false; + } + + @Override + public void setCollectMetrics(boolean collectMetrics) { + } + + @Override + public void writeMetrics(MetricsContainer container) { + } + + @Override + public void configure(Configuration config) { + } + } + + @Test + public void testHandle1() throws Exception { + Log4jConfigurationFactory.enableFactory(Level.DEBUG); + + Properties props = new Properties(); + props.put("allowPartialSession", "true"); + props.put("ports", "4214"); + List<Event> events = EventUtils.readEvents("pcap/http/http_req_resp.pcap", props); + assertEquals(4, events.size()); + + TestHttpClientListener listner = new TestHttpClientListener(); + LocalEmitter emitter = new LocalEmitter(); + HttpSynchClientWorker worker = new HttpSynchClientWorker(emitter, "test", 0); + worker.setListeners(Arrays.asList(listner)); + worker.setConnectPartialSession(true); + + worker.start(); + SessionEvent sessionEvent = (SessionEvent) events.get(0); + worker.handle(new SessionStatusEvent(sessionEvent.getSessionInfo(), SessionStatusEvent.STATUS_ESTABLISHED)); + events.forEach(worker::handle); + worker.join(); + + System.out.println(""); + } +}