Skip to content

Commit

Permalink
Remove junit4, blacklist it on pom.xml, update all tests to use junit… (
Browse files Browse the repository at this point in the history
#344)

* Remove junit4, blacklist it on pom.xml, update all tests to use junit5 commands

* Optimize imports in src/test/ to remove duplicates

* Remove accidental failed -> Assertions.failed conversion

* Fix another accidental fail replacement
  • Loading branch information
StrongestNumber9 authored Sep 18, 2024
1 parent 40ca1bf commit 7fa5dff
Show file tree
Hide file tree
Showing 84 changed files with 2,299 additions and 2,346 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
<artifactId>greenmail-junit5</artifactId>
<version>1.6.13</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
Expand Down Expand Up @@ -314,6 +320,11 @@
</goals>
<configuration>
<rules>
<bannedDependencies>
<excludes>
<exclude>junit:junit</exclude>
</excludes>
</bannedDependencies>
<requireMavenVersion>
<version>3.2.5</version>
</requireMavenVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
import org.apache.spark.sql.types.MetadataBuilder;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -59,8 +58,6 @@
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertTrue;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AccumTransformationStreamingTest {

Expand All @@ -81,18 +78,18 @@ public class AccumTransformationStreamingTest {

private StreamingTestUtil streamingTestUtil;

@org.junit.jupiter.api.BeforeAll
@BeforeAll
void setEnv() {
this.streamingTestUtil = new StreamingTestUtil(this.testSchema);
this.streamingTestUtil.setEnv();
}

@org.junit.jupiter.api.BeforeEach
@BeforeEach
void setUp() {
this.streamingTestUtil.setUp();
}

@org.junit.jupiter.api.AfterEach
@AfterEach
void tearDown() {
this.streamingTestUtil.tearDown();
}
Expand All @@ -115,7 +112,7 @@ public void accumBasicQueryTest() {
.map(r -> r.getAs(0))
.collect(Collectors.toList());
List<Object> expected = Arrays.asList("-10", "-10", "0", "35", "82.2");
assertTrue(rawCol.containsAll(expected));
Assertions.assertTrue(rawCol.containsAll(expected));
});
}

Expand All @@ -133,7 +130,7 @@ public void accumRenameFieldQueryTest() {
.map(r -> r.getAs(0))
.collect(Collectors.toList());
List<Object> expected = Arrays.asList("-10", "-10", "0", "35", "82.2");
assertTrue(newCol.containsAll(expected));
Assertions.assertTrue(newCol.containsAll(expected));
});
}

Expand All @@ -152,7 +149,7 @@ public void accumMixedStringsQueryTest() {
.collect(Collectors.toList());
// expect to skip strings in data and return original data as-is
List<Object> expected = Arrays.asList("10", "string", "110", "another_string", "165.0");
assertTrue(rawCol.containsAll(expected));
Assertions.assertTrue(rawCol.containsAll(expected));
});
}

