You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2022/06/06 20:23:25 UTC
[nifi] branch main updated: NIFI-10093 Set timeout to 5 seconds on SocketProtocolListenerTest (#6101)
This is an automated email from the ASF dual-hosted git repository.
markap14 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new e618e85da7 NIFI-10093 Set timeout to 5 seconds on SocketProtocolListenerTest (#6101)
e618e85da7 is described below
commit e618e85da72af7e5e6c8e7cd2f7a2e0fff3fbe4a
Author: exceptionfactory <ex...@apache.org>
AuthorDate: Mon Jun 6 15:23:17 2022 -0500
NIFI-10093 Set timeout to 5 seconds on SocketProtocolListenerTest (#6101)
---
.../cluster/protocol/jaxb/JaxbProtocolContext.java | 2 +-
.../protocol/impl/SocketProtocolListenerTest.java | 58 +++++++---------------
2 files changed, 19 insertions(+), 41 deletions(-)
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/jaxb/JaxbProtocolContext.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/jaxb/JaxbProtocolContext.java
index 2baade5f6c..918c36d861 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/jaxb/JaxbProtocolContext.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/main/java/org/apache/nifi/cluster/protocol/jaxb/JaxbProtocolContext.java
@@ -46,7 +46,7 @@ import java.nio.ByteBuffer;
* @param <T> The type of protocol message.
*
*/
-public class JaxbProtocolContext<T> implements ProtocolContext {
+public class JaxbProtocolContext<T> implements ProtocolContext<T> {
private static final int BUF_SIZE = (int) Math.pow(2, 10); // 1k
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/impl/SocketProtocolListenerTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/impl/SocketProtocolListenerTest.java
index 128399c657..74e4a4780d 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/impl/SocketProtocolListenerTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/impl/SocketProtocolListenerTest.java
@@ -19,7 +19,7 @@ package org.apache.nifi.cluster.protocol.impl;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
-import java.net.SocketTimeoutException;
+
import org.apache.nifi.cluster.protocol.ProtocolContext;
import org.apache.nifi.cluster.protocol.ProtocolMessageMarshaller;
import org.apache.nifi.cluster.protocol.ProtocolMessageUnmarshaller;
@@ -32,17 +32,18 @@ import org.apache.nifi.cluster.protocol.impl.testutils.ReflexiveProtocolHandler;
import org.apache.nifi.io.socket.ServerSocketConfiguration;
import org.apache.nifi.io.socket.SocketConfiguration;
import org.apache.nifi.io.socket.SocketUtils;
-import org.junit.After;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-/**
- */
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class SocketProtocolListenerTest {
+ private static final int SOCKET_TIMEOUT_MILLISECONDS = 5000;
+
+ private static final int LISTENER_THREADS = 1;
+
private SocketProtocolListener listener;
private Socket socket;
@@ -51,28 +52,27 @@ public class SocketProtocolListenerTest {
private ProtocolMessageUnmarshaller<ProtocolMessage> unmarshaller;
- @Before
+ @BeforeEach
public void setup() throws Exception {
-
- final ProtocolContext protocolContext = new JaxbProtocolContext(JaxbProtocolUtils.JAXB_CONTEXT);
+ final ProtocolContext<ProtocolMessage> protocolContext = new JaxbProtocolContext<>(JaxbProtocolUtils.JAXB_CONTEXT);
marshaller = protocolContext.createMarshaller();
unmarshaller = protocolContext.createUnmarshaller();
ServerSocketConfiguration configuration = new ServerSocketConfiguration();
- configuration.setSocketTimeout(1000);
+ configuration.setSocketTimeout(SOCKET_TIMEOUT_MILLISECONDS);
- listener = new SocketProtocolListener(5, 0, configuration, protocolContext);
+ listener = new SocketProtocolListener(LISTENER_THREADS, 0, configuration, protocolContext);
listener.start();
int port = listener.getPort();
SocketConfiguration config = new SocketConfiguration();
config.setReuseAddress(true);
- config.setSocketTimeout(1000);
+ config.setSocketTimeout(SOCKET_TIMEOUT_MILLISECONDS);
socket = SocketUtils.createSocket(new InetSocketAddress("localhost", port), config);
}
- @After
+ @AfterEach
public void teardown() throws IOException {
try {
if (listener.isRunning()) {
@@ -93,7 +93,7 @@ public class SocketProtocolListenerTest {
}
@Test
- public void testRequest() throws Exception {
+ public void testPing() throws Exception {
ProtocolMessage msg = new PingMessage();
ReflexiveProtocolHandler handler = new ReflexiveProtocolHandler();
@@ -109,26 +109,4 @@ public class SocketProtocolListenerTest {
assertEquals(1, handler.getMessages().size());
assertEquals(msg.getType(), handler.getMessages().get(0).getType());
}
-
- @Ignore("this test is unreliable on slow build environments")
- @Test
- public void testDelayedRequest() throws Exception {
- ProtocolMessage msg = new PingMessage();
-
- DelayedProtocolHandler handler = new DelayedProtocolHandler(2000);
- listener.addHandler(handler);
-
- // marshal message to output stream
- marshaller.marshal(msg, socket.getOutputStream());
-
- try {
- socket.getInputStream().read();
- fail("Socket timeout not received.");
- } catch (SocketTimeoutException ste) {
- }
-
- assertEquals(1, handler.getMessages().size());
- assertEquals(msg.getType(), handler.getMessages().get(0).getType());
- }
-
}