changeset 1199:5d7f5a716a8c

unit tests - minor
author Devel 1
date Mon, 22 Jun 2020 12:45:07 +0200
parents 6370efaa0ef5
children e29869666961
files stress-tester/src/test/java/com/passus/st/client/netflow/FlowExecutorNetflowTest.java stress-tester/src/test/java/com/passus/st/utils/server/SimpleDatagramServer.java
diffstat 2 files changed, 24 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/test/java/com/passus/st/client/netflow/FlowExecutorNetflowTest.java	Mon Jun 22 12:39:24 2020 +0200
+++ b/stress-tester/src/test/java/com/passus/st/client/netflow/FlowExecutorNetflowTest.java	Mon Jun 22 12:45:07 2020 +0200
@@ -40,29 +40,32 @@
         server.setListener(listener);
         server.start();
 
-        Map<String, Object> props = new HashMap<>();
-        props.put("protocols", ArrayUtils.asSet(Protocols.NETFLOW));
-        List<Event> events = EventUtils.readEvents("pcap/netflow/netflow_v9_template_data.pcap", props);
-
-        NioEmitter emitter = prepareEmitter("*:* -> localhost:2000");
-        emitter.start();
-
-        FlowExecutor flowExecutor = new FlowExecutor();
-        flowExecutor.setEmitter(emitter);
-        flowExecutor.setConnectPartialSession(true);
         try {
-            flowExecutor.start();
-            events.forEach(flowExecutor::handle);
-            flowExecutor.join(5_000);
+            Map<String, Object> props = new HashMap<>();
+            props.put("protocols", ArrayUtils.asSet(Protocols.NETFLOW));
+            List<Event> events = EventUtils.readEvents("pcap/netflow/netflow_v9_template_data.pcap", props);
 
-            assertEquals(0, listener.getErrors());
-            assertEquals(2, listener.getReceived().size());
-            Iterator<Netflow9> it = listener.getReceived().iterator();
-            assertEquals(92463920L, it.next().getFlowSequence());
-            assertEquals(92463921L, it.next().getFlowSequence());
+            NioEmitter emitter = prepareEmitter("*:* -> localhost:2000");
+            emitter.start();
+
+            FlowExecutor flowExecutor = new FlowExecutor();
+            flowExecutor.setEmitter(emitter);
+            flowExecutor.setConnectPartialSession(true);
+            try {
+                flowExecutor.start();
+                events.forEach(flowExecutor::handle);
+                flowExecutor.join(5_000);
+
+                assertEquals(0, listener.getErrors());
+                assertEquals(2, listener.getReceived().size());
+                Iterator<Netflow9> it = listener.getReceived().iterator();
+                assertEquals(92463920L, it.next().getFlowSequence());
+                assertEquals(92463921L, it.next().getFlowSequence());
+            } finally {
+                ServiceUtils.stopQuietly(flowExecutor);
+                ServiceUtils.stopQuietly(emitter);
+            }
         } finally {
-            ServiceUtils.stopQuietly(flowExecutor);
-            ServiceUtils.stopQuietly(emitter);
             ServiceUtils.stopQuietly(server);
         }
 
--- a/stress-tester/src/test/java/com/passus/st/utils/server/SimpleDatagramServer.java	Mon Jun 22 12:39:24 2020 +0200
+++ b/stress-tester/src/test/java/com/passus/st/utils/server/SimpleDatagramServer.java	Mon Jun 22 12:45:07 2020 +0200
@@ -27,6 +27,7 @@
             return;
         }
 
+        System.out.println("Thread: " + Thread.currentThread().getName());
         try {
             serverSocket = new DatagramSocket(port, InetAddress.getByName(host));
             logger.debug("Datagram socket created.");