Expand All @@ -175,7 +172,7 @@ public void accumMixedStringsQueryWithRenameFieldTest() {
"10", streamingTestUtil.getCtx().nullValue.value(), "110",
streamingTestUtil.getCtx().nullValue.value(), "165.0"
);
assertTrue(newCol.containsAll(expected));
Assertions.assertTrue(newCol.containsAll(expected));
});
}
}
34 changes: 16 additions & 18 deletions src/test/java/com/teragrep/pth10/AddtotalsTransformationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@
import org.apache.spark.sql.types.MetadataBuilder;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AddtotalsTransformationTest {

Expand All @@ -78,18 +76,18 @@ public class AddtotalsTransformationTest {

private StreamingTestUtil streamingTestUtil;

@org.junit.jupiter.api.BeforeAll
@BeforeAll
void setEnv() {
this.streamingTestUtil = new StreamingTestUtil(this.testSchema);
this.streamingTestUtil.setEnv();
}

@org.junit.jupiter.api.BeforeEach
@BeforeEach
void setUp() {
this.streamingTestUtil.setUp();
}

@org.junit.jupiter.api.AfterEach
@AfterEach
void tearDown() {
this.streamingTestUtil.tearDown();
}
Expand All @@ -109,12 +107,12 @@ void addtotals_noparams_test() {
.sorted()
.collect(Collectors.toList());
List<String> expected = Arrays.asList("36.0", "11.0", "1.0", "-9.0", "48.2");
assertEquals(5, res.size());
assertEquals(5, expected.size());
Assertions.assertEquals(5, res.size());
Assertions.assertEquals(5, expected.size());

for (String r : res) {
if (!expected.contains(r)) {
fail("Value <" + r + "> was not one of the expected values!");
Assertions.fail("Value <" + r + "> was not one of the expected values!");
}
}
});
Expand All @@ -135,12 +133,12 @@ void addtotals_colParam_test() {
.sorted(Double::compareTo)
.collect(Collectors.toList());
List<Double> expected = Arrays.asList(-10d, 0d, 10d, 35d, 47.2d, 82.2d);
assertEquals(6, res.size());
assertEquals(6, expected.size());
Assertions.assertEquals(6, res.size());
Assertions.assertEquals(6, expected.size());

for (Double r : res) {
if (!expected.contains(r)) {
fail("Value <" + r + "> was not one of the expected values!");
Assertions.fail("Value <" + r + "> was not one of the expected values!");
}
}
});
Expand All @@ -156,12 +154,12 @@ void addtotals_fieldNames_test() {
.performDPLTest("index=* | addtotals col=true row=true labelfield=x1 fieldname=x2", testFile, ds -> {
List<String> fieldsInData = Arrays.asList(ds.schema().fieldNames());
// source schema + labelfield and fieldname
assertEquals(testSchema.length() + 2, fieldsInData.size());
Assertions.assertEquals(testSchema.length() + 2, fieldsInData.size());
// check that fieldname and labelfield are present in schema
assertTrue(fieldsInData.contains("x1"));
assertTrue(fieldsInData.contains("x2"));
Assertions.assertTrue(fieldsInData.contains("x1"));
Assertions.assertTrue(fieldsInData.contains("x2"));
// 5 source rows plus last row for column sums
assertEquals(6, ds.count());
Assertions.assertEquals(6, ds.count());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@
import org.apache.spark.sql.types.MetadataBuilder;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.jupiter.api.Assertions.assertEquals;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class AggregateAfterSequentialCommandTest {

Expand All @@ -77,18 +74,18 @@ public class AggregateAfterSequentialCommandTest {

private StreamingTestUtil streamingTestUtil;

@org.junit.jupiter.api.BeforeAll
@BeforeAll
void setEnv() {
this.streamingTestUtil = new StreamingTestUtil(this.testSchema);
this.streamingTestUtil.setEnv();
}

@org.junit.jupiter.api.BeforeEach
@BeforeEach
void setUp() {
this.streamingTestUtil.setUp();
}

@org.junit.jupiter.api.AfterEach
@AfterEach
void tearDown() {
this.streamingTestUtil.tearDown();
}
Expand All @@ -107,7 +104,7 @@ public void aggregateAfterDedupTest() {
.performDPLTest(
"index=index_A | spath path=rainfall_rate | dedup rainfall_rate | stats sum(rainfall_rate)",
testFile, ds -> {
assertEquals("139.875", ds.select("sum(rainfall_rate)").first().getString(0));
Assertions.assertEquals("139.875", ds.select("sum(rainfall_rate)").first().getString(0));
}
);
}
Expand All @@ -122,7 +119,7 @@ public void aggregateBeforeSeqModeAndAfter() {
.performDPLTest(
"index=index_A | spath path=rainfall_rate | stats count(rainfall_rate) as cr by _raw | dedup cr | stats sum(cr)",
testFile, ds -> {
assertEquals("5", ds.select("sum(cr)").first().getString(0));
Assertions.assertEquals("5", ds.select("sum(cr)").first().getString(0));
}
);
}
Expand All @@ -137,7 +134,7 @@ public void aggregateAfterHdfsLoadTest() {
.performDPLTest(
"index=index_A | spath | teragrep exec hdfs save /tmp/pth_10/aggregateAfterHdfsLoadTest overwrite=true",
testFile, ds -> {
assertEquals(new StructType(new StructField[] {
Assertions.assertEquals(new StructType(new StructField[] {
new StructField(
"_time",
DataTypes.TimestampType,
Expand All @@ -163,7 +160,7 @@ public void aggregateAfterHdfsLoadTest() {
.performDPLTest(
"| teragrep exec hdfs load /tmp/pth_10/aggregateAfterHdfsLoadTest | dedup rainfall_rate | stats sum(rainfall_rate)",
testFile, ds -> {
assertEquals("139.875", ds.select("sum(rainfall_rate)").first().getString(0));
Assertions.assertEquals("139.875", ds.select("sum(rainfall_rate)").first().getString(0));
}
);
}
Expand Down
24 changes: 10 additions & 14 deletions src/test/java/com/teragrep/pth10/BloomFilterOperationsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,15 @@
import org.apache.spark.sql.types.MetadataBuilder;
import org.apache.spark.sql.types.StructField;
import org.apache.spark.sql.types.StructType;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class BloomFilterOperationsTest {

Expand All @@ -81,7 +78,7 @@ public class BloomFilterOperationsTest {

private StreamingTestUtil streamingTestUtil;

@org.junit.jupiter.api.BeforeAll
@BeforeAll
void setEnv() {
streamingTestUtil = new StreamingTestUtil(this.testSchema);
streamingTestUtil.setEnv();
Expand All @@ -92,7 +89,7 @@ void setEnv() {
*/
}

@org.junit.jupiter.api.BeforeEach
@BeforeEach
void setUp() {
streamingTestUtil.setUp();
/*
Expand All @@ -102,7 +99,7 @@ void setUp() {
*/
}

@org.junit.jupiter.api.AfterEach
@AfterEach
void tearDown() {
streamingTestUtil.tearDown();
}
Expand All @@ -121,18 +118,17 @@ public void estimateTest() {
.performDPLTest(
"index=index_A earliest=2020-01-01T00:00:00z latest=2023-01-01T00:00:00z | teragrep exec tokenizer | teragrep exec bloom estimate",
testFile, ds -> {
assertEquals(
"[partition, estimate(tokens)]", Arrays.toString(ds.columns()), "Batch handler dataset contained an unexpected column arrangement !"
);
Assertions
.assertEquals("[partition, estimate(tokens)]", Arrays.toString(ds.columns()), "Batch handler dataset contained an unexpected column arrangement !");
List<Integer> results = ds
.select("estimate(tokens)")
.collectAsList()
.stream()
.map(r -> Integer.parseInt(r.get(0).toString()))
.collect(Collectors.toList());

assertEquals(results.get(0), 1);
assertTrue(results.get(1) > 1);
Assertions.assertEquals(results.get(0), 1);
Assertions.assertTrue(results.get(1) > 1);
}
);
}
Expand Down
Loading

0 comments on commit 7fa5dff

Please sign in to comment.