This is an automated email from the ASF dual-hosted git repository.
exceptionfactory 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 df2c187761 NIFI-10298 Changed nifi-framework-cluster tests to use Java
and JUnit 5
df2c187761 is described below
commit df2c18776118abf55c2eb7f05c4525d6aa4d4123
Author: Emilio Setiadarma <[email protected]>
AuthorDate: Fri Jul 29 14:08:20 2022 -0700
NIFI-10298 Changed nifi-framework-cluster tests to use Java and JUnit 5
This closes #6262
Signed-off-by: David Handermann <[email protected]>
---
.../okhttp/OkHttpReplicationClientTest.groovy | 245 ---------------------
.../flow/TestPopularVoteFlowElection.java | 12 +-
.../heartbeat/TestAbstractHeartbeatMonitor.java | 54 +----
.../endpoints/AccessPolicyEndpointMergerTest.java | 12 +-
.../endpoints/CurrentUserEndpointMergerTest.java | 8 +-
.../endpoints/TestProcessorEndpointMerger.java | 6 +-
.../endpoints/TestStatusHistoryEndpointMerger.java | 4 +-
.../http/replication/TestResponseUtils.java | 6 +-
.../TestThreadPoolRequestReplicator.java | 128 +++++------
.../okhttp/OkHttpReplicationClientTest.java | 213 ++++++++++++++++++
.../okhttp/TestJsonEntitySerializer.java | 6 +-
.../node/TestNodeClusterCoordinator.java | 52 +++--
...ileBasedClusterNodeFirewallFactoryBeanTest.java | 12 +-
.../impl/FileBasedClusterNodeFirewallTest.java | 60 ++---
.../cluster/integration/ClusterConnectionIT.java | 44 ++--
.../manager/AccessPolicyEntityMergerTest.java | 8 +-
.../RemoteProcessGroupEntityMergerTest.java | 8 +-
.../nifi/cluster/manager/UserEntityMergerTest.java | 8 +-
.../cluster/manager/UserGroupEntityMergerTest.java | 8 +-
19 files changed, 407 insertions(+), 487 deletions(-)
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/groovy/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.groovy
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/groovy/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.groovy
deleted file mode 100644
index 2390fc7a96..0000000000
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/groovy/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.groovy
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.nifi.cluster.coordination.http.replication.okhttp
-
-import org.apache.nifi.security.util.TemporaryKeyStoreBuilder
-import org.apache.nifi.security.util.TlsConfiguration
-import org.apache.nifi.util.NiFiProperties
-import org.junit.BeforeClass
-import org.junit.Test
-import org.junit.runner.RunWith
-import org.junit.runners.JUnit4
-
-@RunWith(JUnit4.class)
-class OkHttpReplicationClientTest extends GroovyTestCase {
- private static TlsConfiguration tlsConfiguration
-
- @BeforeClass
- static void setUpOnce() throws Exception {
- tlsConfiguration = new TemporaryKeyStoreBuilder().build()
- }
-
- private static NiFiProperties mockNiFiProperties() {
- return NiFiProperties.createBasicNiFiProperties(null)
- }
-
- @Test
- void testShouldReplaceNonZeroContentLengthHeader() {
- // Arrange
- def headers = ["Content-Length": "123", "Other-Header": "arbitrary
value"]
- String method = "DELETE"
-
- NiFiProperties mockProperties = mockNiFiProperties()
-
- OkHttpReplicationClient client = new
OkHttpReplicationClient(mockProperties)
-
- // Act
- client.checkContentLengthHeader(method, headers)
-
- // Assert
- assert headers.size() == 2
- assert headers."Content-Length" == "0"
- }
-
- @Test
- void testShouldReplaceNonZeroContentLengthHeaderOnDeleteCaseInsensitive() {
- // Arrange
- def headers = ["Content-Length": "123", "Other-Header": "arbitrary
value"]
- String method = "delete"
-
- NiFiProperties mockProperties = mockNiFiProperties()
-
- OkHttpReplicationClient client = new
OkHttpReplicationClient(mockProperties)
-
- // Act
- client.checkContentLengthHeader(method, headers)
-
- // Assert
- assert headers.size() == 2
- assert headers."Content-Length" == "0"
- }
-
- @Test
- void testShouldNotReplaceContentLengthHeaderWhenZeroOrNull() {
- // Arrange
- String method = "DELETE"
- def zeroOrNullContentLengths = [null, "0"]
-
- NiFiProperties mockProperties = mockNiFiProperties()
-
- OkHttpReplicationClient client = new
OkHttpReplicationClient(mockProperties)
-
- // Act
- zeroOrNullContentLengths.each { String contentLength ->
- def headers = ["Content-Length": contentLength, "Other-Header":
"arbitrary value"]
- client.checkContentLengthHeader(method, headers)
-
- // Assert
- assert headers.size() == 2
- assert headers."Content-Length" == contentLength
- }
- }
-
- @Test
- void testShouldNotReplaceNonZeroContentLengthHeaderOnOtherMethod() {
- // Arrange
- def headers = ["Content-Length": "123", "Other-Header": "arbitrary
value"]
-
- NiFiProperties mockProperties = mockNiFiProperties()
-
- OkHttpReplicationClient client = new
OkHttpReplicationClient(mockProperties)
-
- def nonDeleteMethods = ["POST", "PUT", "GET", "HEAD"]
-
- // Act
- nonDeleteMethods.each { String method ->
- client.checkContentLengthHeader(method, headers)
-
- // Assert
- assert headers.size() == 2
- assert headers."Content-Length" == "123"
- }
- }
-
- @Test
- void testShouldUseKeystorePasswordIfKeyPasswordIsBlank() {
- // Arrange
- Map propsMap = [
- (NiFiProperties.SECURITY_TRUSTSTORE) :
tlsConfiguration.truststorePath,
- (NiFiProperties.SECURITY_TRUSTSTORE_TYPE) :
tlsConfiguration.truststoreType.type,
- (NiFiProperties.SECURITY_TRUSTSTORE_PASSWD):
tlsConfiguration.truststorePassword,
- (NiFiProperties.SECURITY_KEYSTORE) :
tlsConfiguration.keystorePath,
- (NiFiProperties.SECURITY_KEYSTORE_TYPE) :
tlsConfiguration.keystoreType.type,
- (NiFiProperties.SECURITY_KEYSTORE_PASSWD) :
tlsConfiguration.keystorePassword,
- (NiFiProperties.SECURITY_KEY_PASSWD) : "",
- (NiFiProperties.WEB_HTTPS_HOST) : "localhost",
- (NiFiProperties.WEB_HTTPS_PORT) : "51552",
- ]
- NiFiProperties mockNiFiProperties = new NiFiProperties(new
Properties(propsMap))
-
- // Act
- OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties)
-
- // Assert
- assert client.isTLSConfigured()
- }
-
- @Test
- void testShouldUseKeystorePasswordIfKeyPasswordIsNull() {
- // Arrange
- Map flowfileEncryptionProps = [
- (NiFiProperties.SECURITY_TRUSTSTORE) :
tlsConfiguration.truststorePath,
- (NiFiProperties.SECURITY_TRUSTSTORE_TYPE) :
tlsConfiguration.truststoreType.type,
- (NiFiProperties.SECURITY_TRUSTSTORE_PASSWD):
tlsConfiguration.truststorePassword,
- (NiFiProperties.SECURITY_KEYSTORE) :
tlsConfiguration.keystorePath,
- (NiFiProperties.SECURITY_KEYSTORE_TYPE) :
tlsConfiguration.keystoreType.type,
- (NiFiProperties.SECURITY_KEYSTORE_PASSWD) :
tlsConfiguration.keystorePassword,
- (NiFiProperties.WEB_HTTPS_HOST) : "localhost",
- (NiFiProperties.WEB_HTTPS_PORT) : "51552",
- ]
- NiFiProperties mockNiFiProperties = new NiFiProperties(new
Properties(flowfileEncryptionProps))
-
- // Act
- OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties)
-
- // Assert
- assert client.isTLSConfigured()
- }
-
- @Test
- void testShouldFailIfKeyPasswordIsSetButKeystorePasswordIsBlank() {
- // Arrange
- Map propsMap = [
- (NiFiProperties.SECURITY_TRUSTSTORE) :
tlsConfiguration.truststorePath,
- (NiFiProperties.SECURITY_TRUSTSTORE_TYPE) :
tlsConfiguration.truststoreType.type,
- (NiFiProperties.SECURITY_TRUSTSTORE_PASSWD):
tlsConfiguration.truststorePassword,
- (NiFiProperties.SECURITY_KEYSTORE) :
tlsConfiguration.keystorePath,
- (NiFiProperties.SECURITY_KEYSTORE_TYPE) :
tlsConfiguration.keystoreType.type,
- (NiFiProperties.SECURITY_KEYSTORE_PASSWD) :
tlsConfiguration.keystorePassword,
- (NiFiProperties.SECURITY_KEYSTORE_PASSWD) : "",
- (NiFiProperties.WEB_HTTPS_HOST) : "localhost",
- (NiFiProperties.WEB_HTTPS_PORT) : "51552",
- ]
- NiFiProperties mockNiFiProperties = new NiFiProperties(new
Properties(propsMap))
-
- // Act
- OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties)
-
- // Assert
- assert !client.isTLSConfigured()
- }
-
- @Test
- void testShouldFailIfKeyPasswordAndKeystorePasswordAreBlank() {
- // Arrange
- Map propsMap = [
- (NiFiProperties.SECURITY_TRUSTSTORE) :
tlsConfiguration.truststorePath,
- (NiFiProperties.SECURITY_TRUSTSTORE_TYPE) :
tlsConfiguration.truststoreType.type,
- (NiFiProperties.SECURITY_TRUSTSTORE_PASSWD):
tlsConfiguration.truststorePassword,
- (NiFiProperties.SECURITY_KEYSTORE) :
tlsConfiguration.keystorePath,
- (NiFiProperties.SECURITY_KEYSTORE_TYPE) :
tlsConfiguration.keystoreType.type,
- (NiFiProperties.SECURITY_KEYSTORE_PASSWD) : "",
- (NiFiProperties.SECURITY_KEY_PASSWD) : "",
- (NiFiProperties.WEB_HTTPS_HOST) : "localhost",
- (NiFiProperties.WEB_HTTPS_PORT) : "51552",
- ]
- NiFiProperties mockNiFiProperties = new NiFiProperties(new
Properties(propsMap))
-
- // Act
- OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties)
-
- // Assert
- assert !client.isTLSConfigured()
- }
-
- @Test
- void testShouldDetermineIfTLSConfigured() {
- // Arrange
- Map propsMap = [(NiFiProperties.WEB_HTTPS_HOST): "localhost",
- (NiFiProperties.WEB_HTTPS_PORT): "51552",]
-
- Map tlsPropsMap = [
- (NiFiProperties.SECURITY_TRUSTSTORE) :
tlsConfiguration.truststorePath,
- (NiFiProperties.SECURITY_TRUSTSTORE_TYPE) :
tlsConfiguration.truststoreType.type,
- (NiFiProperties.SECURITY_TRUSTSTORE_PASSWD):
tlsConfiguration.truststorePassword,
- (NiFiProperties.SECURITY_KEYSTORE) :
tlsConfiguration.keystorePath,
- (NiFiProperties.SECURITY_KEYSTORE_TYPE) :
tlsConfiguration.keystoreType.type,
- (NiFiProperties.SECURITY_KEYSTORE_PASSWD) :
tlsConfiguration.keystorePassword
- ] + propsMap
-
-
- NiFiProperties mockNiFiProperties = new NiFiProperties(new
Properties(propsMap))
- NiFiProperties mockTLSNiFiProperties = new NiFiProperties(new
Properties(tlsPropsMap))
-
- // Remove the keystore password to create an invalid configuration
- Map invalidTlsPropsMap = tlsPropsMap
- invalidTlsPropsMap.remove(NiFiProperties.SECURITY_KEYSTORE_PASSWD)
- NiFiProperties mockInvalidTLSNiFiProperties = new NiFiProperties(new
Properties(invalidTlsPropsMap))
-
- // Act
- OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties)
- OkHttpReplicationClient invalidTlsClient = new
OkHttpReplicationClient(mockInvalidTLSNiFiProperties)
- OkHttpReplicationClient tlsClient = new
OkHttpReplicationClient(mockTLSNiFiProperties)
-
- // Assert
- assert !client.isTLSConfigured()
- assert !invalidTlsClient.isTLSConfigured()
- assert tlsClient.isTLSConfigured()
- }
-}
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/flow/TestPopularVoteFlowElection.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/flow/TestPopularVoteFlowElection.java
index 8db6eb9a3c..6270a14211 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/flow/TestPopularVoteFlowElection.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/flow/TestPopularVoteFlowElection.java
@@ -20,7 +20,7 @@ package org.apache.nifi.cluster.coordination.flow;
import org.apache.nifi.cluster.protocol.DataFlow;
import org.apache.nifi.cluster.protocol.NodeIdentifier;
import org.apache.nifi.cluster.protocol.StandardDataFlow;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
@@ -29,11 +29,11 @@ import java.util.HashSet;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestPopularVoteFlowElection {
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/heartbeat/TestAbstractHeartbeatMonitor.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/heartbeat/TestAbstractHeartbeatMonitor.java
index 5efb9ca033..f90e039129 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/heartbeat/TestAbstractHeartbeatMonitor.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/heartbeat/TestAbstractHeartbeatMonitor.java
@@ -30,14 +30,12 @@ import org.apache.nifi.cluster.protocol.NodeIdentifier;
import org.apache.nifi.reporting.Severity;
import org.apache.nifi.services.FlowService;
import org.apache.nifi.util.NiFiProperties;
-import org.junit.After;
-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 java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -50,21 +48,21 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestAbstractHeartbeatMonitor {
private NodeIdentifier nodeId;
private TestFriendlyHeartbeatMonitor monitor;
- @Before
+ @BeforeEach
public void setup() throws Exception {
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH,
"src/test/resources/conf/nifi.properties");
nodeId = new NodeIdentifier(UUID.randomUUID().toString(), "localhost",
9999, "localhost", 8888, "localhost", 777, "localhost", null, null, false);
}
- @After
- public void clear() throws IOException {
+ @AfterEach
+ public void clear() {
if (monitor != null) {
monitor.stop();
}
@@ -77,7 +75,7 @@ public class TestAbstractHeartbeatMonitor {
* @throws InterruptedException if interrupted
*/
@Test
- public void testNewConnectedHeartbeatFromUnknownNode() throws IOException,
InterruptedException {
+ public void testNewConnectedHeartbeatFromUnknownNode() throws
InterruptedException {
final List<NodeIdentifier> requestedToConnect =
Collections.synchronizedList(new ArrayList<>());
final ClusterCoordinatorAdapter coordinator = new
ClusterCoordinatorAdapter() {
@Override
@@ -139,40 +137,6 @@ public class TestAbstractHeartbeatMonitor {
assertTrue(requestedToConnect.isEmpty());
}
- @Ignore("this test is too unstable in terms of timing on different
size/types of testing envs")
- @Test
- public void testDisconnectionOfTerminatedNodeDueToLackOfHeartbeat() throws
Exception {
- final NodeIdentifier nodeId1 = nodeId;
- final NodeIdentifier nodeId2 = new
NodeIdentifier(UUID.randomUUID().toString(), "localhost", 7777, "localhost",
6666, "localhost", 5555, "localhost", null, null, false);
-
- final ClusterCoordinatorAdapter adapter = new
ClusterCoordinatorAdapter();
- final TestFriendlyHeartbeatMonitor monitor = createMonitor(adapter);
-
- // set state to connecting
- adapter.requestNodeConnect(nodeId1);
- adapter.requestNodeConnect(nodeId2);
-
- // ensure each node is connected
-
assertTrue(adapter.getNodeIdentifiers(NodeConnectionState.CONNECTING).containsAll(Arrays.asList(nodeId1,
nodeId2)));
-
- // let each node heartbeat in
- monitor.addHeartbeat(createHeartbeat(nodeId1,
NodeConnectionState.CONNECTED));
- monitor.addHeartbeat(createHeartbeat(nodeId2,
NodeConnectionState.CONNECTED));
- monitor.waitForProcessed();
-
- // ensure each node is now connected
-
assertTrue(adapter.getNodeIdentifiers(NodeConnectionState.CONNECTED).containsAll(Arrays.asList(nodeId1,
nodeId2)));
-
- // purge the heartbeats, simulate nodeId2 termination by only having a
nodeId1 heartbeat be present
- monitor.purgeHeartbeats();
- monitor.addHeartbeat(createHeartbeat(nodeId1,
NodeConnectionState.CONNECTED));
- monitor.waitForProcessed();
-
- // the node that did not heartbeat in should be disconnected
-
assertTrue(adapter.getNodeIdentifiers(NodeConnectionState.CONNECTED).contains(nodeId1));
-
assertTrue(adapter.getNodeIdentifiers(NodeConnectionState.DISCONNECTED).contains(nodeId2));
- }
-
@Test
public void testConnectingNodeMarkedConnectedWhenHeartbeatReceived()
throws InterruptedException {
final Set<NodeIdentifier> requestedToConnect =
Collections.synchronizedSet(new HashSet<>());
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/AccessPolicyEndpointMergerTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/AccessPolicyEndpointMergerTest.java
index c8a06eda0b..817c58d940 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/AccessPolicyEndpointMergerTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/AccessPolicyEndpointMergerTest.java
@@ -16,26 +16,26 @@
*/
package org.apache.nifi.cluster.coordination.http.endpoints;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.net.URI;
import java.util.UUID;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class AccessPolicyEndpointMergerTest {
@Test
- public void testCanHandle() throws Exception {
+ public void testCanHandle() {
final AccessPolicyEndpointMerger merger = new
AccessPolicyEndpointMerger();
assertTrue(merger.canHandle(URI.create("http://localhost:8080/nifi-api/policies"),
"POST"));
assertFalse(merger.canHandle(URI.create("http://localhost:8080/nifi-api/policies"),
"GET"));
assertFalse(merger.canHandle(URI.create("http://localhost:8080/nifi-api/policies"),
"PUT"));
-
assertTrue(merger.canHandle(URI.create("http://localhost:8080/nifi-api/policies/"
+ UUID.randomUUID().toString()), "PUT"));
+
assertTrue(merger.canHandle(URI.create("http://localhost:8080/nifi-api/policies/"
+ UUID.randomUUID()), "PUT"));
assertFalse(merger.canHandle(URI.create("http://localhost:8080/nifi-api/policies/Read/flow"),
"GET"));
assertTrue(merger.canHandle(URI.create("http://localhost:8080/nifi-api/policies/read/flow"),
"GET"));
-
assertTrue(merger.canHandle(URI.create("http://localhost:8080/nifi-api/policies/read/processors/"
+ UUID.randomUUID().toString()), "GET"));
+
assertTrue(merger.canHandle(URI.create("http://localhost:8080/nifi-api/policies/read/processors/"
+ UUID.randomUUID()), "GET"));
}
}
\ No newline at end of file
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/CurrentUserEndpointMergerTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/CurrentUserEndpointMergerTest.java
index a93cd68e66..c12e2b2fe9 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/CurrentUserEndpointMergerTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/CurrentUserEndpointMergerTest.java
@@ -23,7 +23,7 @@ import
org.apache.nifi.web.api.dto.ComponentRestrictionPermissionDTO;
import org.apache.nifi.web.api.dto.PermissionsDTO;
import org.apache.nifi.web.api.dto.RequiredPermissionDTO;
import org.apache.nifi.web.api.entity.CurrentUserEntity;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Collections;
import java.util.HashMap;
@@ -31,9 +31,9 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
public class CurrentUserEndpointMergerTest {
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/TestProcessorEndpointMerger.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/TestProcessorEndpointMerger.java
index e59f096764..eccc969932 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/TestProcessorEndpointMerger.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/TestProcessorEndpointMerger.java
@@ -19,7 +19,7 @@ package org.apache.nifi.cluster.coordination.http.endpoints;
import org.apache.nifi.cluster.manager.ErrorMerger;
import org.apache.nifi.cluster.protocol.NodeIdentifier;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
@@ -27,8 +27,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestProcessorEndpointMerger {
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/TestStatusHistoryEndpointMerger.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/TestStatusHistoryEndpointMerger.java
index dba973c34d..a00d5ef7dc 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/TestStatusHistoryEndpointMerger.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/TestStatusHistoryEndpointMerger.java
@@ -17,7 +17,7 @@
package org.apache.nifi.cluster.coordination.http.endpoints;
-import static org.junit.Assert.assertEquals;
+import org.junit.jupiter.api.Test;
import java.text.DateFormat;
import java.text.ParseException;
@@ -25,7 +25,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestStatusHistoryEndpointMerger {
@Test
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestResponseUtils.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestResponseUtils.java
index 4bb7b679a1..0d8746f943 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestResponseUtils.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestResponseUtils.java
@@ -19,7 +19,7 @@ package org.apache.nifi.cluster.coordination.http.replication;
import org.apache.nifi.cluster.manager.NodeResponse;
import org.apache.nifi.cluster.protocol.NodeIdentifier;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import javax.ws.rs.core.Response;
import java.net.URI;
@@ -30,8 +30,8 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
public class TestResponseUtils {
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestThreadPoolRequestReplicator.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestThreadPoolRequestReplicator.java
index c79dad3739..b9c51aba6f 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestThreadPoolRequestReplicator.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestThreadPoolRequestReplicator.java
@@ -34,9 +34,10 @@ import org.apache.nifi.web.api.entity.Entity;
import org.apache.nifi.web.api.entity.ProcessorEntity;
import org.apache.nifi.web.security.ProxiedEntitiesUtils;
import org.apache.nifi.web.security.token.NiFiAuthenticationToken;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -60,20 +61,27 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class TestThreadPoolRequestReplicator {
- @BeforeClass
+ @BeforeAll
public static void setupClass() {
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH,
"src/test/resources/conf/nifi.properties");
}
+ @AfterAll
+ public static void clearProperty() {
+ System.clearProperty(NiFiProperties.PROPERTIES_FILE_PATH);
+ }
+
@Test
public void testFailedRequestsAreCleanedUp() {
withReplicator(replicator -> {
@@ -89,12 +97,12 @@ public class TestThreadPoolRequestReplicator {
final AsyncClusterResponse response =
replicator.replicate(nodeIds, HttpMethod.GET, uri, entity, new HashMap<>(),
true, true);
// We should get back the same response object
- assertTrue(response ==
replicator.getClusterResponse(response.getRequestIdentifier()));
+ assertEquals(response,
replicator.getClusterResponse(response.getRequestIdentifier()));
assertEquals(HttpMethod.GET, response.getMethod());
assertEquals(nodeIds, response.getNodesInvolved());
- assertTrue(response ==
replicator.getClusterResponse(response.getRequestIdentifier()));
+ assertEquals(response,
replicator.getClusterResponse(response.getRequestIdentifier()));
final NodeResponse nodeResponse = response.awaitMergedResponse(3,
TimeUnit.SECONDS);
assertEquals(8000, nodeResponse.getNodeId().getApiPort());
@@ -125,12 +133,12 @@ public class TestThreadPoolRequestReplicator {
final AsyncClusterResponse response =
replicator.replicate(nodeIds, HttpMethod.GET, uri, entity, new HashMap<>(),
true, true);
// We should get back the same response object
- assertTrue(response ==
replicator.getClusterResponse(response.getRequestIdentifier()));
+ assertEquals(response,
replicator.getClusterResponse(response.getRequestIdentifier()));
assertEquals(HttpMethod.GET, response.getMethod());
assertEquals(nodeIds, response.getNodesInvolved());
- assertTrue(response ==
replicator.getClusterResponse(response.getRequestIdentifier()));
+ assertEquals(response,
replicator.getClusterResponse(response.getRequestIdentifier()));
final NodeResponse nodeResponse = response.awaitMergedResponse(3,
TimeUnit.SECONDS);
assertEquals(8000, nodeResponse.getNodeId().getApiPort());
@@ -192,7 +200,8 @@ public class TestThreadPoolRequestReplicator {
}, Response.Status.OK, 0L, null, expectedRequestChain,
expectedProxiedEntityGroups);
}
- @Test(timeout = 15000)
+ @Test
+ @Timeout(value = 15)
public void testLongWaitForResponse() {
withReplicator(replicator -> {
final Set<NodeIdentifier> nodeIds = new HashSet<>();
@@ -208,7 +217,7 @@ public class TestThreadPoolRequestReplicator {
final AsyncClusterResponse response =
replicator.replicate(nodeIds, HttpMethod.GET, uri, entity, new HashMap<>(),
true, true);
// We should get back the same response object
- assertTrue(response ==
replicator.getClusterResponse(response.getRequestIdentifier()));
+ assertEquals(response,
replicator.getClusterResponse(response.getRequestIdentifier()));
final NodeResponse completedNodeResponse =
response.awaitMergedResponse(2, TimeUnit.SECONDS);
assertNotNull(completedNodeResponse);
@@ -221,7 +230,8 @@ public class TestThreadPoolRequestReplicator {
}, Status.OK, 1000, new ProcessingException(new
SocketTimeoutException()));
}
- @Test(timeout = 15000)
+ @Test
+ @Timeout(value = 15)
public void testCompleteOnError() {
withReplicator(replicator -> {
final Set<NodeIdentifier> nodeIds = new HashSet<>();
@@ -246,8 +256,9 @@ public class TestThreadPoolRequestReplicator {
}, null, 0L, new IllegalArgumentException("Exception created for unit
test"));
}
- @Test(timeout = 15000)
- public void testMultipleRequestWithTwoPhaseCommit() {
+ @Test
+ @Timeout(value = 15)
+ public void testMultipleRequestWithTwoPhaseCommit() throws Exception {
final Set<NodeIdentifier> nodeIds = new HashSet<>();
final NodeIdentifier nodeId = new NodeIdentifier("1", "localhost",
8100, "localhost", 8101, "localhost", 8102, 8103, false);
nodeIds.add(nodeId);
@@ -285,24 +296,19 @@ public class TestThreadPoolRequestReplicator {
}
};
- try {
- // set the user
- final Authentication authentication = new
NiFiAuthenticationToken(new NiFiUserDetails(StandardNiFiUser.ANONYMOUS));
-
SecurityContextHolder.getContext().setAuthentication(authentication);
+ // set the user
+ final Authentication authentication = new NiFiAuthenticationToken(new
NiFiUserDetails(StandardNiFiUser.ANONYMOUS));
+ SecurityContextHolder.getContext().setAuthentication(authentication);
- final AsyncClusterResponse clusterResponse =
replicator.replicate(nodeIds, HttpMethod.POST,
- new URI("http://localhost:80/processors/1"), new
ProcessorEntity(), new HashMap<>(), true, true);
- clusterResponse.awaitMergedResponse();
+ final AsyncClusterResponse clusterResponse =
replicator.replicate(nodeIds, HttpMethod.POST,
+ new URI("http://localhost:80/processors/1"), new
ProcessorEntity(), new HashMap<>(), true, true);
+ clusterResponse.awaitMergedResponse();
- // Ensure that we received two requests - the first should contain
the X-NcmExpects header; the second should not.
- // These assertions are validated above, in the overridden
replicateRequest method.
- assertEquals(2, requestCount.get());
- } catch (final Exception e) {
- e.printStackTrace();
- Assert.fail(e.toString());
- } finally {
- replicator.shutdown();
- }
+ // Ensure that we received two requests - the first should contain the
X-NcmExpects header; the second should not.
+ // These assertions are validated above, in the overridden
replicateRequest method.
+ assertEquals(2, requestCount.get());
+
+ replicator.shutdown();
}
private ClusterCoordinator createClusterCoordinator() {
@@ -317,7 +323,8 @@ public class TestThreadPoolRequestReplicator {
return coordinator;
}
- @Test(timeout = 15000)
+ @Test
+ @Timeout(value = 15)
public void testOneNodeRejectsTwoPhaseCommit() {
final Set<NodeIdentifier> nodeIds = new HashSet<>();
nodeIds.add(new NodeIdentifier("1", "localhost", 8100, "localhost",
8101, "localhost", 8102, 8103, false));
@@ -352,26 +359,19 @@ public class TestThreadPoolRequestReplicator {
}
};
- try {
- // set the user
+ final IllegalClusterStateException exception =
assertThrows(IllegalClusterStateException.class, () -> {
final Authentication authentication = new
NiFiAuthenticationToken(new NiFiUserDetails(StandardNiFiUser.ANONYMOUS));
SecurityContextHolder.getContext().setAuthentication(authentication);
final AsyncClusterResponse clusterResponse =
replicator.replicate(nodeIds, HttpMethod.POST,
new URI("http://localhost:80/processors/1"), new
ProcessorEntity(), new HashMap<>(), true, true);
clusterResponse.awaitMergedResponse();
-
- Assert.fail("Expected to get an IllegalClusterStateException but
did not");
- } catch (final IllegalClusterStateException e) {
- // Expected
- } catch (final Exception e) {
- Assert.fail(e.toString());
- } finally {
- replicator.shutdown();
- }
+ });
+ replicator.shutdown();
}
- @Test(timeout = 5000)
+ @Test
+ @Timeout(value = 5)
public void testMonitorNotifiedOnException() {
withReplicator(replicator -> {
final Object monitor = new Object();
@@ -402,8 +402,7 @@ public class TestThreadPoolRequestReplicator {
// wait for the background thread to notify that it is
synchronized on monitor.
preNotifyLatch.await();
- try {
- // set the user
+ assertThrows(IllegalArgumentException.class, () -> {
final Authentication authentication = new
NiFiAuthenticationToken(new NiFiUserDetails(StandardNiFiUser.ANONYMOUS));
SecurityContextHolder.getContext().setAuthentication(authentication);
@@ -413,18 +412,16 @@ public class TestThreadPoolRequestReplicator {
// Pass in Collections.emptySet() for the node ID's so that an
Exception is thrown
replicator.replicate(Collections.emptySet(), "GET", new
URI("localhost:8080/nifi"), Collections.emptyMap(),
- updatedHeaders, true, null, true, true, monitor);
- Assert.fail("replicate did not throw
IllegalArgumentException");
- } catch (final IllegalArgumentException iae) {
- // expected
- }
+ updatedHeaders, true, null, true, true, monitor);
+ });
// wait for monitor to be notified.
postNotifyLatch.await();
});
}
- @Test(timeout = 5000)
+ @Test
+ @Timeout(value = 5)
public void testMonitorNotifiedOnSuccessfulCompletion() {
withReplicator(replicator -> {
final Object monitor = new Object();
@@ -477,7 +474,8 @@ public class TestThreadPoolRequestReplicator {
}
- @Test(timeout = 5000)
+ @Test
+ @Timeout(value = 5)
public void testMonitorNotifiedOnFailureResponse() {
withReplicator(replicator -> {
final Object monitor = new Object();
@@ -557,11 +555,9 @@ public class TestThreadPoolRequestReplicator {
final StandardAsyncClusterResponse response) {
if (delayMillis > 0L) {
- try {
+ assertDoesNotThrow(() -> {
Thread.sleep(delayMillis);
- } catch (InterruptedException e) {
- Assert.fail("Thread Interrupted during test");
- }
+ }, "Thread Interrupted during test");
}
if (failure != null) {
@@ -570,11 +566,11 @@ public class TestThreadPoolRequestReplicator {
// ensure the request chain is in the request
final Object proxiedEntities =
request.getHeaders().get(ProxiedEntitiesUtils.PROXY_ENTITIES_CHAIN);
- Assert.assertEquals(expectedRequestChain, proxiedEntities);
+ assertEquals(expectedRequestChain, proxiedEntities);
// ensure the proxied entity groups are in the request
final Object proxiedEntityGroups =
request.getHeaders().get(ProxiedEntitiesUtils.PROXY_ENTITY_GROUPS);
- Assert.assertEquals(expectedProxiedEntityGroups,
proxiedEntityGroups);
+ assertEquals(expectedProxiedEntityGroups, proxiedEntityGroups);
// Return given response from all nodes.
final Response clientResponse = mock(Response.class);
@@ -583,14 +579,10 @@ public class TestThreadPoolRequestReplicator {
}
};
- try {
+ assertDoesNotThrow(() -> {
function.withReplicator(replicator);
- } catch (final Exception e) {
- e.printStackTrace();
- Assert.fail(e.toString());
- } finally {
- replicator.shutdown();
- }
+ });
+ replicator.shutdown();
}
private interface WithReplicator {
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.java
new file mode 100644
index 0000000000..17d83de0fe
--- /dev/null
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/OkHttpReplicationClientTest.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.cluster.coordination.http.replication.okhttp;
+
+import org.apache.nifi.security.util.TemporaryKeyStoreBuilder;
+import org.apache.nifi.security.util.TlsConfiguration;
+import org.apache.nifi.util.NiFiProperties;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class OkHttpReplicationClientTest {
+ private static TlsConfiguration tlsConfiguration;
+
+ @BeforeAll
+ public static void setUpOnce() {
+ tlsConfiguration = new TemporaryKeyStoreBuilder().build();
+ }
+
+ @Test
+ public void testShouldReplaceNonZeroContentLengthHeader() {
+ final Map<String, String> headers = new HashMap<>();
+ headers.put("Content-Length", "123");
+ headers.put("Other-Header", "arbitrary value");
+
+ // must be case-insensitive
+ final String[] methods = new String[] {"DELETE", "delete", "DeLeTe"};
+
+ final NiFiProperties mockProperties = mockNiFiProperties();
+
+ final OkHttpReplicationClient client = new
OkHttpReplicationClient(mockProperties);
+
+ for (final String method: methods) {
+ client.prepareRequest(method, headers, null);
+
+ assertEquals(2, headers.size());
+ assertEquals("0", headers.get("Content-Length"));
+ }
+ }
+
+ @Test
+ void testShouldNotReplaceContentLengthHeaderWhenZeroOrNull() {
+ final String method = "DELETE";
+ final String[] zeroOrNullContentLengths = new String[] {null, "0"};
+
+ final NiFiProperties mockProperties = mockNiFiProperties();
+
+ final OkHttpReplicationClient client = new
OkHttpReplicationClient(mockProperties);
+
+ final Map<String, String> headers = new HashMap<>();
+ for (final String contentLength: zeroOrNullContentLengths) {
+ headers.put("Content-Length", contentLength);
+ headers.put("Other-Header", "arbitrary value");
+
+ client.prepareRequest(method, headers, null);
+
+ assertEquals(2, headers.size());
+ assertEquals(contentLength, headers.get("Content-Length"));
+ }
+ }
+
+ @Test
+ void testShouldNotReplaceNonZeroContentLengthHeaderOnOtherMethod() {
+ final Map<String, String> headers = new HashMap<>();
+ headers.put("Content-Length", "123");
+ headers.put("Other-Header", "arbitrary value");
+
+ final NiFiProperties mockProperties = mockNiFiProperties();
+
+ final OkHttpReplicationClient client = new
OkHttpReplicationClient(mockProperties);
+
+ final String[] nonDeleteMethods = new String[] {"POST", "PUT", "GET",
"HEAD"};
+
+ for (final String method: nonDeleteMethods) {
+ client.prepareRequest(method, headers, null);
+
+ assertEquals(2, headers.size());
+ assertEquals("123", headers.get("Content-Length"));
+ }
+ }
+
+ @Test
+ void testShouldUseKeystorePasswordIfKeyPasswordIsBlank() {
+ final Map<String, String> propsMap = new HashMap<>();
+ propsMap.put(NiFiProperties.SECURITY_TRUSTSTORE,
tlsConfiguration.getTruststorePath());
+ propsMap.put(NiFiProperties.SECURITY_TRUSTSTORE_TYPE,
tlsConfiguration.getTruststoreType().getType());
+ propsMap.put(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD,
tlsConfiguration.getTruststorePassword());
+ propsMap.put(NiFiProperties.SECURITY_KEYSTORE,
tlsConfiguration.getKeystorePath());
+ propsMap.put(NiFiProperties.SECURITY_KEYSTORE_TYPE,
tlsConfiguration.getKeystoreType().getType());
+ propsMap.put(NiFiProperties.SECURITY_KEYSTORE_PASSWD,
tlsConfiguration.getKeystorePassword());
+ propsMap.put(NiFiProperties.SECURITY_KEY_PASSWD, "");
+ propsMap.put(NiFiProperties.WEB_HTTPS_HOST, "localhost");
+ propsMap.put(NiFiProperties.WEB_HTTPS_PORT, "51552");
+
+ final NiFiProperties mockNiFiProperties = new NiFiProperties(propsMap);
+
+ final OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties);
+
+ assertTrue(client.isTLSConfigured());
+ }
+
+ @Test
+ void testShouldUseKeystorePasswordIfKeyPasswordIsNull() {
+ final Map<String, String> flowfileEncryptionProps = new HashMap<>();
+ flowfileEncryptionProps.put(NiFiProperties.SECURITY_TRUSTSTORE,
tlsConfiguration.getTruststorePath());
+ flowfileEncryptionProps.put(NiFiProperties.SECURITY_TRUSTSTORE_TYPE,
tlsConfiguration.getTruststoreType().getType());
+ flowfileEncryptionProps.put(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD,
tlsConfiguration.getTruststorePassword());
+ flowfileEncryptionProps.put(NiFiProperties.SECURITY_KEYSTORE,
tlsConfiguration.getKeystorePath());
+ flowfileEncryptionProps.put(NiFiProperties.SECURITY_KEYSTORE_TYPE,
tlsConfiguration.getKeystoreType().getType());
+ flowfileEncryptionProps.put(NiFiProperties.SECURITY_KEYSTORE_PASSWD,
tlsConfiguration.getKeystorePassword());
+ flowfileEncryptionProps.put(NiFiProperties.WEB_HTTPS_HOST,
"localhost");
+ flowfileEncryptionProps.put(NiFiProperties.WEB_HTTPS_PORT, "51552");
+
+ final NiFiProperties mockNiFiProperties = new
NiFiProperties(flowfileEncryptionProps);
+
+ final OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties);
+
+ assertTrue(client.isTLSConfigured());
+ }
+
+ @Test
+ void testShouldFailIfKeyPasswordIsSetButKeystorePasswordIsBlank() {
+ final Map<String, String> propsMap = new HashMap<>();
+ propsMap.put(NiFiProperties.SECURITY_TRUSTSTORE,
tlsConfiguration.getTruststorePath());
+ propsMap.put(NiFiProperties.SECURITY_TRUSTSTORE_TYPE,
tlsConfiguration.getTruststoreType().getType());
+ propsMap.put(NiFiProperties.SECURITY_KEYSTORE,
tlsConfiguration.getKeystorePath());
+ propsMap.put(NiFiProperties.SECURITY_KEYSTORE_TYPE,
tlsConfiguration.getKeystoreType().getType());
+ propsMap.put(NiFiProperties.SECURITY_KEYSTORE_PASSWD, "");
+ propsMap.put(NiFiProperties.WEB_HTTPS_HOST, "localhost");
+ propsMap.put(NiFiProperties.WEB_HTTPS_PORT, "51552");
+
+ final NiFiProperties mockNiFiProperties = new NiFiProperties(propsMap);
+
+ final OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties);
+
+ assertFalse(client.isTLSConfigured());
+ }
+
+ @Test
+ void testShouldFailIfKeyPasswordAndKeystorePasswordAreBlank() {
+ final Map<String, String> propsMap = new HashMap<>();
+ propsMap.put(NiFiProperties.SECURITY_TRUSTSTORE,
tlsConfiguration.getTruststorePath());
+ propsMap.put(NiFiProperties.SECURITY_TRUSTSTORE_TYPE,
tlsConfiguration.getTruststoreType().getType());
+ propsMap.put(NiFiProperties.SECURITY_KEYSTORE,
tlsConfiguration.getKeystorePath());
+ propsMap.put(NiFiProperties.SECURITY_KEYSTORE_TYPE,
tlsConfiguration.getKeystoreType().getType());
+ propsMap.put(NiFiProperties.SECURITY_KEYSTORE_PASSWD, "");
+ propsMap.put(NiFiProperties.SECURITY_KEY_PASSWD, "");
+ propsMap.put(NiFiProperties.WEB_HTTPS_HOST, "localhost");
+ propsMap.put(NiFiProperties.WEB_HTTPS_PORT, "51552");
+
+ final NiFiProperties mockNiFiProperties = new NiFiProperties(propsMap);
+
+ final OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties);
+
+ assertFalse(client.isTLSConfigured());
+ }
+
+ @Test
+ void testShouldDetermineIfTLSConfigured() {
+ final Map<String, String> propsMap = new HashMap<>();
+ propsMap.put(NiFiProperties.WEB_HTTPS_HOST, "localhost");
+ propsMap.put(NiFiProperties.WEB_HTTPS_PORT, "51552");
+
+ final Map<String, String> tlsPropsMap = new HashMap<>(propsMap);
+ tlsPropsMap.put(NiFiProperties.SECURITY_TRUSTSTORE,
tlsConfiguration.getTruststorePath());
+ tlsPropsMap.put(NiFiProperties.SECURITY_TRUSTSTORE_TYPE,
tlsConfiguration.getTruststoreType().getType());
+ tlsPropsMap.put(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD,
tlsConfiguration.getTruststorePassword());
+ tlsPropsMap.put(NiFiProperties.SECURITY_KEYSTORE,
tlsConfiguration.getKeystorePath());
+ tlsPropsMap.put(NiFiProperties.SECURITY_KEYSTORE_TYPE,
tlsConfiguration.getKeystoreType().getType());
+ tlsPropsMap.put(NiFiProperties.SECURITY_KEYSTORE_PASSWD,
tlsConfiguration.getKeystorePassword());
+
+ final Map<String, String> invalidTlsPropsMap = new
HashMap<>(tlsPropsMap);
+ // Remove the keystore password to create an invalid configuration
+ invalidTlsPropsMap.remove(NiFiProperties.SECURITY_KEYSTORE_PASSWD);
+
+ final NiFiProperties mockNiFiProperties = new NiFiProperties(propsMap);
+ final NiFiProperties mockTLSNiFiProperties = new
NiFiProperties(tlsPropsMap);
+ final NiFiProperties mockInvalidTLSNiFiProperties = new
NiFiProperties(invalidTlsPropsMap);
+
+ final OkHttpReplicationClient client = new
OkHttpReplicationClient(mockNiFiProperties);
+ final OkHttpReplicationClient invalidTlsClient = new
OkHttpReplicationClient(mockInvalidTLSNiFiProperties);
+ final OkHttpReplicationClient tlsClient = new
OkHttpReplicationClient(mockTLSNiFiProperties);
+
+ assertFalse(client.isTLSConfigured());
+ assertFalse(invalidTlsClient.isTLSConfigured());
+ assertTrue(tlsClient.isTLSConfigured());
+ }
+
+ private static NiFiProperties mockNiFiProperties() {
+ return NiFiProperties.createBasicNiFiProperties(null);
+ }
+}
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/TestJsonEntitySerializer.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/TestJsonEntitySerializer.java
index dd96826694..5e22902ca5 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/TestJsonEntitySerializer.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/okhttp/TestJsonEntitySerializer.java
@@ -17,8 +17,6 @@
package org.apache.nifi.cluster.coordination.http.replication.okhttp;
-import static org.junit.Assert.assertEquals;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -31,11 +29,13 @@ import org.apache.nifi.web.api.dto.ProcessorDTO;
import org.apache.nifi.web.api.dto.util.TimeAdapter;
import org.apache.nifi.web.api.entity.BulletinEntity;
import org.apache.nifi.web.api.entity.ProcessorEntity;
-import org.junit.Test;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestJsonEntitySerializer {
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java
index 511620c461..df18a1d7b1 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/node/TestNodeClusterCoordinator.java
@@ -38,9 +38,9 @@ import org.apache.nifi.state.MockStateMap;
import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.web.revision.RevisionManager;
import org.apache.nifi.web.revision.RevisionSnapshot;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
@@ -57,10 +57,11 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
@@ -79,7 +80,7 @@ public class TestNodeClusterCoordinator {
return NiFiProperties.createBasicNiFiProperties(null, addProps);
}
- @Before
+ @BeforeEach
public void setup() throws IOException {
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH,
"src/test/resources/conf/nifi.properties");
@@ -110,7 +111,7 @@ public class TestNodeClusterCoordinator {
}
@Test
- public void testConnectionResponseIndicatesAllNodes() throws IOException {
+ public void testConnectionResponseIndicatesAllNodes() {
// Add a disconnected node
coordinator.updateNodeStatus(new NodeConnectionStatus(createNodeId(1),
DisconnectionCode.LACK_OF_HEARTBEAT));
coordinator.updateNodeStatus(new NodeConnectionStatus(createNodeId(2),
NodeConnectionState.DISCONNECTING));
@@ -174,7 +175,8 @@ public class TestNodeClusterCoordinator {
assertEquals(5, response.getTryLaterSeconds());
}
- @Test(timeout = 5000)
+ @Test
+ @Timeout(value = 5)
public void testUnknownNodeAskedToConnectOnAttemptedConnectionComplete()
throws IOException, InterruptedException {
final ClusterCoordinationProtocolSenderListener senderListener =
Mockito.mock(ClusterCoordinationProtocolSenderListener.class);
final AtomicReference<ReconnectionRequestMessage> requestRef = new
AtomicReference<>();
@@ -221,8 +223,9 @@ public class TestNodeClusterCoordinator {
assertTrue(Arrays.equals(dataFlow.getSnippets(), df.getSnippets()));
}
- @Test(timeout = 5000)
- public void testFinishNodeConnectionResultsInConnectedState() throws
IOException, InterruptedException {
+ @Test
+ @Timeout(value = 5)
+ public void testFinishNodeConnectionResultsInConnectedState() throws
InterruptedException {
final NodeIdentifier nodeId = createNodeId(1);
// Create a connection request message and send to the coordinator
@@ -244,8 +247,9 @@ public class TestNodeClusterCoordinator {
assertEquals(NodeConnectionState.CONNECTED,
coordinator.getConnectionStatus(nodeId).getState());
}
- @Test(timeout = 5000)
- public void testStatusChangesReplicated() throws InterruptedException,
IOException {
+ @Test
+ @Timeout(value = 5)
+ public void testStatusChangesReplicated() throws InterruptedException {
final RevisionManager revisionManager =
Mockito.mock(RevisionManager.class);
when(revisionManager.getAllRevisions()).thenReturn(emptyRevisionSnapshot);
@@ -285,7 +289,7 @@ public class TestNodeClusterCoordinator {
}
@Test
- public void testGetConnectionStates() throws IOException {
+ public void testGetConnectionStates() {
// Add a disconnected node
coordinator.updateNodeStatus(new NodeConnectionStatus(createNodeId(1),
DisconnectionCode.LACK_OF_HEARTBEAT));
coordinator.updateNodeStatus(new NodeConnectionStatus(createNodeId(2),
NodeConnectionState.DISCONNECTING));
@@ -315,7 +319,7 @@ public class TestNodeClusterCoordinator {
}
@Test
- public void testGetNodeIdentifiers() throws IOException {
+ public void testGetNodeIdentifiers() {
// Add a disconnected node
coordinator.updateNodeStatus(new NodeConnectionStatus(createNodeId(1),
DisconnectionCode.LACK_OF_HEARTBEAT));
coordinator.updateNodeStatus(new NodeConnectionStatus(createNodeId(2),
NodeConnectionState.DISCONNECTING));
@@ -341,7 +345,8 @@ public class TestNodeClusterCoordinator {
assertTrue(disconnectedIds.contains(createNodeId(1)));
}
- @Test(timeout = 5000)
+ @Test
+ @Timeout(value = 5)
public void testRequestNodeDisconnect() throws InterruptedException {
// Add a connected node
final NodeIdentifier nodeId1 = createNodeId(1);
@@ -365,7 +370,8 @@ public class TestNodeClusterCoordinator {
assertEquals(NodeConnectionState.DISCONNECTED, status.getState());
}
- @Test(timeout = 5000)
+ @Test
+ @Timeout(value = 5)
public void testCannotDisconnectLastNode() throws InterruptedException {
// Add a connected node
final NodeIdentifier nodeId1 = createNodeId(1);
@@ -381,18 +387,16 @@ public class TestNodeClusterCoordinator {
coordinator.requestNodeDisconnect(nodeId2,
DisconnectionCode.USER_DISCONNECTED, "Unit Test");
- try {
+ assertThrows(IllegalNodeDisconnectionException.class, () -> {
coordinator.requestNodeDisconnect(nodeId1,
DisconnectionCode.USER_DISCONNECTED, "Unit Test");
- Assert.fail("Expected an IllegalNodeDisconnectionException when
trying to disconnect last node but it wasn't thrown");
- } catch (final IllegalNodeDisconnectionException inde) {
- // expected
- }
+ });
// Should still be able to request that node 2 disconnect, since it's
not the node that is connected
coordinator.requestNodeDisconnect(nodeId2,
DisconnectionCode.USER_DISCONNECTED, "Unit Test");
}
- @Test(timeout = 5000)
+ @Test
+ @Timeout(value = 5)
public void testUpdateNodeStatusOutOfOrder() throws InterruptedException {
// Add a connected node
final NodeIdentifier nodeId1 = createNodeId(1);
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallFactoryBeanTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallFactoryBeanTest.java
index 2d284f956d..d1c1aa5967 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallFactoryBeanTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallFactoryBeanTest.java
@@ -20,16 +20,16 @@ import org.apache.nifi.cluster.firewall.ClusterNodeFirewall;
import org.apache.nifi.cluster.spring.FileBasedClusterNodeFirewallFactoryBean;
import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.util.StringUtils;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
public class FileBasedClusterNodeFirewallFactoryBeanTest {
private static final String PROPERTIES_SUFFIX = ".firewall.properties";
@@ -38,7 +38,7 @@ public class FileBasedClusterNodeFirewallFactoryBeanTest {
private NiFiProperties properties;
- @Before
+ @BeforeEach
public void setFactoryBean() {
properties =
NiFiProperties.createBasicNiFiProperties(StringUtils.EMPTY);
factoryBean = new FileBasedClusterNodeFirewallFactoryBean();
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallTest.java
index 81c60726bd..16a46528f8 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/firewall/impl/FileBasedClusterNodeFirewallTest.java
@@ -16,20 +16,21 @@
*/
package org.apache.nifi.cluster.firewall.impl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
public class FileBasedClusterNodeFirewallTest {
@@ -43,8 +44,8 @@ public class FileBasedClusterNodeFirewallTest {
private File restoreDirectory;
- @Rule
- public final TemporaryFolder temp = new TemporaryFolder();
+ @TempDir
+ private Path tempDir;
private static final String NONEXISTENT_HOSTNAME = "abc";
@@ -55,7 +56,7 @@ public class FileBasedClusterNodeFirewallTest {
* This can be a problem i.e. on residential ISPs in the USA because the
provider will often
* wildcard match all possible DNS names in an attempt to serve
advertising.
*/
- @BeforeClass
+ @BeforeAll
public static void ensureBadHostsDoNotWork() {
final InetAddress ip;
try {
@@ -65,35 +66,18 @@ public class FileBasedClusterNodeFirewallTest {
}
}
- @Before
+ @BeforeEach
public void setup() throws Exception {
ipsConfig = new
File(getClass().getResource("/org/apache/nifi/cluster/firewall/impl/ips.txt").toURI());
emptyConfig = new
File(getClass().getResource("/org/apache/nifi/cluster/firewall/impl/empty.txt").toURI());
- restoreDirectory = temp.newFolder("firewall_restore");
+ restoreDirectory =
Files.createDirectory(tempDir.resolve("firewall_restore")).toFile();
ipsFirewall = new FileBasedClusterNodeFirewall(ipsConfig,
restoreDirectory);
acceptAllFirewall = new FileBasedClusterNodeFirewall(emptyConfig);
}
- /**
- * We have two garbage lines in our test config file, ensure they didn't
get turned into hosts.
- */
- @Ignore("This does not run consistently on different environments")
- @Test
- public void ensureBadDataWasIgnored() {
- assumeTrue(badHostsDoNotResolve);
- assertFalse("firewall treated our malformed data as a host. If " +
- "`host \"bad data should be skipped\"` works locally,
this test should have been " +
- "skipped.",
- ipsFirewall.isPermissible("bad data should be skipped"));
- assertFalse("firewall treated our malformed data as a host. If " +
- "`host \"more bad data\"` works locally, this test
should have been " +
- "skipped.",
- ipsFirewall.isPermissible("more bad data"));
- }
-
@Test
public void testSyncWithRestore() {
assertEquals(ipsConfig.length(), new File(restoreDirectory,
ipsConfig.getName()).length());
@@ -117,9 +101,9 @@ public class FileBasedClusterNodeFirewallTest {
@Test
public void testIsPermissibleWithMalformedData() {
assumeTrue(badHostsDoNotResolve);
- assertFalse("firewall allowed host '" + NONEXISTENT_HOSTNAME + "'
rather than rejecting as malformed. If `host " + NONEXISTENT_HOSTNAME + "` "
- + "works locally, this test should have been skipped.",
- ipsFirewall.isPermissible(NONEXISTENT_HOSTNAME));
+ assertFalse(ipsFirewall.isPermissible(NONEXISTENT_HOSTNAME),
+ "firewall allowed host '" + NONEXISTENT_HOSTNAME + "' rather
than rejecting as malformed. " +
+ "If `host " + NONEXISTENT_HOSTNAME + "` works locally,
this test should have been skipped.");
}
@Test
@@ -130,9 +114,9 @@ public class FileBasedClusterNodeFirewallTest {
@Test
public void testIsPermissibleWithEmptyConfigWithMalformedData() {
assumeTrue(badHostsDoNotResolve);
- assertTrue("firewall did not allow malformed host '" +
NONEXISTENT_HOSTNAME + "' under permissive configs. If " +
- "`host " + NONEXISTENT_HOSTNAME + "` works locally,
this test should have been skipped.",
- acceptAllFirewall.isPermissible(NONEXISTENT_HOSTNAME));
+ assertTrue(acceptAllFirewall.isPermissible(NONEXISTENT_HOSTNAME),
+ "firewall did not allow malformed host '" +
NONEXISTENT_HOSTNAME + "' under permissive configs. " +
+ "If `host " + NONEXISTENT_HOSTNAME + "` works locally,
this test should have been skipped.");
}
}
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/integration/ClusterConnectionIT.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/integration/ClusterConnectionIT.java
index 3980865fa5..1cadb7a0ab 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/integration/ClusterConnectionIT.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/integration/ClusterConnectionIT.java
@@ -32,34 +32,36 @@ import
org.apache.nifi.cluster.coordination.node.DisconnectionCode;
import org.apache.nifi.cluster.coordination.node.NodeConnectionState;
import org.apache.nifi.cluster.coordination.node.NodeConnectionStatus;
import org.apache.nifi.cluster.protocol.NodeIdentifier;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
public class ClusterConnectionIT {
private Cluster cluster;
- @BeforeClass
+ @BeforeAll
public static void setup() {
System.setProperty("nifi.properties.file.path",
"src/test/resources/conf/nifi.properties");
}
- @Before
+ @BeforeEach
public void createCluster() throws IOException {
cluster = new Cluster();
cluster.start();
}
- @After
+ @AfterEach
public void destroyCluster() {
if (cluster != null) {
cluster.stop();
}
}
- @Test(timeout = 20000)
- public void testSingleNode() throws InterruptedException {
+ @Test
+ @Timeout(value = 20)
+ public void testSingleNode() {
final Node firstNode = cluster.createNode();
firstNode.waitUntilConnected(10, TimeUnit.SECONDS);
@@ -67,8 +69,9 @@ public class ClusterConnectionIT {
firstNode.waitUntilElectedForRole(ClusterRoles.PRIMARY_NODE, 10,
TimeUnit.SECONDS);
}
- @Test(timeout = 60000)
- public void testThreeNodeCluster() throws InterruptedException {
+ @Test
+ @Timeout(value = 60)
+ public void testThreeNodeCluster() {
cluster.createNode();
cluster.createNode();
cluster.createNode();
@@ -83,7 +86,8 @@ public class ClusterConnectionIT {
System.out.println("\n\n");
}
- @Test(timeout = 60000)
+ @Test
+ @Timeout(value = 60)
public void testNewCoordinatorElected() throws IOException {
final Node firstNode = cluster.createNode();
final Node secondNode = cluster.createNode();
@@ -97,7 +101,8 @@ public class ClusterConnectionIT {
otherNode.waitUntilElectedForRole(ClusterRoles.CLUSTER_COORDINATOR,
10, TimeUnit.SECONDS);
}
- @Test(timeout = 60000)
+ @Test
+ @Timeout(value = 60)
public void testReconnectGetsCorrectClusterTopology() throws IOException {
final Node firstNode = cluster.createNode();
final Node secondNode = cluster.createNode();
@@ -140,8 +145,9 @@ public class ClusterConnectionIT {
cluster.waitForPrimaryNode(10, TimeUnit.SECONDS);
}
- @Test(timeout = 60000)
- public void testRestartAllNodes() throws IOException, InterruptedException
{
+ @Test
+ @Timeout(value = 60)
+ public void testRestartAllNodes() throws IOException {
final Node firstNode = cluster.createNode();
final Node secondNode = cluster.createNode();
final Node thirdNode = cluster.createNode();
@@ -190,8 +196,9 @@ public class ClusterConnectionIT {
}
- @Test(timeout = 30000)
- public void testHeartbeatsMonitored() throws IOException {
+ @Test
+ @Timeout(value = 30)
+ public void testHeartbeatsMonitored() {
final Node firstNode = cluster.createNode();
final Node secondNode = cluster.createNode();
@@ -210,7 +217,8 @@ public class ClusterConnectionIT {
otherNode.assertNodeConnects(nodeToSuspend.getIdentifier(), 10,
TimeUnit.SECONDS);
}
- @Test(timeout = 60000)
+ @Test
+ @Timeout(value = 60)
public void testNodeInheritsClusterTopologyOnHeartbeat() throws
InterruptedException {
final Node node1 = cluster.createNode();
final Node node2 = cluster.createNode();
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/AccessPolicyEntityMergerTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/AccessPolicyEntityMergerTest.java
index 70a941a0e3..e494a4022a 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/AccessPolicyEntityMergerTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/AccessPolicyEntityMergerTest.java
@@ -22,20 +22,20 @@ import org.apache.nifi.web.api.dto.PermissionsDTO;
import org.apache.nifi.web.api.dto.TenantDTO;
import org.apache.nifi.web.api.entity.AccessPolicyEntity;
import org.apache.nifi.web.api.entity.TenantEntity;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class AccessPolicyEntityMergerTest {
@Test
- public void testMergeAccessPolicy() throws Exception {
+ public void testMergeAccessPolicy() {
final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1",
8080, "host-1", 19998, null, null, null, false);
final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2",
8081, "host-2", 19999, null, null, null, false);
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/RemoteProcessGroupEntityMergerTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/RemoteProcessGroupEntityMergerTest.java
index e519a4b049..ef3a570375 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/RemoteProcessGroupEntityMergerTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/RemoteProcessGroupEntityMergerTest.java
@@ -24,19 +24,19 @@ import
org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO;
import org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO;
import org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusSnapshotDTO;
import org.apache.nifi.web.api.entity.RemoteProcessGroupEntity;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class RemoteProcessGroupEntityMergerTest {
@Test
- public void testMergeRemoteProcessGroups() throws Exception {
+ public void testMergeRemoteProcessGroups() {
final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1",
8080, "host-1", 19998, null, null, null, false);
final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2",
8081, "host-2", 19999, null, null, null, false);
@@ -124,7 +124,7 @@ public class RemoteProcessGroupEntityMergerTest {
}
@Test
- public void testNoPortsAvailableOnOneNode() throws Exception {
+ public void testNoPortsAvailableOnOneNode() {
final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1",
8080, "host-1", 19998, null, null, null, false);
final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2",
8081, "host-2", 19999, null, null, null, false);
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/UserEntityMergerTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/UserEntityMergerTest.java
index 03db8b4786..df438412cd 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/UserEntityMergerTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/UserEntityMergerTest.java
@@ -24,20 +24,20 @@ import org.apache.nifi.web.api.dto.UserDTO;
import org.apache.nifi.web.api.entity.AccessPolicySummaryEntity;
import org.apache.nifi.web.api.entity.TenantEntity;
import org.apache.nifi.web.api.entity.UserEntity;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class UserEntityMergerTest {
@Test
- public void testMergeAccessPolicy() throws Exception {
+ public void testMergeAccessPolicy() {
final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1",
8080, "host-1", 19998, null, null, null, false);
final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2",
8081, "host-2", 19999, null, null, null, false);
diff --git
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/UserGroupEntityMergerTest.java
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/UserGroupEntityMergerTest.java
index cc975cb7b1..bb818d5f16 100644
---
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/UserGroupEntityMergerTest.java
+++
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/UserGroupEntityMergerTest.java
@@ -24,20 +24,20 @@ import org.apache.nifi.web.api.dto.UserGroupDTO;
import org.apache.nifi.web.api.entity.AccessPolicyEntity;
import org.apache.nifi.web.api.entity.TenantEntity;
import org.apache.nifi.web.api.entity.UserGroupEntity;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static org.junit.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class UserGroupEntityMergerTest {
@Test
- public void testMergeAccessPolicy() throws Exception {
+ public void testMergeAccessPolicy() {
final NodeIdentifier node1 = new NodeIdentifier("node-1", "host-1",
8080, "host-1", 19998, null, null, null, false);
final NodeIdentifier node2 = new NodeIdentifier("node-2", "host-2",
8081, "host-2", 19999, null, null, null, false);