Skip to content

Commit

Permalink
[Spark] fix PMD for test
Browse files Browse the repository at this point in the history
Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com>
  • Loading branch information
pawel-big-lebowski committed Apr 8, 2024
1 parent 145de87 commit 54e1973
Show file tree
Hide file tree
Showing 40 changed files with 84 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class OpenLineageRunEventTest {
new TypeReference<Map<String, Object>>() {};

@Test
public void testSerializeRunEvent() throws IOException, URISyntaxException {
void testSerializeRunEvent() throws IOException, URISyntaxException {
ObjectMapper mapper = OpenLineageClientUtils.newObjectMapper();

ZonedDateTime dateTime = ZonedDateTime.parse("2021-01-01T00:00:01.000000000+00:00[UTC]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class DebugRunFacetBuilderDelegateTest {
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class DebugRunFacetBuilderDelegateTest {

private static OpenLineageContext openLineageContext =
mock(OpenLineageContext.class, RETURNS_DEEP_STUBS);
Expand All @@ -46,7 +47,7 @@ static void setup() {
}

@Test
public void testSystemDebugFacet() {
void testSystemDebugFacet() {
assertThat(delegate.buildFacet().getSystem())
.hasFieldOrPropertyWithValue("javaVersion", SystemUtils.JAVA_VERSION)
.hasFieldOrPropertyWithValue("javaVendor", SystemUtils.JAVA_VENDOR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

public class DebugRunFacetBuilderTest {
class DebugRunFacetBuilderTest {

private static OpenLineageContext openLineageContext =
mock(OpenLineageContext.class, RETURNS_DEEP_STUBS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import org.apache.spark.scheduler.SparkListenerJobStart;
import org.junit.jupiter.api.Test;

public class SparkPropertyFacetBuilderTest {
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class SparkPropertyFacetBuilderTest {

@Test
void testBuildDefault() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

public class AdaptivePlanEventFilterTest {
class AdaptivePlanEventFilterTest {

OpenLineageContext context = mock(OpenLineageContext.class);
AdaptivePlanEventFilter filter = new AdaptivePlanEventFilter(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

public class CreateViewFilterTest {
class CreateViewFilterTest {

OpenLineageContext context = mock(OpenLineageContext.class);
CreateViewFilter filter = new CreateViewFilter(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class DatabricksEventFilterTest {
class DatabricksEventFilterTest {

SparkListenerEvent event = mock(SparkListenerEvent.class);
OpenLineageContext context = mock(OpenLineageContext.class);
Expand All @@ -32,7 +32,7 @@ public class DatabricksEventFilterTest {
SparkListenerEvent sparkListenerEvent = mock(SparkListenerEvent.class);

@BeforeEach
public void setup() {
void setup() {
when(context.getQueryExecution()).thenReturn(Optional.of(queryExecution));
when(queryExecution
.sparkSession()
Expand All @@ -47,13 +47,13 @@ public void setup() {
}

@Test
public void testDatabricksEventIsFiltered() {
void testDatabricksEventIsFiltered() {
when(node.nodeName()).thenReturn("collect_Limit");
assertThat(filter.isDisabled(event)).isTrue();
}

@Test
public void testSerializeFromObjectIsDisabled() {
void testSerializeFromObjectIsDisabled() {
SerializeFromObject serializeFromObject = mock(SerializeFromObject.class);
when(serializeFromObject.collectLeaves()).thenReturn(ScalaConversionUtils.asScalaSeqEmpty());
when(queryExecution.optimizedPlan()).thenReturn(serializeFromObject);
Expand All @@ -62,19 +62,19 @@ public void testSerializeFromObjectIsDisabled() {
}

@Test
public void testDatabricksEventIsFilteredWithoutUnderscore() {
void testDatabricksEventIsFilteredWithoutUnderscore() {
when(node.nodeName()).thenReturn("collectlimit");
assertThat(filter.isDisabled(event)).isTrue();
}

@Test
public void testDatabricksEventIsNotFiltered() {
void testDatabricksEventIsNotFiltered() {
when(node.nodeName()).thenReturn("action_not_to_be_filtered");
assertThat(filter.isDisabled(event)).isFalse();
}

@Test
public void testOtherEventIsNotFiltered() {
void testOtherEventIsNotFiltered() {
when(queryExecution
.sparkSession()
.sparkContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import org.mockito.MockedStatic;
import scala.collection.immutable.Seq;

public class DeltaEventFilterTest {
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class DeltaEventFilterTest {

public static final String SPARK_SQL_EXTENSIONS = "spark.sql.extensions";
OpenLineageContext context = mock(OpenLineageContext.class);
DeltaEventFilter filter = new DeltaEventFilter(context);
SparkSession sparkSession = mock(SparkSession.class);
Expand All @@ -57,7 +59,7 @@ public void setup() {
void testNotDeltaIsNotDisabled() {
try (MockedStatic mocked = mockStatic(SparkSession.class)) {
when(SparkSession.active()).thenReturn(sparkSession);
when(sparkConf.get("spark.sql.extensions")).thenReturn("non-delta-extension");
when(sparkConf.get(SPARK_SQL_EXTENSIONS)).thenReturn("non-delta-extension");

assertFalse(filter.isDisabled(sparkListenerEvent));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

public class SparkNodesFilterTest {
class SparkNodesFilterTest {

OpenLineageContext context = mock(OpenLineageContext.class);
SparkNodesFilter filter = new SparkNodesFilter(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class JobNameHookTest {
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class JobNameHookTest {

OpenLineageContext context = mock(OpenLineageContext.class);
QueryExecution queryExecution = mock(QueryExecution.class, RETURNS_DEEP_STUBS);
Expand Down Expand Up @@ -64,7 +65,7 @@ public void setup() {
}

@Test
public void testPreBuildWhenAppendingDatasetNameToJobNameDisabled() {
void testPreBuildWhenAppendingDatasetNameToJobNameDisabled() {
when(sparkConf.get("spark.openlineage.jobName.appendDatasetName", "true")).thenReturn("false");

runEventBuilder = mock(OpenLineage.RunEventBuilder.class);
Expand All @@ -73,7 +74,7 @@ public void testPreBuildWhenAppendingDatasetNameToJobNameDisabled() {
}

@Test
public void testPreBuild() {
void testPreBuild() {
runEventBuilder.job(
context
.getOpenLineage()
Expand All @@ -95,7 +96,7 @@ public void testPreBuild() {
}

@Test
public void testPreBuildWhenReplaceDotWithUnderscoreIsTrue() {
void testPreBuildWhenReplaceDotWithUnderscoreIsTrue() {
when(sparkConf.get("spark.openlineage.jobName.replaceDotWithUnderscore", "false"))
.thenReturn("true");

Expand All @@ -120,7 +121,7 @@ public void testPreBuildWhenReplaceDotWithUnderscoreIsTrue() {
}

@Test
public void testPreBuildWhenNoOutputDataset() {
void testPreBuildWhenNoOutputDataset() {
runEventBuilder.job(
context.getOpenLineage().newJobBuilder().name("databricks_shell.append_data").build());

Expand All @@ -130,7 +131,7 @@ public void testPreBuildWhenNoOutputDataset() {
}

@Test
public void testPreBuildWhenNotADefaultName() {
void testPreBuildWhenNotADefaultName() {
runEventBuilder.job(
context.getOpenLineage().newJobBuilder().name("non-default-name.append_data").build());

Expand All @@ -140,7 +141,7 @@ public void testPreBuildWhenNotADefaultName() {
}

@Test
public void testPreBuildWhenJobNamePresentInContext() {
void testPreBuildWhenJobNamePresentInContext() {
when(context.getJobName()).thenReturn("some-job-name");
runEventBuilder.job(context.getOpenLineage().newJobBuilder().build());
builderHook.preBuild(runEventBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import io.openlineage.client.OpenLineage;
import io.openlineage.spark.agent.lifecycle.plan.handlers.JdbcRelationHandler;
import io.openlineage.spark.agent.util.ScalaConversionUtils;
import io.openlineage.spark.api.DatasetFactory;
Expand All @@ -30,7 +29,8 @@
import org.junit.jupiter.api.Test;
import scala.collection.immutable.Map$;

public class JdbcRelationHandlerTest {
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class JdbcRelationHandlerTest {
JdbcRelationHandler jdbcRelationHandler;
DatasetFactory datasetFactory = mock(DatasetFactory.class);
JDBCRelation relation = mock(JDBCRelation.class);
Expand Down Expand Up @@ -84,7 +84,7 @@ void testHandlingJdbcTable() {
when(jdbcOptions.tableOrQuery()).thenReturn(jdbcTable);
when(relation.schema()).thenReturn(schema);

List<OpenLineage.Dataset> datasets = jdbcRelationHandler.getDatasets(relation, url);
jdbcRelationHandler.getDatasets(relation, url);

verify(datasetFactory, times(1))
.getDataset("test.tablename", "postgres://localhost:5432", schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.postgresql.Driver;
import scala.Option;

@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class LogicalRelationDatasetBuilderTest {

SparkSession session = mock(SparkSession.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import scala.Tuple2;

@Slf4j
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class PathUtilsTest {

private static final String HOME_TEST = "/home/test";
Expand Down Expand Up @@ -288,6 +289,7 @@ public void performTest() {
@Nested
class WithHiveSupport {
@Test
@SuppressWarnings("PMD")
void testFromCatalogTableShouldReturnADatasetIdentifierWithTheActualScheme() {
SparkConf sparkConf = new SparkConf();
sparkConf.set("spark.sql.hive.metastore.uris", "thrift://127.0.0.1:9876");
Expand All @@ -309,6 +311,7 @@ void testFromCatalogTableShouldReturnADatasetIdentifierWithTheActualScheme() {
@Nested
class WithoutHiveSupport {
@Test
@SuppressWarnings("PMD")
void testFromCatalogTableShouldReturnADatasetIdentifierWithTheActualScheme() {
SparkConf sparkConf = new SparkConf();
URI tableUri = URI.create("hdfs://namenode/user/hive/warehouse/foo.db/bar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class PlanUtilsTest {

@ParameterizedTest
@MethodSource()
@SuppressWarnings("PMD.UnusedPrivateMethod")
private static Stream<Arguments> provideJdbcUrls() {
return Stream.of(
Arguments.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import scala.collection.JavaConverters;
import scala.collection.Seq;

public class RddPathUtilsTest {
class RddPathUtilsTest {

@Test
void testFindRDDPathsForMapPartitionsRDD() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class RemovePathPatternUtilsTest {
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
class RemovePathPatternUtilsTest {

OpenLineageContext context = mock(OpenLineageContext.class);
SparkConf conf;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.apache.spark.SparkConf;
import org.junit.jupiter.api.Test;

public class SparkConfUtilsTest {
class SparkConfUtilsTest {

SparkConf conf = new SparkConf().set("existing.property", "test");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@
import org.junit.jupiter.api.Test;
import scala.PartialFunction;

@SuppressWarnings("PMD.JUnit5TestShouldBePackagePrivate")
public class VendorsTest implements Vendor {

static class VisitorFactoryTest implements VisitorFactory {

@Override
public List<PartialFunction<LogicalPlan, List<OpenLineage.InputDataset>>> getInputVisitors(
OpenLineageContext context) {
return null;
return Collections.emptyList();
}

@Override
public List<PartialFunction<LogicalPlan, List<OpenLineage.OutputDataset>>> getOutputVisitors(
OpenLineageContext context) {
return null;
return Collections.emptyList();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public Seq<LogicalPlan> children() {
return ScalaConversionUtils.<LogicalPlan>asScalaSeqEmpty();
}

@Override
public LogicalPlan withNewChildrenInternal(IndexedSeq<LogicalPlan> newChildren) {
return null;
}
Expand Down Expand Up @@ -159,6 +160,7 @@ public Seq<LogicalPlan> children() {
return ScalaConversionUtils.<LogicalPlan>asScalaSeqEmpty();
}

@Override
public LogicalPlan withNewChildrenInternal(IndexedSeq<LogicalPlan> newChildren) {
return null;
}
Expand Down

0 comments on commit 54e1973

Please sign in to comment.