Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-48386][TESTS] Replace JVM assert with JUnit Assert in tests #46698

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testChunkedStream() throws Exception {

// Validate we read data correctly
assertEquals(bodyResult.readableBytes(), chunkSize);
assert(bodyResult.readableBytes() < (randomData.length - readIndex));
assertTrue(bodyResult.readableBytes() < (randomData.length - readIndex));
while (bodyResult.readableBytes() > 0) {
assertEquals(bodyResult.readByte(), randomData[readIndex++]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public void testRetryOnSaslTimeout() throws IOException, InterruptedException {
verify(listener, timeout(5000)).onBlockTransferSuccess("b0", block0);
verify(listener).getTransferType();
verifyNoMoreInteractions(listener);
assert(_retryingBlockTransferor.getRetryCount() == 0);
assertEquals(0, _retryingBlockTransferor.getRetryCount());
}

@Test
Expand All @@ -310,7 +310,7 @@ public void testRepeatedSaslRetryFailures() throws IOException, InterruptedExcep
verify(listener, timeout(5000)).onBlockTransferFailure("b0", saslTimeoutException);
verify(listener, times(3)).getTransferType();
verifyNoMoreInteractions(listener);
assert(_retryingBlockTransferor.getRetryCount() == MAX_RETRIES);
assertEquals(MAX_RETRIES, _retryingBlockTransferor.getRetryCount());
}

@Test
Expand Down Expand Up @@ -339,7 +339,7 @@ public void testBlockTransferFailureAfterSasl() throws IOException, InterruptedE
// This should be equal to 1 because after the SASL exception is retried,
// retryCount should be set back to 0. Then after that b1 encounters an
// exception that is retried.
assert(_retryingBlockTransferor.getRetryCount() == 1);
assertEquals(1, _retryingBlockTransferor.getRetryCount());
}

@Test
Expand Down Expand Up @@ -368,7 +368,7 @@ public void testIOExceptionFailsConnectionEvenWithSaslException()
verify(listener, timeout(5000)).onBlockTransferFailure("b0", saslExceptionFinal);
verify(listener, atLeastOnce()).getTransferType();
verifyNoMoreInteractions(listener);
assert(_retryingBlockTransferor.getRetryCount() == MAX_RETRIES);
assertEquals(MAX_RETRIES, _retryingBlockTransferor.getRetryCount());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.apache.commons.lang3.tuple.Pair;
import org.apache.logging.log4j.Level;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import org.apache.spark.internal.SparkLogger;
Expand Down Expand Up @@ -104,8 +105,8 @@ public void testBasicMsgLogger() {
Pair.of(Level.DEBUG, debugFn),
Pair.of(Level.TRACE, traceFn)).forEach(pair -> {
try {
assert (captureLogOutput(pair.getRight()).matches(
expectedPatternForBasicMsg(pair.getLeft())));
Assertions.assertTrue(captureLogOutput(pair.getRight()).matches(
expectedPatternForBasicMsg(pair.getLeft())));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -127,8 +128,8 @@ public void testBasicLoggerWithException() {
Pair.of(Level.DEBUG, debugFn),
Pair.of(Level.TRACE, traceFn)).forEach(pair -> {
try {
assert (captureLogOutput(pair.getRight()).matches(
expectedPatternForBasicMsgWithException(pair.getLeft())));
Assertions.assertTrue(captureLogOutput(pair.getRight()).matches(
Copy link
Member

@dongjoon-hyun dongjoon-hyun May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we import assertTrue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

expectedPatternForBasicMsgWithException(pair.getLeft())));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -147,8 +148,8 @@ public void testLoggerWithMDC() {
Pair.of(Level.WARN, warnFn),
Pair.of(Level.INFO, infoFn)).forEach(pair -> {
try {
assert (captureLogOutput(pair.getRight()).matches(
expectedPatternForMsgWithMDC(pair.getLeft())));
Assertions.assertTrue(captureLogOutput(pair.getRight()).matches(
expectedPatternForMsgWithMDC(pair.getLeft())));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -165,8 +166,8 @@ public void testLoggerWithMDCs() {
Pair.of(Level.WARN, warnFn),
Pair.of(Level.INFO, infoFn)).forEach(pair -> {
try {
assert (captureLogOutput(pair.getRight()).matches(
expectedPatternForMsgWithMDCs(pair.getLeft())));
Assertions.assertTrue(captureLogOutput(pair.getRight()).matches(
expectedPatternForMsgWithMDCs(pair.getLeft())));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -184,8 +185,8 @@ public void testLoggerWithMDCsAndException() {
Pair.of(Level.WARN, warnFn),
Pair.of(Level.INFO, infoFn)).forEach(pair -> {
try {
assert (captureLogOutput(pair.getRight()).matches(
expectedPatternForMsgWithMDCsAndException(pair.getLeft())));
Assertions.assertTrue(captureLogOutput(pair.getRight()).matches(
expectedPatternForMsgWithMDCsAndException(pair.getLeft())));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -202,8 +203,8 @@ public void testLoggerWithMDCValueIsNull() {
Pair.of(Level.WARN, warnFn),
Pair.of(Level.INFO, infoFn)).forEach(pair -> {
try {
assert (captureLogOutput(pair.getRight()).matches(
expectedPatternForMsgWithMDCValueIsNull(pair.getLeft())));
Assertions.assertTrue(captureLogOutput(pair.getRight()).matches(
expectedPatternForMsgWithMDCValueIsNull(pair.getLeft())));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -220,8 +221,8 @@ public void testLoggerWithExternalSystemCustomLogKey() {
Pair.of(Level.WARN, warnFn),
Pair.of(Level.INFO, infoFn)).forEach(pair -> {
try {
assert (captureLogOutput(pair.getRight()).matches(
expectedPatternForExternalSystemCustomLogKey(pair.getLeft())));
Assertions.assertTrue(captureLogOutput(pair.getRight()).matches(
expectedPatternForExternalSystemCustomLogKey(pair.getLeft())));
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import scala.jdk.javaapi.CollectionConverters;

import org.junit.jupiter.api.Assertions;

import org.apache.spark.sql.Encoders;
import org.apache.spark.sql.streaming.*;

Expand Down Expand Up @@ -74,21 +76,21 @@ public scala.collection.Iterator<String> handleInputRows(
} else {
keyCountMap.updateValue(value, 1L);
}
assert(keyCountMap.containsKey(value));
Assertions.assertTrue(keyCountMap.containsKey(value));
keysList.appendValue(value);
sb.append(value);
}

scala.collection.Iterator<String> keys = keysList.get();
while (keys.hasNext()) {
String keyVal = keys.next();
assert(keyCountMap.containsKey(keyVal));
assert(keyCountMap.getValue(keyVal) > 0);
Assertions.assertTrue(keyCountMap.containsKey(keyVal));
Assertions.assertTrue(keyCountMap.getValue(keyVal) > 0);
}

count += numRows;
countState.update(count);
assert (countState.get() == count);
Assertions.assertEquals(count, (long) countState.get());

result.add(sb.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import scala.jdk.javaapi.CollectionConverters;

import org.junit.jupiter.api.Assertions;

import org.apache.spark.sql.Encoders;
import org.apache.spark.sql.streaming.*;

Expand Down Expand Up @@ -71,7 +73,7 @@ public scala.collection.Iterator<String> handleInputRows(
}

testState.clear();
assert(testState.exists() == false);
Assertions.assertFalse(testState.exists());

result.add(sb.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Assertions;

import org.apache.spark.sql.catalyst.InternalRow;
import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
import org.apache.spark.sql.connector.TestingV2Source;
Expand Down Expand Up @@ -66,9 +68,9 @@ public StructType readSchema() {
public Predicate[] pushPredicates(Predicate[] predicates) {
Predicate[] supported = Arrays.stream(predicates).filter(f -> {
if (f.name().equals(">")) {
assert(f.children()[0] instanceof FieldReference);
Assertions.assertInstanceOf(FieldReference.class, f.children()[0]);
FieldReference column = (FieldReference) f.children()[0];
assert(f.children()[1] instanceof LiteralValue);
Assertions.assertInstanceOf(LiteralValue.class, f.children()[1]);
Literal value = (Literal) f.children()[1];
return column.describe().equals("i") && value.value() instanceof Integer;
} else {
Expand All @@ -78,9 +80,9 @@ public Predicate[] pushPredicates(Predicate[] predicates) {

Predicate[] unsupported = Arrays.stream(predicates).filter(f -> {
if (f.name().equals(">")) {
assert(f.children()[0] instanceof FieldReference);
Assertions.assertInstanceOf(FieldReference.class, f.children()[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto. Shall we import assertInstanceOf?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

FieldReference column = (FieldReference) f.children()[0];
assert(f.children()[1] instanceof LiteralValue);
Assertions.assertInstanceOf(LiteralValue.class, f.children()[1]);
Literal value = (LiteralValue) f.children()[1];
return !column.describe().equals("i") || !(value.value() instanceof Integer);
} else {
Expand Down Expand Up @@ -125,9 +127,9 @@ public InputPartition[] planInputPartitions() {
Integer lowerBound = null;
for (Predicate predicate : predicates) {
if (predicate.name().equals(">")) {
assert(predicate.children()[0] instanceof FieldReference);
Assertions.assertInstanceOf(FieldReference.class, predicate.children()[0]);
FieldReference column = (FieldReference) predicate.children()[0];
assert(predicate.children()[1] instanceof LiteralValue);
Assertions.assertInstanceOf(LiteralValue.class, predicate.children()[1]);
Literal value = (Literal) predicate.children()[1];
if ("i".equals(column.describe()) && value.value() instanceof Integer integer) {
lowerBound = integer;
Expand Down