Mercurial > stress-tester
changeset 474:db7bd7630fcf
ST-53
author | Devel 1 |
---|---|
date | Fri, 04 Aug 2017 14:40:09 +0200 |
parents | 629e5b412864 |
children | 803b20d6f0cb |
files | stress-tester/src/test/java/com/passus/st/emitter/RuleBasedSessionMapperTest.java stress-tester/src/test/java/com/passus/st/emitter/SocketAddressProviderBaseTest.java |
diffstat | 2 files changed, 40 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/test/java/com/passus/st/emitter/RuleBasedSessionMapperTest.java Fri Aug 04 13:37:22 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/emitter/RuleBasedSessionMapperTest.java Fri Aug 04 14:40:09 2017 +0200 @@ -2,6 +2,9 @@ import com.passus.net.SocketAddress; import com.passus.st.emitter.SessionMapper.ConnectionParams; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; import static org.testng.AssertJUnit.*; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -44,13 +47,45 @@ assertMatchRule("*:* -> 2.2.2.2:90", new SocketAddress("2.2.2.2:90"), SessionMapper.ANY_SOCKET); assertMatchRule("1.1.1.1:80 -> 2.2.2.2:90", new SocketAddress("2.2.2.2:90"), SessionMapper.ANY_SOCKET); assertMatchRule(" 1.1.1.1:80->2.2.2.2:90 ", new SocketAddress("2.2.2.2:90"), SessionMapper.ANY_SOCKET); - assertMatchRule(" 1.1.1.1:80->2.2.2.2:90 bind 172.16.40.10", new SocketAddress("2.2.2.2:90"), new SocketAddress("172.16.40.10", 0)); - assertMatchRule(" 1.1.1.1:80->2.2.2.2:90 bind 172.16.40.10:*", new SocketAddress("2.2.2.2:90"), new SocketAddress("172.16.40.10", 1)); - assertMatchRule(" 1.1.1.1:80->2.2.2.2:90 bind 172.16.40.10:2001-6000", new SocketAddress("2.2.2.2:90"), new SocketAddress("172.16.40.10", 2001)); + + assertMatchRule("1.1.1.1:80->2.2.2.2:90 bind 172.16.40.10", new SocketAddress("2.2.2.2:90"), new SocketAddress("172.16.40.10", 0)); + assertMatchRule("1.1.1.1:80->2.2.2.2:90 bind 172.16.40.10:*", new SocketAddress("2.2.2.2:90"), new SocketAddress("172.16.40.10", 1)); + assertMatchRule("1.1.1.1:80->2.2.2.2:90 bind 172.16.40.10:2001-6000", new SocketAddress("2.2.2.2:90"), new SocketAddress("172.16.40.10", 2001)); + assertMatchRule("1.1.1.1:80->2.2.2.2:90 bind 172.16.40.10/31:2001-6000", new SocketAddress("2.2.2.2:90"), new SocketAddress("172.16.40.10", 2001)); + assertMatchRule("1.1.1.1:80->2.2.2.2:90 bind 172.16.40.10,172.16.40.20:2001-6000", new SocketAddress("2.2.2.2:90"), new SocketAddress("172.16.40.10", 2001)); + assertMatchRule("1.1.1.1:80->2.2.2.2:90 bind 172.16.40.10-172.16.40.20:2001-6000", new SocketAddress("2.2.2.2:90"), new SocketAddress("172.16.40.10", 2001)); assertNotMatchRule("1.1.1.1:* -> 2.2.2.2:90"); assertNotMatchRule("*:80 -> 2.2.2.2:90"); assertNotMatchRule("1.1.1.1:80 -> 2.2.2.2:90"); } + @Test + public void testBind() throws Exception { + List<SocketAddress> expected1 = Arrays.asList(sa("172.16.40.8", 0), sa("172.16.40.9", 0), sa("172.16.40.8", 0)); + testBind("*:* -> 2.2.2.2:90 bind 172.16.40.8/31", expected1); + testBind("*:* -> 2.2.2.2:90 bind 172.16.40.8,172.16.40.9", expected1); + testBind("*:* -> 2.2.2.2:90 bind 172.16.40.8-172.16.40.9", expected1); + + List<SocketAddress> expected2 = Arrays.asList(sa("172.16.40.8", 1001), sa("172.16.40.9", 1001), sa("172.16.40.8", 1002)); + testBind("*:* -> 2.2.2.2:90 bind 172.16.40.8/31:1001-2000", expected2); + testBind("*:* -> 2.2.2.2:90 bind 172.16.40.8,172.16.40.9:1001-2000", expected2); + testBind("*:* -> 2.2.2.2:90 bind 172.16.40.8-172.16.40.9:1001-2000", expected2); + } + + public void testBind(String rule, List<SocketAddress> expected) throws Exception { + RuleBasedSessionMapper mapper = new RuleBasedSessionMapper(); + mapper.addRule(rule); + List<Integer> localPorts = Arrays.asList(101, 102, 103); + List<SocketAddress> bindAddresses = localPorts.stream().map((lp) -> mapper.map(si(lp)).getBindAddress()).collect(Collectors.toList()); + assertEquals(expected, bindAddresses); + } + + private static SocketAddress sa(String ip, int port) { + return new SocketAddress(ip, port); + } + + private static SessionInfo si(int port) { + return new SessionInfo(sa("3.3.3.3", port), sa("1.1.1.1", 80)); + } }
--- a/stress-tester/src/test/java/com/passus/st/emitter/SocketAddressProviderBaseTest.java Fri Aug 04 13:37:22 2017 +0200 +++ b/stress-tester/src/test/java/com/passus/st/emitter/SocketAddressProviderBaseTest.java Fri Aug 04 14:40:09 2017 +0200 @@ -30,7 +30,7 @@ } @Test - public void testAddresses() { + public void testParseAddresses() { assertEquals(parseAddresses("10.10.10.10"), a("10.10.10.10")); assertEquals(parseAddresses("10.10.10.10, 10.10.10.15"), a("10.10.10.10", "10.10.10.15")); @@ -41,7 +41,7 @@ } @Test - public void testAddressesInvalid() { + public void testParseAddressesInvalid() { shouldThrowIllegalArgumentException(() -> parseAddresses("10.10.10.10/16")); shouldThrowIllegalArgumentException(() -> parseAddresses("10.10.10.10-10.10.10.9")); shouldThrowIllegalArgumentException(() -> parseAddresses("10.10.10.0-10.10.9.100"));