Skip to content

Commit

Permalink
NIFI-13625 Removed or Replaced System.out.println in Tests (#9150)
Browse files Browse the repository at this point in the history
Signed-off-by: David Handermann <[email protected]>
  • Loading branch information
dan-s1 authored Aug 6, 2024
1 parent c5ed5c5 commit f64e68b
Show file tree
Hide file tree
Showing 51 changed files with 133 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collections;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -68,11 +67,6 @@ public void testGet() throws Exception {
throw new IOException("Unexpected code " + response);
}

Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}

assertEquals(RestChangeIngestor.GET_TEXT, response.body().string());
verify(testNotifier, Mockito.never()).notifyListeners(Mockito.any(ByteBuffer.class));
}
Expand All @@ -93,11 +87,6 @@ public void testFileUploadNewConfig() throws Exception {
throw new IOException("Unexpected code " + response);
}

Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}

assertEquals("The result of notifying listeners:\nMockChangeListener successfully handled the configuration change\n", response.body().string());

verify(testNotifier, Mockito.times(1)).notifyListeners(Mockito.eq(ByteBuffer.wrap(testString.getBytes())));
Expand All @@ -119,11 +108,6 @@ public void testFileUploadSameConfig() throws Exception {
throw new IOException("Unexpected code " + response);
}

Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}

assertEquals("Request received but instance is already running this config.", response.body().string());

