Skip to content

Commit

Permalink
NIFI-14051 Replaced type arguments with diamonds, replaced anonymous …
Browse files Browse the repository at this point in the history
…classes with lambdas and replaced certain assertions with more specific assertions.
  • Loading branch information
dan-s1 committed Dec 2, 2024
1 parent 1c9f083 commit 066a51d
Show file tree
Hide file tree
Showing 174 changed files with 2,089 additions and 3,151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -204,16 +203,13 @@ private void computeLineage() {

Map<String, LineageNode> lastEventMap = new HashMap<>(); // maps FlowFile UUID to last event for that FlowFile
final List<ProvenanceEventRecord> sortedRecords = new ArrayList<>(relevantRecords);
sortedRecords.sort(new Comparator<ProvenanceEventRecord>() {
@Override
public int compare(final ProvenanceEventRecord o1, final ProvenanceEventRecord o2) {
// Sort on Event Time, then Event ID.
final int eventTimeComparison = Long.compare(o1.getEventTime(), o2.getEventTime());
if (eventTimeComparison == 0) {
return Long.compare(o1.getEventId(), o2.getEventId());
} else {
return eventTimeComparison;
}
sortedRecords.sort((o1, o2) -> {
// Sort on Event Time, then Event ID.
final int eventTimeComparison = Long.compare(o1.getEventTime(), o2.getEventTime());
if (eventTimeComparison == 0) {
return Long.compare(o1.getEventId(), o2.getEventId());
} else {
return eventTimeComparison;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ private Evaluator<?> buildFunctionEvaluator(final Tree tree, final Evaluator<?>
toStringEvaluator(argEvaluators.get(0), "first argument to contains")), "contains");
}
case IN: {
List<Evaluator<String>> list = new ArrayList<Evaluator<String>>();
List<Evaluator<String>> list = new ArrayList<>();
for (int i = 0; i < argEvaluators.size(); i++) {
list.add(toStringEvaluator(argEvaluators.get(i), i + "th argument to in"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public QueryResult evaluate(final HL7Message message) {
if (value instanceof List) {
possibleValues = (List<Object>) value;
} else if (value instanceof Collection) {
possibleValues = new ArrayList<Object>((Collection<Object>) value);
possibleValues = new ArrayList<>((Collection<Object>) value);
} else {
possibleValues = new ArrayList<>(1);
possibleValues.add(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public Set<String> deadlockedThreads() {
@Override
public Map<Thread.State, Double> threadStatePercentages() {
int totalThreadCount = (Integer) getMetric(THREADS_COUNT);
final Map<Thread.State, Double> threadStatePercentages = new HashMap<Thread.State, Double>();
final Map<Thread.State, Double> threadStatePercentages = new HashMap<>();
for (Thread.State state : Thread.State.values()) {
threadStatePercentages.put(state, (Integer) getMetric(REGISTRY_METRICSET_THREADS + "." + state.name().toLowerCase() + ".count") / (double) totalThreadCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testMissingProperties() {

assertEquals(1, directories.size());

assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0)
assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.getFirst()
.toString());

}
Expand All @@ -84,7 +84,7 @@ public void testBlankProperties() {

assertEquals(1, directories.size());

assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.get(0)
assertEquals(new File(NiFiProperties.DEFAULT_NAR_LIBRARY_DIR).getPath(), directories.getFirst()
.toString());

}
Expand Down Expand Up @@ -116,11 +116,11 @@ public void testValidateProperties() {
properties = loadNiFiProperties("/NiFiProperties/conf/nifi.blank.properties", additionalProperties);

final NiFiProperties test = properties;
assertThrows(Throwable.class, () -> test.validate());
assertThrows(Throwable.class, test::validate);
}

private void assertGoodProperties(final NiFiProperties properties) {
assertDoesNotThrow(() -> properties.validate());
assertDoesNotThrow(properties::validate);
}

@Test
Expand Down Expand Up @@ -150,7 +150,7 @@ public void testAdditionalOidcScopesAreTrimmed() {
}

private NiFiProperties loadNiFiProperties(final String propsPath, final Map<String, String> additionalProperties) {
String realPath = null;
String realPath;
try {
realPath = NiFiPropertiesTest.class.getResource(propsPath).toURI().getPath();
} catch (final URISyntaxException ex) {
Expand Down Expand Up @@ -224,7 +224,7 @@ public void testShouldVerifyExceptionThrownWhenInvalidPortValue() {
additionalProperties.put(NiFiProperties.CLUSTER_NODE_ADDRESS, addressValue);
NiFiProperties properties = loadNiFiProperties("/NiFiProperties/conf/nifi.blank.properties", additionalProperties);

assertThrows(RuntimeException.class, () -> properties.getClusterNodeProtocolAddress());
assertThrows(RuntimeException.class, properties::getClusterNodeProtocolAddress);
}

@Test
Expand All @@ -237,116 +237,106 @@ public void testShouldVerifyExceptionThrownWhenPortValueIsZero() {
additionalProperties.put(NiFiProperties.CLUSTER_NODE_ADDRESS, addressValue);
NiFiProperties properties = loadNiFiProperties("/NiFiProperties/conf/nifi.blank.properties", additionalProperties);

assertThrows(RuntimeException.class, () -> properties.getClusterNodeProtocolAddress());
assertThrows(RuntimeException.class, properties::getClusterNodeProtocolAddress);
}

@Test
public void testShouldHaveReasonableMaxContentLengthValues() {
// Arrange with default values:
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<String, String>() {{
}});
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<>());

// Assert defaults match expectations:
assertNull(properties.getWebMaxContentSize());

// Re-arrange with specific values:
final String size = "size value";
properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<String, String>() {{
put(NiFiProperties.WEB_MAX_CONTENT_SIZE, size);
}});
properties = NiFiProperties.createBasicNiFiProperties(null, Map.of(NiFiProperties.WEB_MAX_CONTENT_SIZE, size));

// Assert specific values are used:
assertEquals(properties.getWebMaxContentSize(), size);
}

@Test
public void testIsZooKeeperTlsConfigurationPresent() {
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<String, String>() {{
put(NiFiProperties.ZOOKEEPER_CLIENT_SECURE, "true");
put(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE, "/a/keystore/filepath/keystore.jks");
put(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_PASSWD, "password");
put(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_TYPE, "JKS");
put(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks");
put(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_PASSWD, "password");
put(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_TYPE, "JKS");
}});
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, Map.of(
NiFiProperties.ZOOKEEPER_CLIENT_SECURE, "true",
NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE, "/a/keystore/filepath/keystore.jks",
NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_PASSWD, "password",
NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_TYPE, "JKS",
NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks",
NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_PASSWD, "password",
NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_TYPE, "JKS"));

assertTrue(properties.isZooKeeperClientSecure());
assertTrue(properties.isZooKeeperTlsConfigurationPresent());
}

@Test
public void testSomeZooKeeperTlsConfigurationIsMissing() {
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<String, String>() {{
put(NiFiProperties.ZOOKEEPER_CLIENT_SECURE, "true");
put(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_PASSWD, "password");
put(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_TYPE, "JKS");
put(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks");
put(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_TYPE, "JKS");
}});
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, Map.of(
NiFiProperties.ZOOKEEPER_CLIENT_SECURE, "true",
NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_PASSWD, "password",
NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_TYPE, "JKS",
NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks",
NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_TYPE, "JKS"));

assertTrue(properties.isZooKeeperClientSecure());
assertFalse(properties.isZooKeeperTlsConfigurationPresent());
}

@Test
public void testZooKeeperTlsPasswordsBlank() {
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<String, String>() {{
put(NiFiProperties.ZOOKEEPER_CLIENT_SECURE, "true");
put(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE, "/a/keystore/filepath/keystore.jks");
put(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_PASSWD, "");
put(NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_TYPE, "JKS");
put(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks");
put(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_PASSWD, "");
put(NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_TYPE, "JKS");
}});
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, Map.of(
NiFiProperties.ZOOKEEPER_CLIENT_SECURE, "true",
NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE, "/a/keystore/filepath/keystore.jks",
NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_PASSWD, "",
NiFiProperties.ZOOKEEPER_SECURITY_KEYSTORE_TYPE, "JKS",
NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks",
NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_PASSWD, "",
NiFiProperties.ZOOKEEPER_SECURITY_TRUSTSTORE_TYPE, "JKS"));

assertTrue(properties.isZooKeeperClientSecure());
assertTrue(properties.isZooKeeperTlsConfigurationPresent());
}

@Test
public void testKeystorePasswordIsMissing() {
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<String, String>() {{
put(NiFiProperties.SECURITY_KEYSTORE, "/a/keystore/filepath/keystore.jks");
put(NiFiProperties.SECURITY_KEYSTORE_TYPE, "JKS");
put(NiFiProperties.SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks");
put(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD, "");
put(NiFiProperties.SECURITY_TRUSTSTORE_TYPE, "JKS");
}});
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, Map.of(
NiFiProperties.SECURITY_KEYSTORE, "/a/keystore/filepath/keystore.jks",
NiFiProperties.SECURITY_KEYSTORE_TYPE, "JKS",
NiFiProperties.SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks",
NiFiProperties.SECURITY_TRUSTSTORE_PASSWD, "",
NiFiProperties.SECURITY_TRUSTSTORE_TYPE, "JKS"));

assertFalse(properties.isTlsConfigurationPresent());
}

@Test
public void testTlsConfigurationIsPresentWithEmptyPasswords() {
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<String, String>() {{
put(NiFiProperties.SECURITY_KEYSTORE, "/a/keystore/filepath/keystore.jks");
put(NiFiProperties.SECURITY_KEYSTORE_PASSWD, "");
put(NiFiProperties.SECURITY_KEYSTORE_TYPE, "JKS");
put(NiFiProperties.SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks");
put(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD, "");
put(NiFiProperties.SECURITY_TRUSTSTORE_TYPE, "JKS");
}});
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, Map.of(
NiFiProperties.SECURITY_KEYSTORE, "/a/keystore/filepath/keystore.jks",
NiFiProperties.SECURITY_KEYSTORE_PASSWD, "",
NiFiProperties.SECURITY_KEYSTORE_TYPE, "JKS",
NiFiProperties.SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks",
NiFiProperties.SECURITY_TRUSTSTORE_PASSWD, "",
NiFiProperties.SECURITY_TRUSTSTORE_TYPE, "JKS"));

assertTrue(properties.isTlsConfigurationPresent());
}

@Test
public void testTlsConfigurationIsNotPresentWithPropertiesMissing() {
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<String, String>() {{
put(NiFiProperties.SECURITY_KEYSTORE_PASSWD, "password");
put(NiFiProperties.SECURITY_KEYSTORE_TYPE, "JKS");
put(NiFiProperties.SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks");
}});
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, Map.of(
NiFiProperties.SECURITY_KEYSTORE_PASSWD, "password",
NiFiProperties.SECURITY_KEYSTORE_TYPE, "JKS",
NiFiProperties.SECURITY_TRUSTSTORE, "/a/truststore/filepath/truststore.jks"));

assertFalse(properties.isTlsConfigurationPresent());
}

@Test
public void testTlsConfigurationIsNotPresentWithNoProperties() {
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<String, String>() {{
}});
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties(null, new HashMap<>());

assertFalse(properties.isTlsConfigurationPresent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public enum RecordFieldType {
MAP("map", null, new MapDataType(null));


private static final Map<String, RecordFieldType> SIMPLE_NAME_MAP = new HashMap<String, RecordFieldType>();
private static final Map<String, RecordFieldType> SIMPLE_NAME_MAP = new HashMap<>();

static {
for (RecordFieldType value : values()) {
Expand Down
Loading

0 comments on commit 066a51d

Please sign in to comment.