changeset 999:e176852a95f6

PortPoolImplTest
author Devel 2
date Mon, 30 Sep 2019 14:17:07 +0200
parents 3f116e71c1cd
children b104ead5034e
files stress-tester/src/test/java/com/passus/st/emitter/PortPoolImplTest.java
diffstat 1 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/test/java/com/passus/st/emitter/PortPoolImplTest.java	Mon Sep 30 14:17:07 2019 +0200
@@ -0,0 +1,42 @@
+package com.passus.st.emitter;
+
+import org.testng.annotations.Test;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+public class PortPoolImplTest {
+
+    @Test
+    public void testBorrow() {
+        PortPoolImpl pool = new PortPoolImpl(1, 3);
+        assertEquals(1, pool.borrow());
+        assertEquals(2, pool.borrow());
+        assertEquals(3, pool.borrow());
+        assertEquals(-1, pool.borrow());
+        assertEquals(0, pool.getFree());
+
+        pool.release(2);
+        assertEquals(2, pool.borrow());
+        assertEquals(0, pool.getFree());
+    }
+
+    @Test
+    public void testBorrowAndRelease() {
+        int min = 1;
+        int max = 10;
+        PortPoolImpl pool = new PortPoolImpl(min, max);
+        for (int i = min; i <= max; i++) {
+            int port = pool.borrow();
+            pool.release(port);
+            assertEquals(max - min + 1, pool.getFree());
+        }
+    }
+
+    @Test
+    public void testReleaseNotBorrowed() {
+        PortPoolImpl pool = new PortPoolImpl(1, 3);
+        assertEquals(3, pool.getFree());
+        pool.release(3);
+        assertEquals(3, pool.getFree());
+    }
+}
\ No newline at end of file