mirror of https://github.com/apache/nifi.git
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:
parent
0f027743d1
commit
1eb4264e34
|
@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class SNMPConfigurationTest {
|
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 String TARGET_PORT = "55556";
|
||||||
private static final int RETRIES = 3;
|
private static final int RETRIES = 3;
|
||||||
private static final int VERSION = SnmpConstants.version3;
|
private static final int VERSION = SnmpConstants.version3;
|
||||||
|
|
|
@ -39,8 +39,8 @@ public class V1V2cSNMPFactoryTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFactoryCreatesV1V2Configuration() {
|
public void testFactoryCreatesV1V2Configuration() {
|
||||||
final V1V2cSNMPFactory snmpFactory = new V1V2cSNMPFactory();
|
final V1V2cSNMPFactory snmpFactory = new V1V2cSNMPFactory();
|
||||||
final int managerPort = NetworkUtils.availablePort();
|
final int managerPort = NetworkUtils.getAvailableUdpPort();
|
||||||
final String targetPort = String.valueOf(NetworkUtils.availablePort());
|
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
|
||||||
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
||||||
|
|
||||||
final Target target = snmpFactory.createTargetInstance(snmpConfiguration);
|
final Target target = snmpFactory.createTargetInstance(snmpConfiguration);
|
||||||
|
@ -55,8 +55,8 @@ public class V1V2cSNMPFactoryTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFactoryCreatesSnmpManager() {
|
public void testFactoryCreatesSnmpManager() {
|
||||||
final V1V2cSNMPFactory snmpFactory = new V1V2cSNMPFactory();
|
final V1V2cSNMPFactory snmpFactory = new V1V2cSNMPFactory();
|
||||||
final int managerPort = NetworkUtils.availablePort();
|
final int managerPort = NetworkUtils.getAvailableUdpPort();
|
||||||
final String targetPort = String.valueOf(NetworkUtils.availablePort());
|
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
|
||||||
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
||||||
|
|
||||||
final Snmp snmpManager = snmpFactory.createSnmpManagerInstance(snmpConfiguration);
|
final Snmp snmpManager = snmpFactory.createSnmpManagerInstance(snmpConfiguration);
|
||||||
|
@ -68,8 +68,8 @@ public class V1V2cSNMPFactoryTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFactoryCreatesResourceHandler() {
|
public void testFactoryCreatesResourceHandler() {
|
||||||
final V1V2cSNMPFactory snmpFactory = spy(V1V2cSNMPFactory.class);
|
final V1V2cSNMPFactory snmpFactory = spy(V1V2cSNMPFactory.class);
|
||||||
final int managerPort = NetworkUtils.availablePort();
|
final int managerPort = NetworkUtils.getAvailableUdpPort();
|
||||||
final String targetPort = String.valueOf(NetworkUtils.availablePort());
|
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
|
||||||
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
||||||
|
|
||||||
snmpFactory.createSNMPResourceHandler(snmpConfiguration);
|
snmpFactory.createSNMPResourceHandler(snmpConfiguration);
|
||||||
|
|
|
@ -49,8 +49,8 @@ public class V3SNMPFactoryTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFactoryCreatesTarget() {
|
public void testFactoryCreatesTarget() {
|
||||||
final V3SNMPFactory snmpFactory = new V3SNMPFactory();
|
final V3SNMPFactory snmpFactory = new V3SNMPFactory();
|
||||||
final int managerPort = NetworkUtils.availablePort();
|
final int managerPort = NetworkUtils.getAvailableUdpPort();
|
||||||
final String targetPort = String.valueOf(NetworkUtils.availablePort());
|
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
|
||||||
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
||||||
|
|
||||||
final Target target = snmpFactory.createTargetInstance(snmpConfiguration);
|
final Target target = snmpFactory.createTargetInstance(snmpConfiguration);
|
||||||
|
@ -65,8 +65,8 @@ public class V3SNMPFactoryTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFactoryCreatesSnmpManager() {
|
public void testFactoryCreatesSnmpManager() {
|
||||||
final V3SNMPFactory snmpFactory = new V3SNMPFactory();
|
final V3SNMPFactory snmpFactory = new V3SNMPFactory();
|
||||||
final int managerPort = NetworkUtils.availablePort();
|
final int managerPort = NetworkUtils.getAvailableUdpPort();
|
||||||
final String targetPort = String.valueOf(NetworkUtils.availablePort());
|
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
|
||||||
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
||||||
|
|
||||||
final Snmp snmpManager = snmpFactory.createSnmpManagerInstance(snmpConfiguration);
|
final Snmp snmpManager = snmpFactory.createSnmpManagerInstance(snmpConfiguration);
|
||||||
|
@ -80,8 +80,8 @@ public class V3SNMPFactoryTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFactoryCreatesResourceHandler() {
|
public void testFactoryCreatesResourceHandler() {
|
||||||
final V3SNMPFactory snmpFactory = spy(V3SNMPFactory.class);
|
final V3SNMPFactory snmpFactory = spy(V3SNMPFactory.class);
|
||||||
final int managerPort = NetworkUtils.availablePort();
|
final int managerPort = NetworkUtils.getAvailableUdpPort();
|
||||||
final String targetPort = String.valueOf(NetworkUtils.availablePort());
|
final String targetPort = String.valueOf(NetworkUtils.getAvailableUdpPort());
|
||||||
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
final SNMPConfiguration snmpConfiguration = getSnmpConfiguration(managerPort, targetPort);
|
||||||
snmpFactory.createSNMPResourceHandler(snmpConfiguration);
|
snmpFactory.createSNMPResourceHandler(snmpConfiguration);
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class SNMPTrapReceiverHandlerTest {
|
||||||
final ProcessSessionFactory mockProcessSessionFactory = mock(ProcessSessionFactory.class);
|
final ProcessSessionFactory mockProcessSessionFactory = mock(ProcessSessionFactory.class);
|
||||||
final MockComponentLog mockComponentLog = new MockComponentLog("componentId", new Object());
|
final MockComponentLog mockComponentLog = new MockComponentLog("componentId", new Object());
|
||||||
final Snmp mockSnmpManager = mock(Snmp.class);
|
final Snmp mockSnmpManager = mock(Snmp.class);
|
||||||
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.availablePort());
|
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.getAvailableUdpPort());
|
||||||
when(snmpConfiguration.getVersion()).thenReturn(SnmpConstants.version1);
|
when(snmpConfiguration.getVersion()).thenReturn(SnmpConstants.version1);
|
||||||
|
|
||||||
final SNMPTrapReceiverHandler trapReceiverHandler = new SNMPTrapReceiverHandler(snmpConfiguration, null);
|
final SNMPTrapReceiverHandler trapReceiverHandler = new SNMPTrapReceiverHandler(snmpConfiguration, null);
|
||||||
|
@ -80,7 +80,7 @@ public class SNMPTrapReceiverHandlerTest {
|
||||||
final Snmp mockSnmpManager = mock(Snmp.class);
|
final Snmp mockSnmpManager = mock(Snmp.class);
|
||||||
|
|
||||||
when(mockSnmpManager.getUSM()).thenReturn(mockUsm);
|
when(mockSnmpManager.getUSM()).thenReturn(mockUsm);
|
||||||
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.availablePort());
|
when(snmpConfiguration.getManagerPort()).thenReturn(NetworkUtils.getAvailableUdpPort());
|
||||||
when(snmpConfiguration.getVersion()).thenReturn(SnmpConstants.version1);
|
when(snmpConfiguration.getVersion()).thenReturn(SnmpConstants.version1);
|
||||||
|
|
||||||
final SNMPTrapReceiverHandler trapReceiverHandler = new SNMPTrapReceiverHandler(snmpConfiguration, null);
|
final SNMPTrapReceiverHandler trapReceiverHandler = new SNMPTrapReceiverHandler(snmpConfiguration, null);
|
||||||
|
@ -118,7 +118,7 @@ public class SNMPTrapReceiverHandlerTest {
|
||||||
final Snmp mockSnmpManager = mock(Snmp.class);
|
final Snmp mockSnmpManager = mock(Snmp.class);
|
||||||
final USM mockUsm = mock(USM.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);
|
when(snmpConfiguration.getVersion()).thenReturn(SnmpConstants.version3);
|
||||||
doAnswer(invocation -> {
|
doAnswer(invocation -> {
|
||||||
UsmUser usmUser = (UsmUser) invocation.getArgument(0);
|
UsmUser usmUser = (UsmUser) invocation.getArgument(0);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class AbstractSNMPProcessorTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
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();
|
getSNMP = (GetSNMP) getTestRunner.getProcessor();
|
||||||
mockProcessContext = new MockProcessContext(getSNMP);
|
mockProcessContext = new MockProcessContext(getSNMP);
|
||||||
mockProcessSession = new MockProcessSession(new SharedSessionState(getSNMP, new AtomicLong(0L)), getSNMP);
|
mockProcessSession = new MockProcessSession(new SharedSessionState(getSNMP, new AtomicLong(0L)), getSNMP);
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class GetSNMPTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnTriggerWithGetStrategyPerformsSnmpGet() {
|
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 GetSNMP spyGetSNMP = spy((GetSNMP) getSnmpTestRunner.getProcessor());
|
||||||
final MockProcessSession mockProcessSession = new MockProcessSession(new SharedSessionState(spyGetSNMP, new AtomicLong(0L)), spyGetSNMP);
|
final MockProcessSession mockProcessSession = new MockProcessSession(new SharedSessionState(spyGetSNMP, new AtomicLong(0L)), spyGetSNMP);
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class GetSNMPTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnTriggerWithWalkStrategyPerformsSnmpWalk() {
|
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 GetSNMP spyGetSNMP = spy((GetSNMP) getSnmpTestRunner.getProcessor());
|
||||||
final MockProcessSession mockProcessSession = new MockProcessSession(new SharedSessionState(spyGetSNMP, new AtomicLong(0L)), spyGetSNMP);
|
final MockProcessSession mockProcessSession = new MockProcessSession(new SharedSessionState(spyGetSNMP, new AtomicLong(0L)), spyGetSNMP);
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class TrapSNMPIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendReceiveV1Trap() throws InterruptedException {
|
public void testSendReceiveV1Trap() throws InterruptedException {
|
||||||
final int listenPort = NetworkUtils.availablePort();
|
final int listenPort = NetworkUtils.getAvailableUdpPort();
|
||||||
|
|
||||||
final V1TrapConfiguration v1TrapConfiguration = TrapConfigurationFactory.getV1TrapConfiguration();
|
final V1TrapConfiguration v1TrapConfiguration = TrapConfigurationFactory.getV1TrapConfiguration();
|
||||||
final SNMPTestRunnerFactory v1TestRunnerFactory = new SNMPV1TestRunnerFactory();
|
final SNMPTestRunnerFactory v1TestRunnerFactory = new SNMPV1TestRunnerFactory();
|
||||||
|
@ -72,7 +72,7 @@ public class TrapSNMPIntegrationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSendReceiveV2Trap() throws InterruptedException {
|
public void testSendReceiveV2Trap() throws InterruptedException {
|
||||||
final int listenPort = NetworkUtils.availablePort();
|
final int listenPort = NetworkUtils.getAvailableUdpPort();
|
||||||
|
|
||||||
final V2TrapConfiguration v2TrapConfiguration = TrapConfigurationFactory.getV2TrapConfiguration();
|
final V2TrapConfiguration v2TrapConfiguration = TrapConfigurationFactory.getV2TrapConfiguration();
|
||||||
final SNMPTestRunnerFactory v2cTestRunnerFactory = new SNMPV2cTestRunnerFactory();
|
final SNMPTestRunnerFactory v2cTestRunnerFactory = new SNMPV2cTestRunnerFactory();
|
||||||
|
|
Loading…
Reference in New Issue