Skip to content

Commit

Permalink
Replace JVM assert with JUnit Assert in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srowen committed Nov 18, 2019
1 parent 388a737 commit 2219d2e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import org.apache.spark.network.shuffle.protocol.ExecutorShuffleInfo;
import org.apache.spark.network.util.JavaUtils;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -122,7 +123,7 @@ private void insertFile(String filename) throws IOException {
private void insertFile(String filename, byte[] block) throws IOException {
OutputStream dataStream = null;
File file = ExecutorDiskUtils.getFile(localDirs, subDirsPerLocalDir, filename);
assert(!file.exists()) : "this test file has been already generated";
Assert.assertFalse("this test file has been already generated", file.exists());
try {
dataStream = new FileOutputStream(
ExecutorDiskUtils.getFile(localDirs, subDirsPerLocalDir, filename));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
package org.apache.spark.streaming.kinesis;

import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream;
import org.junit.Assert;
import org.junit.Test;

import org.apache.spark.streaming.kinesis.KinesisInitialPositions.TrimHorizon;
import org.apache.spark.storage.StorageLevel;
import org.apache.spark.streaming.Duration;
import org.apache.spark.streaming.LocalJavaStreamingContext;
import org.apache.spark.streaming.Seconds;
import org.junit.Test;

public class JavaKinesisInputDStreamBuilderSuite extends LocalJavaStreamingContext {
/**
Expand All @@ -49,13 +51,14 @@ public void testJavaKinesisDStreamBuilder() {
.checkpointInterval(checkpointInterval)
.storageLevel(storageLevel)
.build();
assert(kinesisDStream.streamName() == streamName);
assert(kinesisDStream.endpointUrl() == endpointUrl);
assert(kinesisDStream.regionName() == region);
assert(kinesisDStream.initialPosition().getPosition() == initialPosition.getPosition());
assert(kinesisDStream.checkpointAppName() == appName);
assert(kinesisDStream.checkpointInterval() == checkpointInterval);
assert(kinesisDStream._storageLevel() == storageLevel);
Assert.assertEquals(streamName, kinesisDStream.streamName());
Assert.assertEquals(endpointUrl, kinesisDStream.endpointUrl());
Assert.assertEquals(region, kinesisDStream.regionName());
Assert.assertEquals(initialPosition.getPosition(),
kinesisDStream.initialPosition().getPosition());
Assert.assertEquals(appName, kinesisDStream.checkpointAppName());
Assert.assertEquals(checkpointInterval, kinesisDStream.checkpointInterval());
Assert.assertEquals(storageLevel, kinesisDStream._storageLevel());
ssc.stop();
}

Expand Down Expand Up @@ -83,13 +86,14 @@ public void testJavaKinesisDStreamBuilderOldApi() {
.checkpointInterval(checkpointInterval)
.storageLevel(storageLevel)
.build();
assert(kinesisDStream.streamName() == streamName);
assert(kinesisDStream.endpointUrl() == endpointUrl);
assert(kinesisDStream.regionName() == region);
assert(kinesisDStream.initialPosition().getPosition() == InitialPositionInStream.LATEST);
assert(kinesisDStream.checkpointAppName() == appName);
assert(kinesisDStream.checkpointInterval() == checkpointInterval);
assert(kinesisDStream._storageLevel() == storageLevel);
Assert.assertEquals(streamName, kinesisDStream.streamName());
Assert.assertEquals(endpointUrl, kinesisDStream.endpointUrl());
Assert.assertEquals(region, kinesisDStream.regionName());
Assert.assertEquals(InitialPositionInStream.LATEST,
kinesisDStream.initialPosition().getPosition());
Assert.assertEquals(appName, kinesisDStream.checkpointAppName());
Assert.assertEquals(checkpointInterval, kinesisDStream.checkpointInterval());
Assert.assertEquals(storageLevel, kinesisDStream._storageLevel());
ssc.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.apache.commons.math3.distribution.NormalDistribution;
import org.apache.spark.sql.Encoders;
import org.junit.Assert;
import org.junit.Test;

import org.apache.spark.SharedSparkSession;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void testKSTestCDF() {
.test(dataset, "sample", stdNormalCDF).head();
double pValue1 = results.getDouble(0);
// Cannot reject null hypothesis
assert(pValue1 > pThreshold);
Assert.assertTrue(pValue1 > pThreshold);
}

@Test
Expand All @@ -72,6 +73,6 @@ public void testKSTestNamedDistribution() {
.test(dataset, "sample", "norm", 0.0, 1.0).head();
double pValue1 = results.getDouble(0);
// Cannot reject null hypothesis
assert(pValue1 > pThreshold);
Assert.assertTrue(pValue1 > pThreshold);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@

import java.util.Locale;

import org.junit.Assert;
import org.junit.Test;

public class JavaOutputModeSuite {

@Test
public void testOutputModes() {
OutputMode o1 = OutputMode.Append();
assert(o1.toString().toLowerCase(Locale.ROOT).contains("append"));
Assert.assertTrue(o1.toString().toLowerCase(Locale.ROOT).contains("append"));
OutputMode o2 = OutputMode.Complete();
assert (o2.toString().toLowerCase(Locale.ROOT).contains("complete"));
Assert.assertTrue(o2.toString().toLowerCase(Locale.ROOT).contains("complete"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.spark.util.collection.unsafe.sort.*;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -81,14 +82,14 @@ private void insertRow(UnsafeRow row) {
int recordLength = row.getSizeInBytes();

Object baseObject = dataPage.getBaseObject();
assert(pageCursor + recordLength <= dataPage.getBaseOffset() + dataPage.size());
Assert.assertTrue(pageCursor + recordLength <= dataPage.getBaseOffset() + dataPage.size());
long recordAddress = memoryManager.encodePageNumberAndOffset(dataPage, pageCursor);
UnsafeAlignedOffset.putSize(baseObject, pageCursor, recordLength);
pageCursor += uaoSize;
Platform.copyMemory(recordBase, recordOffset, baseObject, pageCursor, recordLength);
pageCursor += recordLength;

assert(pos < 2);
Assert.assertTrue(pos < 2);
array.set(pos, recordAddress);
pos++;
}
Expand Down Expand Up @@ -141,8 +142,8 @@ public void testBinaryComparatorForSingleColumnRow() throws Exception {
insertRow(row1);
insertRow(row2);

assert(compare(0, 0) == 0);
assert(compare(0, 1) < 0);
Assert.assertEquals(0, compare(0, 0));
Assert.assertTrue(compare(0, 1) < 0);
}

@Test
Expand All @@ -166,8 +167,8 @@ public void testBinaryComparatorForMultipleColumnRow() throws Exception {
insertRow(row1);
insertRow(row2);

assert(compare(0, 0) == 0);
assert(compare(0, 1) < 0);
Assert.assertEquals(0, compare(0, 0));
Assert.assertTrue(compare(0, 1) < 0);
}

@Test
Expand All @@ -193,8 +194,8 @@ public void testBinaryComparatorForArrayColumn() throws Exception {
insertRow(row1);
insertRow(row2);

assert(compare(0, 0) == 0);
assert(compare(0, 1) > 0);
Assert.assertEquals(0, compare(0, 0));
Assert.assertTrue(compare(0, 1) > 0);
}

@Test
Expand Down Expand Up @@ -226,8 +227,8 @@ public void testBinaryComparatorForMixedColumns() throws Exception {
insertRow(row1);
insertRow(row2);

assert(compare(0, 0) == 0);
assert(compare(0, 1) > 0);
Assert.assertEquals(0, compare(0, 0));
Assert.assertTrue(compare(0, 1) > 0);
}

@Test
Expand All @@ -252,8 +253,8 @@ public void testBinaryComparatorForNullColumns() throws Exception {
insertRow(row1);
insertRow(row2);

assert(compare(0, 0) == 0);
assert(compare(0, 1) > 0);
Assert.assertEquals(0, compare(0, 0));
Assert.assertTrue(compare(0, 1) > 0);
}

@Test
Expand All @@ -273,7 +274,7 @@ public void testBinaryComparatorWhenSubtractionIsDivisibleByMaxIntValue() throws
insertRow(row1);
insertRow(row2);

assert(compare(0, 1) < 0);
Assert.assertTrue(compare(0, 1) < 0);
}

@Test
Expand All @@ -293,7 +294,7 @@ public void testBinaryComparatorWhenSubtractionCanOverflowLongValue() throws Exc
insertRow(row1);
insertRow(row2);

assert(compare(0, 1) < 0);
Assert.assertTrue(compare(0, 1) < 0);
}

@Test
Expand All @@ -319,6 +320,6 @@ public void testBinaryComparatorWhenOnlyTheLastColumnDiffers() throws Exception
insertRow(row1);
insertRow(row2);

assert(compare(0, 1) < 0);
Assert.assertTrue(compare(0, 1) < 0);
}
}

0 comments on commit 2219d2e

Please sign in to comment.