verify(testNotifier, Mockito.never()).notifyListeners(Mockito.any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public void testOrderedProperties() throws IOException {
String actualLine = actualReader.readLine();
if (!"#Tue Feb 21 11:03:08 EST 2017".equals(expectedLine)) {
assertEquals(expectedLine, actualLine);
} else {
System.out.println("Skipping timestamp comment line");
}
}
assertNull(actualReader.readLine());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.nifi.parameter.ParameterLookup;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.HashMap;
Expand All @@ -39,6 +41,8 @@

public class TestStandardPreparedQuery {

private static final Logger logger = LoggerFactory.getLogger(TestStandardPreparedQuery.class);

@Test
public void testSimpleReference() {
final Map<String, String> attrs = new HashMap<>();
Expand Down Expand Up @@ -69,7 +73,7 @@ public void test10MIterations() {
assertEquals("world", prepared.evaluateExpressions(new StandardEvaluationContext(attrs), null));
}
final long nanos = System.nanoTime() - start;
System.out.println(TimeUnit.NANOSECONDS.toMillis(nanos));
logger.info("{}", TimeUnit.NANOSECONDS.toMillis(nanos));
}

@Test
Expand All @@ -83,8 +87,7 @@ public void test10MIterationsWithQuery() {
assertEquals("world", Query.evaluateExpressions("${xx}", attrs, ParameterLookup.EMPTY));
}
final long nanos = System.nanoTime() - start;
System.out.println(TimeUnit.NANOSECONDS.toMillis(nanos));

logger.info("{}", TimeUnit.NANOSECONDS.toMillis(nanos));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ public void testAssignAliases() {
possibleValueMap.put("C", valuesC);
possibleValueMap.put("D", valuesD);

for (int i = 0; i < valuesA.size() * valuesB.size() * valuesC.size() * valuesD.size(); i++) {
System.out.println(i + " : " + HL7Query.assignAliases(possibleValueMap, i));
}

verifyAssignments(HL7Query.assignAliases(possibleValueMap, 0), "a", "d", "e", "g");
verifyAssignments(HL7Query.assignAliases(possibleValueMap, 1), "b", "d", "e", "g");
verifyAssignments(HL7Query.assignAliases(possibleValueMap, 2), "c", "d", "e", "g");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.security.auth.Subject;
import javax.security.auth.kerberos.KerberosPrincipal;
Expand All @@ -42,6 +44,8 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

public class KerberosUserIT {
private static final Logger logger = LoggerFactory.getLogger(KerberosUserIT.class);

private static KDCServer kdc;

private static KerberosPrincipal principal1;
Expand Down Expand Up @@ -155,11 +159,11 @@ public void testCheckTGTAndRelogin() throws InterruptedException {
boolean performedRelogin = false;
for (int i = 0; i < 30; i++) {
Thread.sleep(1000);
System.out.println("checkTGTAndRelogin #" + i);
logger.info("checkTGTAndRelogin #{}", i);
performedRelogin = user1.checkTGTAndRelogin();

if (performedRelogin) {
System.out.println("Performed relogin!");
logger.info("Performed relogin!");
break;
}
}
Expand All @@ -179,7 +183,7 @@ public void testCheckTGTAndRelogin() throws InterruptedException {
long currentTimeMillis = System.currentTimeMillis();
long startMilli = kerberosTicket.getStartTime().toInstant().toEpochMilli();
long endMilli = kerberosTicket.getEndTime().toInstant().toEpochMilli();
System.out.println("New ticket is valid for " + TimeUnit.MILLISECONDS.toSeconds(endMilli - startMilli) + " seconds");
logger.info("New ticket is valid for {}", TimeUnit.MILLISECONDS.toSeconds(endMilli - startMilli) + " seconds");
assertTrue(startMilli < currentTimeMillis);
assertTrue(endMilli > currentTimeMillis);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -35,6 +37,8 @@
@Disabled("Tests are time-based")
public class TestLeakyBucketThrottler {

private static final Logger logger = LoggerFactory.getLogger(TestLeakyBucketThrottler.class);

@Test
@Timeout(value = 10000, unit = TimeUnit.MILLISECONDS)
public void testOutputStreamInterface() throws IOException {
Expand Down Expand Up @@ -144,7 +148,7 @@ public void run() {
long millisElapsed = now - startMillis;
bytesWritten += data.length;
float bytesPerSec = (float) bytesWritten / (float) millisElapsed * 1000F;
System.out.println(idx + " : copied data at a rate of " + bytesPerSec + " bytes/sec");
logger.info("{} : copied data at a rate of {} bytes/sec", idx, bytesPerSec);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.apache.nifi.stream.io.RepeatingInputStream;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -36,6 +38,8 @@

public class TestLineDemarcator {

private static final Logger logger = LoggerFactory.getLogger(TestLineDemarcator.class);

@Test
public void testSingleCharacterLines() throws IOException {
final String input = "A\nB\nC\rD\r\nE\r\nF\r\rG";
Expand Down Expand Up @@ -120,7 +124,7 @@ public void testPerformance() throws IOException {
}

final long millis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
System.out.println("Took " + millis + " millis to demarcate " + count + " lines");
logger.info("Took {} millis to demarcate {} lines", millis, count);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wali.DummyRecord;
import org.wali.DummyRecordSerde;
import org.wali.SerDeFactory;
Expand Down Expand Up @@ -50,6 +52,9 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

public class TestSequentialAccessWriteAheadLog {

private static final Logger logger = LoggerFactory.getLogger(TestSequentialAccessWriteAheadLog.class);

@Test
public void testUpdateWithExternalFile(TestInfo testInfo) throws IOException {
final DummyRecordSerde serde = new DummyRecordSerde();
Expand Down Expand Up @@ -369,11 +374,11 @@ public void run() {
final String bps = NumberFormat.getInstance().format(bytesPerSecond);

if (j == 0) {
System.out.println(millis + " ms to insert " + updateCountPerThread * numThreads + " updates using " + numThreads
+ " threads, *as a warmup!* " + eps + " events per second, " + bps + " bytes per second");
logger.info("{} ms to insert {} updates using {} threads, *as a warmup!* {} events per second, {} bytes per second",
millis, updateCountPerThread * numThreads, numThreads, eps, bps);
} else {
System.out.println(millis + " ms to insert " + updateCountPerThread * numThreads + " updates using " + numThreads
+ " threads, " + eps + " events per second, " + bps + " bytes per second");
logger.info("{} ms to insert {} updates using {} threads, {} events per second, {} bytes per second",
millis, updateCountPerThread * numThreads, numThreads, eps, bps);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ public void testStringHashStringRangePutSuccessfulWithMock() throws Initializati

final List<MockFlowFile> flowFiles = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS);
for (final MockFlowFile flowFile : flowFiles) {
System.out.println(flowFile.getAttributes());
assertEquals(document, new String(flowFile.toByteArray()));
}
}
Expand All @@ -191,14 +190,12 @@ public void testStringHashStringRangePutOneSuccessfulOneSizeFailureWithMockBatch

final List<MockFlowFile> flowFilesFailed = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
for (final MockFlowFile flowFile : flowFilesFailed) {
System.out.println(flowFile.getAttributes());
flowFile.assertAttributeExists(PutDynamoDB.AWS_DYNAMO_DB_ITEM_SIZE_ERROR);
assertEquals(item.length, flowFile.getSize());
}

final List<MockFlowFile> flowFilesSuccessful = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS);
for (final MockFlowFile flowFile : flowFilesSuccessful) {
System.out.println(flowFile.getAttributes());
assertEquals(document, new String(flowFile.toByteArray()));
}
}
Expand All @@ -221,14 +218,12 @@ public void testStringHashStringRangePutOneSuccessfulOneSizeFailureWithMockBatch

final List<MockFlowFile> flowFilesFailed = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
for (final MockFlowFile flowFile : flowFilesFailed) {
System.out.println(flowFile.getAttributes());
flowFile.assertAttributeExists(PutDynamoDB.AWS_DYNAMO_DB_ITEM_SIZE_ERROR);
assertEquals(item.length, flowFile.getSize());
}

final List<MockFlowFile> flowFilesSuccessful = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS);
for (final MockFlowFile flowFile : flowFilesSuccessful) {
System.out.println(flowFile.getAttributes());
assertEquals(document, new String(flowFile.toByteArray()));
}
}
Expand All @@ -250,7 +245,6 @@ public void testStringHashStringRangePutFailedWithItemSizeGreaterThan400Kb() thr
final List<MockFlowFile> flowFiles = putRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_FAILURE);
assertEquals(1, flowFiles.size());
for (final MockFlowFile flowFile : flowFiles) {
System.out.println(flowFile.getAttributes());
flowFile.assertAttributeExists(PutDynamoDB.AWS_DYNAMO_DB_ITEM_SIZE_ERROR);
assertEquals(item.length, flowFile.getSize());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.apache.nifi.util.TestRunner;
import org.apache.nifi.util.TestRunners;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -35,6 +37,8 @@
* Provides integration level testing with actual AWS S3 resources for {@link FetchS3Object} and requires additional configuration and resources to work.
*/
public class ITFetchS3Object extends AbstractS3IT {
private static final Logger logger = LoggerFactory.getLogger(ITFetchS3Object.class);

@Test
public void testSimpleGet() throws IOException {
putTestFile("test-file", getFileFromResourceName(SAMPLE_FILE_RESOURCE_NAME));
Expand Down Expand Up @@ -125,7 +129,7 @@ public void testContentsOfFileRetrieved() throws IOException {
out.assertContentEquals(new String(expectedBytes));

for (final Map.Entry<String, String> entry : out.getAttributes().entrySet()) {
System.out.println(entry.getKey() + " : " + entry.getValue());
logger.info("{}:{}", entry.getKey(), entry.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -81,7 +83,7 @@ public class ITPutS3Object extends AbstractS3IT {

final static Pattern reS3ETag = Pattern.compile("[0-9a-fA-f]{32}(-[0-9]+)?");


private static final Logger logger = LoggerFactory.getLogger(ITPutS3Object.class);
private static String kmsKeyId = "";
private static String randomKeyMaterial = "";

Expand Down Expand Up @@ -710,7 +712,7 @@ public void testMultipartSmallerThanMinimum() throws IOException {
tempByteCount += megabyte.length;
}
tempOut.close();
System.out.println("file size: " + tempByteCount);
logger.info("file size: {}", tempByteCount);
assertTrue(tempByteCount < S3_MINIMUM_PART_SIZE);

assertTrue(megabyte.length < S3_MINIMUM_PART_SIZE);
Expand Down Expand Up @@ -754,7 +756,7 @@ public void testMultipartBetweenMinimumAndMaximum() throws IOException, Initiali
tempByteCount += megabyte.length;
}
tempOut.close();
System.out.println("file size: " + tempByteCount);
logger.info("file size: {}", tempByteCount);
assertTrue(tempByteCount > S3_MINIMUM_PART_SIZE && tempByteCount < S3_MAXIMUM_OBJECT_SIZE);
assertTrue(tempByteCount > TEST_PARTSIZE_LONG);

Expand Down Expand Up @@ -806,7 +808,7 @@ public void testObjectTags() throws IOException {
List<Tag> objectTags = result.getTagSet();

for (Tag tag : objectTags) {
System.out.println("Tag Key : " + tag.getKey() + ", Tag Value : " + tag.getValue());
logger.info("Tag Key : {}, Tag Value : {}", tag.getKey(), tag.getValue());
}

assertEquals(1, objectTags.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public void testGetDataFlowMetrics() {
public void testGetVirtualMachineMetrics() {
JvmMetrics virtualMachineMetrics = JmxJvmMetrics.getInstance();
List<Metric> metrics = AzureLogAnalyticsMetricsFactory.getJvmMetrics(virtualMachineMetrics, "testcase", "tests");
String metricsInString = gson.toJson(metrics);
System.out.println(metricsInString);
TestVerification.assertJVMMetrics(metrics);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public void testDeflateDecompress() throws Exception {

runner.assertAllFlowFilesTransferred(ModifyCompression.REL_SUCCESS, 1);
MockFlowFile flowFile = runner.getFlowFilesForRelationship(ModifyCompression.REL_SUCCESS).getFirst();
System.err.println(new String(flowFile.toByteArray()));
flowFile.assertContentEquals(getSamplePath("SampleFile.txt"));
flowFile.assertAttributeEquals(CoreAttributes.FILENAME.key(), "SampleFile.txt");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ private void validateClob(String someClob) throws SQLException, ClassNotFoundExc

final byte[] serializedBytes = outStream.toByteArray();
assertNotNull(serializedBytes);
System.out.println("Avro serialized result size in bytes: " + serializedBytes.length);

st.close();
con.close();
Expand All @@ -140,7 +139,6 @@ private void validateClob(String someClob) throws SQLException, ClassNotFoundExc
while (dataFileReader.hasNext()) {
record = dataFileReader.next(record);
assertEquals(someClob, record.get("SOMECLOB").toString(), "Unreadable code for this Clob value.");
System.out.println(record);
}
}
}
Expand Down
Loading

0 comments on commit f64e68b

Please sign in to comment.