NIFI-9447: Fix SNMP related tests to find available UDP ports instead of TCP

This closes #5576.

Signed-off-by: Tamas Palfy <tamas.bertalan.palfy@gmail.com>
This commit is contained in:
Lehel 2021-12-06 19:24:59 +01:00 committed by Tamas Palfy
parent 0f027743d1
commit 1eb4264e34
7 changed files with 21 additions and 21 deletions

View File

@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
public class SNMPConfigurationTest {
private static final int MANAGER_PORT = NetworkUtils.availablePort();
private static final int MANAGER_PORT = NetworkUtils.getAvailableUdpPort();
private static final String TARGET_PORT = "55556";
private static final int RETRIES = 3;
private static final int VERSION = SnmpConstants.version3;

View File

@ -39,8 +39,8 @@ public class V1V2cSNMPFactoryTest {
@Test
public void testFactoryCreatesV1V2Configuration() {
final V1V2cSNMPFactory snmpFactory = new V1V2cSNMPFactory();
final int managerPort = NetworkUtils.availablePort();
final String targetPort = String.valueOf(NetworkUtils.availablePort());
final int managerPort = NetworkUtils.getAvailableUdpPort();
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
final Target target = snmpFactory.createTargetInstance(snmpConfiguration);
@ -55,8 +55,8 @@ public class V1V2cSNMPFactoryTest {
@Test
public void testFactoryCreatesSnmpManager() {
final V1V2cSNMPFactory snmpFactory = new V1V2cSNMPFactory();
final int managerPort = NetworkUtils.availablePort();
final String targetPort = String.valueOf(NetworkUtils.availablePort());
final int managerPort = NetworkUtils.getAvailableUdpPort();
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
final Snmp snmpManager = snmpFactory.createSnmpManagerInstance(snmpConfiguration);
@ -68,8 +68,8 @@ public class V1V2cSNMPFactoryTest {
@Test
public void testFactoryCreatesResourceHandler() {
final V1V2cSNMPFactory snmpFactory = spy(V1V2cSNMPFactory.class);
final int managerPort = NetworkUtils.availablePort();
final String targetPort = String.valueOf(NetworkUtils.availablePort());
final int managerPort = NetworkUtils.getAvailableUdpPort();
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
snmpFactory.createSNMPResourceHandler(snmpConfiguration);

View File

@ -49,8 +49,8 @@ public class V3SNMPFactoryTest {
@Test
public void testFactoryCreatesTarget() {
final V3SNMPFactory snmpFactory = new V3SNMPFactory();
final int managerPort = NetworkUtils.availablePort();
final String targetPort = String.valueOf(NetworkUtils.availablePort());
final int managerPort = NetworkUtils.getAvailableUdpPort();
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
final Target target = snmpFactory.createTargetInstance(snmpConfiguration);
@ -65,8 +65,8 @@ public class V3SNMPFactoryTest {
@Test
public void testFactoryCreatesSnmpManager() {
final V3SNMPFactory snmpFactory = new V3SNMPFactory();
final int managerPort = NetworkUtils.availablePort();
final String targetPort = String.valueOf(NetworkUtils.availablePort());
final int managerPort = NetworkUtils.getAvailableUdpPort();
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
final Snmp snmpManager = snmpFactory.createSnmpManagerInstance(snmpConfiguration);
@ -80,8 +80,8 @@ public class V3SNMPFactoryTest {
@Test
public void testFactoryCreatesResourceHandler() {
final V3SNMPFactory snmpFactory = spy(V3SNMPFactory.class);
final int managerPort = NetworkUtils.availablePort();
final String targetPort = String.valueOf(NetworkUtils.availablePort());
final int managerPort = NetworkUtils.getAvailableUdpPort();
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
snmpFactory.createSNMPResourceHandler(snmpConfiguration);

View File

@ -58,7 +58,7 @@ public class SNMPTrapReceiverHandlerTest {
final ProcessSessionFactory mockProcessSessionFactory = mock(ProcessSessionFactory.class);
final MockComponentLog mockComponentLog = new MockComponentLog("componentId", new Object());
final Snmp mockSnmpManager = mock(Snmp.class);
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.availablePort());
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.getAvailableUdpPort());
when(snmpConfiguration.getVersion()).thenReturn(SnmpConstants.version1);
final SNMPTrapReceiverHandler trapReceiverHandler = new SNMPTrapReceiverHandler(snmpConfiguration, null);
@ -80,7 +80,7 @@ public class SNMPTrapReceiverHandlerTest {
final Snmp mockSnmpManager = mock(Snmp.class);
when(mockSnmpManager.getUSM()).thenReturn(mockUsm);
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.availablePort());
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.getAvailableUdpPort());
when(snmpConfiguration.getVersion()).thenReturn(SnmpConstants.version1);
final SNMPTrapReceiverHandler trapReceiverHandler = new SNMPTrapReceiverHandler(snmpConfiguration, null);
@ -118,7 +118,7 @@ public class SNMPTrapReceiverHandlerTest {
final Snmp mockSnmpManager = mock(Snmp.class);
final USM mockUsm = mock(USM.class);
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.availablePort());
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.getAvailableUdpPort());
when(snmpConfiguration.getVersion()).thenReturn(SnmpConstants.version3);
doAnswer(invocation -> {
UsmUser usmUser = (UsmUser) invocation.getArgument(0);

View File

@ -53,7 +53,7 @@ public class AbstractSNMPProcessorTest {
@Before
public void init() {
getTestRunner = new SNMPV1TestRunnerFactory().createSnmpGetTestRunner(NetworkUtils.availablePort(), TEST_OID, "GET");
getTestRunner = new SNMPV1TestRunnerFactory().createSnmpGetTestRunner(NetworkUtils.getAvailableUdpPort(), TEST_OID, "GET");
getSNMP = (GetSNMP) getTestRunner.getProcessor();
mockProcessContext = new MockProcessContext(getSNMP);
mockProcessSession = new MockProcessSession(new SharedSessionState(getSNMP, new AtomicLong(0L)), getSNMP);

View File

@ -36,7 +36,7 @@ public class GetSNMPTest {
@Test
public void testOnTriggerWithGetStrategyPerformsSnmpGet() {
final TestRunner getSnmpTestRunner = new SNMPV1TestRunnerFactory().createSnmpGetTestRunner(NetworkUtils.availablePort(), OID, "GET");
final TestRunner getSnmpTestRunner = new SNMPV1TestRunnerFactory().createSnmpGetTestRunner(NetworkUtils.getAvailableUdpPort(), OID, "GET");
final GetSNMP spyGetSNMP = spy((GetSNMP) getSnmpTestRunner.getProcessor());
final MockProcessSession mockProcessSession = new MockProcessSession(new SharedSessionState(spyGetSNMP, new AtomicLong(0L)), spyGetSNMP);
@ -49,7 +49,7 @@ public class GetSNMPTest {
@Test
public void testOnTriggerWithWalkStrategyPerformsSnmpWalk() {
final TestRunner getSnmpTestRunner = new SNMPV1TestRunnerFactory().createSnmpGetTestRunner(NetworkUtils.availablePort(), OID, "WALK");
final TestRunner getSnmpTestRunner = new SNMPV1TestRunnerFactory().createSnmpGetTestRunner(NetworkUtils.getAvailableUdpPort(), OID, "WALK");
final GetSNMP spyGetSNMP = spy((GetSNMP) getSnmpTestRunner.getProcessor());
final MockProcessSession mockProcessSession = new MockProcessSession(new SharedSessionState(spyGetSNMP, new AtomicLong(0L)), spyGetSNMP);

View File

@ -40,7 +40,7 @@ public class TrapSNMPIntegrationTest {
@Test
public void testSendReceiveV1Trap() throws InterruptedException {
final int listenPort = NetworkUtils.availablePort();
final int listenPort = NetworkUtils.getAvailableUdpPort();
final V1TrapConfiguration v1TrapConfiguration = TrapConfigurationFactory.getV1TrapConfiguration();
final SNMPTestRunnerFactory v1TestRunnerFactory = new SNMPV1TestRunnerFactory();
@ -72,7 +72,7 @@ public class TrapSNMPIntegrationTest {
@Test
public void testSendReceiveV2Trap() throws InterruptedException {
final int listenPort = NetworkUtils.availablePort();
final int listenPort = NetworkUtils.getAvailableUdpPort();
final V2TrapConfiguration v2TrapConfiguration = TrapConfigurationFactory.getV2TrapConfiguration();
final SNMPTestRunnerFactory v2cTestRunnerFactory = new SNMPV2cTestRunnerFactory();