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 2023/01/10 18:54:22 UTC
[nifi] branch main updated: NIFI-9167 Converted remaining nifi-framework tests to JUnit 5
This is an automated email from the ASF dual-hosted git repository.
mattyb149 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 0d9dc6c540 NIFI-9167 Converted remaining nifi-framework tests to JUnit 5
0d9dc6c540 is described below
commit 0d9dc6c540a54edf5fd83f28b89f63c1cfb75486
Author: exceptionfactory <ex...@apache.org>
AuthorDate: Wed Jan 4 11:21:42 2023 -0600
NIFI-9167 Converted remaining nifi-framework tests to JUnit 5
NIFI-9167 Addressed feedback and improved tests using TempDir
Signed-off-by: Matthew Burgess <ma...@apache.org>
This closes #6823
---
.../nifi/documentation/html/XmlValidator.java | 18 +-
.../CompositeUserGroupProviderTestBase.java | 16 +-
.../cluster/integration/ClusterConnectionIT.java | 2 +-
.../org/apache/nifi/cluster/integration/Node.java | 9 +-
.../repository/TestStandardProvenanceReporter.java | 62 -------
.../nifi/controller/repository/util/DiskUtils.java | 26 +--
.../StandardControllerServiceProviderIT.java | 6 +-
.../zookeeper/TestZooKeeperStateProvider.java | 4 +-
.../analytics/TestConnectionStatusAnalytics.java | 164 +++++++-----------
.../AbstractStatusHistoryRepositoryTest.java | 190 +++++++++++----------
.../nifi/integration/FrameworkIntegrationTest.java | 14 +-
.../flow/mapping/NiFiRegistryFlowMapperTest.java | 22 +--
.../AbstractNativeLibHandlingClassLoaderTest.java | 102 ++---------
.../apache/nifi/nar/LoadNativeLibAspectTest.java | 14 +-
.../org/apache/nifi/nar/NarBundleUtilTest.java | 13 +-
.../claim/TestStandardResourceClaimManager.java | 96 +----------
...iFiWebApiTest.java => NiFiWebApiFlowUtils.java} | 7 +-
.../accesscontrol/AccessControlHelper.java | 6 +-
.../nifi/web/controller/SearchResultMatcher.java | 2 +-
.../requests/ContentLengthFilterTest.groovy | 8 -
20 files changed, 248 insertions(+), 533 deletions(-)
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java
index 4e6f8c44ef..44c0a4846c 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/XmlValidator.java
@@ -19,10 +19,12 @@ package org.apache.nifi.documentation.html;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
-import org.apache.nifi.xml.processing.ProcessingException;
import org.apache.nifi.xml.processing.parsers.DocumentProvider;
import org.apache.nifi.xml.processing.parsers.StandardDocumentProvider;
-import org.junit.Assert;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class XmlValidator {
private static final String DOCTYPE = "<!DOCTYPE html>";
@@ -36,19 +38,15 @@ public class XmlValidator {
*/
public static void assertXmlValid(String xml) {
final String html = xml.replace(DOCTYPE, EMPTY);
- try {
- final DocumentProvider provider = new StandardDocumentProvider();
- provider.parse(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8)));
- } catch (final ProcessingException e) {
- Assert.fail(e.getMessage());
- }
+ final DocumentProvider provider = new StandardDocumentProvider();
+ assertDoesNotThrow(() -> provider.parse(new ByteArrayInputStream(html.getBytes(StandardCharsets.UTF_8))));
}
public static void assertContains(String original, String subword) {
- Assert.assertTrue(original + " did not contain: " + subword, original.contains(subword));
+ assertTrue(original.contains(subword), original + " did not contain: " + subword);
}
public static void assertNotContains(String original, String subword) {
- Assert.assertFalse(original + " did contain: " + subword, original.contains(subword));
+ assertFalse(original.contains(subword), original + " did contain: " + subword);
}
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization-providers/src/test/java/org/apache/nifi/authorization/CompositeUserGroupProviderTestBase.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization-providers/src/test/java/org/apache/nifi/authorization/CompositeUserGroupProviderTestBase.java
index ce6c9ac50f..a7d7308741 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization-providers/src/test/java/org/apache/nifi/authorization/CompositeUserGroupProviderTestBase.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization-providers/src/test/java/org/apache/nifi/authorization/CompositeUserGroupProviderTestBase.java
@@ -19,7 +19,6 @@ package org.apache.nifi.authorization;
import org.apache.nifi.attribute.expression.language.StandardPropertyValue;
import org.apache.nifi.components.PropertyValue;
import org.apache.nifi.parameter.ParameterLookup;
-import org.junit.Assert;
import java.util.LinkedHashMap;
import java.util.Map;
@@ -29,6 +28,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.apache.nifi.authorization.CompositeUserGroupProvider.PROP_USER_GROUP_PROVIDER_PREFIX;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.eq;
@@ -83,7 +83,7 @@ public class CompositeUserGroupProviderTestBase {
final UserAndGroups user1AndGroups = userGroupProvider.getUserAndGroups(USER_1_IDENTITY);
assertNotNull(user1AndGroups);
assertNotNull(user1AndGroups.getUser());
- Assert.assertEquals(1, user1AndGroups.getGroups().size());
+ assertEquals(1, user1AndGroups.getGroups().size());
final UserAndGroups user2AndGroups = userGroupProvider.getUserAndGroups(USER_2_IDENTITY);
assertNotNull(user2AndGroups);
@@ -92,7 +92,7 @@ public class CompositeUserGroupProviderTestBase {
// groups
assertNotNull(userGroupProvider.getGroup(GROUP_1_IDENTIFIER));
- Assert.assertEquals(1, userGroupProvider.getGroup(GROUP_1_IDENTIFIER).getUsers().size());
+ assertEquals(1, userGroupProvider.getGroup(GROUP_1_IDENTIFIER).getUsers().size());
}
protected UserGroupProvider getUserGroupProviderTwo() {
@@ -115,11 +115,11 @@ public class CompositeUserGroupProviderTestBase {
final UserAndGroups user3AndGroups = userGroupProvider.getUserAndGroups(USER_3_IDENTITY);
assertNotNull(user3AndGroups);
assertNotNull(user3AndGroups.getUser());
- Assert.assertEquals(1, user3AndGroups.getGroups().size());
+ assertEquals(1, user3AndGroups.getGroups().size());
// groups
assertNotNull(userGroupProvider.getGroup(GROUP_2_IDENTIFIER));
- Assert.assertEquals(1, userGroupProvider.getGroup(GROUP_2_IDENTIFIER).getUsers().size());
+ assertEquals(1, userGroupProvider.getGroup(GROUP_2_IDENTIFIER).getUsers().size());
}
protected UserGroupProvider getConflictingUserGroupProvider() {
@@ -146,7 +146,7 @@ public class CompositeUserGroupProviderTestBase {
final UserAndGroups user1AndGroups = userGroupProvider.getUserAndGroups(USER_1_IDENTITY);
assertNotNull(user1AndGroups);
assertNotNull(user1AndGroups.getUser());
- Assert.assertEquals(1, user1AndGroups.getGroups().size());
+ assertEquals(1, user1AndGroups.getGroups().size());
}
protected UserGroupProvider getCollaboratingUserGroupProvider() {
@@ -170,11 +170,11 @@ public class CompositeUserGroupProviderTestBase {
final UserAndGroups user4AndGroups = userGroupProvider.getUserAndGroups(USER_4_IDENTITY);
assertNotNull(user4AndGroups);
assertNotNull(user4AndGroups.getUser());
- Assert.assertEquals(1, user4AndGroups.getGroups().size());
+ assertEquals(1, user4AndGroups.getGroups().size());
// groups
assertNotNull(userGroupProvider.getGroup(GROUP_2_IDENTIFIER));
- Assert.assertEquals(2, userGroupProvider.getGroup(GROUP_2_IDENTIFIER).getUsers().size());
+ assertEquals(2, userGroupProvider.getGroup(GROUP_2_IDENTIFIER).getUsers().size());
}
protected void mockProperties(final AuthorizerConfigurationContext configurationContext) {
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 1cadb7a0ab..3ac476e03c 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
@@ -17,7 +17,7 @@
package org.apache.nifi.cluster.integration;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import java.util.HashMap;
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/integration/Node.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/integration/Node.java
index 035a57aaad..c0046b84fe 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/integration/Node.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/integration/Node.java
@@ -61,10 +61,10 @@ import org.apache.nifi.reporting.Severity;
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.mockito.Mockito;
import java.io.IOException;
+import java.io.UncheckedIOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.util.ArrayList;
@@ -76,6 +76,8 @@ import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
public class Node {
private final NodeIdentifier nodeId;
private final NiFiProperties nodeProperties;
@@ -299,8 +301,7 @@ public class Node {
return new NodeClusterCoordinator(protocolSenderListener, eventReporter, electionManager, flowElection, null,
revisionManager, nodeProperties, extensionManager, protocolSender);
} catch (IOException e) {
- Assert.fail(e.toString());
- return null;
+ throw new UncheckedIOException(e);
}
}
@@ -382,7 +383,7 @@ public class Node {
* @param nodeId id of the node
*/
public void assertNodeIsConnected(final NodeIdentifier nodeId) {
- Assert.assertEquals(NodeConnectionState.CONNECTED, getClusterCoordinator().getConnectionStatus(nodeId).getState());
+ assertEquals(NodeConnectionState.CONNECTED, getClusterCoordinator().getConnectionStatus(nodeId).getState());
}
/**
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardProvenanceReporter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardProvenanceReporter.java
deleted file mode 100644
index 43eead433e..0000000000
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardProvenanceReporter.java
+++ /dev/null
@@ -1,62 +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.controller.repository;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.nifi.flowfile.FlowFile;
-import org.apache.nifi.provenance.ProvenanceEventRecord;
-import org.apache.nifi.provenance.ProvenanceEventRepository;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-
-public class TestStandardProvenanceReporter {
-
- @Test
- @Disabled
- public void testDuplicatesIgnored() {
- final ProvenanceEventRepository mockRepo = Mockito.mock(ProvenanceEventRepository.class);
- final StandardProvenanceReporter reporter = new StandardProvenanceReporter(null, "1234", "TestProc", mockRepo, null);
-
- final List<FlowFile> parents = new ArrayList<>();
- for (int i = 0; i < 10; i++) {
- final FlowFile ff = new StandardFlowFileRecord.Builder().id(i).addAttribute("uuid", String.valueOf(i)).build();
- parents.add(ff);
- }
-
- final FlowFile flowFile = new StandardFlowFileRecord.Builder().id(10L).addAttribute("uuid", "10").build();
-
- reporter.fork(flowFile, parents);
- reporter.fork(flowFile, parents);
-
- final Set<ProvenanceEventRecord> records = reporter.getEvents();
- assertEquals(11, records.size()); // 1 for each parent in the spawn and 1 for the spawn itself
-
- final FlowFile firstParent = parents.get(0);
- parents.clear();
- parents.add(firstParent);
- reporter.fork(flowFile, parents);
- // 1 more emitted for the spawn event containing the child but not for the parent because that one has already been emitted
- assertEquals(12, reporter.getEvents().size());
- }
-
-}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/util/DiskUtils.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/util/DiskUtils.java
index 3828e5bafb..0dbd3d0b97 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/util/DiskUtils.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/util/DiskUtils.java
@@ -16,35 +16,17 @@
*/
package org.apache.nifi.controller.repository.util;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.File;
public class DiskUtils {
- public static void deleteRecursively(final File toDelete, final int numTries) {
- File unableToDelete = null;
- for (int i = 0; i < numTries; i++) {
- unableToDelete = attemptRecursiveDelete(toDelete);
- if (unableToDelete == null) {
- return;
- }
-
- try {
- Thread.sleep(50L);
- } catch (final Exception e) {
- }
- }
-
- assertNull("Unable to delete " + unableToDelete, unableToDelete);
- assertFalse("Thought that I deleted " + toDelete + " but it still exists", toDelete.exists());
- }
-
public static void deleteRecursively(final File toDelete) {
final File unableToDelete = attemptRecursiveDelete(toDelete);
- assertNull("Unable to delete " + unableToDelete, unableToDelete);
- assertFalse("Thought that I deleted " + toDelete + " but it still exists", toDelete.exists());
+ assertNull(unableToDelete, "Unable to delete " + unableToDelete);
+ assertFalse(toDelete.exists(), "Thought that I deleted " + toDelete + " but it still exists");
}
private static File attemptRecursiveDelete(final File toDelete) {
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/StandardControllerServiceProviderIT.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/StandardControllerServiceProviderIT.java
index 547f7976a8..7a2e4bead0 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/StandardControllerServiceProviderIT.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/service/StandardControllerServiceProviderIT.java
@@ -17,7 +17,7 @@
package org.apache.nifi.controller.service;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.beans.PropertyDescriptor;
import java.util.Collections;
@@ -57,9 +57,9 @@ public class StandardControllerServiceProviderIT {
private static Bundle systemBundle;
private static NiFiProperties niFiProperties;
private static ExtensionDiscoveringManager extensionManager;
- private static VariableRegistry variableRegistry = VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY;
+ private static final VariableRegistry variableRegistry = VariableRegistry.ENVIRONMENT_SYSTEM_REGISTRY;
- private static StateManagerProvider stateManagerProvider = new StateManagerProvider() {
+ private static final StateManagerProvider stateManagerProvider = new StateManagerProvider() {
@Override
public StateManager getStateManager(final String componentId) {
return Mockito.mock(StateManager.class);
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/zookeeper/TestZooKeeperStateProvider.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/zookeeper/TestZooKeeperStateProvider.java
index 75e5e5780e..d57db6afa7 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/zookeeper/TestZooKeeperStateProvider.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/state/providers/zookeeper/TestZooKeeperStateProvider.java
@@ -40,8 +40,8 @@ import java.util.Map;
import java.util.Properties;
import java.util.UUID;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
public class TestZooKeeperStateProvider extends AbstractTestStateProvider {
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/analytics/TestConnectionStatusAnalytics.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/analytics/TestConnectionStatusAnalytics.java
index 09362c7683..ea2c95717e 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/analytics/TestConnectionStatusAnalytics.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/analytics/TestConnectionStatusAnalytics.java
@@ -16,23 +16,22 @@
*/
package org.apache.nifi.controller.status.analytics;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
-import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.time.DateUtils;
@@ -42,26 +41,18 @@ import org.apache.nifi.controller.flow.FlowManager;
import org.apache.nifi.controller.queue.FlowFileQueue;
import org.apache.nifi.controller.repository.FlowFileEvent;
import org.apache.nifi.controller.repository.RepositoryStatusReport;
-import org.apache.nifi.controller.status.history.ConnectionStatusDescriptor;
-import org.apache.nifi.controller.status.history.MetricDescriptor;
import org.apache.nifi.controller.status.history.StatusHistory;
import org.apache.nifi.controller.status.history.StatusHistoryRepository;
-import org.apache.nifi.groups.ProcessGroup;
import org.apache.nifi.nar.StandardExtensionDiscoveringManager;
import org.apache.nifi.nar.SystemBundle;
import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.util.Tuple;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
public class TestConnectionStatusAnalytics {
- private static final Set<MetricDescriptor<?>> CONNECTION_METRICS = Arrays.stream(ConnectionStatusDescriptor.values())
- .map(ConnectionStatusDescriptor::getDescriptor)
- .collect(Collectors.toSet());
-
final Connection connection = Mockito.mock(Connection.class);
final FlowFileEvent flowFileEvent = Mockito.mock(FlowFileEvent.class);
final RepositoryStatusReport repositoryStatusReport = Mockito.mock(RepositoryStatusReport.class);
@@ -80,11 +71,9 @@ public class TestConnectionStatusAnalytics {
StandardExtensionDiscoveringManager extensionManager = new StandardExtensionDiscoveringManager();
extensionManager.discoverExtensions(systemBundle, Collections.emptySet());
- final ProcessGroup processGroup = Mockito.mock(ProcessGroup.class);
final StatusHistory statusHistory = Mockito.mock(StatusHistory.class);
final FlowFileQueue flowFileQueue = Mockito.mock(FlowFileQueue.class);
-
final Set<Connection> connections = new HashSet<>();
final String connectionIdentifier = "1";
connections.add(connection);
@@ -108,7 +97,7 @@ public class TestConnectionStatusAnalytics {
}
public Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> getModelMap( String predictionType, Double score,
- Double targetPrediction, Double variablePrediction){
+ Double targetPrediction, Number variablePrediction){
Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = new HashMap<>();
StatusAnalyticsModel model = Mockito.mock(StatusAnalyticsModel.class);
StatusMetricExtractFunction extractFunction = Mockito.mock(StatusMetricExtractFunction.class);
@@ -120,38 +109,35 @@ public class TestConnectionStatusAnalytics {
Double[][] features = new Double[1][1];
Double[] target = new Double[1];
- when(extractFunction.extractMetric(anyString(),any(StatusHistory.class))).then(new Answer<Tuple<Stream<Double[]>,Stream<Double>>>() {
- @Override
- public Tuple<Stream<Double[]>, Stream<Double>> answer(InvocationOnMock invocationOnMock) throws Throwable {
- return new Tuple<>(Stream.of(features), Stream.of(target));
- }
- });
+ when(extractFunction.extractMetric(anyString(),any(StatusHistory.class))).then(
+ (Answer<Tuple<Stream<Double[]>, Stream<Double>>>) invocationOnMock -> new Tuple<>(Stream.of(features), Stream.of(target))
+ );
when(model.getScores()).thenReturn(scores);
when(model.predict(any(Double[].class))).thenReturn(targetPrediction);
- when(model.predictVariable(anyInt(),any(),any())).thenReturn(variablePrediction);
+ when(model.predictVariable(anyInt(),any(),any())).thenReturn(variablePrediction.doubleValue());
return modelMap;
}
@Test
public void testInvalidModelLowScore() {
- Date now = new Date();
- Long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
- Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("queuedCount",.5,100.0,tomorrowMillis.doubleValue());
+ final Date now = new Date();
+ final long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
+ Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("queuedCount",.5,100.0, tomorrowMillis);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime == -1);
+ assertEquals(-1, countTime);
}
- @Test
+ @Test
public void testInvalidModelNaNScore() {
Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("queuedCount",Double.NaN,Double.NaN,Double.NaN);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime == -1);
+ assertEquals(-1, countTime);
}
@Test
@@ -160,7 +146,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime == -1);
+ assertEquals(-1, countTime);
}
@Test
@@ -169,18 +155,18 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long interval = connectionStatusAnalytics.getIntervalTimeMillis();
assertNotNull(interval);
- assert (interval == 180000);
+ assertEquals(180000, interval);
}
@Test
public void testGetTimeToCountBackpressureMillis() {
- Date now = new Date();
- Long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
- Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("queuedCount",.9,100.0,tomorrowMillis.doubleValue());
+ final Date now = new Date();
+ final long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
+ Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("queuedCount",.9,100.0, tomorrowMillis);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime > 0);
+ assertTrue(countTime > 0);
}
@Test
@@ -189,7 +175,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime == -1);
+ assertEquals(-1, countTime);
}
@Test
@@ -198,7 +184,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime == -1);
+ assertEquals(-1, countTime);
}
@Test
@@ -207,30 +193,25 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime == -1);
+ assertEquals(-1, countTime);
}
@Test
public void testMissingModelGetTimeToCount() {
Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("fakeModel",Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
- try {
- connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent);
- fail();
- }catch(IllegalArgumentException iae){
- assertTrue(true);
- }
+ assertThrows(IllegalArgumentException.class, () -> connectionStatusAnalytics.getTimeToCountBackpressureMillis(connection, flowFileEvent));
}
@Test
public void testGetTimeToBytesBackpressureMillis() {
- Date now = new Date();
- Long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
- Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("queuedBytes",.9,100.0,tomorrowMillis.doubleValue());
+ final Date now = new Date();
+ final long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
+ Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("queuedBytes",.9,100.0, tomorrowMillis);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToBytesBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime > 0);
+ assertTrue(countTime > 0);
}
@Test
@@ -239,7 +220,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToBytesBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime == -1);
+ assertEquals(-1, countTime);
}
@Test
@@ -248,7 +229,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToBytesBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime == -1);
+ assertEquals(-1, countTime);
}
@Test
@@ -257,19 +238,14 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long countTime = connectionStatusAnalytics.getTimeToBytesBackpressureMillis(connection, flowFileEvent);
assertNotNull(countTime);
- assert (countTime == -1);
+ assertEquals(-1, countTime);
}
@Test
public void testMissingModelGetTimeToBytes() {
Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("fakeModel",Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
- try {
- connectionStatusAnalytics.getTimeToBytesBackpressureMillis(connection, flowFileEvent);
- fail();
- }catch(IllegalArgumentException iae){
- assertTrue(true);
- }
+ assertThrows(IllegalArgumentException.class, () -> connectionStatusAnalytics.getTimeToBytesBackpressureMillis(connection, flowFileEvent));
}
@Test
@@ -278,7 +254,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long nextIntervalBytes = connectionStatusAnalytics.getNextIntervalBytes(flowFileEvent);
assertNotNull(nextIntervalBytes);
- assert (nextIntervalBytes > 0);
+ assertTrue(nextIntervalBytes > 0);
}
@Test
@@ -287,7 +263,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long nextIntervalBytes = connectionStatusAnalytics.getNextIntervalBytes(flowFileEvent);
assertNotNull(nextIntervalBytes);
- assert (nextIntervalBytes == 0);
+ assertEquals(0, nextIntervalBytes);
}
@Test
@@ -296,7 +272,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long nextIntervalBytes = connectionStatusAnalytics.getNextIntervalBytes(flowFileEvent);
assertNotNull(nextIntervalBytes);
- assert (nextIntervalBytes == -1);
+ assertEquals(-1, nextIntervalBytes);
}
@Test
@@ -305,19 +281,14 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long nextIntervalBytes = connectionStatusAnalytics.getNextIntervalBytes(flowFileEvent);
assertNotNull(nextIntervalBytes);
- assert (nextIntervalBytes == -1);
+ assertEquals(-1, nextIntervalBytes);
}
@Test
public void testMissingModelNextIntervalBytes() {
Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("fakeModel",Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
- try {
- connectionStatusAnalytics.getNextIntervalBytes(flowFileEvent);
- fail();
- }catch(IllegalArgumentException iae){
- assertTrue(true);
- }
+ assertThrows(IllegalArgumentException.class, () -> connectionStatusAnalytics.getNextIntervalBytes(flowFileEvent));
}
@Test
@@ -326,7 +297,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long nextIntervalBytes = connectionStatusAnalytics.getNextIntervalCount(flowFileEvent);
assertNotNull(nextIntervalBytes);
- assert (nextIntervalBytes > 0);
+ assertTrue(nextIntervalBytes > 0);
}
@Test
@@ -335,7 +306,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long nextIntervalCount = connectionStatusAnalytics.getNextIntervalCount(flowFileEvent);
assertNotNull(nextIntervalCount);
- assert (nextIntervalCount == 0);
+ assertEquals(0, nextIntervalCount);
}
@Test
@@ -344,7 +315,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long nextIntervalCount = connectionStatusAnalytics.getNextIntervalCount(flowFileEvent);
assertNotNull(nextIntervalCount);
- assert (nextIntervalCount == -1);
+ assertEquals(-1, nextIntervalCount);
}
@Test
@@ -353,19 +324,14 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long nextIntervalCount = connectionStatusAnalytics.getNextIntervalCount(flowFileEvent);
assertNotNull(nextIntervalCount);
- assert (nextIntervalCount == -1);
+ assertEquals(-1, nextIntervalCount);
}
@Test
public void testMissingModelGetNextIntervalCount() {
Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> modelMap = getModelMap("fakeModel",Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY,Double.POSITIVE_INFINITY);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
- try {
- connectionStatusAnalytics.getNextIntervalCount(flowFileEvent);
- fail();
- }catch(IllegalArgumentException iae){
- assertTrue(true);
- }
+ assertThrows(IllegalArgumentException.class, () -> connectionStatusAnalytics.getNextIntervalCount(flowFileEvent));
}
@Test
@@ -374,7 +340,7 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long percentage = connectionStatusAnalytics.getNextIntervalPercentageUseCount(connection, flowFileEvent);
assertNotNull(percentage);
- assert (percentage == 50);
+ assertEquals(50, percentage);
}
@Test
@@ -383,48 +349,48 @@ public class TestConnectionStatusAnalytics {
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(modelMap);
Long percentage = connectionStatusAnalytics.getNextIntervalPercentageUseBytes(connection, flowFileEvent);
assertNotNull(percentage);
- assert (percentage == 10);
+ assertEquals(10, percentage);
}
@Test
public void testGetScores() {
- Date now = new Date();
- Long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
- Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> bytesModelMap = getModelMap("queuedBytes",.9,10000000.0,tomorrowMillis.doubleValue());
- Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> countModelMap = getModelMap("queuedCount",.9,50.0,tomorrowMillis.doubleValue());
+ final Date now = new Date();
+ final long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
+ Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> bytesModelMap = getModelMap("queuedBytes",.9,10000000.0, tomorrowMillis);
+ Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> countModelMap = getModelMap("queuedCount",.9,50.0, tomorrowMillis);
countModelMap.putAll(bytesModelMap);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(countModelMap);
connectionStatusAnalytics.loadPredictions(repositoryStatusReport);
Map<String,Long> scores = connectionStatusAnalytics.getPredictions();
assertNotNull(scores);
assertFalse(scores.isEmpty());
- assertTrue(scores.get("nextIntervalPercentageUseCount").equals(50L));
- assertTrue(scores.get("nextIntervalBytes").equals(10000000L));
+ assertEquals(50L, scores.get("nextIntervalPercentageUseCount"));
+ assertEquals(10000000L, scores.get("nextIntervalBytes"));
assertTrue(scores.get("timeToBytesBackpressureMillis") > 0);
- assertTrue(scores.get("nextIntervalCount").equals(50L));
- assertTrue(scores.get("nextIntervalPercentageUseBytes").equals(10L));
- assertTrue(scores.get("intervalTimeMillis").equals(180000L));
+ assertEquals(50L, scores.get("nextIntervalCount"));
+ assertEquals(10L, scores.get("nextIntervalPercentageUseBytes"));
+ assertEquals(180000L, scores.get("intervalTimeMillis"));
assertTrue(scores.get("timeToCountBackpressureMillis") > 0);
}
@Test
public void testGetScoresWithBadModel() {
- Date now = new Date();
- Long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
- Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> bytesModelMap = getModelMap("queuedBytes",.9,10000000.0,tomorrowMillis.doubleValue());
- Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> countModelMap = getModelMap("queuedCount",.1,50.0,tomorrowMillis.doubleValue());
+ final Date now = new Date();
+ final long tomorrowMillis = DateUtils.addDays(now,1).toInstant().toEpochMilli();
+ Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> bytesModelMap = getModelMap("queuedBytes",.9,10000000.0, tomorrowMillis);
+ Map<String, Tuple<StatusAnalyticsModel, StatusMetricExtractFunction>> countModelMap = getModelMap("queuedCount",.1,50.0, tomorrowMillis);
countModelMap.putAll(bytesModelMap);
ConnectionStatusAnalytics connectionStatusAnalytics = getConnectionStatusAnalytics(countModelMap);
connectionStatusAnalytics.loadPredictions(repositoryStatusReport);
Map<String,Long> scores = connectionStatusAnalytics.getPredictions();
assertNotNull(scores);
assertFalse(scores.isEmpty());
- assertTrue(scores.get("nextIntervalPercentageUseCount").equals(-1L));
- assertTrue(scores.get("nextIntervalBytes").equals(10000000L));
+ assertEquals(-1L, scores.get("nextIntervalPercentageUseCount"));
+ assertEquals(10000000L, scores.get("nextIntervalBytes"));
assertTrue(scores.get("timeToBytesBackpressureMillis") > 0);
- assertTrue(scores.get("nextIntervalCount").equals(-1L));
- assertTrue(scores.get("nextIntervalPercentageUseBytes").equals(10L));
- assertTrue(scores.get("intervalTimeMillis").equals(180000L));
- assertTrue(scores.get("timeToCountBackpressureMillis") == -1);
+ assertEquals(-1L, scores.get("nextIntervalCount"));
+ assertEquals(10L, scores.get("nextIntervalPercentageUseBytes"));
+ assertEquals(180000L, scores.get("intervalTimeMillis"));
+ assertEquals(-1, scores.get("timeToCountBackpressureMillis"));
}
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/AbstractStatusHistoryRepositoryTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/AbstractStatusHistoryRepositoryTest.java
index 6288080e85..ceaff098e1 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/AbstractStatusHistoryRepositoryTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/status/history/AbstractStatusHistoryRepositoryTest.java
@@ -22,7 +22,6 @@ import org.apache.nifi.controller.status.ProcessGroupStatus;
import org.apache.nifi.controller.status.ProcessorStatus;
import org.apache.nifi.controller.status.RemoteProcessGroupStatus;
import org.apache.nifi.controller.status.StorageStatus;
-import org.junit.Assert;
import java.util.Arrays;
import java.util.Collections;
@@ -32,6 +31,9 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
public abstract class AbstractStatusHistoryRepositoryTest {
protected static final String ROOT_GROUP_ID = "697199b5-8318-4004-8e18-75c6e882f29e";
protected static final String CHILD_GROUP_ID = "fc4aef2e-84d6-4007-9e67-c53050d22398";
@@ -184,102 +186,102 @@ public abstract class AbstractStatusHistoryRepositoryTest {
}
protected void assertStatusHistoryIsEmpty(final StatusHistory statusHistory) {
- Assert.assertTrue(statusHistory.getStatusSnapshots().isEmpty());
+ assertTrue(statusHistory.getStatusSnapshots().isEmpty());
}
protected void assertRootProcessGroupStatusSnapshot(final StatusSnapshot snapshot) {
- Assert.assertEquals(9L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_READ.getDescriptor()).longValue());
- Assert.assertEquals(10L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_WRITTEN.getDescriptor()).longValue());
- Assert.assertEquals(9L+10L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_TRANSFERRED.getDescriptor()).longValue());
- Assert.assertEquals(2L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(1L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(4L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(3L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(8L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.QUEUED_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(7L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.QUEUED_COUNT.getDescriptor()).longValue());
+ assertEquals(9L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_READ.getDescriptor()).longValue());
+ assertEquals(10L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_WRITTEN.getDescriptor()).longValue());
+ assertEquals(9L+10L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_TRANSFERRED.getDescriptor()).longValue());
+ assertEquals(2L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(1L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(4L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(3L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(8L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.QUEUED_BYTES.getDescriptor()).longValue());
+ assertEquals(7L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.QUEUED_COUNT.getDescriptor()).longValue());
// Information is lost due to nano->micro conversion!
- Assert.assertEquals(Double.valueOf((68000000L + 88000000L)/1000/1000).longValue(), snapshot.getStatusMetric(ProcessGroupStatusDescriptor.TASK_MILLIS.getDescriptor()).longValue());
+ assertEquals(Double.valueOf((68000000L + 88000000L)/1000/1000).longValue(), snapshot.getStatusMetric(ProcessGroupStatusDescriptor.TASK_MILLIS.getDescriptor()).longValue());
}
protected void assertChildProcessGroupStatusSnapshot(final StatusSnapshot snapshot) {
- Assert.assertEquals(29L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_READ.getDescriptor()).longValue());
- Assert.assertEquals(30L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_WRITTEN.getDescriptor()).longValue());
- Assert.assertEquals(29L+30L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_TRANSFERRED.getDescriptor()).longValue());
- Assert.assertEquals(22L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(21L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(24L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(23L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(28L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.QUEUED_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(27L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.QUEUED_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(Double.valueOf((88000000L)/1000/1000).longValue(), snapshot.getStatusMetric(ProcessGroupStatusDescriptor.TASK_MILLIS.getDescriptor()).longValue());
+ assertEquals(29L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_READ.getDescriptor()).longValue());
+ assertEquals(30L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_WRITTEN.getDescriptor()).longValue());
+ assertEquals(29L+30L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.BYTES_TRANSFERRED.getDescriptor()).longValue());
+ assertEquals(22L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(21L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(24L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(23L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(28L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.QUEUED_BYTES.getDescriptor()).longValue());
+ assertEquals(27L, snapshot.getStatusMetric(ProcessGroupStatusDescriptor.QUEUED_COUNT.getDescriptor()).longValue());
+ assertEquals(Double.valueOf((88000000L)/1000/1000).longValue(), snapshot.getStatusMetric(ProcessGroupStatusDescriptor.TASK_MILLIS.getDescriptor()).longValue());
}
protected void assertProcessorStatusSnapshot(final StatusSnapshot snapshot) {
- Assert.assertEquals(65L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_READ.getDescriptor()).longValue());
- Assert.assertEquals(66L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_WRITTEN.getDescriptor()).longValue());
- Assert.assertEquals(65L+66L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_TRANSFERRED.getDescriptor()).longValue());
- Assert.assertEquals(62L, snapshot.getStatusMetric(ProcessorStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(61L, snapshot.getStatusMetric(ProcessorStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(64L, snapshot.getStatusMetric(ProcessorStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(63L, snapshot.getStatusMetric(ProcessorStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(67L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(68L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_MILLIS.getDescriptor()).longValue());
- Assert.assertEquals(68000000L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_NANOS.getDescriptor()).longValue());
- Assert.assertEquals(69L, snapshot.getStatusMetric(ProcessorStatusDescriptor.FLOWFILES_REMOVED.getDescriptor()).longValue());
- Assert.assertEquals(70L, snapshot.getStatusMetric(ProcessorStatusDescriptor.AVERAGE_LINEAGE_DURATION.getDescriptor()).longValue());
- Assert.assertEquals(Double.valueOf(68000000/67).longValue(), snapshot.getStatusMetric(ProcessorStatusDescriptor.AVERAGE_TASK_NANOS.getDescriptor()).longValue());
+ assertEquals(65L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_READ.getDescriptor()).longValue());
+ assertEquals(66L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_WRITTEN.getDescriptor()).longValue());
+ assertEquals(65L+66L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_TRANSFERRED.getDescriptor()).longValue());
+ assertEquals(62L, snapshot.getStatusMetric(ProcessorStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(61L, snapshot.getStatusMetric(ProcessorStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(64L, snapshot.getStatusMetric(ProcessorStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(63L, snapshot.getStatusMetric(ProcessorStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(67L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_COUNT.getDescriptor()).longValue());
+ assertEquals(68L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_MILLIS.getDescriptor()).longValue());
+ assertEquals(68000000L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_NANOS.getDescriptor()).longValue());
+ assertEquals(69L, snapshot.getStatusMetric(ProcessorStatusDescriptor.FLOWFILES_REMOVED.getDescriptor()).longValue());
+ assertEquals(70L, snapshot.getStatusMetric(ProcessorStatusDescriptor.AVERAGE_LINEAGE_DURATION.getDescriptor()).longValue());
+ assertEquals(Double.valueOf(68000000/67).longValue(), snapshot.getStatusMetric(ProcessorStatusDescriptor.AVERAGE_TASK_NANOS.getDescriptor()).longValue());
}
protected void assertProcessorWithCounterStatusSnapshot(final StatusSnapshot snapshot, final boolean withCounter) {
- Assert.assertEquals(85L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_READ.getDescriptor()).longValue());
- Assert.assertEquals(86L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_WRITTEN.getDescriptor()).longValue());
- Assert.assertEquals(85L+86L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_TRANSFERRED.getDescriptor()).longValue());
- Assert.assertEquals(82L, snapshot.getStatusMetric(ProcessorStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(81L, snapshot.getStatusMetric(ProcessorStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(84L, snapshot.getStatusMetric(ProcessorStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(83L, snapshot.getStatusMetric(ProcessorStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(87L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(88L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_MILLIS.getDescriptor()).longValue());
- Assert.assertEquals(88000000L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_NANOS.getDescriptor()).longValue());
- Assert.assertEquals(89L, snapshot.getStatusMetric(ProcessorStatusDescriptor.FLOWFILES_REMOVED.getDescriptor()).longValue());
- Assert.assertEquals(90L, snapshot.getStatusMetric(ProcessorStatusDescriptor.AVERAGE_LINEAGE_DURATION.getDescriptor()).longValue());
- Assert.assertEquals(Double.valueOf(88000000/87).longValue(), snapshot.getStatusMetric(ProcessorStatusDescriptor.AVERAGE_TASK_NANOS.getDescriptor()).longValue());
+ assertEquals(85L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_READ.getDescriptor()).longValue());
+ assertEquals(86L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_WRITTEN.getDescriptor()).longValue());
+ assertEquals(85L+86L, snapshot.getStatusMetric(ProcessorStatusDescriptor.BYTES_TRANSFERRED.getDescriptor()).longValue());
+ assertEquals(82L, snapshot.getStatusMetric(ProcessorStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(81L, snapshot.getStatusMetric(ProcessorStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(84L, snapshot.getStatusMetric(ProcessorStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(83L, snapshot.getStatusMetric(ProcessorStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(87L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_COUNT.getDescriptor()).longValue());
+ assertEquals(88L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_MILLIS.getDescriptor()).longValue());
+ assertEquals(88000000L, snapshot.getStatusMetric(ProcessorStatusDescriptor.TASK_NANOS.getDescriptor()).longValue());
+ assertEquals(89L, snapshot.getStatusMetric(ProcessorStatusDescriptor.FLOWFILES_REMOVED.getDescriptor()).longValue());
+ assertEquals(90L, snapshot.getStatusMetric(ProcessorStatusDescriptor.AVERAGE_LINEAGE_DURATION.getDescriptor()).longValue());
+ assertEquals(Double.valueOf(88000000/87).longValue(), snapshot.getStatusMetric(ProcessorStatusDescriptor.AVERAGE_TASK_NANOS.getDescriptor()).longValue());
final Map<String, ? extends MetricDescriptor<?>> counterMetrics = snapshot.getMetricDescriptors()
.stream().filter(d -> d instanceof CounterMetricDescriptor).collect(Collectors.toMap(d -> d.getLabel(), d -> d));
if (withCounter) {
- Assert.assertEquals(2, counterMetrics.size());
- Assert.assertEquals(97L, snapshot.getStatusMetric(counterMetrics.get("counter1 (5 mins)")).longValue());
- Assert.assertEquals(98L, snapshot.getStatusMetric(counterMetrics.get("counter2 (5 mins)")).longValue());
+ assertEquals(2, counterMetrics.size());
+ assertEquals(97L, snapshot.getStatusMetric(counterMetrics.get("counter1 (5 mins)")).longValue());
+ assertEquals(98L, snapshot.getStatusMetric(counterMetrics.get("counter2 (5 mins)")).longValue());
} else {
- Assert.assertTrue(counterMetrics.isEmpty());
+ assertTrue(counterMetrics.isEmpty());
}
}
protected void assertConnectionStatusSnapshot(final StatusSnapshot snapshot) {
- Assert.assertEquals(102L, snapshot.getStatusMetric(ConnectionStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(101L, snapshot.getStatusMetric(ConnectionStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(106L, snapshot.getStatusMetric(ConnectionStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(105L, snapshot.getStatusMetric(ConnectionStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(104L, snapshot.getStatusMetric(ConnectionStatusDescriptor.QUEUED_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(103L, snapshot.getStatusMetric(ConnectionStatusDescriptor.QUEUED_COUNT.getDescriptor()).longValue());
-
- Assert.assertEquals(103L * 110L, snapshot.getStatusMetric(ConnectionStatusDescriptor.TOTAL_QUEUED_DURATION.getDescriptor()).longValue());
- Assert.assertEquals(111L, snapshot.getStatusMetric(ConnectionStatusDescriptor.MAX_QUEUED_DURATION.getDescriptor()).longValue());
- Assert.assertEquals(110L, snapshot.getStatusMetric(ConnectionStatusDescriptor.AVERAGE_QUEUED_DURATION.getDescriptor()).longValue());
+ assertEquals(102L, snapshot.getStatusMetric(ConnectionStatusDescriptor.INPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(101L, snapshot.getStatusMetric(ConnectionStatusDescriptor.INPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(106L, snapshot.getStatusMetric(ConnectionStatusDescriptor.OUTPUT_BYTES.getDescriptor()).longValue());
+ assertEquals(105L, snapshot.getStatusMetric(ConnectionStatusDescriptor.OUTPUT_COUNT.getDescriptor()).longValue());
+ assertEquals(104L, snapshot.getStatusMetric(ConnectionStatusDescriptor.QUEUED_BYTES.getDescriptor()).longValue());
+ assertEquals(103L, snapshot.getStatusMetric(ConnectionStatusDescriptor.QUEUED_COUNT.getDescriptor()).longValue());
+
+ assertEquals(103L * 110L, snapshot.getStatusMetric(ConnectionStatusDescriptor.TOTAL_QUEUED_DURATION.getDescriptor()).longValue());
+ assertEquals(111L, snapshot.getStatusMetric(ConnectionStatusDescriptor.MAX_QUEUED_DURATION.getDescriptor()).longValue());
+ assertEquals(110L, snapshot.getStatusMetric(ConnectionStatusDescriptor.AVERAGE_QUEUED_DURATION.getDescriptor()).longValue());
}
protected void assertRemoteProcessGroupSnapshot(final StatusSnapshot snapshot) {
- Assert.assertEquals(123000L, snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.SENT_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(122L, snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.SENT_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(125000L, snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.RECEIVED_BYTES.getDescriptor()).longValue());
- Assert.assertEquals(124L, snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.RECEIVED_COUNT.getDescriptor()).longValue());
- Assert.assertEquals(Double.valueOf(125000L/300).longValue(), snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.RECEIVED_BYTES_PER_SECOND.getDescriptor()).longValue());
- Assert.assertEquals(Double.valueOf(123000L/300).longValue(), snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.SENT_BYTES_PER_SECOND.getDescriptor()).longValue());
- Assert.assertEquals(Double.valueOf((123000L+125000L)/300).longValue(), snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.TOTAL_BYTES_PER_SECOND.getDescriptor()).longValue());
- Assert.assertEquals(Double.valueOf(128000L).longValue(), snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.AVERAGE_LINEAGE_DURATION.getDescriptor()).longValue());
+ assertEquals(123000L, snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.SENT_BYTES.getDescriptor()).longValue());
+ assertEquals(122L, snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.SENT_COUNT.getDescriptor()).longValue());
+ assertEquals(125000L, snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.RECEIVED_BYTES.getDescriptor()).longValue());
+ assertEquals(124L, snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.RECEIVED_COUNT.getDescriptor()).longValue());
+ assertEquals(Double.valueOf(125000L/300).longValue(), snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.RECEIVED_BYTES_PER_SECOND.getDescriptor()).longValue());
+ assertEquals(Double.valueOf(123000L/300).longValue(), snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.SENT_BYTES_PER_SECOND.getDescriptor()).longValue());
+ assertEquals(Double.valueOf((123000L+125000L)/300).longValue(), snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.TOTAL_BYTES_PER_SECOND.getDescriptor()).longValue());
+ assertEquals(Double.valueOf(128000L).longValue(), snapshot.getStatusMetric(RemoteProcessGroupStatusDescriptor.AVERAGE_LINEAGE_DURATION.getDescriptor()).longValue());
}
protected NodeStatus givenNodeStatus(final int number) {
@@ -353,26 +355,26 @@ public abstract class AbstractStatusHistoryRepositoryTest {
protected void assertNodeStatusHistory(final StatusSnapshot snapshot) {
// Default metrics
- Assert.assertEquals(11, snapshot.getStatusMetric(NodeStatusDescriptor.FREE_HEAP.getDescriptor()).longValue());
- Assert.assertEquals(12, snapshot.getStatusMetric(NodeStatusDescriptor.USED_HEAP.getDescriptor()).longValue());
- Assert.assertEquals(13, snapshot.getStatusMetric(NodeStatusDescriptor.HEAP_UTILIZATION.getDescriptor()).longValue());
- Assert.assertEquals(14, snapshot.getStatusMetric(NodeStatusDescriptor.FREE_NON_HEAP.getDescriptor()).longValue());
- Assert.assertEquals(15, snapshot.getStatusMetric(NodeStatusDescriptor.USED_NON_HEAP.getDescriptor()).longValue());
- Assert.assertEquals(16, snapshot.getStatusMetric(NodeStatusDescriptor.OPEN_FILE_HANDLES.getDescriptor()).longValue());
- Assert.assertEquals(17000000, snapshot.getStatusMetric(NodeStatusDescriptor.PROCESSOR_LOAD_AVERAGE.getDescriptor()).longValue());
- Assert.assertEquals(18, snapshot.getStatusMetric(NodeStatusDescriptor.TOTAL_THREADS.getDescriptor()).longValue());
- Assert.assertEquals(19, snapshot.getStatusMetric(NodeStatusDescriptor.EVENT_DRIVEN_THREADS.getDescriptor()).longValue());
- Assert.assertEquals(20, snapshot.getStatusMetric(NodeStatusDescriptor.TIME_DRIVEN_THREADS.getDescriptor()).longValue());
+ assertEquals(11, snapshot.getStatusMetric(NodeStatusDescriptor.FREE_HEAP.getDescriptor()).longValue());
+ assertEquals(12, snapshot.getStatusMetric(NodeStatusDescriptor.USED_HEAP.getDescriptor()).longValue());
+ assertEquals(13, snapshot.getStatusMetric(NodeStatusDescriptor.HEAP_UTILIZATION.getDescriptor()).longValue());
+ assertEquals(14, snapshot.getStatusMetric(NodeStatusDescriptor.FREE_NON_HEAP.getDescriptor()).longValue());
+ assertEquals(15, snapshot.getStatusMetric(NodeStatusDescriptor.USED_NON_HEAP.getDescriptor()).longValue());
+ assertEquals(16, snapshot.getStatusMetric(NodeStatusDescriptor.OPEN_FILE_HANDLES.getDescriptor()).longValue());
+ assertEquals(17000000, snapshot.getStatusMetric(NodeStatusDescriptor.PROCESSOR_LOAD_AVERAGE.getDescriptor()).longValue());
+ assertEquals(18, snapshot.getStatusMetric(NodeStatusDescriptor.TOTAL_THREADS.getDescriptor()).longValue());
+ assertEquals(19, snapshot.getStatusMetric(NodeStatusDescriptor.EVENT_DRIVEN_THREADS.getDescriptor()).longValue());
+ assertEquals(20, snapshot.getStatusMetric(NodeStatusDescriptor.TIME_DRIVEN_THREADS.getDescriptor()).longValue());
// Storage metrics
- Assert.assertEquals(21, snapshot.getStatusMetric(getDescriptor(snapshot, "contentStorage1Used")).longValue());
- Assert.assertEquals(22, snapshot.getStatusMetric(getDescriptor(snapshot, "contentStorage1Free")).longValue());
- Assert.assertEquals(23, snapshot.getStatusMetric(getDescriptor(snapshot, "contentStorage2Used")).longValue());
- Assert.assertEquals(24, snapshot.getStatusMetric(getDescriptor(snapshot, "contentStorage2Free")).longValue());
- Assert.assertEquals(25, snapshot.getStatusMetric(getDescriptor(snapshot, "provenanceStorage3Used")).longValue());
- Assert.assertEquals(26, snapshot.getStatusMetric(getDescriptor(snapshot, "provenanceStorage3Free")).longValue());
- Assert.assertEquals(27, snapshot.getStatusMetric(getDescriptor(snapshot, "provenanceStorage4Used")).longValue());
- Assert.assertEquals(28, snapshot.getStatusMetric(getDescriptor(snapshot, "provenanceStorage4Free")).longValue());
+ assertEquals(21, snapshot.getStatusMetric(getDescriptor(snapshot, "contentStorage1Used")).longValue());
+ assertEquals(22, snapshot.getStatusMetric(getDescriptor(snapshot, "contentStorage1Free")).longValue());
+ assertEquals(23, snapshot.getStatusMetric(getDescriptor(snapshot, "contentStorage2Used")).longValue());
+ assertEquals(24, snapshot.getStatusMetric(getDescriptor(snapshot, "contentStorage2Free")).longValue());
+ assertEquals(25, snapshot.getStatusMetric(getDescriptor(snapshot, "provenanceStorage3Used")).longValue());
+ assertEquals(26, snapshot.getStatusMetric(getDescriptor(snapshot, "provenanceStorage3Free")).longValue());
+ assertEquals(27, snapshot.getStatusMetric(getDescriptor(snapshot, "provenanceStorage4Used")).longValue());
+ assertEquals(28, snapshot.getStatusMetric(getDescriptor(snapshot, "provenanceStorage4Free")).longValue());
}
private MetricDescriptor<?> getDescriptor(final StatusSnapshot snapshot, final String field) {
@@ -380,16 +382,16 @@ public abstract class AbstractStatusHistoryRepositoryTest {
}
protected void assertGc1Status(final List<GarbageCollectionStatus> gc1) {
- Assert.assertEquals(1, gc1.size());
+ assertEquals(1, gc1.size());
final GarbageCollectionStatus status = gc1.get(0);
- Assert.assertEquals(31, status.getCollectionCount());
- Assert.assertEquals(32, status.getCollectionMillis());
+ assertEquals(31, status.getCollectionCount());
+ assertEquals(32, status.getCollectionMillis());
}
protected void assertGc2Status(final List<GarbageCollectionStatus> gc2) {
- Assert.assertEquals(1, gc2.size());
+ assertEquals(1, gc2.size());
final GarbageCollectionStatus status = gc2.get(0);
- Assert.assertEquals(41, status.getCollectionCount());
- Assert.assertEquals(42, status.getCollectionMillis());
+ assertEquals(41, status.getCollectionCount());
+ assertEquals(42, status.getCollectionMillis());
}
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/integration/FrameworkIntegrationTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/integration/FrameworkIntegrationTest.java
index b369c9aec9..4bc09f7ba3 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/integration/FrameworkIntegrationTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/integration/FrameworkIntegrationTest.java
@@ -106,7 +106,6 @@ import org.apache.nifi.util.NiFiProperties;
import org.apache.nifi.web.revision.RevisionManager;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.rules.Timeout;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -129,15 +128,12 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
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 FrameworkIntegrationTest {
private static final Logger logger = LoggerFactory.getLogger(FrameworkIntegrationTest.class);
- //@Rule
- public Timeout globalTimeout = Timeout.seconds(20);
-
private ResourceClaimManager resourceClaimManager;
private StandardProcessScheduler processScheduler;
@@ -391,7 +387,7 @@ public class FrameworkIntegrationTest {
}
protected final ProcessorNode createProcessorNode(final String processorType, final ProcessGroup destination) {
- final String uuid = getSimpleTypeName(processorType) + "-" + UUID.randomUUID().toString();
+ final String uuid = getSimpleTypeName(processorType) + "-" + UUID.randomUUID();
final BundleCoordinate bundleCoordinate = SystemBundle.SYSTEM_BUNDLE_COORDINATE;
final ProcessorNode procNode = flowController.getFlowManager().createProcessor(processorType, uuid, bundleCoordinate, Collections.emptySet(), true, true, null);
if (destination != null) {
@@ -406,7 +402,7 @@ public class FrameworkIntegrationTest {
}
protected final ControllerServiceNode createControllerServiceNode(final String controllerServiceType) {
- final String uuid = getSimpleTypeName(controllerServiceType) + "-" + UUID.randomUUID().toString();
+ final String uuid = getSimpleTypeName(controllerServiceType) + "-" + UUID.randomUUID();
final BundleCoordinate bundleCoordinate = SystemBundle.SYSTEM_BUNDLE_COORDINATE;
final ControllerServiceNode serviceNode = flowController.getFlowManager().createControllerService(controllerServiceType, uuid, bundleCoordinate, Collections.emptySet(), true, true, null);
rootProcessGroup.addControllerService(serviceNode);
@@ -561,7 +557,7 @@ public class FrameworkIntegrationTest {
}
}
- assertEquals("Expected to encounter " + count + " Provenance Events of type " + eventType + " but encountered " + encountered, count, encountered);
+ assertEquals(count, encountered, "Expected to encounter " + count + " Provenance Events of type " + eventType + " but encountered " + encountered);
}
protected void triggerOnce(final ProcessorNode processor) throws ExecutionException, InterruptedException {
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapperTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapperTest.java
index 02cbd19865..ad4c67e6fe 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapperTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/registry/flow/mapping/NiFiRegistryFlowMapperTest.java
@@ -104,10 +104,10 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
-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.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
@@ -131,7 +131,7 @@ public class NiFiRegistryFlowMapperTest {
@Mock
private ParameterProvider parameterProvider;
- private NiFiRegistryFlowMapper flowMapper = new NiFiRegistryFlowMapper(extensionManager);
+ private final NiFiRegistryFlowMapper flowMapper = new NiFiRegistryFlowMapper(extensionManager);
private int counter = 1;
@@ -360,9 +360,7 @@ public class NiFiRegistryFlowMapperTest {
final Collection<Parameter> parameters = parameterContext.getParameters().values();
final Set<VersionedParameter> versionedParameters = versionedParameterContext.getParameters();
// parameter order is not deterministic - use unique names to map up matching parameters
- final Iterator<Parameter> parametersIterator = parameters.iterator();
- while (parametersIterator.hasNext()) {
- final Parameter parameter = parametersIterator.next();
+ for (Parameter parameter : parameters) {
final Iterator<VersionedParameter> versionedParameterIterator = versionedParameters.iterator();
while (versionedParameterIterator.hasNext()) {
final VersionedParameter versionedParameter = versionedParameterIterator.next();
@@ -373,7 +371,7 @@ public class NiFiRegistryFlowMapperTest {
}
}
}
- assertTrue("Failed to match parameters by unique name", versionedParameters.isEmpty());
+ assertTrue(versionedParameters.isEmpty(), "Failed to match parameters by unique name");
}
@@ -701,9 +699,7 @@ public class NiFiRegistryFlowMapperTest {
// first verify the number of processors matches
assertEquals(processorNodes.size(), versionedProcessors.size());
// processor order is not deterministic - use unique names to map up matching processors
- final Iterator<ProcessorNode> processorNodesIterator = processorNodes.iterator();
- while (processorNodesIterator.hasNext()) {
- final ProcessorNode processorNode = processorNodesIterator.next();
+ for (ProcessorNode processorNode : processorNodes) {
final Iterator<VersionedProcessor> versionedProcessorIterator = versionedProcessors.iterator();
while (versionedProcessorIterator.hasNext()) {
final VersionedProcessor versionedProcessor = versionedProcessorIterator.next();
@@ -714,7 +710,7 @@ public class NiFiRegistryFlowMapperTest {
}
}
}
- assertTrue("Failed to match processors by unique name", versionedProcessors.isEmpty());
+ assertTrue(versionedProcessors.isEmpty(), "Failed to match processors by unique name");
// verify connections
final Set<Connection> connections = processGroup.getConnections();
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/AbstractNativeLibHandlingClassLoaderTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/AbstractNativeLibHandlingClassLoaderTest.java
index 01fd49f818..673b6bf30b 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/AbstractNativeLibHandlingClassLoaderTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/AbstractNativeLibHandlingClassLoaderTest.java
@@ -16,10 +16,11 @@
*/
package org.apache.nifi.nar;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.io.File;
import java.io.IOException;
@@ -28,7 +29,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Comparator;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -37,19 +38,20 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
+@ExtendWith(MockitoExtension.class)
public class AbstractNativeLibHandlingClassLoaderTest {
public static final String NATIVE_LIB_NAME = "native_lib";
@Mock
private AbstractNativeLibHandlingClassLoader testSubjectHelper;
+ @TempDir
private Path tempDirectory;
private String javaLibraryPath = "";
@@ -61,26 +63,8 @@ public class AbstractNativeLibHandlingClassLoaderTest {
private boolean isOsMaxOsx;
private boolean isOsLinux;
- @Before
- public void setUp() throws Exception {
- initMocks(this);
- tempDirectory = Files.createTempDirectory(this.getClass().getSimpleName());
- }
-
- @After
- public void tearDown() throws Exception {
- tempDirectory.toFile().deleteOnExit();
-
- Files.walk(tempDirectory)
- .sorted(Comparator.reverseOrder())
- .map(Path::toFile)
- .forEach(File::delete);
-
- }
-
@Test
public void testFindLibraryShouldReturnNullOnWindowsWhenNoDLLAvailable() throws Exception {
- // GIVEN
isOsWindows = true;
createTempFile("so");
@@ -90,14 +74,11 @@ public class AbstractNativeLibHandlingClassLoaderTest {
String expected = null;
- // WHEN
- // THEN
testFindLibrary(expected);
}
@Test
public void testFindLibraryShouldReturnDLLOnWindows() throws Exception {
- // GIVEN
isOsWindows = true;
Path expectedNativeLib = createTempFile("dll");
@@ -108,28 +89,22 @@ public class AbstractNativeLibHandlingClassLoaderTest {
String expected = expectedNativeLib.toFile().getAbsolutePath();
- // WHEN
- // THEN
testFindLibrary(expected);
}
@Test
public void testFindLibraryShouldReturnNullOnMacWhenNoDylibOrSoAvailable() throws Exception {
- // GIVEN
isOsMaxOsx = true;
createTempFile("dll");
String expected = null;
- // WHEN
- // THEN
testFindLibrary(expected);
}
@Test
public void testFindLibraryShouldReturnDylibOnMac() throws Exception {
- // GIVEN
isOsMaxOsx = true;
createTempFile("dll");
@@ -140,14 +115,11 @@ public class AbstractNativeLibHandlingClassLoaderTest {
String expected = expectedNativeLib.toFile().getAbsolutePath();
- // WHEN
- // THEN
testFindLibrary(expected);
}
@Test
public void testFindLibraryShouldReturnLibDylibOnMac() throws Exception {
- // GIVEN
isOsMaxOsx = true;
createTempFile("dll");
@@ -157,14 +129,11 @@ public class AbstractNativeLibHandlingClassLoaderTest {
String expected = expectedNativeLib.toFile().getAbsolutePath();
- // WHEN
- // THEN
testFindLibrary(expected);
}
@Test
public void testFindLibraryMayReturnSoOnMac() throws Exception {
- // GIVEN
isOsMaxOsx = true;
createTempFile("dll");
@@ -173,14 +142,11 @@ public class AbstractNativeLibHandlingClassLoaderTest {
String expected = expectedNativeLib.toFile().getAbsolutePath();
- // WHEN
- // THEN
testFindLibrary(expected);
}
@Test
public void testFindLibraryMayReturnLibSoOnMac() throws Exception {
- // GIVEN
isOsMaxOsx = true;
createTempFile("dll");
@@ -188,14 +154,11 @@ public class AbstractNativeLibHandlingClassLoaderTest {
String expected = expectedNativeLib.toFile().getAbsolutePath();
- // WHEN
- // THEN
testFindLibrary(expected);
}
@Test
public void testFindLibraryShouldReturnNullOnLinuxWhenNoSoAvailable() throws Exception {
- // GIVEN
isOsLinux = true;
createTempFile("dll");
@@ -204,14 +167,11 @@ public class AbstractNativeLibHandlingClassLoaderTest {
String expected = null;
- // WHEN
- // THEN
testFindLibrary(expected);
}
@Test
public void testFindLibraryShouldReturnSoOnLinux() throws Exception {
- // GIVEN
isOsLinux = true;
createTempFile("dll");
@@ -222,14 +182,11 @@ public class AbstractNativeLibHandlingClassLoaderTest {
String expected = expectedNativeLib.toFile().getAbsolutePath();
- // WHEN
- // THEN
testFindLibrary(expected);
}
@Test
public void testFindLibraryShouldReturnLibSoOnLinux() throws Exception {
- // GIVEN
isOsLinux = true;
createTempFile("dll");
@@ -239,8 +196,6 @@ public class AbstractNativeLibHandlingClassLoaderTest {
String expected = expectedNativeLib.toFile().getAbsolutePath();
- // WHEN
- // THEN
testFindLibrary(expected);
}
@@ -252,10 +207,9 @@ public class AbstractNativeLibHandlingClassLoaderTest {
@Test
public void testFindLibraryShouldReturnLibLocation() throws Exception {
- // GIVEN
File nativeLibDir = mock(File.class);
- nativeLibDirs = Arrays.asList(nativeLibDir);
+ nativeLibDirs = Collections.singletonList(nativeLibDir);
Path libPath = createTempFile("mocked").toAbsolutePath();
when(testSubjectHelper.findLibrary("libName", nativeLibDir)).thenReturn("libLocation");
@@ -265,10 +219,8 @@ public class AbstractNativeLibHandlingClassLoaderTest {
AbstractNativeLibHandlingClassLoader testSubject = createTestSubject();
- // WHEN
String actual = testSubject.findLibrary("libName");
- // THEN
assertEquals(expected, actual);
verify(testSubjectHelper).findLibrary("libName", nativeLibDir);
verify(testSubjectHelper).createTempCopy("libName", "libLocation");
@@ -277,7 +229,6 @@ public class AbstractNativeLibHandlingClassLoaderTest {
@Test
public void testFindLibraryShouldReturnFirstFoundLibLocation() throws Exception {
- // GIVEN
File nativeLibDir1 = mock(File.class);
File nativeLibDir2 = mock(File.class);
File nativeLibDir3 = mock(File.class);
@@ -293,10 +244,8 @@ public class AbstractNativeLibHandlingClassLoaderTest {
AbstractNativeLibHandlingClassLoader testSubject = createTestSubject();
- // WHEN
String actual = testSubject.findLibrary("libName");
- // THEN
assertEquals(expected, actual);
verify(testSubjectHelper).findLibrary("libName", nativeLibDir1);
verify(testSubjectHelper).findLibrary("libName", nativeLibDir2);
@@ -306,10 +255,9 @@ public class AbstractNativeLibHandlingClassLoaderTest {
@Test
public void testFindLibraryShouldReturnCachedLibLocation() throws Exception {
- // GIVEN
File nativeLibDir = mock(File.class);
- nativeLibDirs = Arrays.asList(nativeLibDir);
+ nativeLibDirs = Collections.singletonList(nativeLibDir);
Path cachedLibPath = createTempFile("cached", "mocked").toAbsolutePath();
nativeLibNameToPath.put("libName", cachedLibPath);
@@ -317,20 +265,17 @@ public class AbstractNativeLibHandlingClassLoaderTest {
AbstractNativeLibHandlingClassLoader testSubject = createTestSubject();
String expected = cachedLibPath.toFile().getAbsolutePath();
- // WHEN
String actual = testSubject.findLibrary("libName");
- // THEN
assertEquals(expected, actual);
verifyNoMoreInteractions(testSubjectHelper);
}
@Test
public void testFindLibraryShouldReturnFoundThenCachedLibLocation() throws Exception {
- // GIVEN
File nativeLibDir = mock(File.class);
- nativeLibDirs = Arrays.asList(nativeLibDir);
+ nativeLibDirs = Collections.singletonList(nativeLibDir);
Path libPath = createTempFile("mocked").toAbsolutePath();
when(testSubjectHelper.findLibrary("libName", nativeLibDir)).thenReturn("libLocation");
@@ -340,11 +285,9 @@ public class AbstractNativeLibHandlingClassLoaderTest {
AbstractNativeLibHandlingClassLoader testSubject = createTestSubject();
- // WHEN
String actual1 = testSubject.findLibrary("libName");
String actual2 = testSubject.findLibrary("libName");
- // THEN
assertEquals(expected, actual1);
assertEquals(expected, actual2);
verify(testSubjectHelper).findLibrary("libName", nativeLibDir);
@@ -353,77 +296,62 @@ public class AbstractNativeLibHandlingClassLoaderTest {
}
@Test
- public void testFindLibraryShouldReturnNullWhenLibDirNotRegistered() throws Exception {
- // GIVEN
+ public void testFindLibraryShouldReturnNullWhenLibDirNotRegistered() {
nativeLibDirs = new ArrayList<>();
AbstractNativeLibHandlingClassLoader testSubject = createTestSubject();
String expected = null;
- // WHEN
String actual = testSubject.findLibrary("libName");
- // THEN
assertEquals(expected, actual);
verifyNoMoreInteractions(testSubjectHelper);
}
@Test
- public void testFindLibraryShouldReturnNullWhenLibNotFound() throws Exception {
- // GIVEN
+ public void testFindLibraryShouldReturnNullWhenLibNotFound() {
File nativeLibDir = mock(File.class);
- nativeLibDirs = Arrays.asList(nativeLibDir);
+ nativeLibDirs = Collections.singletonList(nativeLibDir);
when(testSubjectHelper.findLibrary("libName", nativeLibDir)).thenReturn(null);
AbstractNativeLibHandlingClassLoader testSubject = createTestSubject();
String expected = null;
- // WHEN
String actual = testSubject.findLibrary("libName");
- // THEN
assertEquals(expected, actual);
verify(testSubjectHelper).findLibrary("libName", nativeLibDir);
verifyNoMoreInteractions(testSubjectHelper);
}
@Test
- public void testToDirShouldReturnNullForNullInput() throws Exception {
- // GIVEN
+ public void testToDirShouldReturnNullForNullInput() {
File expected = null;
- // WHEN
File actual = createTestSubject().toDir(null);
- // THEN
assertEquals(expected, actual);
}
@Test
public void testToDirShouldReturnParentForFile() throws Exception {
- // GIVEN
Path filePath = createTempFile("mocked").toAbsolutePath();
File expected = filePath.getParent().toFile();
- // WHEN
File actual = createTestSubject().toDir(filePath.toFile());
- // THEN
assertEquals(expected, actual);
}
@Test
public void testToDirShouldReturnDirUnchanged() throws Exception {
- // GIVEN
Path dirPath = createTempFile("mocked").getParent();
File expected = dirPath.toFile();
- // WHEN
File actual = createTestSubject().toDir(dirPath.toFile());
- // THEN
assertEquals(expected, actual);
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/LoadNativeLibAspectTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/LoadNativeLibAspectTest.java
index 6bb1fbf3d6..0a9e6d8780 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/LoadNativeLibAspectTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/LoadNativeLibAspectTest.java
@@ -17,18 +17,18 @@
package org.apache.nifi.nar;
import org.aspectj.lang.ProceedingJoinPoint;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -41,7 +41,7 @@ public class LoadNativeLibAspectTest {
private ProceedingJoinPoint joinPoint;
- @Before
+ @BeforeEach
public void setUp() {
aspect = new LoadNativeLibAspect();
joinPoint = mock(ProceedingJoinPoint.class);
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/NarBundleUtilTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/NarBundleUtilTest.java
index df6a36154f..bba05a3e6b 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/NarBundleUtilTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-nar-utils/src/test/java/org/apache/nifi/nar/NarBundleUtilTest.java
@@ -18,13 +18,14 @@ package org.apache.nifi.nar;
import org.apache.nifi.bundle.BundleCoordinate;
import org.apache.nifi.bundle.BundleDetails;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
public class NarBundleUtilTest {
@@ -92,10 +93,10 @@ public class NarBundleUtilTest {
assertEquals("bbende", narDetails.getBuiltBy());
}
- @Test(expected = IOException.class)
- public void testFromManifestWhenNarDirectoryDoesNotExist() throws IOException {
+ @Test
+ public void testFromManifestWhenNarDirectoryDoesNotExist() {
final File manifest = new File("src/test/resources/nars/nar-does-not-exist");
- NarBundleUtil.fromNarDirectory(manifest);
+ assertThrows(IOException.class, () -> NarBundleUtil.fromNarDirectory(manifest));
}
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-repository-models/src/test/java/org/apache/nifi/controller/repository/claim/TestStandardResourceClaimManager.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-repository-models/src/test/java/org/apache/nifi/controller/repository/claim/TestStandardResourceClaimManager.java
index f4fe120e8d..96dd21416e 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-repository-models/src/test/java/org/apache/nifi/controller/repository/claim/TestStandardResourceClaimManager.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-repository-models/src/test/java/org/apache/nifi/controller/repository/claim/TestStandardResourceClaimManager.java
@@ -17,24 +17,21 @@
package org.apache.nifi.controller.repository.claim;
-import static org.junit.Assert.assertEquals;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import java.util.ArrayList;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
public class TestStandardResourceClaimManager {
-
- @Test(timeout = 10000)
+ @Timeout(10)
+ @Test
public void testGetClaimantCountWhileMarkingDestructable() throws InterruptedException, ExecutionException {
final StandardResourceClaimManager manager = new StandardResourceClaimManager();
@@ -57,83 +54,6 @@ public class TestStandardResourceClaimManager {
assertEquals(0, manager.getClaimantCount(lastClaim));
assertNull(future.getNow(null));
manager.drainDestructableClaims(new ArrayList<>(), 1);
- assertTrue(completedObject == future.get());
- }
-
-
- @Test
- @Ignore("Unit test was created to repeat a concurrency bug in StandardResourceClaimManager. "
- + "However, now that the concurrency bug has been fixed, the test will deadlock. Leaving here for now in case it's valuable before the commit is pushed")
- public void testIncrementAndDecrementThreadSafety() throws InterruptedException {
- final AtomicBoolean waitToRemove = new AtomicBoolean(true);
- final CountDownLatch decrementComplete = new CountDownLatch(1);
-
- final StandardResourceClaimManager manager = new StandardResourceClaimManager() {
- @Override
- protected void removeClaimantCount(final ResourceClaim claim) {
- decrementComplete.countDown();
-
- while (waitToRemove.get()) {
- try {
- Thread.sleep(10L);
- } catch (final InterruptedException ie) {
- Assert.fail("Interrupted while waiting to remove claimant count");
- }
- }
-
- super.removeClaimantCount(claim);
- }
- };
-
- final ResourceClaim resourceClaim = manager.newResourceClaim("container", "section", "id", false, false);
- assertEquals(1, manager.incrementClaimantCount(resourceClaim)); // increment claimant count to 1.
-
- assertEquals(1, manager.getClaimantCount(resourceClaim));
-
- // Decrement the claimant count. This should decrement the count to 0. However, we have 'waitToRemove' set to true,
- // so the manager will not actually remove the claimant count (or return from this method) until we set 'waitToRemove'
- // to false. We do this so that we can increment the claimant count in a separate thread. Because we will be incrementing
- // the count in 1 thread and decrementing it in another thread, the end result should be that the claimant count is still
- // at 1.
- final Runnable decrementCountRunnable = new Runnable() {
- @Override
- public void run() {
- manager.decrementClaimantCount(resourceClaim);
- }
- };
-
- final Runnable incrementCountRunnable = new Runnable() {
- @Override
- public void run() {
- // Wait until the count has been decremented
- try {
- decrementComplete.await();
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail(e.toString());
- }
-
- // Increment the claimant count
- manager.incrementClaimantCount(resourceClaim);
-
- // allow the 'decrement Thread' to complete
- waitToRemove.set(false);
- }
- };
-
- // Start the threads so that the claim count is incremented and decremented at the same time
- final Thread decrementThread = new Thread(decrementCountRunnable);
- final Thread incrementThread = new Thread(incrementCountRunnable);
-
- decrementThread.start();
- incrementThread.start();
-
- // Wait for both threads to complete
- incrementThread.join();
- decrementThread.join();
-
- // claimant count should still be 1, since 1 thread incremented it and 1 thread decremented it!
- assertEquals(1, manager.getClaimantCount(resourceClaim));
+ assertSame(completedObject, future.get());
}
-
}
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/NiFiWebApiTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/NiFiWebApiFlowUtils.java
similarity index 99%
rename from nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/NiFiWebApiTest.java
rename to nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/NiFiWebApiFlowUtils.java
index 3856220b3f..778ebceb83 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/NiFiWebApiTest.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/NiFiWebApiFlowUtils.java
@@ -34,18 +34,13 @@ import org.apache.nifi.web.api.entity.LabelEntity;
import org.apache.nifi.web.api.entity.PortEntity;
import org.apache.nifi.web.api.entity.ProcessGroupEntity;
import org.apache.nifi.web.api.entity.ProcessorEntity;
-import org.junit.Ignore;
import javax.ws.rs.client.Client;
import javax.ws.rs.core.Response;
import java.util.HashSet;
import java.util.Set;
-/**
- *
- */
-@Ignore
-public class NiFiWebApiTest {
+public class NiFiWebApiFlowUtils {
public static void populateFlow(Client client, String baseUrl, NiFiTestUser user, String clientId) throws Exception {
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/AccessControlHelper.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/AccessControlHelper.java
index c03260f270..376ef65323 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/AccessControlHelper.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/integration/accesscontrol/AccessControlHelper.java
@@ -17,7 +17,7 @@
package org.apache.nifi.integration.accesscontrol;
import org.apache.nifi.bundle.Bundle;
-import org.apache.nifi.integration.NiFiWebApiTest;
+import org.apache.nifi.integration.NiFiWebApiFlowUtils;
import org.apache.nifi.integration.util.NiFiTestAuthorizer;
import org.apache.nifi.integration.util.NiFiTestServer;
import org.apache.nifi.integration.util.NiFiTestUser;
@@ -36,7 +36,7 @@ import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Access control test for the dfm user.
@@ -110,7 +110,7 @@ public class AccessControlHelper {
anonymousUser = new NiFiTestUser(server.getClient(), StringUtils.EMPTY);
// populate the initial data flow
- NiFiWebApiTest.populateFlow(server.getClient(), baseUrl, readWriteUser, READ_WRITE_CLIENT_ID);
+ NiFiWebApiFlowUtils.populateFlow(server.getClient(), baseUrl, readWriteUser, READ_WRITE_CLIENT_ID);
}
public NiFiTestUser getReadUser() {
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/SearchResultMatcher.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/SearchResultMatcher.java
index 58d0477973..ba30c1dec9 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/SearchResultMatcher.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/test/java/org/apache/nifi/web/controller/SearchResultMatcher.java
@@ -24,7 +24,7 @@ import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class SearchResultMatcher {
private final Set<ComponentSearchResultDTO> outputPortResults = new HashSet<>();
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/test/groovy/org/apache/nifi/web/security/requests/ContentLengthFilterTest.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/test/groovy/org/apache/nifi/web/security/requests/ContentLengthFilterTest.groovy
index 3eed2c1dc5..82eb941811 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/test/groovy/org/apache/nifi/web/security/requests/ContentLengthFilterTest.groovy
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-security/src/test/groovy/org/apache/nifi/web/security/requests/ContentLengthFilterTest.groovy
@@ -23,7 +23,6 @@ import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.FilterHolder
import org.eclipse.jetty.servlet.ServletContextHandler
import org.eclipse.jetty.servlet.ServletHolder
-import org.junit.BeforeClass
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@@ -62,13 +61,6 @@ class ContentLengthFilterTest {
private LocalConnector localConnector
private ServletContextHandler contextUnderTest
- @BeforeClass
- static void setUpOnce() {
- logger.metaClass.methodMissing = { String name, args ->
- logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
- }
- }
-
@BeforeEach
void setUp() {
createSimpleReadServer()