From 0a42342cefc3d13ae9b3d4d55b802d9d906ddfbd Mon Sep 17 00:00:00 2001 From: Zoltan Haindrich Date: Tue, 19 Mar 2024 12:05:12 +0100 Subject: [PATCH] Update Calcite*Test to use junit5 (#16106) * Update Calcite*Test to use junit5 * change the way temp dirs are handled * add openrewrite workflow to safeguard upgrade * replace junitparamrunner with standard junit5 parametered tests * update a few rules to junit5 api * lots of boring changes * cleanup QueryLogHook * cleanup * fix compile error: ARRAYS_DATASOURCE * fix test * remove enclosed * empty +TEST:TDigestSketchSqlAggregatorTest,HllSketchSqlAggregatorTest,DoublesSketchSqlAggregatorTest,ThetaSketchSqlAggregatorTest,ArrayOfDoublesSketchSqlAggregatorTest,BloomFilterSqlAggregatorTest,BloomDimFilterSqlTest,CatalogIngestionTest,CatalogQueryTest,FixedBucketsHistogramQuantileSqlAggregatorTest,QuantileSqlAggregatorTest,MSQArraysTest,MSQDataSketchesTest,MSQExportTest,MSQFaultsTest,MSQInsertTest,MSQLoadedSegmentTests,MSQParseExceptionsTest,MSQReplaceTest,MSQSelectTest,InsertLockPreemptedFaultTest,MSQWarningsTest,SqlMSQStatementResourcePostTest,SqlStatementResourceTest,CalciteSelectJoinQueryMSQTest,CalciteSelectQueryMSQTest,CalciteUnionQueryMSQTest,MSQTestBase,VarianceSqlAggregatorTest,SleepSqlTest,SqlRowTransformerTest,DruidAvaticaHandlerTest,DruidStatementTest,BaseCalciteQueryTest,CalciteArraysQueryTest,CalciteCorrelatedQueryTest,CalciteExplainQueryTest,CalciteExportTest,CalciteIngestionDmlTest,CalciteInsertDmlTest,CalciteJoinQueryTest,CalciteLookupFunctionQueryTest,CalciteMultiValueStringQueryTest,CalciteNestedDataQueryTest,CalciteParameterQueryTest,CalciteQueryTest,CalciteReplaceDmlTest,CalciteScanSignatureTest,CalciteSelectQueryTest,CalciteSimpleQueryTest,CalciteSubqueryTest,CalciteSysQueryTest,CalciteTableAppendTest,CalciteTimeBoundaryQueryTest,CalciteUnionQueryTest,CalciteWindowQueryTest,DecoupledPlanningCalciteJoinQueryTest,DecoupledPlanningCalciteQueryTest,DecoupledPlanningCalciteUnionQueryTest,DrillWindowQueryTest,DruidPlannerResourceAnalyzeTest,IngestTableFunctionTest,QueryTestRunner,SqlTestFrameworkConfig,SqlAggregationModuleTest,ExpressionsTest,GreatestExpressionTest,IPv4AddressMatchExpressionTest,IPv4AddressParseExpressionTest,IPv4AddressStringifyExpressionTest,LeastExpressionTest,TimeFormatOperatorConversionTest,CombineAndSimplifyBoundsTest,FiltrationTest,SqlQueryTest,CalcitePlannerModuleTest,CalcitesTest,DruidCalciteSchemaModuleTest,DruidSchemaNoDataInitTest,InformationSchemaTest,NamedDruidSchemaTest,NamedLookupSchemaTest,NamedSystemSchemaTest,RootSchemaProviderTest,SystemSchemaTest,CalciteTestBase,SqlResourceTest * use @Nested * add rule to remove enclosed; upgrade surefire * remove enclosed * cleanup * add comment about surefire exclude --- .github/workflows/static-checks.yml | 24 +- .../compressed-bigdecimal/pom.xml | 35 +- ...pressedBigDecimalMaxSqlAggregatorTest.java | 20 +- ...pressedBigDecimalMinSqlAggregatorTest.java | 19 +- ...ressedBigDecimalSqlAggregatorTestBase.java | 10 +- ...pressedBigDecimalSumSqlAggregatorTest.java | 19 +- extensions-contrib/tdigestsketch/pom.xml | 25 ++ .../sql/TDigestSketchSqlAggregatorTest.java | 7 +- extensions-core/datasketches/pom.xml | 25 ++ .../hll/sql/HllSketchSqlAggregatorTest.java | 7 +- .../sql/DoublesSketchSqlAggregatorTest.java | 7 +- .../sql/ThetaSketchSqlAggregatorTest.java | 7 +- ...ArrayOfDoublesSketchSqlAggregatorTest.java | 7 +- extensions-core/druid-bloom-filter/pom.xml | 35 +- .../sql/BloomFilterSqlAggregatorTest.java | 7 +- .../filter/sql/BloomDimFilterSqlTest.java | 8 +- extensions-core/druid-catalog/pom.xml | 33 +- .../catalog/sql/CatalogIngestionTest.java | 11 +- .../druid/catalog/sql/CatalogQueryTest.java | 16 +- .../inputsource/hdfs/HdfsInputSourceTest.java | 3 - extensions-core/histogram/pom.xml | 35 +- ...etsHistogramQuantileSqlAggregatorTest.java | 7 +- .../sql/QuantileSqlAggregatorTest.java | 7 +- .../JdbcExtractionNamespaceUrlCheckTest.java | 3 - .../lookup/jdbc/JdbcDataFetcherTest.java | 3 - .../jdbc/JdbcDataFetcherUrlCheckTest.java | 3 - extensions-core/multi-stage-query/pom.xml | 29 +- .../apache/druid/msq/exec/MSQArraysTest.java | 117 ++--- .../druid/msq/exec/MSQDataSketchesTest.java | 2 +- .../apache/druid/msq/exec/MSQExportTest.java | 6 +- .../apache/druid/msq/exec/MSQFaultsTest.java | 32 +- .../apache/druid/msq/exec/MSQInsertTest.java | 265 ++++++----- .../druid/msq/exec/MSQLoadedSegmentTests.java | 6 +- .../msq/exec/MSQParseExceptionsTest.java | 23 +- .../apache/druid/msq/exec/MSQReplaceTest.java | 190 ++++---- .../apache/druid/msq/exec/MSQSelectTest.java | 349 ++++++++------- .../error/InsertLockPreemptedFaultTest.java | 2 +- .../msq/indexing/error/MSQWarningsTest.java | 9 +- .../SqlMSQStatementResourcePostTest.java | 10 +- .../resources/SqlStatementResourceTest.java | 8 +- .../msq/test/CalciteArraysQueryMSQTest.java | 2 +- .../druid/msq/test/CalciteMSQTestsHelper.java | 230 +++++----- .../test/CalciteSelectJoinQueryMSQTest.java | 15 +- .../msq/test/CalciteSelectQueryMSQTest.java | 46 +- .../msq/test/CalciteUnionQueryMSQTest.java | 8 +- .../apache/druid/msq/test/MSQTestBase.java | 149 +++---- .../druid/msq/test/MSQTestFileUtils.java | 74 ---- extensions-core/stats/pom.xml | 36 +- .../sql/VarianceSqlAggregatorTest.java | 7 +- extensions-core/testing-tools/pom.xml | 25 ++ .../apache/druid/query/sql/SleepSqlTest.java | 2 +- .../ParallelIndexSupervisorTaskTest.java | 2 - .../PartialDimensionCardinalityTaskTest.java | 3 - .../PartialDimensionDistributionTaskTest.java | 3 - .../distribution/StringSketchTest.java | 4 - ...tIndexTaskInputRowIteratorBuilderTest.java | 3 - pom.xml | 36 +- .../input/HandlingInputRowIteratorTest.java | 3 - .../org/apache/druid/frame/FrameTest.java | 2 - .../ReadableByteChunksFrameChannelTest.java | 2 - .../processor/FrameProcessorExecutorTest.java | 2 - .../frame/processor/SuperSorterTest.java | 2 - .../segment/FrameStorageAdapterTest.java | 2 - .../druid/guice/DruidSecondaryModuleTest.java | 3 - .../util/common/guava/TopNSequenceTest.java | 2 - .../apache/druid/metadata/TaskLookupTest.java | 3 - .../org/apache/druid/query/DruidsTest.java | 3 - .../GroupingAggregatorFactoryTest.java | 2 - .../scan/ScanQueryRunnerFactoryTest.java | 2 - .../QueryableIndexStorageAdapterTest.java | 2 - .../segment/data/VSizeLongSerdeTest.java | 2 - .../ArrayContainsElementFilterTests.java | 2 - .../segment/filter/EqualityFilterTests.java | 2 - .../druid/segment/filter/NullFilterTests.java | 2 - .../segment/filter/RangeFilterTests.java | 2 - .../table/IndexedTableJoinMatcherTest.java | 4 - .../druid/utils/ConnectionUriUtilsTest.java | 3 - .../utils/DynamicConfigProviderUtilsTest.java | 3 - rewrite.yml | 157 +++++++ server/pom.xml | 25 ++ .../druid/client/JsonParserIteratorTest.java | 2 - .../druid/metadata/TestDerbyConnector.java | 19 + sql/pom.xml | 15 +- .../druid/sql/SqlRowTransformerTest.java | 6 +- .../apache/druid/sql/SqlStatementTest.java | 4 - .../sql/avatica/DruidAvaticaHandlerTest.java | 112 +++-- .../druid/sql/avatica/DruidStatementTest.java | 34 +- .../sql/calcite/BaseCalciteQueryTest.java | 192 ++++---- .../sql/calcite/CalciteArraysQueryTest.java | 2 +- .../calcite/CalciteCorrelatedQueryTest.java | 28 +- .../sql/calcite/CalciteExplainQueryTest.java | 2 +- .../druid/sql/calcite/CalciteExportTest.java | 8 +- .../sql/calcite/CalciteIngestionDmlTest.java | 11 +- .../sql/calcite/CalciteInsertDmlTest.java | 12 +- .../sql/calcite/CalciteJoinQueryTest.java | 412 +++++++++--------- .../CalciteLookupFunctionQueryTest.java | 7 +- .../CalciteMultiValueStringQueryTest.java | 2 +- .../calcite/CalciteNestedDataQueryTest.java | 23 +- .../calcite/CalciteParameterQueryTest.java | 2 +- .../druid/sql/calcite/CalciteQueryTest.java | 46 +- .../sql/calcite/CalciteReplaceDmlTest.java | 6 +- .../sql/calcite/CalciteScanSignatureTest.java | 2 +- .../sql/calcite/CalciteSelectQueryTest.java | 2 +- .../sql/calcite/CalciteSimpleQueryTest.java | 2 +- .../sql/calcite/CalciteSubqueryTest.java | 138 +++--- .../sql/calcite/CalciteSysQueryTest.java | 8 +- .../sql/calcite/CalciteTableAppendTest.java | 20 +- .../calcite/CalciteTimeBoundaryQueryTest.java | 2 +- .../sql/calcite/CalciteUnionQueryTest.java | 13 +- .../sql/calcite/CalciteWindowQueryTest.java | 33 +- ...DecoupledPlanningCalciteJoinQueryTest.java | 26 +- .../DecoupledPlanningCalciteQueryTest.java | 7 +- ...ecoupledPlanningCalciteUnionQueryTest.java | 7 +- .../druid/sql/calcite/DisableUnless.java | 23 +- .../sql/calcite/DrillWindowQueryTest.java | 36 +- .../DruidPlannerResourceAnalyzeTest.java | 2 +- .../sql/calcite/IngestTableFunctionTest.java | 7 +- .../druid/sql/calcite/NotYetSupported.java | 95 ++-- .../druid/sql/calcite/QueryTestBuilder.java | 3 - .../druid/sql/calcite/QueryTestRunner.java | 17 +- .../sql/calcite/SqlTestFrameworkConfig.java | 57 +-- .../aggregation/SqlAggregationModuleTest.java | 12 +- .../calcite/expression/ExpressionsTest.java | 6 +- .../expression/GreatestExpressionTest.java | 6 +- .../IPv4AddressMatchExpressionTest.java | 6 +- .../IPv4AddressParseExpressionTest.java | 6 +- .../IPv4AddressStringifyExpressionTest.java | 6 +- .../expression/LeastExpressionTest.java | 6 +- .../expression/OperatorConversionsTest.java | 3 - .../TimeFormatOperatorConversionTest.java | 24 +- .../CombineAndSimplifyBoundsTest.java | 30 +- .../calcite/filtration/FiltrationTest.java | 2 +- .../druid/sql/calcite/http/SqlQueryTest.java | 2 +- .../parser/DruidSqlParserUtilsTest.java | 2 - .../planner/CalcitePlannerModuleTest.java | 14 +- .../sql/calcite/planner/CalcitesTest.java | 2 +- .../rule/DruidLogicalValuesRuleTest.java | 2 - .../schema/DruidCalciteSchemaModuleTest.java | 12 +- .../schema/DruidSchemaNoDataInitTest.java | 2 +- .../calcite/schema/InformationSchemaTest.java | 6 +- .../calcite/schema/NamedDruidSchemaTest.java | 12 +- .../calcite/schema/NamedLookupSchemaTest.java | 12 +- .../calcite/schema/NamedSystemSchemaTest.java | 6 +- .../schema/RootSchemaProviderTest.java | 22 +- .../sql/calcite/schema/SystemSchemaTest.java | 24 +- .../sql/calcite/util/CalciteTestBase.java | 70 ++- .../druid/sql/calcite/util/QueryLogHook.java | 82 +--- .../sql/calcite/util/SqlTestFramework.java | 21 +- .../druid/sql/http/SqlResourceTest.java | 42 +- 149 files changed, 2283 insertions(+), 1910 deletions(-) delete mode 100644 extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestFileUtils.java create mode 100644 rewrite.yml diff --git a/.github/workflows/static-checks.yml b/.github/workflows/static-checks.yml index c77d15888ed..a87000ac07e 100644 --- a/.github/workflows/static-checks.yml +++ b/.github/workflows/static-checks.yml @@ -34,7 +34,7 @@ env: MVN: mvn -B MAVEN_SKIP: -P skip-static-checks -Dweb.console.skip=true -Dmaven.javadoc.skip=true MAVEN_SKIP_TESTS: -P skip-tests - MAVEN_OPTS: -Xmx3000m + MAVEN_OPTS: -Xmx8g jobs: static-checks: @@ -144,6 +144,28 @@ jobs: --levels ERROR \ --scope JavaInspectionsScope + openrewrite: + runs-on: ubuntu-latest + steps: + - name: checkout branch + uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: 'zulu' + java-version: '8' + cache: 'maven' + + - name: maven install + run: | + echo 'Running Maven install...' && + ${MVN} clean install -q -ff -pl '!distribution' ${MAVEN_SKIP} ${MAVEN_SKIP_TESTS} -T1C && + ${MVN} install -q -ff -pl 'distribution' ${MAVEN_SKIP} ${MAVEN_SKIP_TESTS} + + - name: rewrite:dryRun + run: | + ${MVN} rewrite:dryRun ${MAVEN_SKIP} + web-checks: strategy: fail-fast: false diff --git a/extensions-contrib/compressed-bigdecimal/pom.xml b/extensions-contrib/compressed-bigdecimal/pom.xml index 5dfaf7c38e1..c70fb2251cc 100644 --- a/extensions-contrib/compressed-bigdecimal/pom.xml +++ b/extensions-contrib/compressed-bigdecimal/pom.xml @@ -63,6 +63,36 @@ + + junit + junit + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + org.apache.druid druid-processing @@ -91,11 +121,6 @@ test-jar test - - junit - junit - test - org.hamcrest java-hamcrest diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMaxSqlAggregatorTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMaxSqlAggregatorTest.java index 06709040b64..1223135ab27 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMaxSqlAggregatorTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMaxSqlAggregatorTest.java @@ -19,11 +19,17 @@ package org.apache.druid.compressedbigdecimal; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; + + public class CompressedBigDecimalMaxSqlAggregatorTest extends CompressedBigDecimalSqlAggregatorTestBase { private static final String FUNCTION_NAME = CompressedBigDecimalMaxSqlAggregator.NAME; @Override + @Test public void testCompressedBigDecimalAggWithNumberParse() { testCompressedBigDecimalAggWithNumberParseHelper( @@ -34,15 +40,19 @@ public class CompressedBigDecimalMaxSqlAggregatorTest extends CompressedBigDecim } @Override + @Test public void testCompressedBigDecimalAggWithStrictNumberParse() { - testCompressedBigDecimalAggWithStrictNumberParseHelper( - FUNCTION_NAME, - CompressedBigDecimalMaxAggregatorFactory::new - ); + assertThrows(NumberFormatException.class, () -> { + testCompressedBigDecimalAggWithStrictNumberParseHelper( + FUNCTION_NAME, + CompressedBigDecimalMaxAggregatorFactory::new + ); + }); } @Override + @Test public void testCompressedBigDecimalAggDefaultNumberParseAndCustomSizeAndScale() { testCompressedBigDecimalAggDefaultNumberParseAndCustomSizeAndScaleHelper( @@ -53,6 +63,7 @@ public class CompressedBigDecimalMaxSqlAggregatorTest extends CompressedBigDecim } @Override + @Test public void testCompressedBigDecimalAggDefaultScale() { testCompressedBigDecimalAggDefaultScaleHelper( @@ -63,6 +74,7 @@ public class CompressedBigDecimalMaxSqlAggregatorTest extends CompressedBigDecim } @Override + @Test public void testCompressedBigDecimalAggDefaultSizeAndScale() { testCompressedBigDecimalAggDefaultSizeAndScaleHelper( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMinSqlAggregatorTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMinSqlAggregatorTest.java index 3a18dd49652..e739b928f2e 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMinSqlAggregatorTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMinSqlAggregatorTest.java @@ -19,11 +19,16 @@ package org.apache.druid.compressedbigdecimal; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertThrows; + public class CompressedBigDecimalMinSqlAggregatorTest extends CompressedBigDecimalSqlAggregatorTestBase { private static final String FUNCTION_NAME = CompressedBigDecimalMinSqlAggregator.NAME; @Override + @Test public void testCompressedBigDecimalAggWithNumberParse() { testCompressedBigDecimalAggWithNumberParseHelper( @@ -34,15 +39,19 @@ public class CompressedBigDecimalMinSqlAggregatorTest extends CompressedBigDecim } @Override + @Test public void testCompressedBigDecimalAggWithStrictNumberParse() { - testCompressedBigDecimalAggWithStrictNumberParseHelper( - FUNCTION_NAME, - CompressedBigDecimalMinAggregatorFactory::new - ); + assertThrows(NumberFormatException.class, () -> { + testCompressedBigDecimalAggWithStrictNumberParseHelper( + FUNCTION_NAME, + CompressedBigDecimalMinAggregatorFactory::new + ); + }); } @Override + @Test public void testCompressedBigDecimalAggDefaultNumberParseAndCustomSizeAndScale() { testCompressedBigDecimalAggDefaultNumberParseAndCustomSizeAndScaleHelper( @@ -53,6 +62,7 @@ public class CompressedBigDecimalMinSqlAggregatorTest extends CompressedBigDecim } @Override + @Test public void testCompressedBigDecimalAggDefaultScale() { testCompressedBigDecimalAggDefaultScaleHelper( @@ -63,6 +73,7 @@ public class CompressedBigDecimalMinSqlAggregatorTest extends CompressedBigDecim } @Override + @Test public void testCompressedBigDecimalAggDefaultSizeAndScale() { testCompressedBigDecimalAggDefaultSizeAndScaleHelper( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSqlAggregatorTestBase.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSqlAggregatorTestBase.java index 2acc0d88e8d..baa9c0f32e8 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSqlAggregatorTestBase.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSqlAggregatorTestBase.java @@ -48,9 +48,8 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -80,11 +79,11 @@ public abstract class CompressedBigDecimalSqlAggregatorTestBase extends BaseCalc final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { QueryableIndex index = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() @@ -120,7 +119,8 @@ public abstract class CompressedBigDecimalSqlAggregatorTestBase extends BaseCalc @Test public abstract void testCompressedBigDecimalAggWithNumberParse(); - @Test(expected = NumberFormatException.class) + // expected: NumberFormatException.class + @Test public abstract void testCompressedBigDecimalAggWithStrictNumberParse(); @Test diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSumSqlAggregatorTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSumSqlAggregatorTest.java index db248ef67f0..8970f002ffe 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSumSqlAggregatorTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSumSqlAggregatorTest.java @@ -19,11 +19,16 @@ package org.apache.druid.compressedbigdecimal; +import org.junit.jupiter.api.Test; + +import static org.junit.Assert.assertThrows; + public class CompressedBigDecimalSumSqlAggregatorTest extends CompressedBigDecimalSqlAggregatorTestBase { private static final String FUNCTION_NAME = CompressedBigDecimalSumSqlAggregator.NAME; @Override + @Test public void testCompressedBigDecimalAggWithNumberParse() { testCompressedBigDecimalAggWithNumberParseHelper( @@ -34,15 +39,19 @@ public class CompressedBigDecimalSumSqlAggregatorTest extends CompressedBigDecim } @Override + @Test public void testCompressedBigDecimalAggWithStrictNumberParse() { - testCompressedBigDecimalAggWithStrictNumberParseHelper( - FUNCTION_NAME, - CompressedBigDecimalSumAggregatorFactory::new - ); + assertThrows(NumberFormatException.class, () -> { + testCompressedBigDecimalAggWithStrictNumberParseHelper( + FUNCTION_NAME, + CompressedBigDecimalSumAggregatorFactory::new + ); + }); } @Override + @Test public void testCompressedBigDecimalAggDefaultNumberParseAndCustomSizeAndScale() { testCompressedBigDecimalAggDefaultNumberParseAndCustomSizeAndScaleHelper( @@ -53,6 +62,7 @@ public class CompressedBigDecimalSumSqlAggregatorTest extends CompressedBigDecim } @Override + @Test public void testCompressedBigDecimalAggDefaultScale() { testCompressedBigDecimalAggDefaultScaleHelper( @@ -63,6 +73,7 @@ public class CompressedBigDecimalSumSqlAggregatorTest extends CompressedBigDecim } @Override + @Test public void testCompressedBigDecimalAggDefaultSizeAndScale() { testCompressedBigDecimalAggDefaultSizeAndScaleHelper( diff --git a/extensions-contrib/tdigestsketch/pom.xml b/extensions-contrib/tdigestsketch/pom.xml index 824a9af4398..ccfa7f6fb65 100644 --- a/extensions-contrib/tdigestsketch/pom.xml +++ b/extensions-contrib/tdigestsketch/pom.xml @@ -139,6 +139,31 @@ junit test + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + org.easymock easymock diff --git a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestSketchSqlAggregatorTest.java b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestSketchSqlAggregatorTest.java index de515814d23..2a3db93b81a 100644 --- a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestSketchSqlAggregatorTest.java +++ b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/sql/TDigestSketchSqlAggregatorTest.java @@ -53,9 +53,8 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.List; public class TDigestSketchSqlAggregatorTest extends BaseCalciteQueryTest @@ -72,13 +71,13 @@ public class TDigestSketchSqlAggregatorTest extends BaseCalciteQueryTest final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { TDigestSketchModule.registerSerde(); final QueryableIndex index = IndexBuilder.create(CalciteTests.getJsonMapper()) - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() diff --git a/extensions-core/datasketches/pom.xml b/extensions-core/datasketches/pom.xml index 4f2180f0e3b..bdd5b039161 100644 --- a/extensions-core/datasketches/pom.xml +++ b/extensions-core/datasketches/pom.xml @@ -150,6 +150,31 @@ junit test + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + joda-time joda-time diff --git a/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSqlAggregatorTest.java b/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSqlAggregatorTest.java index 538ca817180..b0eae011e2c 100644 --- a/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSqlAggregatorTest.java +++ b/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/hll/sql/HllSketchSqlAggregatorTest.java @@ -86,9 +86,8 @@ import org.apache.druid.timeline.partition.LinearShardSpec; import org.joda.time.DateTimeZone; import org.joda.time.Period; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -257,12 +256,12 @@ public class HllSketchSqlAggregatorTest extends BaseCalciteQueryTest final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { HllSketchModule.registerSerde(); final QueryableIndex index = IndexBuilder .create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() diff --git a/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSqlAggregatorTest.java b/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSqlAggregatorTest.java index c71890c036c..fe8680de984 100644 --- a/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSqlAggregatorTest.java +++ b/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/quantiles/sql/DoublesSketchSqlAggregatorTest.java @@ -62,9 +62,8 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -84,13 +83,13 @@ public class DoublesSketchSqlAggregatorTest extends BaseCalciteQueryTest final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { DoublesSketchModule.registerSerde(); final QueryableIndex index = IndexBuilder.create(CalciteTests.getJsonMapper()) - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() diff --git a/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSqlAggregatorTest.java b/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSqlAggregatorTest.java index 2650e15a04b..19dc255ff2f 100644 --- a/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSqlAggregatorTest.java +++ b/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/theta/sql/ThetaSketchSqlAggregatorTest.java @@ -70,9 +70,8 @@ import org.apache.druid.timeline.partition.LinearShardSpec; import org.joda.time.DateTimeZone; import org.joda.time.Period; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -111,12 +110,12 @@ public class ThetaSketchSqlAggregatorTest extends BaseCalciteQueryTest final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { SketchModule.registerSerde(); final QueryableIndex index = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() diff --git a/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/tuple/sql/ArrayOfDoublesSketchSqlAggregatorTest.java b/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/tuple/sql/ArrayOfDoublesSketchSqlAggregatorTest.java index 134c2c76e4f..0ed01f3f411 100644 --- a/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/tuple/sql/ArrayOfDoublesSketchSqlAggregatorTest.java +++ b/extensions-core/datasketches/src/test/java/org/apache/druid/query/aggregation/datasketches/tuple/sql/ArrayOfDoublesSketchSqlAggregatorTest.java @@ -52,9 +52,8 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.List; import java.util.stream.Collectors; @@ -111,12 +110,12 @@ public class ArrayOfDoublesSketchSqlAggregatorTest extends BaseCalciteQueryTest final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { ArrayOfDoublesSketchModule.registerSerde(); final QueryableIndex index = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory( OffHeapMemorySegmentWriteOutMediumFactory.instance() ) diff --git a/extensions-core/druid-bloom-filter/pom.xml b/extensions-core/druid-bloom-filter/pom.xml index 6106ba74ca2..fcb6905b195 100644 --- a/extensions-core/druid-bloom-filter/pom.xml +++ b/extensions-core/druid-bloom-filter/pom.xml @@ -109,6 +109,36 @@ + + junit + junit + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + org.apache.druid druid-processing @@ -130,11 +160,6 @@ test test-jar - - junit - junit - test - org.easymock easymock diff --git a/extensions-core/druid-bloom-filter/src/test/java/org/apache/druid/query/aggregation/bloom/sql/BloomFilterSqlAggregatorTest.java b/extensions-core/druid-bloom-filter/src/test/java/org/apache/druid/query/aggregation/bloom/sql/BloomFilterSqlAggregatorTest.java index 8dcab824abf..8d00b5b559a 100644 --- a/extensions-core/druid-bloom-filter/src/test/java/org/apache/druid/query/aggregation/bloom/sql/BloomFilterSqlAggregatorTest.java +++ b/extensions-core/druid-bloom-filter/src/test/java/org/apache/druid/query/aggregation/bloom/sql/BloomFilterSqlAggregatorTest.java @@ -54,9 +54,8 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.List; public class BloomFilterSqlAggregatorTest extends BaseCalciteQueryTest @@ -77,11 +76,11 @@ public class BloomFilterSqlAggregatorTest extends BaseCalciteQueryTest final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { final QueryableIndex index = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() diff --git a/extensions-core/druid-bloom-filter/src/test/java/org/apache/druid/query/filter/sql/BloomDimFilterSqlTest.java b/extensions-core/druid-bloom-filter/src/test/java/org/apache/druid/query/filter/sql/BloomDimFilterSqlTest.java index 15152694ce4..49632c79a81 100644 --- a/extensions-core/druid-bloom-filter/src/test/java/org/apache/druid/query/filter/sql/BloomDimFilterSqlTest.java +++ b/extensions-core/druid-bloom-filter/src/test/java/org/apache/druid/query/filter/sql/BloomDimFilterSqlTest.java @@ -39,8 +39,8 @@ import org.apache.druid.sql.calcite.BaseCalciteQueryTest; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.http.SqlParameter; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; @@ -219,7 +219,7 @@ public class BloomDimFilterSqlTest extends BaseCalciteQueryTest ); } - @Ignore("this test is really slow and is intended to use for comparisons with testBloomFilterBigParameter") + @Disabled("this test is really slow and is intended to use for comparisons with testBloomFilterBigParameter") @Test public void testBloomFilterBigNoParam() throws IOException { @@ -247,7 +247,7 @@ public class BloomDimFilterSqlTest extends BaseCalciteQueryTest ); } - @Ignore("this test is for comparison with testBloomFilterBigNoParam") + @Disabled("this test is for comparison with testBloomFilterBigNoParam") @Test public void testBloomFilterBigParameter() throws IOException { diff --git a/extensions-core/druid-catalog/pom.xml b/extensions-core/druid-catalog/pom.xml index 5c4614573fd..6e16ff62ccc 100644 --- a/extensions-core/druid-catalog/pom.xml +++ b/extensions-core/druid-catalog/pom.xml @@ -148,13 +148,38 @@ - org.easymock - easymock + junit + junit test - junit - junit + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + + + org.easymock + easymock test diff --git a/extensions-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogIngestionTest.java b/extensions-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogIngestionTest.java index e4020cc86d0..aa3e0f9b852 100644 --- a/extensions-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogIngestionTest.java +++ b/extensions-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogIngestionTest.java @@ -28,7 +28,7 @@ import org.apache.druid.catalog.storage.CatalogTests; import org.apache.druid.catalog.sync.CachedMetadataCatalog; import org.apache.druid.catalog.sync.MetadataCatalog; import org.apache.druid.java.util.common.granularity.Granularities; -import org.apache.druid.metadata.TestDerbyConnector; +import org.apache.druid.metadata.TestDerbyConnector.DerbyConnectorRule5; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.CalciteIngestionDmlTest; @@ -36,8 +36,8 @@ import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.planner.CatalogResolver; import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.SqlTestFramework; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.util.Arrays; @@ -48,9 +48,8 @@ import static org.junit.Assert.fail; */ public class CatalogIngestionTest extends CalciteIngestionDmlTest { - @ClassRule - public static final TestDerbyConnector.DerbyConnectorRule DERBY_CONNECTION_RULE = - new TestDerbyConnector.DerbyConnectorRule(); + @RegisterExtension + public static final DerbyConnectorRule5 DERBY_CONNECTION_RULE = new DerbyConnectorRule5(); /** * Signature for the foo datasource after applying catalog metadata. diff --git a/extensions-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogQueryTest.java b/extensions-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogQueryTest.java index 2ee9041fc92..b947c2e2c96 100644 --- a/extensions-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogQueryTest.java +++ b/extensions-core/druid-catalog/src/test/java/org/apache/druid/catalog/sql/CatalogQueryTest.java @@ -27,14 +27,14 @@ import org.apache.druid.catalog.storage.CatalogStorage; import org.apache.druid.catalog.storage.CatalogTests; import org.apache.druid.catalog.sync.CachedMetadataCatalog; import org.apache.druid.catalog.sync.MetadataCatalog; -import org.apache.druid.metadata.TestDerbyConnector; +import org.apache.druid.metadata.TestDerbyConnector.DerbyConnectorRule5; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; import org.apache.druid.sql.calcite.SqlSchema; import org.apache.druid.sql.calcite.planner.CatalogResolver; import org.apache.druid.sql.calcite.util.SqlTestFramework; -import org.junit.After; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.util.Arrays; import java.util.Collections; @@ -43,8 +43,8 @@ import static org.junit.Assert.fail; public class CatalogQueryTest extends BaseCalciteQueryTest { - @Rule - public final TestDerbyConnector.DerbyConnectorRule derbyConnectorRule = new TestDerbyConnector.DerbyConnectorRule(); + @RegisterExtension + public static final DerbyConnectorRule5 DERBY_CONNECTION_RULE = new DerbyConnectorRule5(); private CatalogTests.DbFixture dbFixture; private CatalogStorage storage; @@ -70,7 +70,7 @@ public class CatalogQueryTest extends BaseCalciteQueryTest .run(); } - @After + @AfterEach public void catalogTearDown() { CatalogTests.tearDown(dbFixture); @@ -79,7 +79,7 @@ public class CatalogQueryTest extends BaseCalciteQueryTest @Override public CatalogResolver createCatalogResolver() { - dbFixture = new CatalogTests.DbFixture(derbyConnectorRule); + dbFixture = new CatalogTests.DbFixture(DERBY_CONNECTION_RULE); storage = dbFixture.storage; MetadataCatalog catalog = new CachedMetadataCatalog( storage, diff --git a/extensions-core/hdfs-storage/src/test/java/org/apache/druid/inputsource/hdfs/HdfsInputSourceTest.java b/extensions-core/hdfs-storage/src/test/java/org/apache/druid/inputsource/hdfs/HdfsInputSourceTest.java index 918f051d224..10cff01c2b9 100644 --- a/extensions-core/hdfs-storage/src/test/java/org/apache/druid/inputsource/hdfs/HdfsInputSourceTest.java +++ b/extensions-core/hdfs-storage/src/test/java/org/apache/druid/inputsource/hdfs/HdfsInputSourceTest.java @@ -53,10 +53,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; import java.io.BufferedWriter; import java.io.File; @@ -76,7 +74,6 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; -@RunWith(Enclosed.class) public class HdfsInputSourceTest extends InitializedNullHandlingTest { private static final String PATH = "hdfs://localhost:7020/foo/bar"; diff --git a/extensions-core/histogram/pom.xml b/extensions-core/histogram/pom.xml index 787571ccef7..936b592614c 100644 --- a/extensions-core/histogram/pom.xml +++ b/extensions-core/histogram/pom.xml @@ -93,6 +93,36 @@ + + junit + junit + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + org.apache.druid druid-processing @@ -114,11 +144,6 @@ test test-jar - - junit - junit - test - org.easymock easymock diff --git a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/sql/FixedBucketsHistogramQuantileSqlAggregatorTest.java b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/sql/FixedBucketsHistogramQuantileSqlAggregatorTest.java index 75a29ab4f2f..bb6a7e82ba9 100644 --- a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/sql/FixedBucketsHistogramQuantileSqlAggregatorTest.java +++ b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/sql/FixedBucketsHistogramQuantileSqlAggregatorTest.java @@ -56,9 +56,8 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.List; public class FixedBucketsHistogramQuantileSqlAggregatorTest extends BaseCalciteQueryTest @@ -75,12 +74,12 @@ public class FixedBucketsHistogramQuantileSqlAggregatorTest extends BaseCalciteQ final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { ApproximateHistogramDruidModule.registerSerde(); final QueryableIndex index = IndexBuilder.create(CalciteTests.getJsonMapper()) - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() diff --git a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/sql/QuantileSqlAggregatorTest.java b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/sql/QuantileSqlAggregatorTest.java index 3ee18f886f0..a14be3162e5 100644 --- a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/sql/QuantileSqlAggregatorTest.java +++ b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/sql/QuantileSqlAggregatorTest.java @@ -55,9 +55,8 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.List; public class QuantileSqlAggregatorTest extends BaseCalciteQueryTest @@ -74,12 +73,12 @@ public class QuantileSqlAggregatorTest extends BaseCalciteQueryTest final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { ApproximateHistogramDruidModule.registerSerde(); final QueryableIndex index = IndexBuilder.create(CalciteTests.getJsonMapper()) - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() diff --git a/extensions-core/lookups-cached-global/src/test/java/org/apache/druid/query/lookup/namespace/JdbcExtractionNamespaceUrlCheckTest.java b/extensions-core/lookups-cached-global/src/test/java/org/apache/druid/query/lookup/namespace/JdbcExtractionNamespaceUrlCheckTest.java index 178abca9c49..d2ba30b4946 100644 --- a/extensions-core/lookups-cached-global/src/test/java/org/apache/druid/query/lookup/namespace/JdbcExtractionNamespaceUrlCheckTest.java +++ b/extensions-core/lookups-cached-global/src/test/java/org/apache/druid/query/lookup/namespace/JdbcExtractionNamespaceUrlCheckTest.java @@ -25,13 +25,10 @@ import org.apache.druid.server.initialization.JdbcAccessSecurityConfig; import org.joda.time.Period; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import java.util.Set; -@RunWith(Enclosed.class) public class JdbcExtractionNamespaceUrlCheckTest { private static final String TABLE_NAME = "abstractDbRenameTest"; diff --git a/extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/jdbc/JdbcDataFetcherTest.java b/extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/jdbc/JdbcDataFetcherTest.java index 1139d4c91fc..b437d2a3d55 100644 --- a/extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/jdbc/JdbcDataFetcherTest.java +++ b/extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/jdbc/JdbcDataFetcherTest.java @@ -35,9 +35,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.skife.jdbi.v2.Handle; import java.io.IOException; @@ -45,7 +43,6 @@ import java.io.UncheckedIOException; import java.util.Collections; import java.util.Map; -@RunWith(Enclosed.class) public class JdbcDataFetcherTest extends InitializedNullHandlingTest { private static final String TABLE_NAME = "tableName"; diff --git a/extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/jdbc/JdbcDataFetcherUrlCheckTest.java b/extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/jdbc/JdbcDataFetcherUrlCheckTest.java index 8f7f2e9d6d6..b38875b5189 100644 --- a/extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/jdbc/JdbcDataFetcherUrlCheckTest.java +++ b/extensions-core/lookups-cached-single/src/test/java/org/apache/druid/server/lookup/jdbc/JdbcDataFetcherUrlCheckTest.java @@ -24,13 +24,10 @@ import org.apache.druid.metadata.MetadataStorageConnectorConfig; import org.apache.druid.server.initialization.JdbcAccessSecurityConfig; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import java.util.Set; -@RunWith(Enclosed.class) public class JdbcDataFetcherUrlCheckTest { private static final String TABLE_NAME = "tableName"; diff --git a/extensions-core/multi-stage-query/pom.xml b/extensions-core/multi-stage-query/pom.xml index 163a90ae09b..58e1976d556 100644 --- a/extensions-core/multi-stage-query/pom.xml +++ b/extensions-core/multi-stage-query/pom.xml @@ -203,11 +203,31 @@ + + junit + junit + test + org.junit.jupiter junit-jupiter-api test + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + org.easymock easymock @@ -224,8 +244,13 @@ test - junit - junit + org.junit.jupiter + junit-jupiter + test + + + org.junit.vintage + junit-vintage-engine test diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQArraysTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQArraysTest.java index cbf2d68a285..d3f7e6a1473 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQArraysTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQArraysTest.java @@ -49,11 +49,10 @@ import org.apache.druid.sql.calcite.planner.ColumnMappings; import org.apache.druid.timeline.SegmentId; import org.apache.druid.utils.CompressionUtils; import org.hamcrest.CoreMatchers; -import org.junit.Before; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.io.IOException; @@ -71,14 +70,12 @@ import java.util.Map; /** * Tests INSERT and SELECT behaviour of MSQ with arrays and MVDs */ -@RunWith(Parameterized.class) public class MSQArraysTest extends MSQTestBase { private String dataFileNameJsonString; private String dataFileSignatureJsonString; private DataSource dataFileExternalDataSource; - @Parameterized.Parameters(name = "{index}:with context {0}") public static Collection data() { Object[][] data = new Object[][]{ @@ -90,17 +87,11 @@ public class MSQArraysTest extends MSQTestBase return Arrays.asList(data); } - @Parameterized.Parameter(0) - public String contextName; - - @Parameterized.Parameter(1) - public Map context; - - @Before + @BeforeEach public void setup() throws IOException { // Read the file and make the name available to the tests - File dataFile = temporaryFolder.newFile(); + File dataFile = newTempFile("dataFile"); final InputStream resourceStream = NestedDataTestUtils.class.getClassLoader() .getResourceAsStream(NestedDataTestUtils.ARRAY_TYPES_DATA_FILE); final InputStream decompressing = CompressionUtils.decompress( @@ -134,8 +125,9 @@ public class MSQArraysTest extends MSQTestBase * Tests the behaviour of INSERT query when arrayIngestMode is set to none (default) and the user tries to ingest * string arrays */ - @Test - public void testInsertStringArrayWithArrayIngestModeNone() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertStringArrayWithArrayIngestModeNone(String contextName, Map context) { final Map adjustedContext = new HashMap<>(context); @@ -156,8 +148,9 @@ public class MSQArraysTest extends MSQTestBase * Tests the behaviour of INSERT query when arrayIngestMode is set to none (default) and the user tries to ingest * string arrays */ - @Test - public void testReplaceMvdWithStringArray() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceMvdWithStringArray(String contextName, Map context) { final Map adjustedContext = new HashMap<>(context); adjustedContext.put(MultiStageQueryContext.CTX_ARRAY_INGEST_MODE, "array"); @@ -182,8 +175,9 @@ public class MSQArraysTest extends MSQTestBase * Tests the behaviour of INSERT query when arrayIngestMode is set to none (default) and the user tries to ingest * string arrays */ - @Test - public void testReplaceStringArrayWithMvdInArrayMode() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceStringArrayWithMvdInArrayMode(String contextName, Map context) { final Map adjustedContext = new HashMap<>(context); adjustedContext.put(MultiStageQueryContext.CTX_ARRAY_INGEST_MODE, "array"); @@ -209,8 +203,9 @@ public class MSQArraysTest extends MSQTestBase * Tests the behaviour of INSERT query when arrayIngestMode is set to none (default) and the user tries to ingest * string arrays */ - @Test - public void testReplaceStringArrayWithMvdInMvdMode() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceStringArrayWithMvdInMvdMode(String contextName, Map context) { final Map adjustedContext = new HashMap<>(context); adjustedContext.put(MultiStageQueryContext.CTX_ARRAY_INGEST_MODE, "mvd"); @@ -236,8 +231,9 @@ public class MSQArraysTest extends MSQTestBase * Tests the behaviour of INSERT query when arrayIngestMode is set to none (default) and the user tries to ingest * string arrays */ - @Test - public void testReplaceMvdWithStringArraySkipValidation() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceMvdWithStringArraySkipValidation(String contextName, Map context) { final Map adjustedContext = new HashMap<>(context); adjustedContext.put(MultiStageQueryContext.CTX_ARRAY_INGEST_MODE, "array"); @@ -284,8 +280,9 @@ public class MSQArraysTest extends MSQTestBase * Tests the behaviour of INSERT query when arrayIngestMode is set to none (default) and the user tries to ingest * string arrays */ - @Test - public void testReplaceMvdWithMvd() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceMvdWithMvd(String contextName, Map context) { final Map adjustedContext = new HashMap<>(context); adjustedContext.put(MultiStageQueryContext.CTX_ARRAY_INGEST_MODE, "array"); @@ -322,8 +319,9 @@ public class MSQArraysTest extends MSQTestBase * Tests the behaviour of INSERT query when arrayIngestMode is set to mvd (default) and the only array type to be * ingested is string array */ - @Test - public void testInsertOnFoo1WithMultiValueToArrayGroupByWithDefaultContext() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithMultiValueToArrayGroupByWithDefaultContext(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -343,8 +341,9 @@ public class MSQArraysTest extends MSQTestBase /** * Tests the INSERT query when 'auto' type is set */ - @Test - public void testInsertArraysAutoType() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertArraysAutoType(String contextName, Map context) { List expectedRows = Arrays.asList( new Object[]{1672531200000L, null, null, null}, @@ -396,8 +395,9 @@ public class MSQArraysTest extends MSQTestBase * Tests the behaviour of INSERT query when arrayIngestMode is set to mvd and the user tries to ingest numeric array * types as well */ - @Test - public void testInsertArraysWithStringArraysAsMVDs() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertArraysWithStringArraysAsMVDs(String contextName, Map context) { final Map adjustedContext = new HashMap<>(context); adjustedContext.put(MultiStageQueryContext.CTX_ARRAY_INGEST_MODE, "mvd"); @@ -430,8 +430,9 @@ public class MSQArraysTest extends MSQTestBase * Tests the behaviour of INSERT query when arrayIngestMode is set to array and the user tries to ingest all * array types */ - @Test - public void testInsertArraysAsArrays() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertArraysAsArrays(String contextName, Map context) { final List expectedRows = Arrays.asList( new Object[]{ @@ -602,27 +603,30 @@ public class MSQArraysTest extends MSQTestBase .verifyResults(); } - @Test - public void testSelectOnArraysWithArrayIngestModeAsNone() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnArraysWithArrayIngestModeAsNone(String contextName, Map context) { - testSelectOnArrays("none"); + testSelectOnArrays(contextName, context, "none"); } - @Test - public void testSelectOnArraysWithArrayIngestModeAsMVD() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnArraysWithArrayIngestModeAsMVD(String contextName, Map context) { - testSelectOnArrays("mvd"); + testSelectOnArrays(contextName, context, "mvd"); } - @Test - public void testSelectOnArraysWithArrayIngestModeAsArray() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnArraysWithArrayIngestModeAsArray(String contextName, Map context) { - testSelectOnArrays("array"); + testSelectOnArrays(contextName, context, "array"); } // Tests the behaviour of the select with the given arrayIngestMode. The expectation should be the same, since the // arrayIngestMode should only determine how the array gets ingested at the end. - public void testSelectOnArrays(String arrayIngestMode) + public void testSelectOnArrays(String contextName, Map context, String arrayIngestMode) { final List expectedRows = Arrays.asList( new Object[]{ @@ -839,8 +843,9 @@ public class MSQArraysTest extends MSQTestBase .verifyResults(); } - @Test - public void testScanWithOrderByOnStringArray() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testScanWithOrderByOnStringArray(String contextName, Map context) { final List expectedRows = Arrays.asList( new Object[]{Arrays.asList("d", "e")}, @@ -902,8 +907,9 @@ public class MSQArraysTest extends MSQTestBase .verifyResults(); } - @Test - public void testScanWithOrderByOnLongArray() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testScanWithOrderByOnLongArray(String contextName, Map context) { final List expectedRows = Arrays.asList( new Object[]{null}, @@ -964,8 +970,9 @@ public class MSQArraysTest extends MSQTestBase .verifyResults(); } - @Test - public void testScanWithOrderByOnDoubleArray() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testScanWithOrderByOnDoubleArray(String contextName, Map context) { final List expectedRows = Arrays.asList( new Object[]{null}, @@ -1026,8 +1033,9 @@ public class MSQArraysTest extends MSQTestBase .verifyResults(); } - @Test - public void testScanExternBooleanArray() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testScanExternBooleanArray(String contextName, Map context) { final List expectedRows = Collections.singletonList( new Object[]{Arrays.asList(1L, 0L, null)} @@ -1073,8 +1081,9 @@ public class MSQArraysTest extends MSQTestBase .verifyResults(); } - @Test - public void testScanExternArrayWithNonConvertibleType() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testScanExternArrayWithNonConvertibleType(String contextName, Map context) { final List expectedRows = Collections.singletonList( new Object[]{Arrays.asList(null, null)} diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQDataSketchesTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQDataSketchesTest.java index 1f856027de3..15fa79390c9 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQDataSketchesTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQDataSketchesTest.java @@ -36,7 +36,7 @@ import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.planner.ColumnMapping; import org.apache.druid.sql.calcite.planner.ColumnMappings; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests of MSQ with functions from the "druid-datasketches" extension. diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQExportTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQExportTest.java index 4619335bb87..cbe9a358f72 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQExportTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQExportTest.java @@ -27,7 +27,7 @@ import org.apache.druid.msq.util.MultiStageQueryContext; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.BufferedReader; import java.io.File; @@ -106,14 +106,14 @@ public class MSQExportTest extends MSQTestBase } @Test - public void testNumberOfRowsPerFile() throws IOException + public void testNumberOfRowsPerFile() { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) .add("dim1", ColumnType.STRING) .add("cnt", ColumnType.LONG).build(); - File exportDir = temporaryFolder.newFolder("export/"); + File exportDir = newTempFolder("export"); Map queryContext = new HashMap<>(DEFAULT_MSQ_CONTEXT); queryContext.put(MultiStageQueryContext.CTX_ROWS_PER_PAGE, 1); diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQFaultsTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQFaultsTest.java index 974f617ff2d..b3b1442074b 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQFaultsTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQFaultsTest.java @@ -19,6 +19,7 @@ package org.apache.druid.msq.exec; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import org.apache.druid.error.DruidException; @@ -40,7 +41,6 @@ import org.apache.druid.msq.indexing.error.TooManyColumnsFault; import org.apache.druid.msq.indexing.error.TooManyInputFilesFault; import org.apache.druid.msq.indexing.error.TooManyPartitionsFault; import org.apache.druid.msq.test.MSQTestBase; -import org.apache.druid.msq.test.MSQTestFileUtils; import org.apache.druid.msq.test.MSQTestTaskActionClient; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; @@ -49,13 +49,16 @@ import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.DimensionRangeShardSpec; import org.apache.druid.timeline.partition.LinearShardSpec; import org.hamcrest.CoreMatchers; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.StandardOpenOption; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -291,7 +294,7 @@ public class MSQFaultsTest extends MSQTestBase .add("__time", ColumnType.LONG) .build(); - File file = MSQTestFileUtils.generateTemporaryNdJsonFile(temporaryFolder, 30000, 1); + File file = createNdJsonFile(newTempFile("ndjson30k"), 30000, 1); String filePathAsJson = queryFramework().queryJsonMapper().writeValueAsString(file.getAbsolutePath()); testIngestQuery().setSql(" insert into foo1 SELECT\n" @@ -311,6 +314,27 @@ public class MSQFaultsTest extends MSQTestBase } + /** + * Helper method that populates a file with {@code numRows} rows and {@code numColumns} columns where the + * first column is a string 'timestamp' while the rest are string columns with junk value + */ + public static File createNdJsonFile(File file, final int numRows, final int numColumns) throws IOException + { + for (int currentRow = 0; currentRow < numRows; ++currentRow) { + StringBuilder sb = new StringBuilder(); + sb.append("{"); + sb.append("\"timestamp\":\"2016-06-27T00:00:11.080Z\""); + for (int currentColumn = 1; currentColumn < numColumns; ++currentColumn) { + sb.append(StringUtils.format(",\"column%s\":\"val%s\"", currentColumn, currentRow)); + } + sb.append("}"); + Files.write(file.toPath(), ImmutableList.of(sb.toString()), StandardCharsets.UTF_8, StandardOpenOption.APPEND); + } + return file; + } + + + @Test public void testInsertWithManyColumns() { @@ -399,7 +423,7 @@ public class MSQFaultsTest extends MSQTestBase final int numFiles = 20000; - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadFileNameAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); String externalFiles = String.join(", ", Collections.nCopies(numFiles, toReadFileNameAsJson)); diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQInsertTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQInsertTest.java index 6ce1785672f..d22b2d7481e 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQInsertTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQInsertTest.java @@ -38,7 +38,6 @@ import org.apache.druid.msq.indexing.error.RowTooLargeFault; import org.apache.druid.msq.kernel.WorkerAssignmentStrategy; import org.apache.druid.msq.test.CounterSnapshotMatcher; import org.apache.druid.msq.test.MSQTestBase; -import org.apache.druid.msq.test.MSQTestFileUtils; import org.apache.druid.msq.util.MultiStageQueryContext; import org.apache.druid.query.QueryContexts; import org.apache.druid.query.aggregation.LongSumAggregatorFactory; @@ -48,10 +47,9 @@ import org.apache.druid.segment.column.RowSignature; import org.apache.druid.segment.column.ValueType; import org.apache.druid.timeline.SegmentId; import org.hamcrest.CoreMatchers; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; import java.io.File; @@ -67,7 +65,6 @@ import java.util.Set; import java.util.TreeSet; -@RunWith(Parameterized.class) public class MSQInsertTest extends MSQTestBase { @@ -82,7 +79,6 @@ public class MSQInsertTest extends MSQTestBase .build(); private final HashFunction fn = Hashing.murmur3_128(); - @Parameterized.Parameters(name = "{index}:with context {0}") public static Collection data() { Object[][] data = new Object[][]{ @@ -94,15 +90,9 @@ public class MSQInsertTest extends MSQTestBase }; return Arrays.asList(data); } - - @Parameterized.Parameter(0) - public String contextName; - - @Parameterized.Parameter(1) - public Map context; - - @Test - public void testInsertOnFoo1() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1(String contextName, Map context) { List expectedRows = expectedFooRows(); int expectedCounterRows = expectedRows.size(); @@ -154,8 +144,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertWithExistingTimeColumn() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertWithExistingTimeColumn(String contextName, Map context) throws IOException { List expectedRows = ImmutableList.of( new Object[] {1678897351000L, "A"}, @@ -168,9 +159,7 @@ public class MSQInsertTest extends MSQTestBase .add("flags", ColumnType.STRING) .build(); - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, - "/dataset-with-time-column.json" - ); + final File toRead = getResourceAsTemporaryFile("/dataset-with-time-column.json"); final String toReadFileNameAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); testIngestQuery().setSql(" INSERT INTO foo1 SELECT\n" @@ -193,8 +182,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertWithUnnestInline() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertWithUnnestInline(String contextName, Map context) { List expectedRows = ImmutableList.of( new Object[]{1692226800000L, 1L}, @@ -218,8 +208,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertWithUnnest() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertWithUnnest(String contextName, Map context) { List expectedRows = ImmutableList.of( new Object[]{946684800000L, "a"}, @@ -248,8 +239,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertWithUnnestWithVirtualColumns() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertWithUnnestWithVirtualColumns(String contextName, Map context) { List expectedRows = ImmutableList.of( new Object[]{946684800000L, 1.0f}, @@ -282,10 +274,11 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertOnExternalDataSource() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnExternalDataSource(String contextName, Map context) throws IOException { - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadFileNameAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -347,8 +340,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertOnFoo1WithGroupByLimitWithoutClusterBy() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithGroupByLimitWithoutClusterBy(String contextName, Map context) { List expectedRows = expectedFooRows(); int expectedCounterRows = expectedRows.size(); @@ -395,8 +389,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertOnFoo1WithTwoCountAggregatorsWithRollupContext() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithTwoCountAggregatorsWithRollupContext(String contextName, Map context) { final List expectedRows = expectedFooRows(); @@ -434,8 +429,9 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertOnFoo1WithGroupByLimitWithClusterBy() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithGroupByLimitWithClusterBy(String contextName, Map context) { List expectedRows = expectedFooRows(); int expectedCounterRows = expectedRows.size(); @@ -485,8 +481,10 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertOnFoo1WithTimeFunction() + + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithTimeFunction(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -504,8 +502,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertOnFoo1WithTimeAggregator() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithTimeAggregator(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -534,8 +533,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertOnFoo1WithTimeAggregatorAndMultipleWorkers() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithTimeAggregatorAndMultipleWorkers(String contextName, Map context) { Map localContext = new HashMap<>(context); localContext.put(MultiStageQueryContext.CTX_TASK_ASSIGNMENT_STRATEGY, WorkerAssignmentStrategy.MAX.name()); @@ -568,8 +568,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertOnFoo1WithTimePostAggregator() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithTimePostAggregator(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -599,8 +600,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertOnFoo1WithTimeFunctionWithSequential() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithTimeFunctionWithSequential(String contextName, Map context) { List expectedRows = expectedFooRows(); int expectedCounterRows = expectedRows.size(); @@ -610,7 +612,7 @@ public class MSQInsertTest extends MSQTestBase .add("__time", ColumnType.LONG) .add("dim1", ColumnType.STRING) .add("cnt", ColumnType.LONG).build(); - Map context = ImmutableMap.builder() + Map newContext = ImmutableMap.builder() .putAll(DEFAULT_MSQ_CONTEXT) .put( MultiStageQueryContext.CTX_CLUSTER_STATISTICS_MERGE_MODE, @@ -620,10 +622,10 @@ public class MSQInsertTest extends MSQTestBase testIngestQuery().setSql( "insert into foo1 select floor(__time to day) as __time , dim1 , count(*) as cnt from foo where dim1 is not null group by 1, 2 PARTITIONED by day clustered by dim1") - .setQueryContext(context) + .setQueryContext(newContext) .setExpectedDataSource("foo1") .setExpectedRowSignature(rowSignature) - .setQueryContext(MSQInsertTest.this.context) + .setQueryContext(context) .setExpectedSegment(expectedFooSegments()) .setExpectedResultRows(expectedRows) .setExpectedCountersForStageWorkerChannel( @@ -660,8 +662,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertOnFoo1WithMultiValueDim() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithMultiValueDim(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -677,8 +680,9 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertOnFoo1MultiValueDimWithLimitWithoutClusterBy() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1MultiValueDimWithLimitWithoutClusterBy(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -694,8 +698,9 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertOnFoo1MultiValueDimWithLimitWithClusterBy() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1MultiValueDimWithLimitWithClusterBy(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -711,8 +716,9 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertOnFoo1WithMultiValueDimGroupBy() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithMultiValueDimGroupBy(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -728,8 +734,9 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertOnFoo1WithMultiValueMeasureGroupBy() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithMultiValueMeasureGroupBy(String contextName, Map context) { testIngestQuery().setSql( "INSERT INTO foo1 SELECT count(dim3) FROM foo WHERE dim3 IS NOT NULL GROUP BY 1 PARTITIONED BY ALL TIME") @@ -742,9 +749,9 @@ public class MSQInsertTest extends MSQTestBase } - - @Test - public void testInsertOnFoo1WithAutoTypeArrayGroupBy() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithAutoTypeArrayGroupBy(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -777,8 +784,9 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertOnFoo1WithArrayIngestModeArrayGroupByInsertAsArray() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithArrayIngestModeArrayGroupByInsertAsArray(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -812,8 +820,9 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertOnFoo1WithArrayIngestModeArrayGroupByInsertAsMvd() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithArrayIngestModeArrayGroupByInsertAsMvd(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -847,8 +856,9 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertOnFoo1WithMultiValueDimGroupByWithoutGroupByEnable() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOnFoo1WithMultiValueDimGroupByWithoutGroupByEnable(String contextName, Map context) { Map localContext = ImmutableMap.builder() .putAll(context) @@ -868,8 +878,9 @@ public class MSQInsertTest extends MSQTestBase .verifyExecutionError(); } - @Test - public void testRollUpOnFoo1UpOnFoo1() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testRollUpOnFoo1UpOnFoo1(String contextName, Map context) { List expectedRows = expectedFooRows(); int expectedCounterRows = expectedRows.size(); @@ -925,8 +936,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testRollUpOnFoo1WithTimeFunction() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testRollUpOnFoo1WithTimeFunction(String contextName, Map context) { List expectedRows = expectedFooRows(); int expectedCounterRows = expectedRows.size(); @@ -982,8 +994,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertWithClusteredByDescendingThrowsException() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertWithClusteredByDescendingThrowsException(String contextName, Map context) { // Add a DESC clustered by column, which should not be allowed testIngestQuery().setSql("INSERT INTO foo1 " @@ -999,8 +1012,9 @@ public class MSQInsertTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testRollUpOnFoo1WithTimeFunctionComplexCol() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testRollUpOnFoo1WithTimeFunctionComplexCol(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -1025,8 +1039,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testRollUpOnFoo1ComplexCol() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testRollUpOnFoo1ComplexCol(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -1048,10 +1063,11 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testRollUpOnExternalDataSource() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testRollUpOnExternalDataSource(String contextName, Map context) throws IOException { - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadFileNameAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -1115,10 +1131,11 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test() - public void testRollUpOnExternalDataSourceWithCompositeKey() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testRollUpOnExternalDataSourceWithCompositeKey(String contextName, Map context) throws IOException { - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadFileNameAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -1191,8 +1208,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertWrongTypeTimestamp() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertWrongTypeTimestamp(String contextName, Map context) { final RowSignature rowSignature = RowSignature.builder() @@ -1220,8 +1238,9 @@ public class MSQInsertTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testIncorrectInsertQuery() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testIncorrectInsertQuery(String contextName, Map context) { testIngestQuery() .setSql( @@ -1234,8 +1253,9 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testInsertRestrictedColumns() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertRestrictedColumns(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -1262,8 +1282,9 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testInsertDuplicateColumnNames() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertDuplicateColumnNames(String contextName, Map context) { testIngestQuery() .setSql(" insert into foo1 SELECT\n" @@ -1284,8 +1305,9 @@ public class MSQInsertTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testInsertQueryWithInvalidSubtaskCount() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertQueryWithInvalidSubtaskCount(String contextName, Map context) { Map localContext = new HashMap<>(context); localContext.put(MultiStageQueryContext.CTX_MAX_NUM_TASKS, 1); @@ -1306,10 +1328,11 @@ public class MSQInsertTest extends MSQTestBase .verifyExecutionError(); } - @Test - public void testInsertWithTooLargeRowShouldThrowException() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertWithTooLargeRowShouldThrowException(String contextName, Map context) throws IOException { - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadFileNameAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); Mockito.doReturn(500).when(workerMemoryParameters).getLargeFrameSize(); @@ -1335,8 +1358,9 @@ public class MSQInsertTest extends MSQTestBase .verifyExecutionError(); } - @Test - public void testInsertLimitWithPeriodGranularityThrowsException() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertLimitWithPeriodGranularityThrowsException(String contextName, Map context) { testIngestQuery().setSql(" INSERT INTO foo " + "SELECT __time, m1 " @@ -1352,8 +1376,9 @@ public class MSQInsertTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testInsertOffsetThrowsException() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testInsertOffsetThrowsException(String contextName, Map context) { testIngestQuery().setSql(" INSERT INTO foo " + "SELECT __time, m1 " @@ -1368,20 +1393,21 @@ public class MSQInsertTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testCorrectNumberOfWorkersUsedAutoModeWithoutBytesLimit() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testCorrectNumberOfWorkersUsedAutoModeWithoutBytesLimit(String contextName, Map context) throws IOException { Map localContext = new HashMap<>(context); localContext.put(MultiStageQueryContext.CTX_TASK_ASSIGNMENT_STRATEGY, WorkerAssignmentStrategy.AUTO.name()); localContext.put(MultiStageQueryContext.CTX_MAX_NUM_TASKS, 4); - final File toRead1 = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/multipleFiles/wikipedia-sampled-1.json"); + final File toRead1 = getResourceAsTemporaryFile("/multipleFiles/wikipedia-sampled-1.json"); final String toReadFileNameAsJson1 = queryFramework().queryJsonMapper().writeValueAsString(toRead1.getAbsolutePath()); - final File toRead2 = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/multipleFiles/wikipedia-sampled-2.json"); + final File toRead2 = getResourceAsTemporaryFile("/multipleFiles/wikipedia-sampled-2.json"); final String toReadFileNameAsJson2 = queryFramework().queryJsonMapper().writeValueAsString(toRead2.getAbsolutePath()); - final File toRead3 = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/multipleFiles/wikipedia-sampled-3.json"); + final File toRead3 = getResourceAsTemporaryFile("/multipleFiles/wikipedia-sampled-3.json"); final String toReadFileNameAsJson3 = queryFramework().queryJsonMapper().writeValueAsString(toRead3.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -1418,21 +1444,22 @@ public class MSQInsertTest extends MSQTestBase } - @Test - public void testCorrectNumberOfWorkersUsedAutoModeWithBytesLimit() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testCorrectNumberOfWorkersUsedAutoModeWithBytesLimit(String contextName, Map context) throws IOException { Map localContext = new HashMap<>(context); localContext.put(MultiStageQueryContext.CTX_TASK_ASSIGNMENT_STRATEGY, WorkerAssignmentStrategy.AUTO.name()); localContext.put(MultiStageQueryContext.CTX_MAX_NUM_TASKS, 4); localContext.put(MultiStageQueryContext.CTX_MAX_INPUT_BYTES_PER_WORKER, 10); - final File toRead1 = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/multipleFiles/wikipedia-sampled-1.json"); + final File toRead1 = getResourceAsTemporaryFile("/multipleFiles/wikipedia-sampled-1.json"); final String toReadFileNameAsJson1 = queryFramework().queryJsonMapper().writeValueAsString(toRead1.getAbsolutePath()); - final File toRead2 = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/multipleFiles/wikipedia-sampled-2.json"); + final File toRead2 = getResourceAsTemporaryFile("/multipleFiles/wikipedia-sampled-2.json"); final String toReadFileNameAsJson2 = queryFramework().queryJsonMapper().writeValueAsString(toRead2.getAbsolutePath()); - final File toRead3 = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/multipleFiles/wikipedia-sampled-3.json"); + final File toRead3 = getResourceAsTemporaryFile("/multipleFiles/wikipedia-sampled-3.json"); final String toReadFileNameAsJson3 = queryFramework().queryJsonMapper().writeValueAsString(toRead3.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -1468,9 +1495,11 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyInsertQuery() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyInsertQuery(String contextName, Map context) { + // Insert with a condition which results in 0 rows being inserted -- do nothing. testIngestQuery().setSql( "INSERT INTO foo1 " @@ -1484,9 +1513,11 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyInsertQueryWithAllGranularity() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyInsertQueryWithAllGranularity(String contextName, Map context) { + // Insert with a condition which results in 0 rows being inserted -- do nothing. testIngestQuery().setSql( "INSERT INTO foo1 " @@ -1500,9 +1531,11 @@ public class MSQInsertTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyInsertLimitQuery() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyInsertLimitQuery(String contextName, Map context) { + // Insert with a condition which results in 0 rows being inserted -- do nothing. testIngestQuery().setSql( "INSERT INTO foo1 " diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQLoadedSegmentTests.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQLoadedSegmentTests.java index c787066937f..ab06f851af0 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQLoadedSegmentTests.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQLoadedSegmentTests.java @@ -51,8 +51,8 @@ import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; import org.hamcrest.CoreMatchers; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -87,7 +87,7 @@ public class MSQLoadedSegmentTests extends MSQTestBase 2 ); - @Before + @BeforeEach public void setUp() { loadedSegmentsMetadata.add(new ImmutableSegmentLoadInfo(LOADED_SEGMENT_1, ImmutableSet.of(DATA_SERVER_1))); diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQParseExceptionsTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQParseExceptionsTest.java index 7dd9674e06a..e1d0520362b 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQParseExceptionsTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQParseExceptionsTest.java @@ -32,7 +32,6 @@ import org.apache.druid.msq.indexing.error.CannotParseExternalDataFault; import org.apache.druid.msq.indexing.error.InvalidNullByteFault; import org.apache.druid.msq.querykit.scan.ExternalColumnSelectorFactory; import org.apache.druid.msq.test.MSQTestBase; -import org.apache.druid.msq.test.MSQTestFileUtils; import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.scan.ScanQuery; @@ -44,7 +43,7 @@ import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.planner.ColumnMapping; import org.apache.druid.sql.calcite.planner.ColumnMappings; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; @@ -53,15 +52,11 @@ import java.util.Map; public class MSQParseExceptionsTest extends MSQTestBase { - + @Test public void testIngestWithNullByte() throws IOException { - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile( - temporaryFolder, - this, - "/unparseable-null-byte-string.csv" - ); + final File toRead = getResourceAsTemporaryFile("/unparseable-null-byte-string.csv"); final String toReadAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -145,11 +140,7 @@ public class MSQParseExceptionsTest extends MSQTestBase @Test public void testIngestWithSanitizedNullByte() throws IOException { - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile( - temporaryFolder, - this, - "/unparseable-null-byte-string.csv" - ); + final File toRead = getResourceAsTemporaryFile("/unparseable-null-byte-string.csv"); final String toReadAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -243,11 +234,7 @@ public class MSQParseExceptionsTest extends MSQTestBase @Test public void testMultiValueStringWithIncorrectType() throws IOException { - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile( - temporaryFolder, - this, - "/unparseable-mv-string-array.json" - ); + final File toRead = getResourceAsTemporaryFile("/unparseable-mv-string-array.json"); final String toReadAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQReplaceTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQReplaceTest.java index 700c032b950..77eeed05367 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQReplaceTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQReplaceTest.java @@ -31,7 +31,6 @@ import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.msq.test.CounterSnapshotMatcher; import org.apache.druid.msq.test.MSQTestBase; -import org.apache.druid.msq.test.MSQTestFileUtils; import org.apache.druid.msq.test.MSQTestTaskActionClient; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; @@ -40,13 +39,13 @@ import org.apache.druid.timeline.SegmentId; import org.apache.druid.timeline.partition.DimensionRangeShardSpec; import org.easymock.EasyMock; import org.joda.time.Interval; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import javax.annotation.Nonnull; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -58,7 +57,6 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -@RunWith(Parameterized.class) public class MSQReplaceTest extends MSQTestBase { @@ -72,7 +70,6 @@ public class MSQReplaceTest extends MSQTestBase ) .build(); - @Parameterized.Parameters(name = "{index}:with context {0}") public static Collection data() { Object[][] data = new Object[][]{ @@ -84,15 +81,9 @@ public class MSQReplaceTest extends MSQTestBase }; return Arrays.asList(data); } - - @Parameterized.Parameter(0) - public String contextName; - - @Parameterized.Parameter(1) - public Map context; - - @Test - public void testReplaceOnFooWithAll() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceOnFooWithAll(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -172,8 +163,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceOnFooWithWhere() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceOnFooWithWhere(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -221,14 +213,15 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceOnFoo1WithAllExtern() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceOnFoo1WithAllExtern(String contextName, Map context) throws IOException { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) .add("cnt", ColumnType.LONG).build(); - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadFileNameAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); testIngestQuery().setSql(" REPLACE INTO foo1 OVERWRITE ALL SELECT " @@ -296,14 +289,15 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceOnFoo1WithWhereExtern() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceOnFoo1WithWhereExtern(String contextName, Map context) throws IOException { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) .add("user", ColumnType.STRING).build(); - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadFileNameAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); testIngestQuery().setSql( @@ -362,8 +356,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceIncorrectSyntax() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceIncorrectSyntax(String contextName, Map context) { testIngestQuery() .setSql("REPLACE INTO foo1 OVERWRITE SELECT * FROM foo PARTITIONED BY ALL TIME") @@ -376,8 +371,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testReplaceSegmentEntireTable() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceSegmentEntireTable(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -433,8 +429,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceSegmentsRepartitionTable() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceSegmentsRepartitionTable(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -516,8 +513,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceWithWhereClause() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceWithWhereClause(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -589,8 +587,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceWhereClauseLargerThanData() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceWhereClauseLargerThanData(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -665,8 +664,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceLimitWithPeriodGranularityThrowsException() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceLimitWithPeriodGranularityThrowsException(String contextName, Map context) { testIngestQuery().setSql(" REPLACE INTO foo " + "OVERWRITE ALL " @@ -681,8 +681,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testReplaceOffsetThrowsException() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceOffsetThrowsException(String contextName, Map context) { testIngestQuery().setSql(" REPLACE INTO foo " + "OVERWRITE ALL " @@ -698,8 +699,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testReplaceTimeChunks() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceTimeChunks(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -745,8 +747,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceTimeChunksLargerThanData() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceTimeChunksLargerThanData(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -800,8 +803,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceAllOverEternitySegment() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceAllOverEternitySegment(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -852,8 +856,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceOnFoo1Range() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceOnFoo1Range(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -875,8 +880,9 @@ public class MSQReplaceTest extends MSQTestBase } - @Test - public void testReplaceOnFoo1RangeClusteredBySubset() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceOnFoo1RangeClusteredBySubset(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -913,8 +919,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceSegmentsInsertIntoNewTable() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceSegmentsInsertIntoNewTable(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -944,8 +951,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceWithClusteredByDescendingThrowsException() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceWithClusteredByDescendingThrowsException(String contextName, Map context) { // Add a DESC clustered by column, which should not be allowed testIngestQuery().setSql(" REPLACE INTO foobar " @@ -961,8 +969,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testReplaceUnnestSegmentEntireTable() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceUnnestSegmentEntireTable(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -1020,8 +1029,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceUnnestWithVirtualColumnSegmentEntireTable() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceUnnestWithVirtualColumnSegmentEntireTable(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -1083,8 +1093,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceUnnestSegmentWithTimeFilter() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceUnnestSegmentWithTimeFilter(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -1157,8 +1168,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testReplaceTombstonesOverPartiallyOverlappingSegments() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testReplaceTombstonesOverPartiallyOverlappingSegments(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -1223,8 +1235,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceAll() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceAll(String contextName, Map context) { // An empty replace all with no used segment should effectively be the same as an empty insert testIngestQuery().setSql( @@ -1241,8 +1254,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceInterval() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceInterval(String contextName, Map context) { // An empty replace interval with no used segment should effectively be the same as an empty insert testIngestQuery().setSql( @@ -1259,8 +1273,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceAllOverExistingSegment() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceAllOverExistingSegment(String contextName, Map context) { Interval existingSegmentInterval = Intervals.of("2001-01-01T/2001-01-02T"); DataSegment existingDataSegment = DataSegment.builder() @@ -1290,8 +1305,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceIntervalOverPartiallyOverlappingSegment() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceIntervalOverPartiallyOverlappingSegment(String contextName, Map context) { // Create a data segment which lies partially outside the generated segment DataSegment existingDataSegment = DataSegment.builder() @@ -1325,8 +1341,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceIntervalOverPartiallyOverlappingStart() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceIntervalOverPartiallyOverlappingStart(String contextName, Map context) { // Create a data segment whose start partially lies outside the query's replace interval DataSegment existingDataSegment = DataSegment.builder() @@ -1362,8 +1379,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceIntervalOverPartiallyOverlappingEnd() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceIntervalOverPartiallyOverlappingEnd(String contextName, Map context) { // Create a data segment whose end partially lies outside the query's replace interval DataSegment existingDataSegment = DataSegment.builder() @@ -1399,8 +1417,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceAllOverEternitySegment() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceAllOverEternitySegment(String contextName, Map context) { // Create a data segment spanning eternity DataSegment existingDataSegment = DataSegment.builder() @@ -1432,8 +1451,9 @@ public class MSQReplaceTest extends MSQTestBase } - @Test - public void testEmptyReplaceAllWithAllGrainOverFiniteIntervalSegment() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceAllWithAllGrainOverFiniteIntervalSegment(String contextName, Map context) { // Create a finite-interval segment DataSegment existingDataSegment = DataSegment.builder() @@ -1463,8 +1483,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceAllWithAllGrainOverEternitySegment() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceAllWithAllGrainOverEternitySegment(String contextName, Map context) { // Create a segment spanning eternity DataSegment existingDataSegment = DataSegment.builder() @@ -1495,8 +1516,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceAllWithAllGrainOverHalfEternitySegment() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceAllWithAllGrainOverHalfEternitySegment(String contextName, Map context) { // Create a segment spanning half-eternity DataSegment existingDataSegment = DataSegment.builder() @@ -1526,8 +1548,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceLimitQuery() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceLimitQuery(String contextName, Map context) { // A limit query which results in 0 rows being inserted -- do nothing. testIngestQuery().setSql( @@ -1544,8 +1567,9 @@ public class MSQReplaceTest extends MSQTestBase .verifyResults(); } - @Test - public void testEmptyReplaceIntervalOverEternitySegment() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testEmptyReplaceIntervalOverEternitySegment(String contextName, Map context) { // Create a data segment spanning eternity DataSegment existingDataSegment = DataSegment.builder() diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQSelectTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQSelectTest.java index c0dfe0f77f3..745cc33040f 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQSelectTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQSelectTest.java @@ -44,7 +44,6 @@ import org.apache.druid.msq.indexing.report.MSQResultsReport; import org.apache.druid.msq.querykit.common.SortMergeJoinFrameProcessorFactory; import org.apache.druid.msq.test.CounterSnapshotMatcher; import org.apache.druid.msq.test.MSQTestBase; -import org.apache.druid.msq.test.MSQTestFileUtils; import org.apache.druid.msq.util.MultiStageQueryContext; import org.apache.druid.query.InlineDataSource; import org.apache.druid.query.LookupDataSource; @@ -81,10 +80,9 @@ import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.util.CalciteTests; import org.hamcrest.CoreMatchers; import org.junit.Assert; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -98,7 +96,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -@RunWith(Parameterized.class) public class MSQSelectTest extends MSQTestBase { @@ -126,7 +123,6 @@ public class MSQSelectTest extends MSQTestBase ) .build(); - @Parameterized.Parameters(name = "{index}:with context {0}") public static Collection data() { Object[][] data = new Object[][]{ @@ -140,15 +136,9 @@ public class MSQSelectTest extends MSQTestBase return Arrays.asList(data); } - - @Parameterized.Parameter(0) - public String contextName; - - @Parameterized.Parameter(1) - public Map context; - - @Test - public void testCalculator() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testCalculator(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("EXPR$0", ColumnType.LONG) @@ -173,7 +163,7 @@ public class MSQSelectTest extends MSQTestBase ) .columnMappings(ColumnMappings.identity(resultSignature)) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -183,8 +173,9 @@ public class MSQSelectTest extends MSQTestBase .setExpectedResultRows(ImmutableList.of(new Object[]{2})).verifyResults(); } - @Test - public void testSelectOnFoo() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnFoo(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("cnt", ColumnType.LONG) @@ -205,7 +196,7 @@ public class MSQSelectTest extends MSQTestBase ) .columnMappings(ColumnMappings.identity(resultSignature)) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -225,8 +216,8 @@ public class MSQSelectTest extends MSQTestBase .setExpectedCountersForStageWorkerChannel( CounterSnapshotMatcher .with() - .rows(isPageSizeLimited() ? new long[]{2, 2, 2} : new long[]{6}) - .frames(isPageSizeLimited() ? new long[]{1, 1, 1} : new long[]{1}), + .rows(isPageSizeLimited(contextName) ? new long[]{2, 2, 2} : new long[]{6}) + .frames(isPageSizeLimited(contextName) ? new long[]{1, 1, 1} : new long[]{1}), 0, 0, "shuffle" ) .setExpectedResultRows(ImmutableList.of( @@ -239,8 +230,9 @@ public class MSQSelectTest extends MSQTestBase )).verifyResults(); } - @Test - public void testSelectOnFoo2() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnFoo2(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("m1", ColumnType.LONG) @@ -265,7 +257,7 @@ public class MSQSelectTest extends MSQTestBase .build()) .columnMappings(ColumnMappings.identity(resultSignature)) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -290,15 +282,16 @@ public class MSQSelectTest extends MSQTestBase .setExpectedCountersForStageWorkerChannel( CounterSnapshotMatcher .with() - .rows(isPageSizeLimited() ? new long[]{1L, 2L} : new long[]{3L}) - .frames(isPageSizeLimited() ? new long[]{1L, 1L} : new long[]{1L}), + .rows(isPageSizeLimited(contextName) ? new long[]{1L, 2L} : new long[]{3L}) + .frames(isPageSizeLimited(contextName) ? new long[]{1L, 1L} : new long[]{1L}), 0, 0, "shuffle" ) .verifyResults(); } - @Test - public void testSelectOnFooDuplicateColumnNames() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnFooDuplicateColumnNames(String contextName, Map context) { // Duplicate column names are OK in SELECT statements. @@ -335,7 +328,7 @@ public class MSQSelectTest extends MSQTestBase ) .columnMappings(expectedColumnMappings) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -354,8 +347,8 @@ public class MSQSelectTest extends MSQTestBase .setExpectedCountersForStageWorkerChannel( CounterSnapshotMatcher .with() - .rows(isPageSizeLimited() ? new long[]{2, 2, 2} : new long[]{6}) - .frames(isPageSizeLimited() ? new long[]{1, 1, 1} : new long[]{1}), + .rows(isPageSizeLimited(contextName) ? new long[]{2, 2, 2} : new long[]{6}) + .frames(isPageSizeLimited(contextName) ? new long[]{1, 1, 1} : new long[]{1}), 0, 0, "shuffle" ) .setExpectedResultRows(ImmutableList.of( @@ -368,8 +361,9 @@ public class MSQSelectTest extends MSQTestBase )).verifyResults(); } - @Test - public void testSelectOnFooWhereMatchesNoSegments() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnFooWhereMatchesNoSegments(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("cnt", ColumnType.LONG) @@ -398,7 +392,7 @@ public class MSQSelectTest extends MSQTestBase ) .columnMappings(ColumnMappings.identity(resultSignature)) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -409,8 +403,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testSelectOnFooWhereMatchesNoData() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnFooWhereMatchesNoData(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("cnt", ColumnType.LONG) @@ -432,7 +427,7 @@ public class MSQSelectTest extends MSQTestBase ) .columnMappings(ColumnMappings.identity(resultSignature)) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -443,8 +438,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testSelectAndOrderByOnFooWhereMatchesNoData() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectAndOrderByOnFooWhereMatchesNoData(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("cnt", ColumnType.LONG) @@ -467,7 +463,7 @@ public class MSQSelectTest extends MSQTestBase ) .columnMappings(ColumnMappings.identity(resultSignature)) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -478,8 +474,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testGroupByOnFoo() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByOnFoo(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("cnt", ColumnType.LONG) @@ -512,7 +509,7 @@ public class MSQSelectTest extends MSQTestBase ) )) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -537,8 +534,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testGroupByOrderByDimension() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByOrderByDimension(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("m1", ColumnType.FLOAT) @@ -579,7 +577,7 @@ public class MSQSelectTest extends MSQTestBase ) )) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -613,8 +611,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testSelectWithLimit() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectWithLimit(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("cnt", ColumnType.LONG) @@ -636,7 +635,7 @@ public class MSQSelectTest extends MSQTestBase ) .columnMappings(ColumnMappings.identity(resultSignature)) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -668,8 +667,9 @@ public class MSQSelectTest extends MSQTestBase )).verifyResults(); } - @Test - public void testSelectWithGroupByLimit() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectWithGroupByLimit(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("cnt", ColumnType.LONG) @@ -705,7 +705,7 @@ public class MSQSelectTest extends MSQTestBase ) )) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -715,8 +715,9 @@ public class MSQSelectTest extends MSQTestBase } - @Test - public void testSelectLookup() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectLookup(String contextName, Map context) { final RowSignature rowSignature = RowSignature.builder().add("EXPR$0", ColumnType.LONG).build(); @@ -735,7 +736,7 @@ public class MSQSelectTest extends MSQTestBase .build()) .columnMappings(new ColumnMappings(ImmutableList.of(new ColumnMapping("a0", "EXPR$0")))) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -744,8 +745,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testJoinWithLookup() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testJoinWithLookup(String contextName, Map context) { final RowSignature rowSignature = RowSignature.builder() @@ -791,7 +793,7 @@ public class MSQSelectTest extends MSQTestBase ) ) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -809,8 +811,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testSubquery() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSubquery(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("cnt", ColumnType.LONG) @@ -840,7 +843,7 @@ public class MSQSelectTest extends MSQTestBase .query(query) .columnMappings(new ColumnMappings(ImmutableList.of(new ColumnMapping("a0", "cnt")))) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -866,19 +869,21 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testBroadcastJoin() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testBroadcastJoin(String contextName, Map context) { - testJoin(JoinAlgorithm.BROADCAST); + testJoin(contextName, context, JoinAlgorithm.BROADCAST); } - @Test - public void testSortMergeJoin() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSortMergeJoin(String contextName, Map context) { - testJoin(JoinAlgorithm.SORT_MERGE); + testJoin(contextName, context, JoinAlgorithm.SORT_MERGE); } - private void testJoin(final JoinAlgorithm joinAlgorithm) + private void testJoin(String contextName, Map context, final JoinAlgorithm joinAlgorithm) { final Map queryContext = ImmutableMap.builder() @@ -1011,7 +1016,7 @@ public class MSQSelectTest extends MSQTestBase ) ) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -1025,8 +1030,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testGroupByOrderByAggregation() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByOrderByAggregation(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("m1", ColumnType.FLOAT) @@ -1069,7 +1075,7 @@ public class MSQSelectTest extends MSQTestBase ) ) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -1104,8 +1110,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testGroupByOrderByAggregationWithLimit() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByOrderByAggregationWithLimit(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("m1", ColumnType.FLOAT) @@ -1148,7 +1155,7 @@ public class MSQSelectTest extends MSQTestBase ) ) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -1180,8 +1187,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testGroupByOrderByAggregationWithLimitAndOffset() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByOrderByAggregationWithLimitAndOffset(String contextName, Map context) { RowSignature rowSignature = RowSignature.builder() .add("m1", ColumnType.FLOAT) @@ -1225,7 +1233,7 @@ public class MSQSelectTest extends MSQTestBase ) ) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -1256,10 +1264,11 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testExternGroupBy() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testExternGroupBy(String contextName, Map context) throws IOException { - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -1325,7 +1334,7 @@ public class MSQSelectTest extends MSQTestBase ) )) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -1349,13 +1358,14 @@ public class MSQSelectTest extends MSQTestBase } - @Test - public void testExternSelectWithMultipleWorkers() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testExternSelectWithMultipleWorkers(String contextName, Map context) throws IOException { Map multipleWorkerContext = new HashMap<>(context); multipleWorkerContext.put(MultiStageQueryContext.CTX_MAX_NUM_TASKS, 3); - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -1438,7 +1448,7 @@ public class MSQSelectTest extends MSQTestBase ) )) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -1456,8 +1466,8 @@ public class MSQSelectTest extends MSQTestBase .setExpectedCountersForStageWorkerChannel( CounterSnapshotMatcher .with() - .rows(isPageSizeLimited() ? new long[]{1L, 1L, 1L, 1L, 1L} : new long[]{5L}) - .frames(isPageSizeLimited() ? new long[]{1L, 1L, 1L, 1L, 1L} : new long[]{1L}), + .rows(isPageSizeLimited(contextName) ? new long[]{1L, 1L, 1L, 1L, 1L} : new long[]{5L}) + .frames(isPageSizeLimited(contextName) ? new long[]{1L, 1L, 1L, 1L, 1L} : new long[]{1L}), 0, 0, "shuffle" ) .setExpectedCountersForStageWorkerChannel( @@ -1473,12 +1483,12 @@ public class MSQSelectTest extends MSQTestBase .setExpectedCountersForStageWorkerChannel( CounterSnapshotMatcher .with() - .rows(isPageSizeLimited() ? new long[]{1L, 1L, 1L, 1L, 1L} : new long[]{5L}) - .frames(isPageSizeLimited() ? new long[]{1L, 1L, 1L, 1L, 1L} : new long[]{1L}), + .rows(isPageSizeLimited(contextName) ? new long[]{1L, 1L, 1L, 1L, 1L} : new long[]{5L}) + .frames(isPageSizeLimited(contextName) ? new long[]{1L, 1L, 1L, 1L, 1L} : new long[]{1L}), 0, 1, "shuffle" ); // adding result stage counter checks - if (isPageSizeLimited()) { + if (isPageSizeLimited(contextName)) { selectTester.setExpectedCountersForStageWorkerChannel( CounterSnapshotMatcher .with().rows(2, 0, 2, 0, 2), @@ -1500,8 +1510,9 @@ public class MSQSelectTest extends MSQTestBase selectTester.verifyResults(); } - @Test - public void testIncorrectSelectQuery() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testIncorrectSelectQuery(String contextName, Map context) { testSelectQuery() .setSql("select a from ") @@ -1512,8 +1523,9 @@ public class MSQSelectTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testSelectOnInformationSchemaSource() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnInformationSchemaSource(String contextName, Map context) { testSelectQuery() .setSql("SELECT * FROM INFORMATION_SCHEMA.SCHEMATA") @@ -1524,8 +1536,9 @@ public class MSQSelectTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testSelectOnSysSource() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnSysSource(String contextName, Map context) { testSelectQuery() .setSql("SELECT * FROM sys.segments") @@ -1536,8 +1549,9 @@ public class MSQSelectTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testSelectOnSysSourceWithJoin() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnSysSourceWithJoin(String contextName, Map context) { testSelectQuery() .setSql("select s.segment_id, s.num_rows, f.dim1 from sys.segments as s, foo as f") @@ -1548,8 +1562,9 @@ public class MSQSelectTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testSelectOnSysSourceContainingWith() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnSysSourceContainingWith(String contextName, Map context) { testSelectQuery() .setSql("with segment_source as (SELECT * FROM sys.segments) " @@ -1561,8 +1576,9 @@ public class MSQSelectTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testSelectOnUserDefinedSourceContainingWith() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectOnUserDefinedSourceContainingWith(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("m1", ColumnType.LONG) @@ -1590,7 +1606,7 @@ public class MSQSelectTest extends MSQTestBase ) .columnMappings(ColumnMappings.identity(resultSignature)) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -1615,15 +1631,16 @@ public class MSQSelectTest extends MSQTestBase .setExpectedCountersForStageWorkerChannel( CounterSnapshotMatcher .with() - .rows(isPageSizeLimited() ? new long[]{1, 2} : new long[]{3}) - .frames(isPageSizeLimited() ? new long[]{1, 1} : new long[]{1}), + .rows(isPageSizeLimited(contextName) ? new long[]{1, 2} : new long[]{3}) + .frames(isPageSizeLimited(contextName) ? new long[]{1, 1} : new long[]{1}), 0, 0, "shuffle" ) .verifyResults(); } - @Test - public void testScanWithMultiValueSelectQuery() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testScanWithMultiValueSelectQuery(String contextName, Map context) { RowSignature expectedScanSignature = RowSignature.builder() .add("dim3", ColumnType.STRING) @@ -1660,7 +1677,7 @@ public class MSQSelectTest extends MSQTestBase ) ) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -1676,8 +1693,9 @@ public class MSQSelectTest extends MSQTestBase )).verifyResults(); } - @Test - public void testHavingOnApproximateCountDistinct() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testHavingOnApproximateCountDistinct(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("dim2", ColumnType.STRING) @@ -1730,7 +1748,7 @@ public class MSQSelectTest extends MSQTestBase new ColumnMapping("a0", "col") ))) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -1745,8 +1763,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testGroupByWithMultiValue() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByWithMultiValue(String contextName, Map context) { Map localContext = enableMultiValueUnnesting(context, true); RowSignature rowSignature = RowSignature.builder() @@ -1784,7 +1803,7 @@ public class MSQSelectTest extends MSQTestBase ) )) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -1794,8 +1813,9 @@ public class MSQSelectTest extends MSQTestBase } - @Test - public void testGroupByWithMultiValueWithoutGroupByEnable() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByWithMultiValueWithoutGroupByEnable(String contextName, Map context) { Map localContext = enableMultiValueUnnesting(context, false); @@ -1811,8 +1831,9 @@ public class MSQSelectTest extends MSQTestBase .verifyExecutionError(); } - @Test - public void testGroupByWithMultiValueMvToArray() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByWithMultiValueMvToArray(String contextName, Map context) { Map localContext = enableMultiValueUnnesting(context, true); @@ -1857,7 +1878,7 @@ public class MSQSelectTest extends MSQTestBase ) )) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -1868,8 +1889,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testGroupByArrayWithMultiValueMvToArray() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByArrayWithMultiValueMvToArray(String contextName, Map context) { Map localContext = enableMultiValueUnnesting(context, true); @@ -1927,7 +1949,7 @@ public class MSQSelectTest extends MSQTestBase ) ) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -1936,10 +1958,11 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testTimeColumnAggregationFromExtern() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testTimeColumnAggregationFromExtern(String contextName, Map context) throws IOException { - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); RowSignature rowSignature = RowSignature.builder() @@ -1976,8 +1999,9 @@ public class MSQSelectTest extends MSQTestBase .verifyPlanningErrors(); } - @Test - public void testGroupByWithMultiValueMvToArrayWithoutGroupByEnable() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByWithMultiValueMvToArrayWithoutGroupByEnable(String contextName, Map context) { Map localContext = enableMultiValueUnnesting(context, false); @@ -1994,8 +2018,9 @@ public class MSQSelectTest extends MSQTestBase .verifyExecutionError(); } - @Test - public void testGroupByWithComplexColumnThrowsUnsupportedException() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByWithComplexColumnThrowsUnsupportedException(String contextName, Map context) { testSelectQuery() .setSql("select unique_dim1 from foo2 group by unique_dim1") @@ -2008,8 +2033,9 @@ public class MSQSelectTest extends MSQTestBase .verifyExecutionError(); } - @Test - public void testGroupByMultiValueMeasureQuery() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByMultiValueMeasureQuery(String contextName, Map context) { final RowSignature rowSignature = RowSignature.builder() .add("__time", ColumnType.LONG) @@ -2046,7 +2072,7 @@ public class MSQSelectTest extends MSQTestBase ) )) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -2064,8 +2090,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testGroupByOnFooWithDurableStoragePathAssertions() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testGroupByOnFooWithDurableStoragePathAssertions(String contextName, Map context) throws IOException { RowSignature rowSignature = RowSignature.builder() .add("cnt", ColumnType.LONG) @@ -2100,7 +2127,7 @@ public class MSQSelectTest extends MSQTestBase )) ) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -2118,14 +2145,15 @@ public class MSQSelectTest extends MSQTestBase } } - @Test - public void testSelectRowsGetUntruncatedByDefault() throws IOException + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectRowsGetUntruncatedByDefault(String contextName, Map context) throws IOException { RowSignature dummyRowSignature = RowSignature.builder().add("timestamp", ColumnType.LONG).build(); final int numFiles = 200; - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadFileNameAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); String externalFiles = String.join(", ", Collections.nCopies(numFiles, toReadFileNameAsJson)); @@ -2179,7 +2207,7 @@ public class MSQSelectTest extends MSQTestBase ) )) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build()) @@ -2188,10 +2216,13 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testJoinUsesDifferentAlgorithm() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testJoinUsesDifferentAlgorithm(String contextName, Map context) { + + // This test asserts that the join algorithnm used is a different one from that supplied. In sqlCompatible() mode // the query gets planned differently, therefore we do use the sortMerge processor. Instead of having separate // handling, a similar test has been described in CalciteJoinQueryMSQTest, therefore we don't want to repeat that @@ -2274,7 +2305,7 @@ public class MSQSelectTest extends MSQTestBase new ColumnMapping("a0", "cnt") ) )) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .tuningConfig(MSQTuningConfig.defaultConfig()) @@ -2293,8 +2324,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testSelectUnnestOnInlineFoo() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectUnnestOnInlineFoo(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("EXPR$0", ColumnType.LONG) @@ -2333,7 +2365,7 @@ public class MSQSelectTest extends MSQTestBase .build()) .columnMappings(expectedColumnMappings) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -2349,8 +2381,9 @@ public class MSQSelectTest extends MSQTestBase } - @Test - public void testSelectUnnestOnFoo() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectUnnestOnFoo(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("j0.unnest", ColumnType.STRING) @@ -2387,7 +2420,7 @@ public class MSQSelectTest extends MSQTestBase .build()) .columnMappings(expectedColumnMappings) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -2417,8 +2450,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testSelectUnnestOnQueryFoo() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testSelectUnnestOnQueryFoo(String contextName, Map context) { RowSignature resultSignature = RowSignature.builder() .add("j0.unnest", ColumnType.STRING) @@ -2475,7 +2509,7 @@ public class MSQSelectTest extends MSQTestBase .build()) .columnMappings(expectedColumnMappings) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -2494,8 +2528,9 @@ public class MSQSelectTest extends MSQTestBase .verifyResults(); } - @Test - public void testUnionAllUsingUnionDataSource() + @MethodSource("data") + @ParameterizedTest(name = "{index}:with context {0}") + public void testUnionAllUsingUnionDataSource(String contextName, Map context) { final RowSignature rowSignature = RowSignature.builder() @@ -2542,7 +2577,7 @@ public class MSQSelectTest extends MSQTestBase .build()) .columnMappings(ColumnMappings.identity(rowSignature)) .tuningConfig(MSQTuningConfig.defaultConfig()) - .destination(isDurableStorageDestination() + .destination(isDurableStorageDestination(contextName, context) ? DurableStorageMSQDestination.INSTANCE : TaskReportMSQDestination.INSTANCE) .build() @@ -2595,12 +2630,12 @@ public class MSQSelectTest extends MSQTestBase return localContext; } - public boolean isDurableStorageDestination() + private boolean isDurableStorageDestination(String contextName, Map context) { return QUERY_RESULTS_WITH_DURABLE_STORAGE.equals(contextName) || QUERY_RESULTS_WITH_DEFAULT_CONTEXT.equals(context); } - public boolean isPageSizeLimited() + public boolean isPageSizeLimited(String contextName) { return QUERY_RESULTS_WITH_DURABLE_STORAGE.equals(contextName); } diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/error/InsertLockPreemptedFaultTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/error/InsertLockPreemptedFaultTest.java index 807a86b7775..5da165dbc46 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/error/InsertLockPreemptedFaultTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/error/InsertLockPreemptedFaultTest.java @@ -24,7 +24,7 @@ import org.apache.druid.msq.test.MSQTestBase; import org.apache.druid.msq.test.MSQTestTaskActionClient; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class InsertLockPreemptedFaultTest extends MSQTestBase { diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/error/MSQWarningsTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/error/MSQWarningsTest.java index f21d92ee90f..6a262cd38c1 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/error/MSQWarningsTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/error/MSQWarningsTest.java @@ -28,7 +28,6 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.msq.indexing.MSQSpec; import org.apache.druid.msq.indexing.MSQTuningConfig; import org.apache.druid.msq.test.MSQTestBase; -import org.apache.druid.msq.test.MSQTestFileUtils; import org.apache.druid.msq.util.MultiStageQueryContext; import org.apache.druid.query.Query; import org.apache.druid.query.QueryContexts; @@ -45,8 +44,8 @@ import org.apache.druid.sql.calcite.planner.ColumnMapping; import org.apache.druid.sql.calcite.planner.ColumnMappings; import org.apache.druid.sql.calcite.util.CalciteTests; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; @@ -64,10 +63,10 @@ public class MSQWarningsTest extends MSQTestBase private Query defaultQuery; private ColumnMappings defaultColumnMappings; - @Before + @BeforeEach public void setUp3() throws IOException { - File tempFile = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/unparseable.gz"); + File tempFile = getResourceAsTemporaryFile("/unparseable.gz"); // Rename the file and the file's extension from .tmp to .gz to prevent issues with 'parsing' the file toRead = new File(tempFile.getParentFile(), "unparseable.gz"); diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlMSQStatementResourcePostTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlMSQStatementResourcePostTest.java index 3ffa42d64cc..6d81da64aab 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlMSQStatementResourcePostTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlMSQStatementResourcePostTest.java @@ -39,7 +39,6 @@ import org.apache.druid.msq.sql.entity.PageInformation; import org.apache.druid.msq.sql.entity.ResultSetInformation; import org.apache.druid.msq.sql.entity.SqlStatementResult; import org.apache.druid.msq.test.MSQTestBase; -import org.apache.druid.msq.test.MSQTestFileUtils; import org.apache.druid.msq.test.MSQTestOverlordServiceClient; import org.apache.druid.msq.util.MultiStageQueryContext; import org.apache.druid.query.ExecutionMode; @@ -50,11 +49,12 @@ import org.apache.druid.sql.http.ResultFormat; import org.apache.druid.sql.http.SqlQuery; import org.apache.druid.storage.NilStorageConnector; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.ws.rs.core.Response; import javax.ws.rs.core.StreamingOutput; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -69,7 +69,7 @@ public class SqlMSQStatementResourcePostTest extends MSQTestBase private SqlStatementResource resource; - @Before + @BeforeEach public void init() { resource = new SqlStatementResource( @@ -445,7 +445,7 @@ public class SqlMSQStatementResourcePostTest extends MSQTestBase context.put(MultiStageQueryContext.CTX_ROWS_PER_PAGE, 2); context.put(MultiStageQueryContext.CTX_MAX_NUM_TASKS, 3); - final File toRead = MSQTestFileUtils.getResourceAsTemporaryFile(temporaryFolder, this, "/wikipedia-sampled.json"); + final File toRead = getResourceAsTemporaryFile("/wikipedia-sampled.json"); final String toReadAsJson = queryFramework().queryJsonMapper().writeValueAsString(toRead.getAbsolutePath()); diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlStatementResourceTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlStatementResourceTest.java index e3995a4a96c..3d41b46825a 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlStatementResourceTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/sql/resources/SqlStatementResourceTest.java @@ -92,8 +92,8 @@ import org.jboss.netty.handler.codec.http.HttpResponseStatus; import org.jboss.netty.handler.codec.http.HttpVersion; import org.joda.time.DateTime; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.Mockito; @@ -699,7 +699,7 @@ public class SqlStatementResourceTest extends MSQTestBase ); } - @Before + @BeforeEach public void init() throws Exception { overlordClient = Mockito.mock(OverlordClient.class); @@ -708,7 +708,7 @@ public class SqlStatementResourceTest extends MSQTestBase sqlStatementFactory, objectMapper, overlordClient, - new LocalFileStorageConnector(tmpFolder.newFolder("local")), + new LocalFileStorageConnector(newTempFolder("local")), authorizerMapper ); } diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteArraysQueryMSQTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteArraysQueryMSQTest.java index 7e7d20ebe65..4e036f59518 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteArraysQueryMSQTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteArraysQueryMSQTest.java @@ -42,7 +42,7 @@ public class CalciteArraysQueryMSQTest extends CalciteArraysQueryTest { super.configureGuice(builder); builder.addModules( - CalciteMSQTestsHelper.fetchModules(temporaryFolder, TestGroupByBuffers.createDefault()).toArray(new Module[0]) + CalciteMSQTestsHelper.fetchModules(this::newTempFolder, TestGroupByBuffers.createDefault()).toArray(new Module[0]) ); } diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteMSQTestsHelper.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteMSQTestsHelper.java index bbacca1e54a..fc7cfe5d9be 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteMSQTestsHelper.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteMSQTestsHelper.java @@ -82,13 +82,14 @@ import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.SegmentId; import org.easymock.EasyMock; import org.joda.time.Interval; -import org.junit.rules.TemporaryFolder; import org.mockito.Mockito; import javax.annotation.Nullable; -import java.io.IOException; + +import java.io.File; import java.util.List; import java.util.Set; +import java.util.function.Function; import java.util.function.Supplier; import static org.apache.druid.sql.calcite.util.CalciteTests.ARRAYS_DATASOURCE; @@ -113,10 +114,12 @@ import static org.mockito.Mockito.doThrow; public class CalciteMSQTestsHelper { public static List fetchModules( - TemporaryFolder temporaryFolder, + Function tempFolderProducer, TestGroupByBuffers groupByBuffers ) { + File cacheManagerDir = tempFolderProducer.apply("test"); + File storageDir = tempFolderProducer.apply("localsegments"); Module customBindings = binder -> { @@ -152,29 +155,18 @@ public class CalciteMSQTestsHelper ); ObjectMapper testMapper = MSQTestBase.setupObjectMapper(dummyInjector); IndexIO indexIO = new IndexIO(testMapper, ColumnConfig.DEFAULT); - SegmentCacheManager segmentCacheManager = null; - try { - segmentCacheManager = new SegmentCacheManagerFactory(testMapper).manufacturate(temporaryFolder.newFolder( - "test")); - } - catch (IOException e) { - e.printStackTrace(); - } + SegmentCacheManager segmentCacheManager = new SegmentCacheManagerFactory(testMapper) + .manufacturate(cacheManagerDir); LocalDataSegmentPusherConfig config = new LocalDataSegmentPusherConfig(); MSQTestSegmentManager segmentManager = new MSQTestSegmentManager(segmentCacheManager, indexIO); - try { - config.storageDirectory = temporaryFolder.newFolder("localsegments"); - } - catch (IOException e) { - throw new ISE(e, "Unable to create folder"); - } + config.storageDirectory = storageDir; binder.bind(DataSegmentPusher.class).toProvider(() -> new MSQTestDelegateDataSegmentPusher( new LocalDataSegmentPusher(config), segmentManager )); binder.bind(DataSegmentAnnouncer.class).toInstance(new NoopDataSegmentAnnouncer()); binder.bind(DataSegmentProvider.class) - .toInstance((segmentId, channelCounters, isReindex) -> getSupplierForSegment(segmentId)); + .toInstance((segmentId, channelCounters, isReindex) -> getSupplierForSegment(tempFolderProducer, segmentId)); binder.bind(DataServerQueryHandlerFactory.class).toInstance(getTestDataServerQueryHandlerFactory()); GroupByQueryConfig groupByQueryConfig = new GroupByQueryConfig(); @@ -206,116 +198,104 @@ public class CalciteMSQTestsHelper return mockFactory; } - private static Supplier> getSupplierForSegment(SegmentId segmentId) + private static Supplier> getSupplierForSegment(Function tempFolderProducer, SegmentId segmentId) { - final TemporaryFolder temporaryFolder = new TemporaryFolder(); - try { - temporaryFolder.create(); - } - catch (IOException e) { - e.printStackTrace(); - } final QueryableIndex index; - try { - switch (segmentId.getDataSource()) { - case DATASOURCE1: - IncrementalIndexSchema foo1Schema = new IncrementalIndexSchema.Builder() - .withMetrics( - new CountAggregatorFactory("cnt"), - new FloatSumAggregatorFactory("m1", "m1"), - new DoubleSumAggregatorFactory("m2", "m2"), - new HyperUniquesAggregatorFactory("unique_dim1", "dim1") - ) - .withRollup(false) - .build(); - index = IndexBuilder - .create() - .tmpDir(temporaryFolder.newFolder()) - .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) - .schema(foo1Schema) - .rows(ROWS1) - .buildMMappedIndex(); - break; - case DATASOURCE2: - final IncrementalIndexSchema indexSchemaDifferentDim3M1Types = new IncrementalIndexSchema.Builder() - .withDimensionsSpec( - new DimensionsSpec( - ImmutableList.of( - new StringDimensionSchema("dim1"), - new StringDimensionSchema("dim2"), - new LongDimensionSchema("dim3") - ) - ) - ) - .withMetrics( - new CountAggregatorFactory("cnt"), - new LongSumAggregatorFactory("m1", "m1"), - new DoubleSumAggregatorFactory("m2", "m2"), - new HyperUniquesAggregatorFactory("unique_dim1", "dim1") - ) - .withRollup(false) - .build(); - index = IndexBuilder - .create() - .tmpDir(temporaryFolder.newFolder()) - .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) - .schema(indexSchemaDifferentDim3M1Types) - .rows(ROWS2) - .buildMMappedIndex(); - break; - case DATASOURCE3: - case CalciteTests.BROADCAST_DATASOURCE: - index = IndexBuilder - .create() - .tmpDir(temporaryFolder.newFolder()) - .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) - .schema(INDEX_SCHEMA_NUMERIC_DIMS) - .rows(ROWS1_WITH_NUMERIC_DIMS) - .buildMMappedIndex(); - break; - case DATASOURCE5: - index = IndexBuilder - .create() - .tmpDir(temporaryFolder.newFolder()) - .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) - .schema(INDEX_SCHEMA_LOTS_O_COLUMNS) - .rows(ROWS_LOTS_OF_COLUMNS) - .buildMMappedIndex(); - break; - case ARRAYS_DATASOURCE: - index = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) - .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) - .schema( - new IncrementalIndexSchema.Builder() - .withTimestampSpec(NestedDataTestUtils.AUTO_SCHEMA.getTimestampSpec()) - .withDimensionsSpec(NestedDataTestUtils.AUTO_SCHEMA.getDimensionsSpec()) - .withMetrics( - new CountAggregatorFactory("cnt") - ) - .withRollup(false) - .build() - ) - .inputSource( - ResourceInputSource.of( - NestedDataTestUtils.class.getClassLoader(), - NestedDataTestUtils.ARRAY_TYPES_DATA_FILE - ) - ) - .inputFormat(TestDataBuilder.DEFAULT_JSON_INPUT_FORMAT) - .inputTmpDir(temporaryFolder.newFolder()) - .buildMMappedIndex(); - break; - case CalciteTests.WIKIPEDIA_FIRST_LAST: - index = TestDataBuilder.makeWikipediaIndexWithAggregation(temporaryFolder.newFolder()); - break; - default: - throw new ISE("Cannot query segment %s in test runner", segmentId); + switch (segmentId.getDataSource()) { + case DATASOURCE1: + IncrementalIndexSchema foo1Schema = new IncrementalIndexSchema.Builder() + .withMetrics( + new CountAggregatorFactory("cnt"), + new FloatSumAggregatorFactory("m1", "m1"), + new DoubleSumAggregatorFactory("m2", "m2"), + new HyperUniquesAggregatorFactory("unique_dim1", "dim1") + ) + .withRollup(false) + .build(); + index = IndexBuilder + .create() + .tmpDir(tempFolderProducer.apply("tmpDir")) + .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) + .schema(foo1Schema) + .rows(ROWS1) + .buildMMappedIndex(); + break; + case DATASOURCE2: + final IncrementalIndexSchema indexSchemaDifferentDim3M1Types = new IncrementalIndexSchema.Builder() + .withDimensionsSpec( + new DimensionsSpec( + ImmutableList.of( + new StringDimensionSchema("dim1"), + new StringDimensionSchema("dim2"), + new LongDimensionSchema("dim3") + ) + ) + ) + .withMetrics( + new CountAggregatorFactory("cnt"), + new LongSumAggregatorFactory("m1", "m1"), + new DoubleSumAggregatorFactory("m2", "m2"), + new HyperUniquesAggregatorFactory("unique_dim1", "dim1") + ) + .withRollup(false) + .build(); + index = IndexBuilder + .create() + .tmpDir(tempFolderProducer.apply("tmpDir")) + .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) + .schema(indexSchemaDifferentDim3M1Types) + .rows(ROWS2) + .buildMMappedIndex(); + break; + case DATASOURCE3: + case CalciteTests.BROADCAST_DATASOURCE: + index = IndexBuilder + .create() + .tmpDir(tempFolderProducer.apply("tmpDir")) + .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) + .schema(INDEX_SCHEMA_NUMERIC_DIMS) + .rows(ROWS1_WITH_NUMERIC_DIMS) + .buildMMappedIndex(); + break; + case DATASOURCE5: + index = IndexBuilder + .create() + .tmpDir(tempFolderProducer.apply("tmpDir")) + .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) + .schema(INDEX_SCHEMA_LOTS_O_COLUMNS) + .rows(ROWS_LOTS_OF_COLUMNS) + .buildMMappedIndex(); + break; + case ARRAYS_DATASOURCE: + index = IndexBuilder.create() + .tmpDir(tempFolderProducer.apply("tmpDir")) + .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) + .schema( + new IncrementalIndexSchema.Builder() + .withTimestampSpec(NestedDataTestUtils.AUTO_SCHEMA.getTimestampSpec()) + .withDimensionsSpec(NestedDataTestUtils.AUTO_SCHEMA.getDimensionsSpec()) + .withMetrics( + new CountAggregatorFactory("cnt") + ) + .withRollup(false) + .build() + ) + .inputSource( + ResourceInputSource.of( + NestedDataTestUtils.class.getClassLoader(), + NestedDataTestUtils.ARRAY_TYPES_DATA_FILE + ) + ) + .inputFormat(TestDataBuilder.DEFAULT_JSON_INPUT_FORMAT) + .inputTmpDir(tempFolderProducer.apply("tmpDir")) + .buildMMappedIndex(); + break; + case CalciteTests.WIKIPEDIA_FIRST_LAST: + index = TestDataBuilder.makeWikipediaIndexWithAggregation(tempFolderProducer.apply("tmpDir")); + break; + default: + throw new ISE("Cannot query segment %s in test runner", segmentId); - } - } - catch (IOException e) { - throw new ISE(e, "Unable to load index for segment %s", segmentId); } Segment segment = new Segment() { diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectJoinQueryMSQTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectJoinQueryMSQTest.java index 4c75312172d..fa72ca1d753 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectJoinQueryMSQTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectJoinQueryMSQTest.java @@ -36,14 +36,11 @@ import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.run.EngineFeature; import org.apache.druid.sql.calcite.run.QueryMaker; import org.apache.druid.sql.calcite.run.SqlEngine; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; /** * Runs {@link CalciteJoinQueryTest} but with MSQ engine. */ -@RunWith(Enclosed.class) -public abstract class CalciteSelectJoinQueryMSQTest +public class CalciteSelectJoinQueryMSQTest { /** * Run all tests with {@link JoinAlgorithm#BROADCAST}. @@ -87,19 +84,23 @@ public abstract class CalciteSelectJoinQueryMSQTest { private final JoinAlgorithm joinAlgorithm; - protected Base(final JoinAlgorithm joinAlgorithm) { - super(joinAlgorithm == JoinAlgorithm.SORT_MERGE); this.joinAlgorithm = joinAlgorithm; } + @Override + public boolean isSortBasedJoin() + { + return joinAlgorithm == JoinAlgorithm.SORT_MERGE; + } + @Override public void configureGuice(DruidInjectorBuilder builder) { super.configureGuice(builder); builder.addModules( - CalciteMSQTestsHelper.fetchModules(temporaryFolder, TestGroupByBuffers.createDefault()).toArray(new Module[0]) + CalciteMSQTestsHelper.fetchModules(this::newTempFolder, TestGroupByBuffers.createDefault()).toArray(new Module[0]) ); } diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectQueryMSQTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectQueryMSQTest.java index ac954734e1a..b2d9ab1e9eb 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectQueryMSQTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteSelectQueryMSQTest.java @@ -35,8 +35,11 @@ import org.apache.druid.sql.calcite.CalciteQueryTest; import org.apache.druid.sql.calcite.QueryTestBuilder; import org.apache.druid.sql.calcite.run.SqlEngine; import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; + +import java.util.concurrent.TimeUnit; /** * Runs {@link CalciteQueryTest} but with MSQ engine @@ -47,7 +50,7 @@ public class CalciteSelectQueryMSQTest extends CalciteQueryTest public void configureGuice(DruidInjectorBuilder builder) { super.configureGuice(builder); - builder.addModules(CalciteMSQTestsHelper.fetchModules(temporaryFolder, TestGroupByBuffers.createDefault()).toArray(new Module[0])); + builder.addModules(CalciteMSQTestsHelper.fetchModules(this::newTempFolder, TestGroupByBuffers.createDefault()).toArray(new Module[0])); } @@ -86,77 +89,88 @@ public class CalciteSelectQueryMSQTest extends CalciteQueryTest .verifyNativeQueries(new VerifyMSQSupportedNativeQueriesPredicate()); } - @Ignore + @Disabled @Override + @Test public void testCannotInsertWithNativeEngine() { } - @Ignore + @Disabled @Override + @Test public void testCannotReplaceWithNativeEngine() { } - @Ignore + @Disabled @Override + @Test public void testRequireTimeConditionSimpleQueryNegative() { } - @Ignore + @Disabled @Override + @Test public void testRequireTimeConditionSubQueryNegative() { } - @Ignore + @Disabled @Override + @Test public void testRequireTimeConditionSemiJoinNegative() { } - @Ignore + @Disabled @Override + @Test public void testExactCountDistinctWithFilter() { } - @Ignore + @Disabled @Override + @Test public void testUnplannableScanOrderByNonTime() { } - @Ignore + @Disabled @Override + @Test public void testUnplannableJoinQueriesInNonSQLCompatibleMode() { } - @Ignore + @Disabled @Override + @Test public void testQueryWithMoreThanMaxNumericInFilter() { } - @Ignore + @Disabled @Override + @Test public void testUnSupportedNullsFirst() { } - @Ignore + @Disabled @Override + @Test public void testUnSupportedNullsLast() { } @@ -180,7 +194,8 @@ public class CalciteSelectQueryMSQTest extends CalciteQueryTest } } - @Test(timeout = 40000) + @Test + @Timeout(value = 40000, unit = TimeUnit.MILLISECONDS) public void testJoinMultipleTablesWithWhereCondition() { testBuilder() @@ -217,6 +232,7 @@ public class CalciteSelectQueryMSQTest extends CalciteQueryTest } @Override + @Test public void testFilterParseLongNullable() { // this isn't really correct in default value mode, the result should be ImmutableList.of(new Object[]{0L}) diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteUnionQueryMSQTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteUnionQueryMSQTest.java index 9f1d7cc242d..babd3251a46 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteUnionQueryMSQTest.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/CalciteUnionQueryMSQTest.java @@ -43,8 +43,8 @@ import org.apache.druid.sql.calcite.QueryTestBuilder; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.run.SqlEngine; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; /** * Runs {@link CalciteUnionQueryTest} but with MSQ engine @@ -56,7 +56,7 @@ public class CalciteUnionQueryMSQTest extends CalciteUnionQueryTest { super.configureGuice(builder); builder.addModules( - CalciteMSQTestsHelper.fetchModules(temporaryFolder, TestGroupByBuffers.createDefault()).toArray(new Module[0]) + CalciteMSQTestsHelper.fetchModules(this::newTempFolder, TestGroupByBuffers.createDefault()).toArray(new Module[0]) ); } @@ -113,7 +113,7 @@ public class CalciteUnionQueryMSQTest extends CalciteUnionQueryTest } - @Ignore("Ignored till MSQ can plan UNION ALL with any operand") + @Disabled("Ignored till MSQ can plan UNION ALL with any operand") @Test public void testUnionOnSubqueries() { diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java index 4fbaba52e83..40dc06a7652 100644 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java +++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java @@ -192,13 +192,10 @@ import org.apache.druid.timeline.partition.ShardSpec; import org.apache.druid.timeline.partition.TombstoneShardSpec; import org.easymock.EasyMock; import org.hamcrest.Matcher; -import org.hamcrest.MatcherAssert; import org.joda.time.Interval; -import org.junit.After; import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.mockito.Mockito; import javax.annotation.Nonnull; @@ -218,6 +215,7 @@ import java.util.Optional; import java.util.Set; import java.util.SortedMap; import java.util.TreeMap; +import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -226,6 +224,7 @@ import static org.apache.druid.sql.calcite.util.CalciteTests.DATASOURCE1; import static org.apache.druid.sql.calcite.util.CalciteTests.DATASOURCE2; import static org.apache.druid.sql.calcite.util.TestDataBuilder.ROWS1; import static org.apache.druid.sql.calcite.util.TestDataBuilder.ROWS2; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; @@ -321,8 +320,6 @@ public class MSQTestBase extends BaseCalciteQueryTest private MSQTestSegmentManager segmentManager; private SegmentCacheManager segmentCacheManager; - @Rule - public TemporaryFolder tmpFolder = new TemporaryFolder(); private TestGroupByBuffers groupByBuffers; protected final WorkerMemoryParameters workerMemoryParameters = Mockito.spy( @@ -368,7 +365,7 @@ public class MSQTestBase extends BaseCalciteQueryTest }); } - @After + @AfterEach public void tearDown2() { groupByBuffers.close(); @@ -391,7 +388,7 @@ public class MSQTestBase extends BaseCalciteQueryTest // is created in the main injector, but it depends on the SegmentCacheManagerFactory // which depends on the object mapper that the injector will provide, once it // is built, but has not yet been build while we build the SQL engine. - @Before + @BeforeEach public void setUp2() throws Exception { groupByBuffers = TestGroupByBuffers.createDefault(); @@ -408,12 +405,7 @@ public class MSQTestBase extends BaseCalciteQueryTest ObjectMapper secondMapper = setupObjectMapper(secondInjector); indexIO = new IndexIO(secondMapper, ColumnConfig.DEFAULT); - try { - segmentCacheManager = new SegmentCacheManagerFactory(secondMapper).manufacturate(tmpFolder.newFolder("test")); - } - catch (IOException exception) { - throw new ISE(exception, "Unable to create segmentCacheManager"); - } + segmentCacheManager = new SegmentCacheManagerFactory(secondMapper).manufacturate(newTempFolder("cacheManager")); MSQSqlModule sqlModule = new MSQSqlModule(); @@ -445,18 +437,13 @@ public class MSQTestBase extends BaseCalciteQueryTest binder.bind(QueryProcessingPool.class) .toInstance(new ForwardingQueryProcessingPool(Execs.singleThreaded("Test-runner-processing-pool"))); binder.bind(DataSegmentProvider.class) - .toInstance((segmentId, channelCounters, isReindex) -> getSupplierForSegment(segmentId)); + .toInstance((segmentId, channelCounters, isReindex) -> getSupplierForSegment(this::newTempFolder, segmentId)); binder.bind(DataServerQueryHandlerFactory.class).toInstance(getTestDataServerQueryHandlerFactory()); binder.bind(IndexIO.class).toInstance(indexIO); binder.bind(SpecificSegmentsQuerySegmentWalker.class).toInstance(qf.walker()); LocalDataSegmentPusherConfig config = new LocalDataSegmentPusherConfig(); - try { - config.storageDirectory = tmpFolder.newFolder("localsegments"); - } - catch (IOException e) { - throw new ISE(e, "Unable to create folder"); - } + config.storageDirectory = newTempFolder("storageDir"); binder.bind(DataSegmentPusher.class).toInstance(new MSQTestDelegateDataSegmentPusher( new LocalDataSegmentPusher(config), segmentManager @@ -474,7 +461,7 @@ public class MSQTestBase extends BaseCalciteQueryTest StorageConnectorProvider.class, MultiStageQuery.class ); - localFileStorageDir = tmpFolder.newFolder("fault"); + localFileStorageDir = newTempFolder("faultStorageDir"); localFileStorageConnector = Mockito.spy( new LocalFileStorageConnector(localFileStorageDir) ); @@ -620,71 +607,59 @@ public class MSQTestBase extends BaseCalciteQueryTest } @Nonnull - private Supplier> getSupplierForSegment(SegmentId segmentId) + private Supplier> getSupplierForSegment(Function tempFolderProducer, SegmentId segmentId) { if (segmentManager.getSegment(segmentId) == null) { final QueryableIndex index; - TemporaryFolder temporaryFolder = new TemporaryFolder(); - try { - temporaryFolder.create(); - } - catch (IOException e) { - throw new ISE(e, "Unable to create temporary folder for tests"); - } - try { - switch (segmentId.getDataSource()) { - case DATASOURCE1: - IncrementalIndexSchema foo1Schema = new IncrementalIndexSchema.Builder() - .withMetrics( - new CountAggregatorFactory("cnt"), - new FloatSumAggregatorFactory("m1", "m1"), - new DoubleSumAggregatorFactory("m2", "m2"), - new HyperUniquesAggregatorFactory("unique_dim1", "dim1") - ) - .withRollup(false) - .build(); - index = IndexBuilder - .create() - .tmpDir(new File(temporaryFolder.newFolder(), "1")) - .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) - .schema(foo1Schema) - .rows(ROWS1) - .buildMMappedIndex(); - break; - case DATASOURCE2: - final IncrementalIndexSchema indexSchemaDifferentDim3M1Types = new IncrementalIndexSchema.Builder() - .withDimensionsSpec( - new DimensionsSpec( - ImmutableList.of( - new StringDimensionSchema("dim1"), - new StringDimensionSchema("dim2"), - new LongDimensionSchema("dim3") - ) - ) - ) - .withMetrics( - new CountAggregatorFactory("cnt"), - new LongSumAggregatorFactory("m1", "m1"), - new DoubleSumAggregatorFactory("m2", "m2"), - new HyperUniquesAggregatorFactory("unique_dim1", "dim1") - ) - .withRollup(false) - .build(); - index = IndexBuilder - .create() - .tmpDir(new File(temporaryFolder.newFolder(), "1")) - .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) - .schema(indexSchemaDifferentDim3M1Types) - .rows(ROWS2) - .buildMMappedIndex(); - break; - default: - throw new ISE("Cannot query segment %s in test runner", segmentId); + switch (segmentId.getDataSource()) { + case DATASOURCE1: + IncrementalIndexSchema foo1Schema = new IncrementalIndexSchema.Builder() + .withMetrics( + new CountAggregatorFactory("cnt"), + new FloatSumAggregatorFactory("m1", "m1"), + new DoubleSumAggregatorFactory("m2", "m2"), + new HyperUniquesAggregatorFactory("unique_dim1", "dim1") + ) + .withRollup(false) + .build(); + index = IndexBuilder + .create() + .tmpDir(new File(tempFolderProducer.apply("tmpDir"), "1")) + .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) + .schema(foo1Schema) + .rows(ROWS1) + .buildMMappedIndex(); + break; + case DATASOURCE2: + final IncrementalIndexSchema indexSchemaDifferentDim3M1Types = new IncrementalIndexSchema.Builder() + .withDimensionsSpec( + new DimensionsSpec( + ImmutableList.of( + new StringDimensionSchema("dim1"), + new StringDimensionSchema("dim2"), + new LongDimensionSchema("dim3") + ) + ) + ) + .withMetrics( + new CountAggregatorFactory("cnt"), + new LongSumAggregatorFactory("m1", "m1"), + new DoubleSumAggregatorFactory("m2", "m2"), + new HyperUniquesAggregatorFactory("unique_dim1", "dim1") + ) + .withRollup(false) + .build(); + index = IndexBuilder + .create() + .tmpDir(new File(tempFolderProducer.apply("tmpDir"), "1")) + .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) + .schema(indexSchemaDifferentDim3M1Types) + .rows(ROWS2) + .buildMMappedIndex(); + break; + default: + throw new ISE("Cannot query segment %s in test runner", segmentId); - } - } - catch (IOException e) { - throw new ISE(e, "Unable to load index for segment %s", segmentId); } Segment segment = new Segment() { @@ -1015,7 +990,7 @@ public class MSQTestBase extends BaseCalciteQueryTest () -> runMultiStageQuery(sql, queryContext) ); - MatcherAssert.assertThat(e, expectedValidationErrorMatcher); + assertThat(e, expectedValidationErrorMatcher); } protected void verifyWorkerCount(CounterSnapshotsTree counterSnapshotsTree) @@ -1339,7 +1314,7 @@ public class MSQTestBase extends BaseCalciteQueryTest Assert.fail(StringUtils.format("Query did not throw an exception (sql = [%s])", sql)); } catch (Exception e) { - MatcherAssert.assertThat( + assertThat( StringUtils.format("Query error did not match expectations (sql = [%s])", sql), e, expectedExecutionErrorMatcher @@ -1457,7 +1432,7 @@ public class MSQTestBase extends BaseCalciteQueryTest if (expectedExecutionErrorMatcher == null) { throw new ISE(e, "Query %s failed", sql); } - MatcherAssert.assertThat(e, expectedExecutionErrorMatcher); + assertThat(e, expectedExecutionErrorMatcher); return null; } } diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestFileUtils.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestFileUtils.java deleted file mode 100644 index 4ba1a0e6233..00000000000 --- a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestFileUtils.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.druid.msq.test; - -import com.google.common.collect.ImmutableList; -import com.google.common.io.ByteStreams; -import org.apache.druid.java.util.common.IOE; -import org.apache.druid.java.util.common.StringUtils; -import org.junit.rules.TemporaryFolder; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.StandardOpenOption; - -public class MSQTestFileUtils -{ - - /** - * Helper method that copies a resource to a temporary file, then returns it. - */ - public static File getResourceAsTemporaryFile(TemporaryFolder temporaryFolder, Object object, final String resource) throws IOException - { - final File file = temporaryFolder.newFile(); - final InputStream stream = object.getClass().getResourceAsStream(resource); - - if (stream == null) { - throw new IOE("No such resource [%s]", resource); - } - - ByteStreams.copy(stream, Files.newOutputStream(file.toPath())); - return file; - } - - /** - * Helper method that populates a temporary file with {@code numRows} rows and {@code numColumns} columns where the - * first column is a string 'timestamp' while the rest are string columns with junk value - */ - public static File generateTemporaryNdJsonFile(TemporaryFolder temporaryFolder, final int numRows, final int numColumns) throws IOException - { - final File file = temporaryFolder.newFile(); - for (int currentRow = 0; currentRow < numRows; ++currentRow) { - StringBuilder sb = new StringBuilder(); - sb.append("{"); - sb.append("\"timestamp\":\"2016-06-27T00:00:11.080Z\""); - for (int currentColumn = 1; currentColumn < numColumns; ++currentColumn) { - sb.append(StringUtils.format(",\"column%s\":\"val%s\"", currentColumn, currentRow)); - } - sb.append("}"); - Files.write(file.toPath(), ImmutableList.of(sb.toString()), StandardCharsets.UTF_8, StandardOpenOption.APPEND); - } - file.deleteOnExit(); - return file; - } -} diff --git a/extensions-core/stats/pom.xml b/extensions-core/stats/pom.xml index 78a148e979b..726c4a71d4d 100644 --- a/extensions-core/stats/pom.xml +++ b/extensions-core/stats/pom.xml @@ -93,6 +93,37 @@ + + junit + junit + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + + org.apache.druid druid-processing @@ -117,11 +148,6 @@ test-jar - - junit - junit - test - org.mockito mockito-core diff --git a/extensions-core/stats/src/test/java/org/apache/druid/query/aggregation/variance/sql/VarianceSqlAggregatorTest.java b/extensions-core/stats/src/test/java/org/apache/druid/query/aggregation/variance/sql/VarianceSqlAggregatorTest.java index 879d6e093a7..66c6290ea3e 100644 --- a/extensions-core/stats/src/test/java/org/apache/druid/query/aggregation/variance/sql/VarianceSqlAggregatorTest.java +++ b/extensions-core/stats/src/test/java/org/apache/druid/query/aggregation/variance/sql/VarianceSqlAggregatorTest.java @@ -62,9 +62,8 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.List; public class VarianceSqlAggregatorTest extends BaseCalciteQueryTest @@ -81,13 +80,13 @@ public class VarianceSqlAggregatorTest extends BaseCalciteQueryTest final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { ComplexMetrics.registerSerde(VarianceSerde.TYPE_NAME, new VarianceSerde()); final QueryableIndex index = IndexBuilder.create(CalciteTests.getJsonMapper().registerModules(new DruidStatsModule().getJacksonModules())) - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() diff --git a/extensions-core/testing-tools/pom.xml b/extensions-core/testing-tools/pom.xml index 408aa2d1a8e..978072714b8 100644 --- a/extensions-core/testing-tools/pom.xml +++ b/extensions-core/testing-tools/pom.xml @@ -125,6 +125,31 @@ junit test + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + nl.jqno.equalsverifier equalsverifier diff --git a/extensions-core/testing-tools/src/test/java/org/apache/druid/query/sql/SleepSqlTest.java b/extensions-core/testing-tools/src/test/java/org/apache/druid/query/sql/SleepSqlTest.java index d8dc51f6c24..9df6d0f3172 100644 --- a/extensions-core/testing-tools/src/test/java/org/apache/druid/query/sql/SleepSqlTest.java +++ b/extensions-core/testing-tools/src/test/java/org/apache/druid/query/sql/SleepSqlTest.java @@ -30,7 +30,7 @@ import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; import org.apache.druid.sql.calcite.filtration.Filtration; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SleepSqlTest extends BaseCalciteQueryTest { diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/ParallelIndexSupervisorTaskTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/ParallelIndexSupervisorTaskTest.java index a3d62b0c10a..a340655dfcc 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/ParallelIndexSupervisorTaskTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/ParallelIndexSupervisorTaskTest.java @@ -62,7 +62,6 @@ import org.joda.time.Interval; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.internal.matchers.ThrowableMessageMatcher; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; @@ -83,7 +82,6 @@ import java.util.stream.IntStream; import static org.easymock.EasyMock.expect; import static org.easymock.EasyMock.mock; -@RunWith(Enclosed.class) public class ParallelIndexSupervisorTaskTest { @RunWith(Parameterized.class) diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/PartialDimensionCardinalityTaskTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/PartialDimensionCardinalityTaskTest.java index d1a143d056c..c4ae9392450 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/PartialDimensionCardinalityTaskTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/PartialDimensionCardinalityTaskTest.java @@ -58,17 +58,14 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -@RunWith(Enclosed.class) public class PartialDimensionCardinalityTaskTest { private static final ObjectMapper OBJECT_MAPPER = ParallelIndexTestingFactory.createObjectMapper(); diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/PartialDimensionDistributionTaskTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/PartialDimensionDistributionTaskTest.java index 8ed96d0ddb0..1346b29d889 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/PartialDimensionDistributionTaskTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/PartialDimensionDistributionTaskTest.java @@ -54,10 +54,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.Arrays; @@ -68,7 +66,6 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.IntStream; -@RunWith(Enclosed.class) public class PartialDimensionDistributionTaskTest { private static final ObjectMapper OBJECT_MAPPER = ParallelIndexTestingFactory.createObjectMapper(); diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/distribution/StringSketchTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/distribution/StringSketchTest.java index f31eeb830cc..6f76d329655 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/distribution/StringSketchTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/distribution/StringSketchTest.java @@ -33,9 +33,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.Arrays; @@ -45,7 +43,6 @@ import java.util.StringJoiner; import java.util.stream.Collectors; import java.util.stream.IntStream; -@RunWith(Enclosed.class) public class StringSketchTest { private static final int FACTOR = 2; @@ -140,7 +137,6 @@ public class StringSketchTest } } - @RunWith(Enclosed.class) public static class PartitionTest { private static final StringSketch SKETCH; diff --git a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/iterator/DefaultIndexTaskInputRowIteratorBuilderTest.java b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/iterator/DefaultIndexTaskInputRowIteratorBuilderTest.java index ddf0fbd5a88..31f310e77ba 100644 --- a/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/iterator/DefaultIndexTaskInputRowIteratorBuilderTest.java +++ b/indexing-service/src/test/java/org/apache/druid/indexing/common/task/batch/parallel/iterator/DefaultIndexTaskInputRowIteratorBuilderTest.java @@ -29,14 +29,11 @@ import org.joda.time.DateTime; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import java.util.Collections; import java.util.List; -@RunWith(Enclosed.class) public class DefaultIndexTaskInputRowIteratorBuilderTest { public static class BuildTest diff --git a/pom.xml b/pom.xml index 7c60fb85b7f..627ed64b399 100644 --- a/pom.xml +++ b/pom.xml @@ -1056,7 +1056,7 @@ org.junit junit-bom - 5.10.0 + 5.10.2 pom import @@ -1347,6 +1347,32 @@ + + org.openrewrite.maven + rewrite-maven-plugin + 5.23.1 + + + org.apache.druid.RewriteRules + + ${maven.multiModuleProjectDirectory}/rewrite.yml + false + true + false + true + + **/*.json + **/*.yaml + + + + + org.openrewrite.recipe + rewrite-testing-frameworks + 2.4.1 + + + org.jacoco jacoco-maven-plugin @@ -1573,6 +1599,7 @@ + 3.0.0 @@ -1709,7 +1736,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.1.2 + 3.2.5 @@ -1741,6 +1768,11 @@ true + + + + diff --git a/processing/src/test/java/org/apache/druid/data/input/HandlingInputRowIteratorTest.java b/processing/src/test/java/org/apache/druid/data/input/HandlingInputRowIteratorTest.java index c70fa397798..3fa5a3bef27 100644 --- a/processing/src/test/java/org/apache/druid/data/input/HandlingInputRowIteratorTest.java +++ b/processing/src/test/java/org/apache/druid/data/input/HandlingInputRowIteratorTest.java @@ -25,8 +25,6 @@ import org.apache.druid.java.util.common.parsers.CloseableIterator; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; import org.mockito.Mockito; import javax.annotation.Nullable; @@ -41,7 +39,6 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith(Enclosed.class) public class HandlingInputRowIteratorTest { public static class AbsentRowTest diff --git a/processing/src/test/java/org/apache/druid/frame/FrameTest.java b/processing/src/test/java/org/apache/druid/frame/FrameTest.java index eafe7f274bc..029e34bc011 100644 --- a/processing/src/test/java/org/apache/druid/frame/FrameTest.java +++ b/processing/src/test/java/org/apache/druid/frame/FrameTest.java @@ -45,7 +45,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.internal.matchers.ThrowableMessageMatcher; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; @@ -61,7 +60,6 @@ import java.nio.channels.Channels; import java.util.ArrayList; import java.util.List; -@RunWith(Enclosed.class) public class FrameTest { // Tests that use good frames built from a standard test file. diff --git a/processing/src/test/java/org/apache/druid/frame/channel/ReadableByteChunksFrameChannelTest.java b/processing/src/test/java/org/apache/druid/frame/channel/ReadableByteChunksFrameChannelTest.java index 2c96be3c1ca..18168a1776e 100644 --- a/processing/src/test/java/org/apache/druid/frame/channel/ReadableByteChunksFrameChannelTest.java +++ b/processing/src/test/java/org/apache/druid/frame/channel/ReadableByteChunksFrameChannelTest.java @@ -36,7 +36,6 @@ import org.hamcrest.CoreMatchers; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; @@ -52,7 +51,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -@RunWith(Enclosed.class) public class ReadableByteChunksFrameChannelTest { /** diff --git a/processing/src/test/java/org/apache/druid/frame/processor/FrameProcessorExecutorTest.java b/processing/src/test/java/org/apache/druid/frame/processor/FrameProcessorExecutorTest.java index 118cd43c48c..b31818964ea 100644 --- a/processing/src/test/java/org/apache/druid/frame/processor/FrameProcessorExecutorTest.java +++ b/processing/src/test/java/org/apache/druid/frame/processor/FrameProcessorExecutorTest.java @@ -58,7 +58,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.internal.matchers.ThrowableMessageMatcher; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; @@ -84,7 +83,6 @@ import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import java.util.stream.Collectors; -@RunWith(Enclosed.class) public class FrameProcessorExecutorTest { @RunWith(Parameterized.class) diff --git a/processing/src/test/java/org/apache/druid/frame/processor/SuperSorterTest.java b/processing/src/test/java/org/apache/druid/frame/processor/SuperSorterTest.java index b0ca2f26a4d..8211839223c 100644 --- a/processing/src/test/java/org/apache/druid/frame/processor/SuperSorterTest.java +++ b/processing/src/test/java/org/apache/druid/frame/processor/SuperSorterTest.java @@ -62,7 +62,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -79,7 +78,6 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; -@RunWith(Enclosed.class) public class SuperSorterTest { private static final Logger log = new Logger(SuperSorterTest.class); diff --git a/processing/src/test/java/org/apache/druid/frame/segment/FrameStorageAdapterTest.java b/processing/src/test/java/org/apache/druid/frame/segment/FrameStorageAdapterTest.java index 1f4b0e45aee..481851a0f75 100644 --- a/processing/src/test/java/org/apache/druid/frame/segment/FrameStorageAdapterTest.java +++ b/processing/src/test/java/org/apache/druid/frame/segment/FrameStorageAdapterTest.java @@ -54,7 +54,6 @@ import org.junit.Assert; import org.junit.Assume; import org.junit.Before; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -65,7 +64,6 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; -@RunWith(Enclosed.class) public class FrameStorageAdapterTest { /** diff --git a/processing/src/test/java/org/apache/druid/guice/DruidSecondaryModuleTest.java b/processing/src/test/java/org/apache/druid/guice/DruidSecondaryModuleTest.java index ddda5a5de82..9bbd2de9df6 100644 --- a/processing/src/test/java/org/apache/druid/guice/DruidSecondaryModuleTest.java +++ b/processing/src/test/java/org/apache/druid/guice/DruidSecondaryModuleTest.java @@ -32,8 +32,6 @@ import com.google.inject.Injector; import com.google.inject.Module; import org.junit.Assert; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; import javax.annotation.Nullable; import javax.validation.Validation; @@ -43,7 +41,6 @@ import java.util.Map; import java.util.Objects; import java.util.Properties; -@RunWith(Enclosed.class) public class DruidSecondaryModuleTest { private static final String PROPERTY_NAME = "druid.injected.val"; diff --git a/processing/src/test/java/org/apache/druid/java/util/common/guava/TopNSequenceTest.java b/processing/src/test/java/org/apache/druid/java/util/common/guava/TopNSequenceTest.java index abf11ad51f8..5c7109642e4 100644 --- a/processing/src/test/java/org/apache/druid/java/util/common/guava/TopNSequenceTest.java +++ b/processing/src/test/java/org/apache/druid/java/util/common/guava/TopNSequenceTest.java @@ -25,7 +25,6 @@ import com.google.common.collect.Lists; import com.google.common.collect.Ordering; import org.junit.Assert; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -37,7 +36,6 @@ import java.util.List; import java.util.Random; -@RunWith(Enclosed.class) public class TopNSequenceTest { private static final List EMPTY = Collections.emptyList(); diff --git a/processing/src/test/java/org/apache/druid/metadata/TaskLookupTest.java b/processing/src/test/java/org/apache/druid/metadata/TaskLookupTest.java index 39714b42de6..76d90737a5f 100644 --- a/processing/src/test/java/org/apache/druid/metadata/TaskLookupTest.java +++ b/processing/src/test/java/org/apache/druid/metadata/TaskLookupTest.java @@ -29,10 +29,7 @@ import org.joda.time.Duration; import org.joda.time.Period; import org.junit.Assert; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; -@RunWith(Enclosed.class) public class TaskLookupTest { public static class CompleteTaskLookupTest diff --git a/processing/src/test/java/org/apache/druid/query/DruidsTest.java b/processing/src/test/java/org/apache/druid/query/DruidsTest.java index f4144d2d55f..51be50650be 100644 --- a/processing/src/test/java/org/apache/druid/query/DruidsTest.java +++ b/processing/src/test/java/org/apache/druid/query/DruidsTest.java @@ -34,10 +34,7 @@ import org.apache.druid.query.timeseries.TimeseriesQuery; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; -@RunWith(Enclosed.class) public class DruidsTest { private static final String DATASOURCE = "datasource"; diff --git a/processing/src/test/java/org/apache/druid/query/aggregation/GroupingAggregatorFactoryTest.java b/processing/src/test/java/org/apache/druid/query/aggregation/GroupingAggregatorFactoryTest.java index 0117bf1e82a..2be56bd0f0e 100644 --- a/processing/src/test/java/org/apache/druid/query/aggregation/GroupingAggregatorFactoryTest.java +++ b/processing/src/test/java/org/apache/druid/query/aggregation/GroupingAggregatorFactoryTest.java @@ -31,7 +31,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -39,7 +38,6 @@ import org.junit.runners.Parameterized; import java.util.Arrays; import java.util.Collection; -@RunWith(Enclosed.class) public class GroupingAggregatorFactoryTest { public static GroupingAggregatorFactory makeFactory(String[] groupings, @Nullable String[] keyDims) diff --git a/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerFactoryTest.java b/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerFactoryTest.java index 3f28688df57..1c9a6c67ded 100644 --- a/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerFactoryTest.java +++ b/processing/src/test/java/org/apache/druid/query/scan/ScanQueryRunnerFactoryTest.java @@ -43,7 +43,6 @@ import org.joda.time.Interval; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -57,7 +56,6 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; -@RunWith(Enclosed.class) public class ScanQueryRunnerFactoryTest { private static final ScanQueryConfig CONFIG = new ScanQueryConfig() diff --git a/processing/src/test/java/org/apache/druid/segment/QueryableIndexStorageAdapterTest.java b/processing/src/test/java/org/apache/druid/segment/QueryableIndexStorageAdapterTest.java index 42fbffe3050..ddb1cc419f3 100644 --- a/processing/src/test/java/org/apache/druid/segment/QueryableIndexStorageAdapterTest.java +++ b/processing/src/test/java/org/apache/druid/segment/QueryableIndexStorageAdapterTest.java @@ -37,7 +37,6 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -46,7 +45,6 @@ import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Collection; -@RunWith(Enclosed.class) public class QueryableIndexStorageAdapterTest { @RunWith(Parameterized.class) diff --git a/processing/src/test/java/org/apache/druid/segment/data/VSizeLongSerdeTest.java b/processing/src/test/java/org/apache/druid/segment/data/VSizeLongSerdeTest.java index dfd05be6fd0..cc832f6662d 100644 --- a/processing/src/test/java/org/apache/druid/segment/data/VSizeLongSerdeTest.java +++ b/processing/src/test/java/org/apache/druid/segment/data/VSizeLongSerdeTest.java @@ -24,7 +24,6 @@ import com.google.common.primitives.Ints; import org.apache.druid.java.util.common.StringUtils; import org.junit.Assert; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -35,7 +34,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.stream.Collectors; -@RunWith(Enclosed.class) public class VSizeLongSerdeTest { @RunWith(Parameterized.class) diff --git a/processing/src/test/java/org/apache/druid/segment/filter/ArrayContainsElementFilterTests.java b/processing/src/test/java/org/apache/druid/segment/filter/ArrayContainsElementFilterTests.java index 434273870ff..2418941bf73 100644 --- a/processing/src/test/java/org/apache/druid/segment/filter/ArrayContainsElementFilterTests.java +++ b/processing/src/test/java/org/apache/druid/segment/filter/ArrayContainsElementFilterTests.java @@ -42,14 +42,12 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.io.Closeable; import java.util.Arrays; -@RunWith(Enclosed.class) public class ArrayContainsElementFilterTests { @RunWith(Parameterized.class) diff --git a/processing/src/test/java/org/apache/druid/segment/filter/EqualityFilterTests.java b/processing/src/test/java/org/apache/druid/segment/filter/EqualityFilterTests.java index 78b40ea43d7..3d35817531f 100644 --- a/processing/src/test/java/org/apache/druid/segment/filter/EqualityFilterTests.java +++ b/processing/src/test/java/org/apache/druid/segment/filter/EqualityFilterTests.java @@ -48,14 +48,12 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.io.Closeable; import java.util.Arrays; -@RunWith(Enclosed.class) public class EqualityFilterTests { @RunWith(Parameterized.class) diff --git a/processing/src/test/java/org/apache/druid/segment/filter/NullFilterTests.java b/processing/src/test/java/org/apache/druid/segment/filter/NullFilterTests.java index 9cb64f75d78..5f9de867eca 100644 --- a/processing/src/test/java/org/apache/druid/segment/filter/NullFilterTests.java +++ b/processing/src/test/java/org/apache/druid/segment/filter/NullFilterTests.java @@ -37,7 +37,6 @@ import org.apache.druid.segment.StorageAdapter; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -45,7 +44,6 @@ import java.io.Closeable; import java.util.Arrays; import java.util.Collections; -@RunWith(Enclosed.class) public class NullFilterTests { @RunWith(Parameterized.class) diff --git a/processing/src/test/java/org/apache/druid/segment/filter/RangeFilterTests.java b/processing/src/test/java/org/apache/druid/segment/filter/RangeFilterTests.java index c21a2198193..424fb28b086 100644 --- a/processing/src/test/java/org/apache/druid/segment/filter/RangeFilterTests.java +++ b/processing/src/test/java/org/apache/druid/segment/filter/RangeFilterTests.java @@ -50,7 +50,6 @@ import org.junit.AfterClass; import org.junit.Assert; import org.junit.Assume; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -59,7 +58,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -@RunWith(Enclosed.class) public class RangeFilterTests { @RunWith(Parameterized.class) diff --git a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java index b1a47355f54..6222d50d446 100644 --- a/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java +++ b/processing/src/test/java/org/apache/druid/segment/join/table/IndexedTableJoinMatcherTest.java @@ -41,9 +41,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -52,12 +50,10 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; import java.util.function.IntFunction; -@RunWith(Enclosed.class) public class IndexedTableJoinMatcherTest { private static final int SIZE = 3; - @RunWith(Enclosed.class) public static class ConditionMatcherFactoryTest { public static class MakeLongProcessorTest extends InitializedNullHandlingTest diff --git a/processing/src/test/java/org/apache/druid/utils/ConnectionUriUtilsTest.java b/processing/src/test/java/org/apache/druid/utils/ConnectionUriUtilsTest.java index f264e0a4fde..754eb05b305 100644 --- a/processing/src/test/java/org/apache/druid/utils/ConnectionUriUtilsTest.java +++ b/processing/src/test/java/org/apache/druid/utils/ConnectionUriUtilsTest.java @@ -24,15 +24,12 @@ import org.apache.druid.java.util.common.IAE; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.mockito.MockedStatic; import org.mockito.Mockito; import java.util.Set; -@RunWith(Enclosed.class) public class ConnectionUriUtilsTest { public static class ThrowIfURLHasNotAllowedPropertiesTest diff --git a/processing/src/test/java/org/apache/druid/utils/DynamicConfigProviderUtilsTest.java b/processing/src/test/java/org/apache/druid/utils/DynamicConfigProviderUtilsTest.java index 496acfabef3..d10973b82ff 100644 --- a/processing/src/test/java/org/apache/druid/utils/DynamicConfigProviderUtilsTest.java +++ b/processing/src/test/java/org/apache/druid/utils/DynamicConfigProviderUtilsTest.java @@ -26,13 +26,10 @@ import org.apache.druid.metadata.MapStringDynamicConfigProvider; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import java.util.Map; -@RunWith(Enclosed.class) public class DynamicConfigProviderUtilsTest { public static class ThrowIfURLHasNotAllowedPropertiesTest diff --git a/rewrite.yml b/rewrite.yml new file mode 100644 index 00000000000..ac715f51e8c --- /dev/null +++ b/rewrite.yml @@ -0,0 +1,157 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.apache.druid.RewriteRules +recipeList: + - org.apache.druid.UpgradeCalciteTestsToJunit5 + - org.openrewrite.java.testing.junit5.RemoveObsoleteRunners: + obsoleteRunners: + - org.junit.experimental.runners.Enclosed +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.apache.druid.UpgradeCalciteTestsToJunit5 +preconditions: + - org.openrewrite.java.search.FindImplementations: + typeName: org.apache.druid.sql.calcite.util.CalciteTestBase +recipeList: + - org.apache.druid.JUnit4to5Migration + - org.openrewrite.staticanalysis.UnnecessaryThrows + #- org.openrewrite.java.testing.junit5.StaticImports +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.apache.druid.EasyMockRunnerToEasyMockExtension +displayName: Replace EasyMock `@RunWith` with `@ExtendWith` usage +recipeList: + - org.openrewrite.java.testing.junit5.RunnerToExtension: + runners: + - org.easymock.EasyMockRunner + extension: org.easymock.EasyMockExtension +--- +# Customized version of org.openrewrite.java.testing.junit5.JUnit4to5Migration +# commented lines are recipes which were disabled +type: specs.openrewrite.org/v1beta/recipe +name: org.apache.druid.JUnit4to5Migration +displayName: Custom JUnit Jupiter migration from JUnit 4.x +description: Migrates JUnit 4.x tests to JUnit Jupiter. +tags: + - junit + - testing +recipeList: + - org.openrewrite.java.testing.junit5.UseWiremockExtension + - org.openrewrite.java.testing.junit5.IgnoreToDisabled + - org.openrewrite.java.testing.junit5.ThrowingRunnableToExecutable + - org.openrewrite.java.testing.junit5.RemoveObsoleteRunners: + obsoleteRunners: [org.junit.runners.JUnit4, org.junit.runners.BlockJUnit4ClassRunner] + - org.openrewrite.maven.RemovePluginDependency: + pluginGroupId: org.apache.maven.plugins + pluginArtifactId: maven-surefire-plugin + groupId: org.apache.maven.surefire + artifactId: surefire-junit* + - org.openrewrite.java.testing.junit5.UseHamcrestAssertThat + - org.openrewrite.java.testing.junit5.MigrateAssumptions + - org.openrewrite.java.testing.junit5.UseMockitoExtension + - org.openrewrite.java.testing.junit5.UseTestMethodOrder + - org.openrewrite.java.testing.junit5.MigrateJUnitTestCase + - org.openrewrite.java.ChangeMethodName: + methodPattern: org.junit.Assert assertEquals(.., Object[], Object[]) + newMethodName: assertArrayEquals + #- org.openrewrite.java.testing.junit5.AssertToAssertions + - org.openrewrite.java.testing.junit5.CategoryToTag + - org.openrewrite.java.testing.junit5.CleanupJUnitImports + - org.openrewrite.java.testing.junit5.TemporaryFolderToTempDir + - org.openrewrite.java.testing.junit5.TempDirNonFinal + - org.openrewrite.java.testing.junit5.TestRuleToTestInfo + - org.openrewrite.java.testing.junit5.UpdateBeforeAfterAnnotations + - org.openrewrite.java.testing.junit5.UpdateTestAnnotation + - org.openrewrite.java.testing.junit5.AddMissingTestBeforeAfterAnnotations + - org.openrewrite.java.testing.junit5.ParameterizedRunnerToParameterized + - org.openrewrite.java.testing.junit5.JUnitParamsRunnerToParameterized + - org.apache.druid.EasyMockRunnerToEasyMockExtension + - org.openrewrite.java.testing.junit5.ExpectedExceptionToAssertThrows + - org.openrewrite.java.testing.junit5.UpdateMockWebServer + - org.openrewrite.java.testing.junit5.VertxUnitToVertxJunit5 + - org.openrewrite.java.testing.junit5.EnclosedToNested + - org.openrewrite.java.testing.junit5.AddMissingNested + - org.openrewrite.java.testing.hamcrest.AddHamcrestIfUsed + - org.openrewrite.java.testing.junit5.UseXMLUnitLegacy + - org.openrewrite.java.dependencies.RemoveDependency: + groupId: junit + artifactId: junit + - org.openrewrite.maven.ExcludeDependency: + groupId: junit + artifactId: junit + - org.openrewrite.maven.RemoveExclusion: + groupId: org.testcontainers + artifactId: testcontainers + exclusionGroupId: junit + exclusionArtifactId: junit + - org.openrewrite.maven.RemoveExclusion: + groupId: org.springframework.boot + artifactId: spring-boot-testcontainers + exclusionGroupId: junit + exclusionArtifactId: junit + - org.openrewrite.java.dependencies.RemoveDependency: + groupId: org.junit.vintage + artifactId: junit-vintage-engine + - org.openrewrite.maven.ExcludeDependency: + groupId: org.junit.vintage + artifactId: junit-vintage-engine + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.junit.jupiter + artifactId: junit-jupiter + version: 5.x + onlyIfUsing: org.junit.Test + scope: test + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.junit.jupiter + artifactId: junit-jupiter + version: 5.x + onlyIfUsing: org.junit.jupiter.api.Test + scope: test + acceptTransitive: true + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.junit.jupiter + artifactId: junit-jupiter-api + version: 5.x + onlyIfUsing: org.junit.Test + scope: test + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.junit.jupiter + artifactId: junit-jupiter-api + version: 5.x + onlyIfUsing: org.junit.jupiter.api.Test + scope: test + acceptTransitive: true + - org.openrewrite.java.dependencies.AddDependency: + groupId: org.junit.jupiter + artifactId: junit-jupiter-params + version: 5.x + onlyIfUsing: org.junit.jupiter.params.ParameterizedTest + scope: test + acceptTransitive: true + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.mockito + artifactId: "*" + newVersion: 3.x + overrideManagedVersion: false + - org.openrewrite.maven.UpgradePluginVersion: + groupId: org.apache.maven.plugins + artifactId: maven-surefire-plugin + newVersion: 2.22.x + - org.openrewrite.maven.UpgradePluginVersion: + groupId: org.apache.maven.plugins + artifactId: maven-failsafe-plugin + newVersion: 2.22.x diff --git a/server/pom.xml b/server/pom.xml index a0132ee3a02..410b51480ed 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -328,6 +328,31 @@ junit test + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-migrationsupport + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.vintage + junit-vintage-engine + test + org.mockito mockito-core diff --git a/server/src/test/java/org/apache/druid/client/JsonParserIteratorTest.java b/server/src/test/java/org/apache/druid/client/JsonParserIteratorTest.java index 5cce3c2fd3f..ab0e44c0430 100644 --- a/server/src/test/java/org/apache/druid/client/JsonParserIteratorTest.java +++ b/server/src/test/java/org/apache/druid/client/JsonParserIteratorTest.java @@ -39,7 +39,6 @@ import org.apache.druid.query.QueryUnsupportedException; import org.apache.druid.query.ResourceLimitExceededException; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -54,7 +53,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -@RunWith(Enclosed.class) public class JsonParserIteratorTest { private static final JavaType JAVA_TYPE = Mockito.mock(JavaType.class); diff --git a/server/src/test/java/org/apache/druid/metadata/TestDerbyConnector.java b/server/src/test/java/org/apache/druid/metadata/TestDerbyConnector.java index 1fa2ef2302c..b195fdad8de 100644 --- a/server/src/test/java/org/apache/druid/metadata/TestDerbyConnector.java +++ b/server/src/test/java/org/apache/druid/metadata/TestDerbyConnector.java @@ -25,6 +25,9 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.metadata.storage.derby.DerbyConnector; import org.joda.time.DateTime; import org.junit.Assert; +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeAllCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.rules.ExternalResource; import org.skife.jdbi.v2.DBI; import org.skife.jdbi.v2.exceptions.UnableToObtainConnectionException; @@ -190,4 +193,20 @@ public class TestDerbyConnector extends DerbyConnector .toUpperCase(Locale.ENGLISH); } } + + public static class DerbyConnectorRule5 extends DerbyConnectorRule implements BeforeAllCallback, AfterAllCallback + { + + @Override + public void beforeAll(ExtensionContext context) + { + before(); + } + + @Override + public void afterAll(ExtensionContext context) + { + after(); + } + } } diff --git a/sql/pom.xml b/sql/pom.xml index 1941df02be5..e4d920dfba0 100644 --- a/sql/pom.xml +++ b/sql/pom.xml @@ -203,8 +203,8 @@ test - org.junit.vintage - junit-vintage-engine + org.junit.jupiter + junit-jupiter-migrationsupport test @@ -212,6 +212,17 @@ junit-jupiter-params test + + org.junit.vintage + junit-vintage-engine + test + + + org.opentest4j + opentest4j + 1.3.0 + test + org.apache.commons commons-lang3 diff --git a/sql/src/test/java/org/apache/druid/sql/SqlRowTransformerTest.java b/sql/src/test/java/org/apache/druid/sql/SqlRowTransformerTest.java index 1ca9db2a3c7..5286df34d6b 100644 --- a/sql/src/test/java/org/apache/druid/sql/SqlRowTransformerTest.java +++ b/sql/src/test/java/org/apache/druid/sql/SqlRowTransformerTest.java @@ -33,8 +33,8 @@ import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.format.ISODateTimeFormat; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -43,7 +43,7 @@ public class SqlRowTransformerTest extends CalciteTestBase { private RelDataType rowType; - @Before + @BeforeEach public void setup() { final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(DruidTypeSystem.INSTANCE); diff --git a/sql/src/test/java/org/apache/druid/sql/SqlStatementTest.java b/sql/src/test/java/org/apache/druid/sql/SqlStatementTest.java index 9b28df2c0f1..b332b6dabfa 100644 --- a/sql/src/test/java/org/apache/druid/sql/SqlStatementTest.java +++ b/sql/src/test/java/org/apache/druid/sql/SqlStatementTest.java @@ -58,7 +58,6 @@ import org.apache.druid.sql.calcite.planner.PlannerFactory; import org.apache.druid.sql.calcite.planner.PrepareResult; import org.apache.druid.sql.calcite.schema.DruidSchemaCatalog; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.apache.druid.sql.calcite.util.QueryLogHook; import org.apache.druid.sql.http.SqlQuery; import org.easymock.EasyMock; import org.hamcrest.MatcherAssert; @@ -68,7 +67,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.ClassRule; -import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -92,8 +90,6 @@ public class SqlStatementTest private static Closer resourceCloser; @ClassRule public static TemporaryFolder temporaryFolder = new TemporaryFolder(); - @Rule - public QueryLogHook queryLogHook = QueryLogHook.create(); private TestRequestLogger testRequestLogger; private ListeningExecutorService executorService; private SqlStatementFactory sqlStatementFactory; diff --git a/sql/src/test/java/org/apache/druid/sql/avatica/DruidAvaticaHandlerTest.java b/sql/src/test/java/org/apache/druid/sql/avatica/DruidAvaticaHandlerTest.java index 282c70d5772..cccaab75b6f 100644 --- a/sql/src/test/java/org/apache/druid/sql/avatica/DruidAvaticaHandlerTest.java +++ b/sql/src/test/java/org/apache/druid/sql/avatica/DruidAvaticaHandlerTest.java @@ -88,24 +88,23 @@ import org.apache.druid.sql.calcite.schema.DruidSchemaName; import org.apache.druid.sql.calcite.schema.NamedSchema; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.apache.druid.sql.calcite.util.QueryLogHook; import org.apache.druid.sql.guice.SqlModule; import org.eclipse.jetty.server.Server; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; +import org.junit.jupiter.api.io.TempDir; import org.skife.jdbi.v2.DBI; import org.skife.jdbi.v2.Handle; import org.skife.jdbi.v2.ResultIterator; +import java.io.File; import java.io.IOException; import java.sql.Array; import java.sql.Connection; @@ -129,6 +128,7 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; /** * Tests the Avatica-based JDBC implementation using JSON serialization. See @@ -153,33 +153,27 @@ public class DruidAvaticaHandlerTest extends CalciteTestBase private static final String DUMMY_SQL_QUERY_ID = "dummy"; - @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); - private static QueryRunnerFactoryConglomerate conglomerate; private static SpecificSegmentsQuerySegmentWalker walker; private static Closer resourceCloser; private final boolean nullNumeric = !NullHandling.replaceWithDefault(); - @BeforeClass - public static void setUpClass() throws Exception + @BeforeAll + public static void setUpClass(@TempDir File tempDir) { resourceCloser = Closer.create(); conglomerate = QueryStackTests.createQueryRunnerFactoryConglomerate(resourceCloser); - walker = CalciteTests.createMockWalker(conglomerate, temporaryFolder.newFolder()); + walker = CalciteTests.createMockWalker(conglomerate, tempDir); resourceCloser.register(walker); } - @AfterClass + @AfterAll public static void tearDownClass() throws IOException { resourceCloser.close(); } - @Rule - public QueryLogHook queryLogHook = QueryLogHook.create(); - private final PlannerConfig plannerConfig = new PlannerConfig(); private final DruidOperatorTable operatorTable = CalciteTests.createOperatorTable(); private final ExprMacroTable macroTable = CalciteTests.createExprMacroTable(); @@ -266,7 +260,7 @@ public class DruidAvaticaHandlerTest extends CalciteTestBase ); } - @Before + @BeforeEach public void setUp() throws Exception { final DruidSchemaCatalog rootSchema = makeRootSchema(); @@ -328,7 +322,7 @@ public class DruidAvaticaHandlerTest extends CalciteTestBase clientLosAngeles = DriverManager.getConnection(server.url, propertiesLosAngeles); } - @After + @AfterEach public void tearDown() throws Exception { if (server != null) { @@ -858,49 +852,45 @@ public class DruidAvaticaHandlerTest extends CalciteTestBase ); } - @Test(timeout = 90_000L) + @Test + @Timeout(value = 90_000L, unit = TimeUnit.MILLISECONDS) public void testConcurrentQueries() { - queryLogHook.withSkippedLog( - v -> { - final List> futures = new ArrayList<>(); - final ListeningExecutorService exec = MoreExecutors.listeningDecorator( - Execs.multiThreaded(AVATICA_CONFIG.getMaxStatementsPerConnection(), "DruidAvaticaHandlerTest-%d") - ); - for (int i = 0; i < 2000; i++) { - final String query = StringUtils.format("SELECT COUNT(*) + %s AS ci FROM foo", i); - futures.add( - exec.submit(() -> { - try ( - final Statement statement = client.createStatement(); - final ResultSet resultSet = statement.executeQuery(query) - ) { - final List> rows = getRows(resultSet); - return ((Number) Iterables.getOnlyElement(rows).get("ci")).intValue(); - } - catch (SQLException e) { - throw new RuntimeException(e); - } - }) - ); - } - - final List integers; - try { - integers = Futures.allAsList(futures).get(); - } - catch (InterruptedException e) { - throw new RE(e); - } - catch (ExecutionException e) { - throw new RE(e); - } - for (int i = 0; i < 2000; i++) { - Assert.assertEquals(i + 6, (int) integers.get(i)); - } - exec.shutdown(); - } + final List> futures = new ArrayList<>(); + final ListeningExecutorService exec = MoreExecutors.listeningDecorator( + Execs.multiThreaded(AVATICA_CONFIG.getMaxStatementsPerConnection(), "DruidAvaticaHandlerTest-%d") ); + for (int i = 0; i < 2000; i++) { + final String query = StringUtils.format("SELECT COUNT(*) + %s AS ci FROM foo", i); + futures.add( + exec.submit(() -> { + try ( + final Statement statement = client.createStatement(); + final ResultSet resultSet = statement.executeQuery(query)) { + final List> rows = getRows(resultSet); + return ((Number) Iterables.getOnlyElement(rows).get("ci")).intValue(); + } + catch (SQLException e) { + throw new RuntimeException(e); + } + }) + ); + } + + final List integers; + try { + integers = Futures.allAsList(futures).get(); + } + catch (InterruptedException e) { + throw new RE(e); + } + catch (ExecutionException e) { + throw new RE(e); + } + for (int i = 0; i < 2000; i++) { + Assert.assertEquals(i + 6, (int) integers.get(i)); + } + exec.shutdown(); } @Test diff --git a/sql/src/test/java/org/apache/druid/sql/avatica/DruidStatementTest.java b/sql/src/test/java/org/apache/druid/sql/avatica/DruidStatementTest.java index c9dd67b5c7d..81cd1c69231 100644 --- a/sql/src/test/java/org/apache/druid/sql/avatica/DruidStatementTest.java +++ b/sql/src/test/java/org/apache/druid/sql/avatica/DruidStatementTest.java @@ -47,17 +47,15 @@ import org.apache.druid.sql.calcite.planner.PlannerFactory; import org.apache.druid.sql.calcite.schema.DruidSchemaCatalog; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.apache.druid.sql.calcite.util.QueryLogHook; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.List; @@ -73,26 +71,20 @@ public class DruidStatementTest extends CalciteTestBase private static String SELECT_STAR_FROM_FOO = "SELECT * FROM druid.foo"; - @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Rule - public QueryLogHook queryLogHook = QueryLogHook.create(); - private static SpecificSegmentsQuerySegmentWalker walker; private static QueryRunnerFactoryConglomerate conglomerate; private static Closer resourceCloser; - @BeforeClass - public static void setUpClass() throws Exception + @BeforeAll + public static void setUpClass(@TempDir File tempDir) { resourceCloser = Closer.create(); conglomerate = QueryStackTests.createQueryRunnerFactoryConglomerate(resourceCloser); - walker = CalciteTests.createMockWalker(conglomerate, temporaryFolder.newFolder()); + walker = CalciteTests.createMockWalker(conglomerate, tempDir); resourceCloser.register(walker); } - @AfterClass + @AfterAll public static void tearDownClass() throws IOException { resourceCloser.close(); @@ -100,7 +92,7 @@ public class DruidStatementTest extends CalciteTestBase private SqlStatementFactory sqlStatementFactory; - @Before + @BeforeEach public void setUp() { final PlannerConfig plannerConfig = new PlannerConfig(); @@ -128,7 +120,7 @@ public class DruidStatementTest extends CalciteTestBase ); } - @After + @AfterEach public void tearDown() { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java index 5463dbc5e68..d83a9da4c8d 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java @@ -26,9 +26,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import com.google.common.io.ByteStreams; import com.google.inject.Injector; import org.apache.commons.text.StringEscapeUtils; -import org.apache.druid.annotations.UsedByJUnitParamsRunner; import org.apache.druid.common.config.NullHandling; import org.apache.druid.error.DruidException; import org.apache.druid.error.DruidException.Category; @@ -38,6 +38,7 @@ import org.apache.druid.guice.DruidInjectorBuilder; import org.apache.druid.hll.VersionOneHyperLogLogCollector; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; +import org.apache.druid.java.util.common.RE; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.granularity.Granularity; import org.apache.druid.java.util.common.io.Closer; @@ -104,7 +105,6 @@ import org.apache.druid.sql.calcite.run.SqlEngine; import org.apache.druid.sql.calcite.schema.DruidSchemaManager; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.apache.druid.sql.calcite.util.QueryLogHook; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.Builder; import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; @@ -116,20 +116,21 @@ import org.apache.druid.sql.calcite.view.ViewManager; import org.apache.druid.sql.http.SqlParameter; import org.hamcrest.CoreMatchers; import org.hamcrest.Matcher; -import org.hamcrest.MatcherAssert; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Interval; import org.joda.time.chrono.ISOChronology; import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; import org.junit.internal.matchers.ThrowableMessageMatcher; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.extension.RegisterExtension; import javax.annotation.Nullable; + +import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -142,10 +143,11 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * A base class for SQL query testing. It sets up query execution environment, provides useful helper methods, @@ -160,7 +162,7 @@ public class BaseCalciteQueryTest extends CalciteTestBase public static Long NULL_LONG; public static final String HLLC_STRING = VersionOneHyperLogLogCollector.class.getName(); - @BeforeClass + @BeforeAll public static void setupNullValues() { NULL_STRING = NullHandling.defaultStringValue(); @@ -296,14 +298,9 @@ public class BaseCalciteQueryTest extends CalciteTestBase public final SqlEngine engine0; final boolean useDefault = NullHandling.replaceWithDefault(); - @Rule(order = 2) - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - public boolean cannotVectorize = false; public boolean skipVectorize = false; - public QueryLogHook queryLogHook; - private QueryComponentSupplier baseComponentSupplier; public PlannerComponentSupplier basePlannerComponentSupplier = new StandardPlannerComponentSupplier(); @@ -630,22 +627,8 @@ public class BaseCalciteQueryTest extends CalciteTestBase return DruidExceptionMatcher.invalidSqlInput().expectMessageContains(s); } - @Rule - public QueryLogHook getQueryLogHook() - { - // Indirection for the JSON mapper. Otherwise, this rule method is called - // before Setup is called, causing the query framework to be built before - // tests have done their setup. The indirection means we access the query - // framework only when we log the first query. By then, the query framework - // will have been created via the normal path. - return queryLogHook = new QueryLogHook(() -> queryFramework().queryJsonMapper()); - } - - @ClassRule - public static SqlTestFrameworkConfig.ClassRule queryFrameworkClassRule = new SqlTestFrameworkConfig.ClassRule(); - - @Rule(order = 3) - public SqlTestFrameworkConfig.MethodRule queryFrameworkRule = queryFrameworkClassRule.methodRule(this); + @RegisterExtension + static SqlTestFrameworkConfig.Rule queryFrameworkRule = new SqlTestFrameworkConfig.Rule(); public SqlTestFramework queryFramework() { @@ -657,7 +640,7 @@ public class BaseCalciteQueryTest extends CalciteTestBase final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { return baseComponentSupplier.createQuerySegmentWalker(conglomerate, joinableFactory, injector); } @@ -679,14 +662,7 @@ public class BaseCalciteQueryTest extends CalciteTestBase @Override public void gatherProperties(Properties properties) { - try { - baseComponentSupplier = new StandardComponentSupplier( - temporaryFolder.newFolder() - ); - } - catch (IOException e) { - throw new RuntimeException(e); - } + baseComponentSupplier = new StandardComponentSupplier(newTempFolder()); baseComponentSupplier.gatherProperties(properties); } @@ -753,7 +729,7 @@ public class BaseCalciteQueryTest extends CalciteTestBase public void assumeFeatureAvailable(EngineFeature feature) { boolean featureAvailable = queryFramework().engine().featureAvailable(feature); - assumeTrue(StringUtils.format("test disabled; feature [%s] is not available!", feature), featureAvailable); + assumeTrue(featureAvailable, StringUtils.format("test disabled; feature [%s] is not available!", feature)); } public void assertQueryIsUnplannable(final String sql, String expectedError) @@ -767,7 +743,7 @@ public class BaseCalciteQueryTest extends CalciteTestBase testQuery(plannerConfig, sql, CalciteTests.REGULAR_USER_AUTH_RESULT, ImmutableList.of(), ImmutableList.of()); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, buildUnplannableExceptionMatcher().expectMessageContains(expectedError) ); @@ -1013,12 +989,6 @@ public class BaseCalciteQueryTest extends CalciteTestBase ); } - @Override - public QueryLogHook queryLogHook() - { - return queryLogHook; - } - @Override public PlannerFixture plannerFixture(PlannerConfig plannerConfig, AuthConfig authConfig) { @@ -1255,7 +1225,7 @@ public class BaseCalciteQueryTest extends CalciteTestBase .build() .run() ); - MatcherAssert.assertThat(e, exceptionMatcher); + assertThat(e, exceptionMatcher); } public void analyzeResources( @@ -1339,7 +1309,7 @@ public class BaseCalciteQueryTest extends CalciteTestBase protected void msqIncompatible() { - assumeFalse("test case is not MSQ compatible", testBuilder().config.isRunningMSQ()); + assumeFalse(testBuilder().config.isRunningMSQ(), "test case is not MSQ compatible"); } protected static boolean isRewriteJoinToFilter(final Map queryContext) @@ -1392,59 +1362,56 @@ public class BaseCalciteQueryTest extends CalciteTestBase * It tests various configs that can be passed to join queries. All the configs provided by this provider should * have the join query engine return the same results. */ - public static class QueryContextForJoinProvider + public static Object[] provideQueryContexts() { - @UsedByJUnitParamsRunner - public static Object[] provideQueryContexts() - { - return new Object[]{ - // default behavior - QUERY_CONTEXT_DEFAULT, - // all rewrites enabled - new ImmutableMap.Builder() - .putAll(QUERY_CONTEXT_DEFAULT) - .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) - .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) - .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build(), - // filter-on-value-column rewrites disabled, everything else enabled - new ImmutableMap.Builder() - .putAll(QUERY_CONTEXT_DEFAULT) - .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) - .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) - .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build(), - // filter rewrites fully disabled, join-to-filter enabled - new ImmutableMap.Builder() - .putAll(QUERY_CONTEXT_DEFAULT) - .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) - .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) - .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build(), - // filter rewrites disabled, but value column filters still set to true (it should be ignored and this should - // behave the same as the previous context) - new ImmutableMap.Builder() - .putAll(QUERY_CONTEXT_DEFAULT) - .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) - .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) - .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) - .build(), - // filter rewrites fully enabled, join-to-filter disabled - new ImmutableMap.Builder() - .putAll(QUERY_CONTEXT_DEFAULT) - .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) - .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) - .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, false) - .build(), - // all rewrites disabled - new ImmutableMap.Builder() - .putAll(QUERY_CONTEXT_DEFAULT) - .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) - .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) - .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, false) - .build(), - }; - } + return new Object[] { + // default behavior + QUERY_CONTEXT_DEFAULT, + // all rewrites enabled + new ImmutableMap.Builder() + .putAll(QUERY_CONTEXT_DEFAULT) + .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) + .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) + .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) + .build(), + // filter-on-value-column rewrites disabled, everything else enabled + new ImmutableMap.Builder() + .putAll(QUERY_CONTEXT_DEFAULT) + .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) + .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) + .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) + .build(), + // filter rewrites fully disabled, join-to-filter enabled + new ImmutableMap.Builder() + .putAll(QUERY_CONTEXT_DEFAULT) + .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) + .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) + .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) + .build(), + // filter rewrites disabled, but value column filters still set to true + // (it should be ignored and this should + // behave the same as the previous context) + new ImmutableMap.Builder() + .putAll(QUERY_CONTEXT_DEFAULT) + .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) + .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) + .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, true) + .build(), + // filter rewrites fully enabled, join-to-filter disabled + new ImmutableMap.Builder() + .putAll(QUERY_CONTEXT_DEFAULT) + .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, true) + .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, true) + .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, false) + .build(), + // all rewrites disabled + new ImmutableMap.Builder() + .putAll(QUERY_CONTEXT_DEFAULT) + .put(QueryContexts.JOIN_FILTER_REWRITE_VALUE_COLUMN_FILTERS_ENABLE_KEY, false) + .put(QueryContexts.JOIN_FILTER_REWRITE_ENABLE_KEY, false) + .put(QueryContexts.REWRITE_JOIN_TO_FILTER_ENABLE_KEY, false) + .build(), + }; } protected Map withLeftDirectAccessEnabled(Map context) @@ -1628,4 +1595,25 @@ public class BaseCalciteQueryTest extends CalciteTestBase sb.append(post); } } + + /** + * Helper method that copies a resource to a temporary file, then returns it. + */ + public File getResourceAsTemporaryFile(final String resource) + { + final File file = newTempFile("resourceAsTempFile"); + final InputStream stream = getClass().getResourceAsStream(resource); + + if (stream == null) { + throw new RE(StringUtils.format("No such resource [%s]", resource)); + } + + try { + ByteStreams.copy(stream, Files.newOutputStream(file.toPath())); + } + catch (IOException e) { + throw new RuntimeException(e); + } + return file; + } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteArraysQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteArraysQueryTest.java index 67c04a9cf91..d7b0a1d45ee 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteArraysQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteArraysQueryTest.java @@ -71,7 +71,7 @@ import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.util.CalciteTests; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteCorrelatedQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteCorrelatedQueryTest.java index a7a5222d888..e0d71b6cfba 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteCorrelatedQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteCorrelatedQueryTest.java @@ -20,8 +20,6 @@ package org.apache.druid.sql.calcite; import com.google.common.collect.ImmutableList; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.AllGranularity; import org.apache.druid.java.util.common.granularity.Granularities; @@ -45,18 +43,16 @@ import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.join.JoinType; import org.apache.druid.segment.virtual.ExpressionVirtualColumn; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.junit.Test; -import org.junit.runner.RunWith; - +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; import java.util.Collections; import java.util.Map; -@RunWith(JUnitParamsRunner.class) public class CalciteCorrelatedQueryTest extends BaseCalciteQueryTest { - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testCorrelatedSubquery(Map queryContext) { cannotVectorize(); @@ -172,8 +168,8 @@ public class CalciteCorrelatedQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testCorrelatedSubqueryWithLeftFilter(Map queryContext) { cannotVectorize(); @@ -261,8 +257,8 @@ public class CalciteCorrelatedQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testCorrelatedSubqueryWithLeftFilter_leftDirectAccessDisabled(Map queryContext) { cannotVectorize(); @@ -356,8 +352,8 @@ public class CalciteCorrelatedQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testCorrelatedSubqueryWithCorrelatedQueryFilter(Map queryContext) { cannotVectorize(); @@ -450,8 +446,8 @@ public class CalciteCorrelatedQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testCorrelatedSubqueryWithCorrelatedQueryFilter_Scan(Map queryContext) { cannotVectorize(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteExplainQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteExplainQueryTest.java index 90167704485..3d7c820902b 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteExplainQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteExplainQueryTest.java @@ -23,7 +23,7 @@ import com.google.common.collect.ImmutableList; import org.apache.druid.common.config.NullHandling; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteExportTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteExportTest.java index 4a97367fcd1..eaf6af9e77b 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteExportTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteExportTest.java @@ -44,9 +44,9 @@ import org.apache.druid.storage.StorageConnector; import org.apache.druid.storage.local.LocalFileExportStorageProvider; import org.apache.druid.storage.local.LocalFileStorageConnectorProvider; import org.hamcrest.CoreMatchers; -import org.junit.Ignore; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.List; @@ -80,7 +80,7 @@ public class CalciteExportTest extends CalciteIngestionDmlTest // Disabled until replace supports external destinations. To be enabled after that point. @Test - @Ignore + @Disabled public void testReplaceIntoExtern() { testIngestionQuery() @@ -207,7 +207,7 @@ public class CalciteExportTest extends CalciteIngestionDmlTest // Disabled until replace supports external destinations. To be enabled after that point. @Test - @Ignore + @Disabled public void testReplaceIntoExternParameterized() { testIngestionQuery() diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteIngestionDmlTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteIngestionDmlTest.java index 071c8ae04d3..29c375b0269 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteIngestionDmlTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteIngestionDmlTest.java @@ -65,10 +65,9 @@ import org.apache.druid.sql.guice.SqlBindings; import org.apache.druid.sql.http.SqlParameter; import org.hamcrest.CoreMatchers; import org.hamcrest.Matcher; -import org.hamcrest.MatcherAssert; -import org.junit.After; import org.junit.Assert; import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.AfterEach; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -82,6 +81,8 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Stream; +import static org.hamcrest.MatcherAssert.assertThat; + public class CalciteIngestionDmlTest extends BaseCalciteQueryTest { protected static final Map DEFAULT_CONTEXT = @@ -181,7 +182,7 @@ public class CalciteIngestionDmlTest extends BaseCalciteQueryTest }); } - @After + @AfterEach public void tearDown() { // Catch situations where tests forgot to call "verify" on their tester. @@ -378,7 +379,6 @@ public class CalciteIngestionDmlTest extends BaseCalciteQueryTest throw new ISE("Test must not have expectedQuery"); } - queryLogHook.clearRecordedQueries(); final Throwable e = Assert.assertThrows( Throwable.class, () -> { @@ -386,8 +386,7 @@ public class CalciteIngestionDmlTest extends BaseCalciteQueryTest } ); - MatcherAssert.assertThat(e, validationErrorMatcher); - Assert.assertTrue(queryLogHook.getRecordedQueries().isEmpty()); + assertThat(e, validationErrorMatcher); } private void verifySuccess() diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java index e089b2a9082..b420c435737 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteInsertDmlTest.java @@ -52,10 +52,9 @@ import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.util.CalciteTests; import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; import org.junit.Assert; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; @@ -69,6 +68,7 @@ import static org.apache.druid.segment.column.ColumnType.DOUBLE; import static org.apache.druid.segment.column.ColumnType.FLOAT; import static org.apache.druid.segment.column.ColumnType.LONG; import static org.apache.druid.segment.column.ColumnType.STRING; +import static org.hamcrest.MatcherAssert.assertThat; public class CalciteInsertDmlTest extends CalciteIngestionDmlTest { @@ -1197,7 +1197,7 @@ public class CalciteInsertDmlTest extends CalciteIngestionDmlTest Assert.fail("Exception should be thrown"); } catch (DruidException e) { - MatcherAssert.assertThat(e, invalidSqlIs( + assertThat(e, invalidSqlIs( "Cannot use an ORDER BY clause on a Query of type [INSERT], use CLUSTERED BY instead" )); } @@ -1216,7 +1216,7 @@ public class CalciteInsertDmlTest extends CalciteIngestionDmlTest Assert.fail("Exception should be thrown"); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs( "Invalid granularity['invalid_granularity'] specified after PARTITIONED BY clause." @@ -1243,7 +1243,7 @@ public class CalciteInsertDmlTest extends CalciteIngestionDmlTest Assert.fail("Exception should be thrown"); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs("Cannot use an ORDER BY clause on a Query of type [INSERT], use CLUSTERED BY instead") ); @@ -1266,7 +1266,7 @@ public class CalciteInsertDmlTest extends CalciteIngestionDmlTest ) ); - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs("Operation [INSERT] requires a PARTITIONED BY to be explicitly defined, but none was found.") ); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java index 9b683cc0388..04727d7f86a 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteJoinQueryTest.java @@ -22,8 +22,6 @@ package org.apache.druid.sql.calcite; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; import org.apache.druid.common.config.NullHandling; import org.apache.druid.error.DruidException; import org.apache.druid.error.DruidExceptionMatcher; @@ -72,6 +70,7 @@ import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.query.groupby.orderby.DefaultLimitSpec; import org.apache.druid.query.groupby.orderby.NoopLimitSpec; import org.apache.druid.query.groupby.orderby.OrderByColumnSpec; +import org.apache.druid.query.groupby.orderby.OrderByColumnSpec.Direction; import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.query.scan.ScanQuery; import org.apache.druid.query.timeboundary.TimeBoundaryQuery; @@ -90,15 +89,16 @@ import org.apache.druid.sql.calcite.NotYetSupported.Modes; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.planner.PlannerConfig; +import org.apache.druid.sql.calcite.run.EngineFeature; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.hamcrest.MatcherAssert; import org.joda.time.DateTimeZone; import org.joda.time.Period; import org.junit.Assert; -import org.junit.Assume; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.ArrayList; import java.util.Collections; @@ -106,25 +106,19 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -@RunWith(JUnitParamsRunner.class) +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class CalciteJoinQueryTest extends BaseCalciteQueryTest { /** - * Used for testing {@link org.apache.druid.sql.calcite.planner.JoinAlgorithm#SORT_MERGE}. + * Used by MSQ subclasses. + * + * Necessary because results come in a different order when using sort-based join. */ - private final boolean sortBasedJoin; - - public CalciteJoinQueryTest() + public boolean isSortBasedJoin() { - this(false); - } - - /** - * Constructor used by MSQ subclasses. Necessary because results come in a different order when using sort-based join. - */ - protected CalciteJoinQueryTest(boolean sortBasedJoin) - { - this.sortBasedJoin = sortBasedJoin; + return false; } @SqlTestFrameworkConfig(minTopNThreshold = 1) @@ -325,8 +319,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") @NotYetSupported(Modes.JOIN_TABLE_TABLE) public void testJoinOuterGroupByAndSubqueryNoLimit(Map queryContext) { @@ -686,8 +680,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") @NotYetSupported(Modes.CANNOT_JOIN_LOOKUP_NON_KEY) public void testFilterAndGroupByLookupUsingJoinOperatorWithValueFilterPushdownMatchesNothing(Map queryContext) @@ -724,8 +718,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testFilterAndGroupByLookupUsingJoinOperatorAllowNulls(Map queryContext) { // Cannot vectorize JOIN operator. @@ -768,8 +762,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) public void testFilterAndGroupByLookupUsingJoinOperatorBackwards(Map queryContext) { @@ -824,9 +818,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testFilterAndGroupByLookupUsingJoinOperatorWithNotFilter(Map queryContext) { @@ -870,8 +864,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest } @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testJoinUnionTablesOnLookup(Map queryContext) { // MSQ does not support UNION ALL. @@ -922,9 +916,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.CANNOT_JOIN_LOOKUP_NON_KEY) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testFilterAndGroupByLookupUsingJoinOperator(Map queryContext) { // Cannot vectorize JOIN operator. @@ -961,8 +955,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testFilterAndGroupByLookupUsingPostAggregationJoinOperator(Map queryContext) { @@ -1018,8 +1012,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testGroupByInnerJoinOnLookupUsingJoinOperator(Map queryContext) { // Cannot vectorize JOIN operator. @@ -1054,8 +1048,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testSelectOnLookupUsingInnerJoinOperator(Map queryContext) { testQuery( @@ -1086,8 +1080,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinTwoLookupsUsingJoinOperator(Map queryContext) { testQuery( @@ -1132,9 +1126,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_UNSUPORTED_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinTableLookupLookupWithFilterWithOuterLimit(Map queryContext) { testQuery( @@ -1176,9 +1170,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_UNSUPORTED_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinTableLookupLookupWithFilterWithoutLimit(Map queryContext) { testQuery( @@ -1218,9 +1212,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_UNSUPORTED_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinTableLookupLookupWithFilterWithOuterLimitWithAllColumns(Map queryContext) { @@ -1263,9 +1257,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_UNSUPORTED_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinTableLookupLookupWithFilterWithoutLimitWithAllColumns(Map queryContext) { testQuery( @@ -1305,9 +1299,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_UNSUPORTED_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testManyManyInnerJoinOnManyManyLookup(Map queryContext) { testQuery( @@ -1535,9 +1529,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.FINALIZING_FIELD_ACCESS) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinQueryOfLookup(Map queryContext) { // Cannot vectorize the subquery. @@ -1588,8 +1582,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testTimeColumnAggregationsOnLookups(Map queryContext) { try { @@ -1602,7 +1596,7 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest Assert.fail("Expected exception to be thrown."); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, new DruidExceptionMatcher(DruidException.Persona.ADMIN, DruidException.Category.INVALID_INPUT, "general") .expectMessageIs( @@ -1615,9 +1609,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest } } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinQueryOfLookupRemovable(Map queryContext) { // Like "testInnerJoinQueryOfLookup", but the subquery is removable. @@ -1654,9 +1648,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinTwoLookupsToTableUsingNumericColumn(Map queryContext) { // Regression test for https://github.com/apache/druid/issues/9646. @@ -1716,9 +1710,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_TABLE_TABLE) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinTwoLookupsToTableUsingNumericColumnInReverse(Map queryContext) { @@ -1774,9 +1768,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_TABLE_TABLE) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinLookupTableTable(Map queryContext) { // Regression test for https://github.com/apache/druid/issues/9646. @@ -1857,9 +1851,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_TABLE_TABLE) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinLookupTableTableChained(Map queryContext) { // Cannot vectorize JOIN operator. @@ -2019,9 +2013,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest // This SQL currently does not result in an optimum plan. // Unfortunately, we have disabled pushing down predicates (conditions and filters) due to https://github.com/apache/druid/pull/9773 // Hence, comma join will result in a cross join with filter on outermost - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_UNSUPORTED_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testCommaJoinTableLookupTableMismatchedTypes(Map queryContext) { // Regression test for https://github.com/apache/druid/issues/9646. @@ -2086,9 +2080,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_TABLE_TABLE) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testJoinTableLookupTableMismatchedTypesWithoutComma(Map queryContext) { // Empty-dataset aggregation queries in MSQ return an empty row, rather than a single row as SQL requires. @@ -2157,9 +2151,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinCastLeft(Map queryContext) { // foo.m1 is FLOAT, l.k is STRING. @@ -2192,8 +2186,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinCastRight(Map queryContext) { // foo.m1 is FLOAT, l.k is STRING. @@ -2239,8 +2233,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinMismatchedTypes(Map queryContext) { // foo.m1 is FLOAT, l.k is STRING. Comparing them generates a CAST. @@ -2286,9 +2280,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinLeftFunction(Map queryContext) { testQuery( @@ -2323,8 +2317,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinRightFunction(Map queryContext) { testQuery( @@ -2366,8 +2360,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinLookupOntoLookupUsingJoinOperator(Map queryContext) { testQuery( @@ -2412,8 +2406,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinThreeLookupsUsingJoinOperator(Map queryContext) { testQuery( @@ -2466,8 +2460,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testSelectOnLookupUsingLeftJoinOperator(Map queryContext) { testQuery( @@ -2511,8 +2505,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testSelectOnLookupUsingRightJoinOperator(Map queryContext) { // MSQ refuses to do RIGHT join with broadcast. @@ -2554,8 +2548,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testSelectOnLookupUsingFullJoinOperator(Map queryContext) { // MSQ refuses to do FULL join with broadcast. @@ -2603,8 +2597,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInAggregationSubquery(Map queryContext) { // Fully removing the join allows this query to vectorize. @@ -2653,8 +2647,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testNotInAggregationSubquery(Map queryContext) { // Cannot vectorize JOIN operator. @@ -2739,9 +2733,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_FILTER_LOCATIONS) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testUsingSubqueryWithExtractionFns(Map queryContext) { // Cannot vectorize JOIN operator. @@ -2800,9 +2794,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinWithIsNullFilter(Map queryContext) { testQuery( @@ -2833,9 +2827,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) - @Ignore // regression test for https://github.com/apache/druid/issues/9924 + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") + @Disabled // regression test for https://github.com/apache/druid/issues/9924 public void testInnerJoinOnMultiValueColumn(Map queryContext) { cannotVectorize(); @@ -2874,8 +2868,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSourcesWithTimeFilter(Map queryContext) { testQuery( @@ -2943,9 +2937,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSourcesWithTimeFilter_withLeftDirectAccess(Map queryContext) { queryContext = withLeftDirectAccessEnabled(queryContext); @@ -3002,8 +2996,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSourcesWithOuterWhere(Map queryContext) { testQuery( @@ -3055,9 +3049,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess(Map queryContext) { queryContext = withLeftDirectAccessEnabled(queryContext); @@ -3104,8 +3098,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSources(Map queryContext) { testQuery( @@ -3157,9 +3151,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinOnTwoInlineDataSources_withLeftDirectAccess(Map queryContext) { queryContext = withLeftDirectAccessEnabled(queryContext); @@ -3206,8 +3200,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinOnTwoInlineDataSourcesWithOuterWhere(Map queryContext) { Druids.ScanQueryBuilder baseScanBuilder = newScanQueryBuilder() @@ -3259,9 +3253,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinOnTwoInlineDataSourcesWithOuterWhere_withLeftDirectAccess(Map queryContext) { queryContext = withLeftDirectAccessEnabled(queryContext); @@ -3308,8 +3302,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinOnTwoInlineDataSources(Map queryContext) { testQuery( @@ -3361,9 +3355,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testGroupByOverGroupByOverInnerJoinOnTwoInlineDataSources(Map queryContext) { skipVectorize(); @@ -3447,9 +3441,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.JOIN_LEFT_DIRECT_ACCESS) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinOnTwoInlineDataSources_withLeftDirectAccess(Map queryContext) { queryContext = withLeftDirectAccessEnabled(queryContext); @@ -3499,8 +3493,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest // This query is expected to fail as we do not support join with constant in the on condition // (see issue https://github.com/apache/druid/issues/9942 for more information) // TODO: Remove expected Exception when https://github.com/apache/druid/issues/9942 is fixed - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") + @SuppressWarnings("unchecked") public void testJoinOnConstantShouldFail(Map queryContext) { assertQueryIsUnplannable( @@ -3589,13 +3584,13 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinSubqueryWithNullKeyFilter(Map queryContext) { // JoinFilterAnalyzer bug causes incorrect results on this test in replace-with-default mode. // This test case was originally added in https://github.com/apache/druid/pull/11434 with a note about this. - Assume.assumeFalse(NullHandling.replaceWithDefault() && QueryContext.of(queryContext).getEnableJoinFilterRewrite()); + Assumptions.assumeFalse(NullHandling.replaceWithDefault() && QueryContext.of(queryContext).getEnableJoinFilterRewrite()); // Cannot vectorize due to 'concat' expression. cannotVectorize(); @@ -3676,9 +3671,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinSubqueryWithSelectorFilter(Map queryContext) { // Cannot vectorize due to 'concat' expression. @@ -3730,9 +3725,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_TABLE_TABLE) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testLeftJoinWithNotNullFilter(Map queryContext) { testQuery( @@ -3778,9 +3773,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_TABLE_TABLE) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoin(Map queryContext) { testQuery( @@ -3833,9 +3828,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_TABLE_TABLE) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testJoinWithExplicitIsNotDistinctFromCondition(Map queryContext) { // Like "testInnerJoin", but uses IS NOT DISTINCT FROM instead of equals. @@ -3879,12 +3874,12 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinSubqueryWithSelectorFilter(Map queryContext) { - if (sortBasedJoin) { + if (isSortBasedJoin()) { // Cannot handle the [l1.k = 'abc'] condition. msqIncompatible(); } @@ -3988,9 +3983,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testTwoSemiJoinsSimultaneously(Map queryContext) { // Fully removing the join allows this query to vectorize. @@ -4054,8 +4049,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testSemiAndAntiJoinSimultaneouslyUsingWhereInSubquery(Map queryContext) { cannotVectorize(); @@ -4160,9 +4155,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testSemiAndAntiJoinSimultaneouslyUsingExplicitJoins(Map queryContext) { cannotVectorize(); @@ -4293,7 +4288,20 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ) ) ) - .setLimitSpec(NoopLimitSpec.instance()) + .setLimitSpec( + queryFramework().engine().featureAvailable(EngineFeature.GROUPBY_IMPLICITLY_SORTS) + ? NoopLimitSpec.instance() + : new DefaultLimitSpec( + ImmutableList.of( + new OrderByColumnSpec( + "d0", + Direction.ASCENDING, + StringComparators.NUMERIC + ) + ), + Integer.MAX_VALUE + ) + ) .setContext(QUERY_CONTEXT_DEFAULT) .build() ), @@ -4306,26 +4314,28 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest // This query is expected to fail as we do not support join on multi valued column // (see issue https://github.com/apache/druid/issues/9924 for more information) // TODO: Remove expected Exception when https://github.com/apache/druid/issues/9924 is fixed - @Test(expected = QueryException.class) - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testJoinOnMultiValuedColumnShouldThrowException(Map queryContext) { // MSQ throws a slightly different error than QueryException. msqIncompatible(); - final String query = "SELECT dim3, l.v from druid.foo f inner join lookup.lookyloo l on f.dim3 = l.k\n"; + assertThrows(QueryException.class, () -> { + final String query = "SELECT dim3, l.v from druid.foo f inner join lookup.lookyloo l on f.dim3 = l.k\n"; - testQuery( - query, - queryContext, - ImmutableList.of(), - ImmutableList.of() - ); + testQuery( + query, + queryContext, + ImmutableList.of(), + ImmutableList.of() + ); + }); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.UNION_WITH_COMPLEX_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testUnionAllTwoQueriesLeftQueryIsJoin(Map queryContext) { // MSQ does not support UNION ALL. @@ -4368,9 +4378,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.UNION_WITH_COMPLEX_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testUnionAllTwoQueriesRightQueryIsJoin(Map queryContext) { // MSQ does not support UNION ALL. @@ -4462,8 +4472,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testTopNFilterJoin(Map queryContext) { // Fully removing the join allows this query to vectorize. @@ -4527,8 +4537,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testTopNFilterJoinWithProjection(Map queryContext) { // Cannot vectorize JOIN operator. @@ -4598,9 +4608,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) - @Ignore("Stopped working after the ability to join on subqueries was added to DruidJoinRule") + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") + @Disabled("Stopped working after the ability to join on subqueries was added to DruidJoinRule") public void testRemovableLeftJoin(Map queryContext) { // LEFT JOIN where the right-hand side can be ignored. @@ -4642,8 +4652,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testCountDistinctOfLookupUsingJoinOperator(Map queryContext) { // Cannot yet vectorize the JOIN operator. @@ -4684,9 +4694,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testJoinWithNonEquiCondition(Map queryContext) { // Native JOIN operator cannot handle the condition, so a SQL JOIN with greater-than is translated into a @@ -4694,7 +4704,7 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest cannotVectorize(); // We don't handle non-equi join conditions for non-sql compatible mode. - Assume.assumeFalse(NullHandling.replaceWithDefault()); + Assumptions.assumeFalse(NullHandling.replaceWithDefault()); testQuery( "SELECT x.m1, y.m1 FROM foo x INNER JOIN foo y ON x.m1 > y.m1", @@ -4747,9 +4757,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_UNSUPORTED_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testJoinWithEquiAndNonEquiCondition(Map queryContext) { // Native JOIN operator cannot handle the condition, so a SQL JOIN with greater-than is translated into a @@ -4757,7 +4767,7 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest cannotVectorize(); // We don't handle non-equi join conditions for non-sql compatible mode. - Assume.assumeFalse(NullHandling.replaceWithDefault()); + Assumptions.assumeFalse(NullHandling.replaceWithDefault()); testQuery( "SELECT x.m1, y.m1 FROM foo x INNER JOIN foo y ON x.m1 = y.m1 AND x.m1 + y.m1 = 6.0", @@ -4793,9 +4803,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testUsingSubqueryAsPartOfAndFilter(Map queryContext) { // Fully removing the join allows this query to vectorize. @@ -4863,8 +4873,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testUsingSubqueryAsPartOfOrFilter(Map queryContext) { // Cannot vectorize JOIN operator. @@ -4953,9 +4963,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_UNSUPORTED_OPERAND) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testNestedGroupByOnInlineDataSourceWithFilter(Map queryContext) { // Cannot vectorize due to virtual columns. @@ -5031,8 +5041,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testGroupByJoinAsNativeQueryWithUnoptimizedFilter(Map queryContext) { // The query below is the same as the inner groupBy on a join datasource from the test @@ -5105,8 +5115,8 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testCountOnSemiJoinSingleColumn(Map queryContext) { testQuery( @@ -5146,9 +5156,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testTopNOnStringWithNonSortedOrUniqueDictionary(Map queryContext) { testQuery( @@ -5187,9 +5197,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.EQUIV_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testTopNOnStringWithNonSortedOrUniqueDictionaryOrderByDim(Map queryContext) { @@ -5228,9 +5238,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.SLIGHTLY_WORSE_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testVirtualColumnOnMVFilterJoinExpression(Map queryContext) { // Doesn't work in MSQ, although it's not really MSQ's fault. In MSQ, the second field (foo2.dim3) is returned as @@ -5285,9 +5295,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @DecoupledTestConfig(nativeQueryIgnore = NativeQueryIgnore.DEFINETLY_WORSE_PLAN) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testVirtualColumnOnMVFilterMultiJoinExpression(Map queryContext) { // Doesn't work in MSQ, although it's not really MSQ's fault. In MSQ, the second field (foo2.dim3) is returned as @@ -5365,9 +5375,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinWithFilterPushdownAndManyFiltersEmptyResults(Map queryContext) { // create the query we expect @@ -5473,9 +5483,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.JOIN_CONDITION_NOT_PUSHED_CONDITION) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testInnerJoinWithFilterPushdownAndManyFiltersNonEmptyResults(Map queryContext) { // create the query we expect @@ -5641,9 +5651,9 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest ); } - @Test - @Parameters(source = QueryContextForJoinProvider.class) @NotYetSupported(Modes.SORT_REMOVE_TROUBLE) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") public void testRegressionFilteredAggregatorsSubqueryJoins(Map queryContext) { cannotVectorize(); @@ -5897,7 +5907,7 @@ public class CalciteJoinQueryTest extends BaseCalciteQueryTest @SuppressWarnings({"unchecked", "rawtypes"}) private List sortIfSortBased(final List results, final int... keyColumns) { - if (sortBasedJoin) { + if (isSortBasedJoin()) { final List retVal = new ArrayList<>(results); retVal.sort( (a, b) -> { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteLookupFunctionQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteLookupFunctionQueryTest.java index 5ef6c7ab912..fb9f0c42bdd 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteLookupFunctionQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteLookupFunctionQueryTest.java @@ -54,10 +54,9 @@ import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.rule.ReverseLookupRule; import org.apache.druid.sql.calcite.util.CalciteTests; import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; import org.junit.Assert; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Test; import javax.annotation.Nullable; import java.util.Arrays; @@ -65,6 +64,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; + public class CalciteLookupFunctionQueryTest extends BaseCalciteQueryTest { private static final Map QUERY_CONTEXT = @@ -1584,7 +1585,7 @@ public class CalciteLookupFunctionQueryTest extends BaseCalciteQueryTest ) ); - MatcherAssert.assertThat( + assertThat( e, ThrowableMessageMatcher.hasMessage(CoreMatchers.startsWith("Too many optimize calls[2]")) ); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteMultiValueStringQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteMultiValueStringQueryTest.java index c118d83c13a..7a319dba3b0 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteMultiValueStringQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteMultiValueStringQueryTest.java @@ -50,8 +50,8 @@ import org.apache.druid.segment.virtual.ListFilteredVirtualColumn; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.util.CalciteTests; import org.hamcrest.CoreMatchers; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java index ac3ac5c1e6b..98a547b9239 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteNestedDataQueryTest.java @@ -75,10 +75,9 @@ import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; import org.hamcrest.CoreMatchers; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Test; -import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -190,12 +189,12 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest final QueryRunnerFactoryConglomerate conglomerate, final JoinableFactoryWrapper joinableFactory, final Injector injector - ) throws IOException + ) { NestedDataModule.registerHandlersAndSerde(); final QueryableIndex index = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() @@ -211,7 +210,7 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest final QueryableIndex indexMix11 = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() @@ -228,7 +227,7 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest final QueryableIndex indexMix12 = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() @@ -244,7 +243,7 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest final QueryableIndex indexMix21 = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() @@ -260,7 +259,7 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest final QueryableIndex indexMix22 = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() @@ -276,7 +275,7 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest final QueryableIndex indexArrays = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() @@ -295,12 +294,12 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest ) ) .inputFormat(TestDataBuilder.DEFAULT_JSON_INPUT_FORMAT) - .inputTmpDir(temporaryFolder.newFolder()) + .inputTmpDir(newTempFolder()) .buildMMappedIndex(); final QueryableIndex indexAllTypesAuto = IndexBuilder.create() - .tmpDir(temporaryFolder.newFolder()) + .tmpDir(newTempFolder()) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) .schema( new IncrementalIndexSchema.Builder() @@ -319,7 +318,7 @@ public class CalciteNestedDataQueryTest extends BaseCalciteQueryTest ) ) .inputFormat(TestDataBuilder.DEFAULT_JSON_INPUT_FORMAT) - .inputTmpDir(temporaryFolder.newFolder()) + .inputTmpDir(newTempFolder()) .buildMMappedIndex(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteParameterQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteParameterQueryTest.java index 5b4c9cd17b4..3f5f73bb98a 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteParameterQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteParameterQueryTest.java @@ -42,7 +42,7 @@ import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.http.SqlParameter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java index 2b75cd226ae..a48ce3df6b4 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java @@ -123,16 +123,15 @@ import org.apache.druid.sql.calcite.run.EngineFeature; import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Interval; import org.joda.time.Period; import org.junit.Assert; -import org.junit.Assume; -import org.junit.Ignore; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Arrays; @@ -143,10 +142,10 @@ import java.util.Map; import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertThrows; -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.junit.jupiter.api.Assumptions.assumeTrue; public class CalciteQueryTest extends BaseCalciteQueryTest { @@ -352,7 +351,7 @@ public class CalciteQueryTest extends BaseCalciteQueryTest ) ); - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs("INSERT operations are not supported by requested SQL engine [native], consider using MSQ.") ); @@ -371,7 +370,7 @@ public class CalciteQueryTest extends BaseCalciteQueryTest ) ); - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs("REPLACE operations are not supported by the requested SQL engine [native]. Consider using MSQ.") ); @@ -2183,7 +2182,7 @@ public class CalciteQueryTest extends BaseCalciteQueryTest } @Test - @Ignore("Disabled since GROUP BY alias can confuse the validator; see DruidConformance::isGroupByAlias") + @Disabled("Disabled since GROUP BY alias can confuse the validator; see DruidConformance::isGroupByAlias") public void testGroupByAndOrderByAlias() { msqIncompatible(); @@ -5791,7 +5790,7 @@ public class CalciteQueryTest extends BaseCalciteQueryTest { msqIncompatible(); - Assume.assumeFalse(NullHandling.sqlCompatible()); + Assumptions.assumeFalse(NullHandling.sqlCompatible()); assertQueryIsUnplannable( // JOIN condition with not-equals (<>). @@ -6307,7 +6306,7 @@ public class CalciteQueryTest extends BaseCalciteQueryTest testBuilder().sql(sql).run(); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs("Illegal TIMESTAMP constant [CAST('z2000-01-01 00:00:00'):TIMESTAMP(3) NOT NULL]") ); @@ -7609,8 +7608,8 @@ public class CalciteQueryTest extends BaseCalciteQueryTest public void testQueryWithMoreThanMaxNumericInFilter() { assumeFalse( - "skip in sql compatible mode, this plans to an OR filter with equality filter children", - NullHandling.sqlCompatible() + NullHandling.sqlCompatible(), + "skip in sql compatible mode, this plans to an OR filter with equality filter children" ); msqIncompatible(); @@ -11419,7 +11418,7 @@ public class CalciteQueryTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs( "Invalid number of arguments to function 'TIME_EXTRACT'. Was expecting 2 arguments (line [1], column [8])" @@ -11613,7 +11612,7 @@ public class CalciteQueryTest extends BaseCalciteQueryTest } @Test - @Ignore("In Calcite 1.17, this test worked, but after upgrading to Calcite 1.21, this query fails with:" + @Disabled("In Calcite 1.17, this test worked, but after upgrading to Calcite 1.21, this query fails with:" + " org.apache.calcite.sql.validate.SqlValidatorException: Column 'dim1' is ambiguous") public void testProjectAfterSort3() { @@ -12431,7 +12430,6 @@ public class CalciteQueryTest extends BaseCalciteQueryTest { msqIncompatible(); Throwable exception = assertThrows(CannotBuildQueryException.class, () -> { - testQuery( PLANNER_CONFIG_REQUIRE_TIME_CONDITION, "SELECT COUNT(*) FROM druid.foo\n" @@ -13989,14 +13987,16 @@ public class CalciteQueryTest extends BaseCalciteQueryTest ); } - @Test(expected = DruidException.class) + @Test public void testStringAggExpressionNonConstantSeparator() { - testQuery( - "SELECT STRING_AGG(DISTINCT CONCAT(dim1, dim2), CONCAT('|', dim1)) FROM foo", - ImmutableList.of(), - ImmutableList.of() - ); + assertThrows(DruidException.class, () -> { + testQuery( + "SELECT STRING_AGG(DISTINCT CONCAT(dim1, dim2), CONCAT('|', dim1)) FROM foo", + ImmutableList.of(), + ImmutableList.of() + ); + }); } @Test diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteReplaceDmlTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteReplaceDmlTest.java index cad3945fbd6..526479ab456 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteReplaceDmlTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteReplaceDmlTest.java @@ -45,9 +45,8 @@ import org.apache.druid.sql.calcite.parser.DruidSqlParserUtils; import org.apache.druid.sql.calcite.parser.DruidSqlReplace; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.hamcrest.MatcherAssert; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Arrays; @@ -61,6 +60,7 @@ import static org.apache.druid.segment.column.ColumnType.FLOAT; import static org.apache.druid.segment.column.ColumnType.LONG; import static org.apache.druid.segment.column.ColumnType.STRING; import static org.apache.druid.segment.column.ColumnType.ofComplex; +import static org.hamcrest.MatcherAssert.assertThat; public class CalciteReplaceDmlTest extends CalciteIngestionDmlTest { @@ -657,7 +657,7 @@ public class CalciteReplaceDmlTest extends CalciteIngestionDmlTest Assert.fail("Exception should be thrown"); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs( "Invalid granularity['invalid_granularity'] specified after PARTITIONED BY clause." diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteScanSignatureTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteScanSignatureTest.java index 8dc5cf5a8de..1d3a04255c6 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteScanSignatureTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteScanSignatureTest.java @@ -37,7 +37,7 @@ import org.apache.druid.sql.calcite.run.QueryMaker; import org.apache.druid.sql.calcite.run.SqlEngine; import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.destination.IngestDestination; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSelectQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSelectQueryTest.java index 0e34c64043f..75732c714bd 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSelectQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSelectQueryTest.java @@ -52,7 +52,7 @@ import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.sql.calcite.util.CalciteTests; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.HashMap; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSimpleQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSimpleQueryTest.java index 5dee57dac32..6fe2205a7ae 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSimpleQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSimpleQueryTest.java @@ -36,7 +36,7 @@ import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * This class tests simple aggregation SQL queries, i.e., no joins and no nested queries. diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSubqueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSubqueryTest.java index 5a3fac0b077..e469b438373 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSubqueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSubqueryTest.java @@ -65,10 +65,9 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.hamcrest.CoreMatchers; import org.joda.time.DateTimeZone; import org.joda.time.Period; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.ArrayList; import java.util.Arrays; @@ -88,23 +87,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue; * 1. Where the memory limit is not set. The intermediate results are materialized as inline rows * 2. Where the memory limit is set. The intermediate results are materialized as frames */ -@RunWith(Parameterized.class) public class CalciteSubqueryTest extends BaseCalciteQueryTest { - - public String testName; - public Map queryContext; - - public CalciteSubqueryTest( - String testName, - Map queryContext - ) - { - this.testName = testName; - this.queryContext = queryContext; - } - - @Parameterized.Parameters(name = "{0}") public static Iterable constructorFeeder() { final List constructors = new ArrayList<>(); @@ -117,8 +101,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest return constructors; } - @Test - public void testExactCountDistinctUsingSubqueryWithWhereToOuterFilter() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testExactCountDistinctUsingSubqueryWithWhereToOuterFilter(String testName, Map queryContext) { // Cannot vectorize topN operator. cannotVectorize(); @@ -165,8 +150,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testExactCountDistinctOfSemiJoinResult() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testExactCountDistinctOfSemiJoinResult(String testName, Map queryContext) { // Cannot vectorize due to extraction dimension spec. cannotVectorize(); @@ -240,8 +226,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testTwoExactCountDistincts() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testTwoExactCountDistincts(String testName, Map queryContext) { testQuery( PLANNER_CONFIG_NO_HLL, @@ -317,8 +304,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testViewAndJoin() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testViewAndJoin(String testName, Map queryContext) { cannotVectorize(); Map queryContextModified = withLeftDirectAccessEnabled(queryContext); @@ -384,8 +372,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testGroupByWithPostAggregatorReferencingTimeFloorColumnOnTimeseries() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testGroupByWithPostAggregatorReferencingTimeFloorColumnOnTimeseries(String testName, Map queryContext) { cannotVectorize(); @@ -431,8 +420,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testUsingSubqueryAsFilterWithInnerSort() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testUsingSubqueryAsFilterWithInnerSort(String testName, Map queryContext) { // Regression test for https://github.com/apache/druid/issues/4208 @@ -484,8 +474,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testUsingSubqueryAsFilterOnTwoColumns() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testUsingSubqueryAsFilterOnTwoColumns(String testName, Map queryContext) { testQuery( "SELECT __time, cnt, dim1, dim2 FROM druid.foo " @@ -544,8 +535,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testMinMaxAvgDailyCountWithLimit() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testMinMaxAvgDailyCountWithLimit(String testName, Map queryContext) { // Cannot vectorize due to virtual columns. cannotVectorize(); @@ -613,8 +605,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testEmptyGroupWithOffsetDoesntInfiniteLoop() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testEmptyGroupWithOffsetDoesntInfiniteLoop(String testName, Map queryContext) { testQuery( "SELECT r0.c, r1.c\n" @@ -676,17 +669,18 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest } - @Test - public void testMaxSubqueryRows() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testMaxSubqueryRows(String testName, Map queryContext) { if ("without memory limit".equals(testName)) { - testMaxSubqueryRowsWithoutMemoryLimit(); + testMaxSubqueryRowsWithoutMemoryLimit(testName, queryContext); } else { - testMaxSubQueryRowsWithLimit(); + testMaxSubQueryRowsWithLimit(testName, queryContext); } } - private void testMaxSubqueryRowsWithoutMemoryLimit() + private void testMaxSubqueryRowsWithoutMemoryLimit(String testName, Map queryContext) { Map modifiedQueryContext = new HashMap<>(queryContext); modifiedQueryContext.put(QueryContexts.MAX_SUBQUERY_ROWS_KEY, 1); @@ -711,7 +705,7 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - private void testMaxSubQueryRowsWithLimit() + private void testMaxSubQueryRowsWithLimit(String testName, Map queryContext) { // Since the results are materializable as frames, we are able to use the memory limit and donot rely on the // row limit for the subquery @@ -760,8 +754,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testZeroMaxNumericInFilter() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testZeroMaxNumericInFilter(String testName, Map queryContext) { Throwable exception = assertThrows(UOE.class, () -> { @@ -785,8 +780,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest assertTrue(exception.getMessage().contains("[maxNumericInFilters] must be greater than 0")); } - @Test - public void testUseTimeFloorInsteadOfGranularityOnJoinResult() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testUseTimeFloorInsteadOfGranularityOnJoinResult(String testName, Map queryContext) { cannotVectorize(); @@ -867,8 +863,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testJoinWithTimeDimension() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testJoinWithTimeDimension(String testName, Map queryContext) { testQuery( PLANNER_CONFIG_DEFAULT, @@ -903,8 +900,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testUsingSubqueryWithLimit() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testUsingSubqueryWithLimit(String testName, Map queryContext) { // Cannot vectorize scan query. cannotVectorize(); @@ -935,8 +933,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testSelfJoin() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testSelfJoin(String testName, Map queryContext) { // Cannot vectorize due to virtual columns. cannotVectorize(); @@ -986,8 +985,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testJoinWithSubqueries() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testJoinWithSubqueries(String testName, Map queryContext) { cannotVectorize(); @@ -1072,8 +1072,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testSingleValueFloatAgg() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testSingleValueFloatAgg(String testName, Map queryContext) { skipVectorize(); cannotVectorize(); @@ -1130,8 +1131,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testSingleValueDoubleAgg() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testSingleValueDoubleAgg(String testName, Map queryContext) { skipVectorize(); cannotVectorize(); @@ -1188,8 +1190,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testSingleValueLongAgg() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testSingleValueLongAgg(String testName, Map queryContext) { skipVectorize(); cannotVectorize(); @@ -1249,8 +1252,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testSingleValueStringAgg() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testSingleValueStringAgg(String testName, Map queryContext) { skipVectorize(); cannotVectorize(); @@ -1311,8 +1315,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testSingleValueStringMultipleRowsAgg() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testSingleValueStringMultipleRowsAgg(String testName, Map queryContext) { skipVectorize(); cannotVectorize(); @@ -1323,8 +1328,9 @@ public class CalciteSubqueryTest extends BaseCalciteQueryTest ); } - @Test - public void testSingleValueEmptyInnerAgg() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testSingleValueEmptyInnerAgg(String testName, Map queryContext) { skipVectorize(); cannotVectorize(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSysQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSysQueryTest.java index 0dc74f9a1bc..f03b13d8e26 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSysQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteSysQueryTest.java @@ -24,14 +24,12 @@ import com.google.common.collect.ImmutableMap; import org.apache.druid.sql.calcite.NotYetSupported.Modes; import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(NotYetSupportedProcessor.class) public class CalciteSysQueryTest extends BaseCalciteQueryTest { - @Rule(order = 0) - public NotYetSupportedProcessor negativeTestProcessor = new NotYetSupportedProcessor(); - @Test public void testTasksSum() { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteTableAppendTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteTableAppendTest.java index f15786c3fb9..8b6170cbfaa 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteTableAppendTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteTableAppendTest.java @@ -24,19 +24,15 @@ import org.apache.druid.error.DruidException; import org.apache.druid.query.Druids; import org.apache.druid.query.scan.ScanQuery.ResultFormat; import org.apache.druid.segment.column.ColumnType; -import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.hamcrest.MatcherAssert; import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; public class CalciteTableAppendTest extends BaseCalciteQueryTest { - @Rule(order = 0) - public NotYetSupportedProcessor negativeTestProcessor = new NotYetSupportedProcessor(); - @Test public void testUnion() { @@ -230,7 +226,7 @@ public class CalciteTableAppendTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs("No match found for function signature APPEND() (line [1], column [24])") ); @@ -247,7 +243,7 @@ public class CalciteTableAppendTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs( "All arguments to APPEND should be literal strings. Argument #2 is not string (line [1], column [37])" @@ -266,7 +262,7 @@ public class CalciteTableAppendTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs( "All arguments to APPEND should be literal strings. Argument #2 is not string (line [1], column [37])" @@ -285,7 +281,7 @@ public class CalciteTableAppendTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs("Table [nonexistent] not found (line [1], column [37])") ); @@ -303,7 +299,7 @@ public class CalciteTableAppendTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat( + assertThat( e, invalidSqlIs("Table [t0] not found (line [1], column [62])") ); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteTimeBoundaryQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteTimeBoundaryQueryTest.java index c4cd002fbea..ff0555cb358 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteTimeBoundaryQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteTimeBoundaryQueryTest.java @@ -33,7 +33,7 @@ import org.apache.druid.query.timeboundary.TimeBoundaryQuery; import org.apache.druid.segment.join.JoinType; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.HashMap; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteUnionQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteUnionQueryTest.java index af0066bba05..54adbc7d900 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteUnionQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteUnionQueryTest.java @@ -31,9 +31,10 @@ import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.sql.calcite.NotYetSupported.Modes; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.hamcrest.MatcherAssert; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; public class CalciteUnionQueryTest extends BaseCalciteQueryTest { @@ -137,7 +138,7 @@ public class CalciteUnionQueryTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [42])")); + assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [42])")); } } @@ -365,7 +366,7 @@ public class CalciteUnionQueryTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [45])")); + assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [45])")); } } @@ -385,7 +386,7 @@ public class CalciteUnionQueryTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [45])")); + assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [45])")); } } @@ -405,7 +406,7 @@ public class CalciteUnionQueryTest extends BaseCalciteQueryTest Assert.fail("query execution should fail"); } catch (DruidException e) { - MatcherAssert.assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [70])")); + assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [70])")); } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteWindowQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteWindowQueryTest.java index eb008a43296..2d5492da5ee 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/CalciteWindowQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/CalciteWindowQueryTest.java @@ -37,11 +37,9 @@ import org.apache.druid.sql.calcite.CalciteWindowQueryTest.WindowQueryTestInputC import org.apache.druid.sql.calcite.QueryTestRunner.QueryResults; import org.apache.druid.sql.calcite.QueryVerification.QueryResultsVerifier; import org.apache.druid.sql.calcite.planner.PlannerContext; -import org.hamcrest.Matchers; import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.net.URL; @@ -53,12 +51,11 @@ import java.util.Objects; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.junit.Assume.assumeThat; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * These tests are file-based, look in resources -> calcite/tests/window for the set of test specifications. */ -@RunWith(Parameterized.class) public class CalciteWindowQueryTest extends BaseCalciteQueryTest { @@ -72,8 +69,7 @@ public class CalciteWindowQueryTest extends BaseCalciteQueryTest private static final ObjectMapper YAML_JACKSON = new DefaultObjectMapper(new YAMLFactory(), "tests"); - @Parameterized.Parameters(name = "{0}") - public static Object parametersForWindowQueryTest() throws Exception + public static Object[] parametersForWindowQueryTest() throws Exception { final URL windowFolderUrl = ClassLoader.getSystemResource("calcite/tests/window"); File windowFolder = new File(windowFolderUrl.toURI()); @@ -86,13 +82,6 @@ public class CalciteWindowQueryTest extends BaseCalciteQueryTest .toArray(); } - private final String filename; - - public CalciteWindowQueryTest(String filename) - { - this.filename = filename; - } - class TestCase implements QueryResultsVerifier { private WindowQueryTestInputClass input; @@ -200,13 +189,14 @@ public class CalciteWindowQueryTest extends BaseCalciteQueryTest } } - @Test + @MethodSource("parametersForWindowQueryTest") + @ParameterizedTest(name = "{0}") @SuppressWarnings("unchecked") - public void windowQueryTest() throws Exception + public void windowQueryTest(String filename) throws Exception { TestCase testCase = new TestCase(filename); - assumeThat(testCase.getType(), Matchers.not(TestType.failingTest)); + assumeTrue(testCase.getType() != TestType.failingTest); if (testCase.getType() == TestType.operatorValidation) { testBuilder() @@ -222,13 +212,14 @@ public class CalciteWindowQueryTest extends BaseCalciteQueryTest } } - @Test + @MethodSource("parametersForWindowQueryTest") + @ParameterizedTest(name = "{0}") @SuppressWarnings("unchecked") - public void windowQueryTestWithCustomContextMaxSubqueryBytes() throws Exception + public void windowQueryTestWithCustomContextMaxSubqueryBytes(String filename) throws Exception { TestCase testCase = new TestCase(filename); - assumeThat(testCase.getType(), Matchers.not(TestType.failingTest)); + assumeTrue(testCase.getType() != TestType.failingTest); if (testCase.getType() == TestType.operatorValidation) { testBuilder() diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java index 05fb6761a41..7c73b112506 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteJoinQueryTest.java @@ -20,32 +20,28 @@ package org.apache.druid.sql.calcite; import com.google.common.collect.ImmutableMap; -import junitparams.Parameters; import org.apache.druid.query.QueryContexts; import org.apache.druid.server.security.AuthConfig; +import org.apache.druid.sql.calcite.DisableUnless.DisableUnlessRule; import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; - +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Map; import static org.junit.Assert.assertNotNull; +@ExtendWith(NotYetSupportedProcessor.class) public class DecoupledPlanningCalciteJoinQueryTest extends CalciteJoinQueryTest { + @RegisterExtension + public DisableUnlessRule sqlCompatOnly = DisableUnless.SQL_COMPATIBLE; - @Rule(order = 0) - public NotYetSupportedProcessor decoupledIgnoreProcessor = new NotYetSupportedProcessor(); - - @Rule - public TestRule sqlCompatOnly = DisableUnless.SQL_COMPATIBLE; - - private static final ImmutableMap CONTEXT_OVERRIDES = - ImmutableMap.builder() + private static final ImmutableMap CONTEXT_OVERRIDES = ImmutableMap.builder() .putAll(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT) .put(PlannerConfig.CTX_NATIVE_QUERY_SQL_PLANNING_MODE, PlannerConfig.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED) .put(QueryContexts.ENABLE_DEBUG, true) @@ -78,8 +74,8 @@ public class DecoupledPlanningCalciteJoinQueryTest extends CalciteJoinQueryTest return builder; } - @Test - @Parameters(source = QueryContextForJoinProvider.class) + @MethodSource("provideQueryContexts") + @ParameterizedTest(name = "{0}") @DecoupledTestConfig public void ensureDecoupledTestConfigAnnotationWorks(Map queryContext) { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java index cf7d47ee084..1a0ae448319 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteQueryTest.java @@ -26,14 +26,11 @@ import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; -import org.junit.Rule; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(NotYetSupportedProcessor.class) public class DecoupledPlanningCalciteQueryTest extends CalciteQueryTest { - - @Rule(order = 0) - public NotYetSupportedProcessor decoupledIgnoreProcessor = new NotYetSupportedProcessor(); - private static final ImmutableMap CONTEXT_OVERRIDES = ImmutableMap.builder() .putAll(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java index 1e8c3d0b37d..7ddfc59c9bc 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DecoupledPlanningCalciteUnionQueryTest.java @@ -26,14 +26,11 @@ import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerComponentSupplier; -import org.junit.Rule; +import org.junit.jupiter.api.extension.ExtendWith; +@ExtendWith(NotYetSupportedProcessor.class) public class DecoupledPlanningCalciteUnionQueryTest extends CalciteUnionQueryTest { - - @Rule(order = 0) - public NotYetSupportedProcessor decoupledIgnoreProcessor = new NotYetSupportedProcessor(); - private static final ImmutableMap CONTEXT_OVERRIDES = ImmutableMap.builder() .putAll(BaseCalciteQueryTest.QUERY_CONTEXT_DEFAULT) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DisableUnless.java b/sql/src/test/java/org/apache/druid/sql/calcite/DisableUnless.java index 81f864f7edf..eead4c61a6a 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DisableUnless.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DisableUnless.java @@ -21,20 +21,20 @@ package org.apache.druid.sql.calcite; import com.google.common.base.Supplier; import org.apache.druid.common.config.NullHandling; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - -import static org.junit.Assume.assumeTrue; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; /** * Collection of conditional disabler rules. */ class DisableUnless { - public static final TestRule SQL_COMPATIBLE = new DisableUnlessRule("NullHandling::sqlCompatible", NullHandling::sqlCompatible); + public static final DisableUnlessRule SQL_COMPATIBLE = new DisableUnlessRule( + "NullHandling::sqlCompatible", NullHandling::sqlCompatible + ); - public static class DisableUnlessRule implements TestRule + public static class DisableUnlessRule implements ExecutionCondition { private Supplier predicate; private String message; @@ -46,10 +46,13 @@ class DisableUnless } @Override - public Statement apply(Statement base, Description description) + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { - assumeTrue("Testcase disabled; because condition not met: " + message, predicate.get()); - return base; + if (predicate.get()) { + return ConditionEvaluationResult.enabled("condition not met"); + } else { + return ConditionEvaluationResult.disabled(message); + } } } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DrillWindowQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DrillWindowQueryTest.java index 078eb8c9834..1cf08165c8e 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DrillWindowQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DrillWindowQueryTest.java @@ -52,6 +52,7 @@ import org.apache.druid.segment.incremental.IncrementalIndexSchema; import org.apache.druid.segment.join.JoinableFactoryWrapper; import org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMediumFactory; import org.apache.druid.server.SpecificSegmentsQuerySegmentWalker; +import org.apache.druid.sql.calcite.DisableUnless.DisableUnlessRule; import org.apache.druid.sql.calcite.NotYetSupported.Modes; import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; import org.apache.druid.sql.calcite.QueryTestRunner.QueryResults; @@ -62,14 +63,14 @@ import org.apache.druid.timeline.partition.NumberedShardSpec; import org.joda.time.DateTime; import org.joda.time.LocalTime; import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.RegisterExtension; import javax.annotation.Nonnull; import javax.annotation.Nullable; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -111,19 +112,18 @@ import static org.junit.Assert.fail; public class DrillWindowQueryTest extends BaseCalciteQueryTest { private static final ObjectMapper MAPPER = new DefaultObjectMapper(); - private DrillTestCase testCase = null; static { NullHandling.initializeForTests(); } - @Rule - public TestRule disableWhenNonSqlCompat = DisableUnless.SQL_COMPATIBLE; + @RegisterExtension + public DisableUnlessRule disableWhenNonSqlCompat = DisableUnless.SQL_COMPATIBLE; - @Rule + @RegisterExtension public NotYetSupportedProcessor ignoreProcessor = new NotYetSupportedProcessor(); - @Rule + @RegisterExtension public DrillTestCaseLoaderRule drillTestCaseRule = new DrillTestCaseLoaderRule(); @Test @@ -174,15 +174,16 @@ public class DrillWindowQueryTest extends BaseCalciteQueryTest String value(); } - class DrillTestCaseLoaderRule implements TestRule + static class DrillTestCaseLoaderRule implements BeforeEachCallback { + public DrillTestCase testCase = null; @Override - public Statement apply(Statement base, Description description) + public void beforeEach(ExtensionContext context) { - DrillTest annotation = description.getAnnotation(DrillTest.class); + Method method = context.getTestMethod().get(); + DrillTest annotation = method.getAnnotation(DrillTest.class); testCase = (annotation == null) ? null : new DrillTestCase(annotation.value()); - return base; } } @@ -241,7 +242,8 @@ public class DrillWindowQueryTest extends BaseCalciteQueryTest public SpecificSegmentsQuerySegmentWalker createQuerySegmentWalker( QueryRunnerFactoryConglomerate conglomerate, JoinableFactoryWrapper joinableFactory, - Injector injector) throws IOException + Injector injector + ) { final SpecificSegmentsQuerySegmentWalker retVal = super.createQuerySegmentWalker( conglomerate, @@ -473,6 +475,7 @@ public class DrillWindowQueryTest extends BaseCalciteQueryTest try { thread = Thread.currentThread(); oldName = thread.getName(); + DrillTestCase testCase = drillTestCaseRule.testCase; thread.setName("drillWindowQuery-" + testCase.filename); testBuilder() @@ -495,14 +498,13 @@ public class DrillWindowQueryTest extends BaseCalciteQueryTest @SuppressWarnings({"rawtypes", "unchecked"}) private void attachIndex(SpecificSegmentsQuerySegmentWalker texasRanger, String dataSource, DimensionSchema... dims) - throws IOException { ArrayList dimensionNames = new ArrayList<>(dims.length); for (DimensionSchema dimension : dims) { dimensionNames.add(dimension.getName()); } - final File tmpFolder = temporaryFolder.newFolder(); + final File tmpFolder = newTempFolder(); final QueryableIndex queryableIndex = IndexBuilder .create() .tmpDir(new File(tmpFolder, dataSource)) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DruidPlannerResourceAnalyzeTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/DruidPlannerResourceAnalyzeTest.java index 6423aae3af1..ed7c40217cb 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DruidPlannerResourceAnalyzeTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DruidPlannerResourceAnalyzeTest.java @@ -28,7 +28,7 @@ import org.apache.druid.server.security.ResourceAction; import org.apache.druid.server.security.ResourceType; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/IngestTableFunctionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/IngestTableFunctionTest.java index 2472736719f..97556b16fb2 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/IngestTableFunctionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/IngestTableFunctionTest.java @@ -46,9 +46,8 @@ import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.http.SqlParameter; import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; -import org.junit.Test; import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Test; import java.io.File; import java.net.URI; @@ -56,6 +55,7 @@ import java.net.URISyntaxException; import java.util.Arrays; import java.util.Collections; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; /** @@ -363,8 +363,7 @@ public class IngestTableFunctionTest extends CalciteIngestionDmlTest .authResult(CalciteTests.REGULAR_USER_AUTH_RESULT) .run() ); - MatcherAssert.assertThat(e, ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo(Access.DEFAULT_ERROR_MESSAGE))); - + assertThat(e, ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo(Access.DEFAULT_ERROR_MESSAGE))); } @Test diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/NotYetSupported.java b/sql/src/test/java/org/apache/druid/sql/calcite/NotYetSupported.java index 358d44267dc..868d5ecdced 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/NotYetSupported.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/NotYetSupported.java @@ -20,27 +20,21 @@ package org.apache.druid.sql.calcite; import com.google.common.base.Throwables; -import junitparams.JUnitParamsRunner; -import org.apache.commons.lang3.RegExUtils; import org.apache.druid.error.DruidException; import org.apache.druid.java.util.common.ISE; import org.junit.AssumptionViolatedException; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runner.RunWith; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.InvocationInterceptor; +import org.junit.jupiter.api.extension.ReflectiveInvocationContext; +import org.opentest4j.IncompleteExecutionException; -import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Method; -import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.Stream; import static org.junit.Assert.assertThrows; @@ -48,22 +42,27 @@ import static org.junit.Assert.assertThrows; * Can be used to mark tests which are not-yet supported for some reason. * * In case a testcase marked with this annotation fails - it means that the - * testcase no longer fails with the annotated expectation. This means that a code change affected this test either + * testcase no longer fails with the annotated expectation. This means that a + * code change affected this test either * *
    - *
  1. it suddenly passes: yay, assuming it makes sense that it suddenly passes, remove the annotation and move on
  2. - *
  3. it suddenly fails with a different error: validate that the new error is expected and either fix to continue failing with the old error or update the expected error.
  4. + *
  5. it suddenly passes: yay, assuming it makes sense that it suddenly passes, + * remove the annotation and move on
  6. + *
  7. it suddenly fails with a different error: validate that the new error is + * expected and either fix to continue failing with the old error or update the + * expected error.
  8. *
* - * During usage; the annotation process have to be added to the testclass. - * Ensure that it's loaded as the most outer-rule by using order=0 - otherwise - * it may interfere with other rules: + * During usage; the annotation process have to be added to registered with the testclass. + * Ensure that it's loaded as the most outer-rule by using the right ExtendWith order - or by + * specifying Order: * - * @Rule(order = 0) + * @Order(0) + * @RegisterExtension * public TestRule notYetSupportedRule = new NotYetSupportedProcessor(); * * @NotYetSupported(NOT_ENOUGH_RULES) - * @Test + * @Test * public void testA() { * } * @@ -77,6 +76,7 @@ public @interface NotYetSupported enum Modes { + // @formatter:off NOT_ENOUGH_RULES(DruidException.class, "not enough rules"), ERROR_HANDLING(AssertionError.class, "targetPersona: is <[A-Z]+> and category: is <[A-Z_]+> and errorCode: is"), EXPRESSION_NOT_GROUPED(DruidException.class, "Expression '[a-z]+' is not being grouped"), @@ -103,6 +103,7 @@ public @interface NotYetSupported SORT_REMOVE_TROUBLE(DruidException.class, "Calcite assertion violated.*Sort\\."), STACK_OVERFLOW(StackOverflowError.class, ""), CANNOT_JOIN_LOOKUP_NON_KEY(RuntimeException.class, "Cannot join lookup with condition referring to non-key"); + // @formatter:on public Class throwableClass; public String regex; @@ -125,33 +126,38 @@ public @interface NotYetSupported * Ensures that test cases disabled with that annotation can still not pass. * If the error is as expected; the testcase is marked as "ignored". */ - class NotYetSupportedProcessor implements TestRule + class NotYetSupportedProcessor implements InvocationInterceptor { @Override - public Statement apply(Statement base, Description description) + public void interceptTestMethod(Invocation invocation, + ReflectiveInvocationContext invocationContext, + ExtensionContext extensionContext) throws Throwable { - NotYetSupported annotation = getAnnotation(description, NotYetSupported.class); + Method method = extensionContext.getTestMethod().get(); + NotYetSupported annotation = method.getAnnotation(NotYetSupported.class); if (annotation == null) { - return base; + invocation.proceed(); + return; } - return new Statement() { - @Override - public void evaluate() { Modes ignoreMode = annotation.value(); Throwable e = null; try { - base.evaluate(); + invocation.proceed(); } catch (Throwable t) { e = t; } - // If the base test case is supposed to be ignored already, just skip the further evaluation + // If the base test case is supposed to be ignored already, just skip + // the further evaluation if (e instanceof AssumptionViolatedException) { throw (AssumptionViolatedException) e; } + if (e instanceof IncompleteExecutionException) { + throw (IncompleteExecutionException) e; + } Throwable finalE = e; assertThrows( "Expected that this testcase will fail - it might got fixed; or failure have changed?", @@ -171,40 +177,15 @@ public @interface NotYetSupported } throw new AssumptionViolatedException("Test is not-yet supported; ignored with:" + annotation); } - }; - } - - private static Method getMethodForName(Class testClass, String realMethodName) - { - List matches = Stream.of(testClass.getMethods()) - .filter(m -> realMethodName.equals(m.getName())) - .collect(Collectors.toList()); - switch (matches.size()) { - case 0: - throw new IllegalArgumentException("Expected to find method...but there is none?"); - case 1: - return matches.get(0); - default: - throw new IllegalArgumentException("method overrides are not supported"); } } - public static T getAnnotation(Description description, Class annotationType) + @Override + public void interceptTestTemplateMethod(Invocation invocation, + ReflectiveInvocationContext invocationContext, + ExtensionContext extensionContext) throws Throwable { - T annotation = description.getAnnotation(annotationType); - if (annotation != null) { - return annotation; - } - Class testClass = description.getTestClass(); - RunWith runWith = testClass.getAnnotation(RunWith.class); - if (runWith == null || !runWith.value().equals(JUnitParamsRunner.class)) { - return null; - } - String mehodName = description.getMethodName(); - String realMethodName = RegExUtils.replaceAll(mehodName, "\\(.*", ""); - - Method m = getMethodForName(testClass, realMethodName); - return m.getAnnotation(annotationType); + interceptTestMethod(invocation, invocationContext, extensionContext); } } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java index 9ae4d129d8f..ff7e9b5a6ba 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestBuilder.java @@ -34,7 +34,6 @@ import org.apache.druid.sql.calcite.QueryTestRunner.QueryResults; import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.apache.druid.sql.calcite.util.QueryLogHook; import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerFixture; import org.apache.druid.sql.http.SqlParameter; import java.util.ArrayList; @@ -68,8 +67,6 @@ public class QueryTestBuilder */ public interface QueryTestConfig { - QueryLogHook queryLogHook(); - ObjectMapper jsonMapper(); PlannerFixture plannerFixture(PlannerConfig plannerConfig, AuthConfig authConfig); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java index ccb2012b94c..58fa5635e8f 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/QueryTestRunner.java @@ -49,12 +49,14 @@ import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; import org.junit.Assert; import org.junit.internal.matchers.ThrowableMessageMatcher; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; /** @@ -248,10 +250,7 @@ public class QueryTestRunner vectorizeValues.add("force"); } - final QueryLogHook queryLogHook = builder.config.queryLogHook(); for (final String vectorize : vectorizeValues) { - queryLogHook.clearRecordedQueries(); - final Map theQueryContext = new HashMap<>(builder.queryContext); theQueryContext.put(QueryContexts.VECTORIZE_KEY, vectorize); theQueryContext.put(QueryContexts.VECTORIZE_VIRTUAL_COLUMNS_KEY, vectorize); @@ -278,13 +277,19 @@ public class QueryTestRunner final PlannerCaptureHook capture = getCaptureHook(); final DirectStatement stmt = sqlStatementFactory.directStatement(query); stmt.setHook(capture); - final Sequence results = stmt.execute().getResults(); + AtomicReference> resultListRef = new AtomicReference<>(); + QueryLogHook queryLogHook = new QueryLogHook(builder().config.jsonMapper()); + queryLogHook.logQueriesFor( + () -> { + resultListRef.set(stmt.execute().getResults().toList()); + } + ); return new QueryResults( query.context(), vectorize, stmt.prepareResult().getReturnedRowType(), - results.toList(), - builder().config.queryLogHook().getRecordedQueries(), + resultListRef.get(), + queryLogHook.getRecordedQueries(), capture ); } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java index cb66572c53b..df50dd62bec 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java @@ -20,19 +20,18 @@ package org.apache.druid.sql.calcite; import org.apache.druid.query.topn.TopNQueryConfig; -import org.apache.druid.sql.calcite.NotYetSupported.NotYetSupportedProcessor; import org.apache.druid.sql.calcite.util.CacheTestHelperModule.ResultCacheMode; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.QueryComponentSupplier; -import org.junit.rules.ExternalResource; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - +import org.junit.jupiter.api.extension.AfterAllCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; @@ -52,50 +51,41 @@ public @interface SqlTestFrameworkConfig ResultCacheMode resultCache() default ResultCacheMode.DISABLED; + + /** * @see {@link SqlTestFrameworkConfig} */ - class ClassRule extends ExternalResource + class Rule implements AfterAllCallback, BeforeEachCallback { - Map configMap = new HashMap<>(); - - public MethodRule methodRule(BaseCalciteQueryTest testHost) - { - return new MethodRule(this, testHost); - } + private SqlTestFrameworkConfig config; + private QueryComponentSupplier testHost; + private Method method; @Override - protected void after() + public void afterAll(ExtensionContext context) { for (ConfigurationInstance f : configMap.values()) { f.close(); } configMap.clear(); } - } - /** - * @see {@link SqlTestFrameworkConfig} - */ - class MethodRule extends ExternalResource - { - private SqlTestFrameworkConfig config; - private ClassRule classRule; - private QueryComponentSupplier testHost; - private Description description; - - public MethodRule(ClassRule classRule, QueryComponentSupplier testHost) + @Override + public void beforeEach(ExtensionContext context) { - this.classRule = classRule; - this.testHost = testHost; + testHost = (QueryComponentSupplier) context.getTestInstance().get(); + method = context.getTestMethod().get(); + setConfig(method.getAnnotation(SqlTestFrameworkConfig.class)); + } @SqlTestFrameworkConfig public SqlTestFrameworkConfig defaultConfig() { try { - SqlTestFrameworkConfig annotation = MethodRule.class + SqlTestFrameworkConfig annotation = getClass() .getMethod("defaultConfig") .getAnnotation(SqlTestFrameworkConfig.class); return annotation; @@ -105,15 +95,12 @@ public @interface SqlTestFrameworkConfig } } - @Override - public Statement apply(Statement base, Description description) + public void setConfig(SqlTestFrameworkConfig annotation) { - this.description = description; - config = description.getAnnotation(SqlTestFrameworkConfig.class); + config = annotation; if (config == null) { config = defaultConfig(); } - return base; } public SqlTestFramework get() @@ -123,12 +110,12 @@ public @interface SqlTestFrameworkConfig public T getAnnotation(Class annotationType) { - return NotYetSupportedProcessor.getAnnotation(description, annotationType); + return method.getAnnotation(annotationType); } private ConfigurationInstance getConfigurationInstance() { - return classRule.configMap.computeIfAbsent(config, this::buildConfiguration); + return configMap.computeIfAbsent(config, this::buildConfiguration); } ConfigurationInstance buildConfiguration(SqlTestFrameworkConfig config) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/aggregation/SqlAggregationModuleTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/aggregation/SqlAggregationModuleTest.java index d9d62b60984..599dd2fb261 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/aggregation/SqlAggregationModuleTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/aggregation/SqlAggregationModuleTest.java @@ -27,20 +27,22 @@ import org.apache.druid.sql.calcite.aggregation.builtin.CountSqlAggregator; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.hamcrest.CoreMatchers; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; + public class SqlAggregationModuleTest extends CalciteTestBase { private SqlAggregationModule target; private Injector injector; - @Before + @BeforeEach public void setUp() { target = new SqlAggregationModule(); @@ -58,7 +60,7 @@ public class SqlAggregationModuleTest extends CalciteTestBase .sorted(Comparator.comparing(o -> o.getClass().getName())) .collect(Collectors.toList()); - Assert.assertThat(aggregators.get(0), CoreMatchers.instanceOf(ApproxCountDistinctSqlAggregator.class)); - Assert.assertThat(aggregators.get(1), CoreMatchers.instanceOf(CountSqlAggregator.class)); + assertThat(aggregators.get(0), CoreMatchers.instanceOf(ApproxCountDistinctSqlAggregator.class)); + assertThat(aggregators.get(1), CoreMatchers.instanceOf(CountSqlAggregator.class)); } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java index 8656f1221f2..2f5f28ad8e7 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/ExpressionsTest.java @@ -69,8 +69,8 @@ import org.apache.druid.sql.calcite.planner.DruidOperatorTable; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.joda.time.Period; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.util.Collections; @@ -132,7 +132,7 @@ public class ExpressionsTest extends CalciteTestBase final DruidOperatorTable operatorTable = new DruidOperatorTable(Collections.emptySet(), Collections.emptySet()); - @Before + @BeforeEach public void setUp() { testHelper = new ExpressionTestHelper(ROW_SIGNATURE, BINDINGS); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/GreatestExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/GreatestExpressionTest.java index 816befbdc0d..f1a5a869a19 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/GreatestExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/GreatestExpressionTest.java @@ -29,8 +29,8 @@ import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.builtin.GreatestOperatorConversion; import org.apache.druid.sql.calcite.util.CalciteTestBase; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.util.Arrays; @@ -61,7 +61,7 @@ public class GreatestExpressionTest extends CalciteTestBase private GreatestOperatorConversion target; private ExpressionTestHelper testHelper; - @Before + @BeforeEach public void setUp() { target = new GreatestOperatorConversion(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressMatchExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressMatchExpressionTest.java index cf1a221d7ac..2bb0116825a 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressMatchExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressMatchExpressionTest.java @@ -27,8 +27,8 @@ import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.builtin.IPv4AddressMatchOperatorConversion; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; @@ -57,7 +57,7 @@ public class IPv4AddressMatchExpressionTest extends CalciteTestBase private IPv4AddressMatchOperatorConversion target; private ExpressionTestHelper testHelper; - @Before + @BeforeEach public void setUp() { target = new IPv4AddressMatchOperatorConversion(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressParseExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressParseExpressionTest.java index f495b6e9500..65ea14d8f87 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressParseExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressParseExpressionTest.java @@ -27,8 +27,8 @@ import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.builtin.IPv4AddressParseOperatorConversion; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; @@ -48,7 +48,7 @@ public class IPv4AddressParseExpressionTest extends CalciteTestBase private IPv4AddressParseOperatorConversion target; private ExpressionTestHelper testHelper; - @Before + @BeforeEach public void setUp() { target = new IPv4AddressParseOperatorConversion(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressStringifyExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressStringifyExpressionTest.java index fb1b358cb08..f1844fb940e 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressStringifyExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/IPv4AddressStringifyExpressionTest.java @@ -27,8 +27,8 @@ import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.builtin.IPv4AddressStringifyOperatorConversion; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; @@ -49,7 +49,7 @@ public class IPv4AddressStringifyExpressionTest extends CalciteTestBase private IPv4AddressStringifyOperatorConversion target; private ExpressionTestHelper testHelper; - @Before + @BeforeEach public void setUp() { target = new IPv4AddressStringifyOperatorConversion(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/LeastExpressionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/LeastExpressionTest.java index 496543a5dd7..eaec03c00c8 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/LeastExpressionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/LeastExpressionTest.java @@ -29,8 +29,8 @@ import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.builtin.LeastOperatorConversion; import org.apache.druid.sql.calcite.util.CalciteTestBase; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.util.Arrays; @@ -61,7 +61,7 @@ public class LeastExpressionTest extends CalciteTestBase private LeastOperatorConversion target; private ExpressionTestHelper testHelper; - @Before + @BeforeEach public void setUp() { target = new LeastOperatorConversion(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/OperatorConversionsTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/OperatorConversionsTest.java index 5a0c52514f3..20369bfcf05 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/OperatorConversionsTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/OperatorConversionsTest.java @@ -41,9 +41,7 @@ import org.apache.druid.sql.calcite.planner.DruidTypeSystem; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; import org.mockito.stubbing.Answer; @@ -51,7 +49,6 @@ import org.mockito.stubbing.Answer; import java.util.ArrayList; import java.util.List; -@RunWith(Enclosed.class) public class OperatorConversionsTest { public static class DefaultOperandTypeCheckerTest diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/expression/TimeFormatOperatorConversionTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/expression/TimeFormatOperatorConversionTest.java index 021e3579515..21e097cc8c9 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/expression/TimeFormatOperatorConversionTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/expression/TimeFormatOperatorConversionTest.java @@ -28,12 +28,14 @@ import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.expression.builtin.TimeFormatOperatorConversion; import org.apache.druid.sql.calcite.util.CalciteTestBase; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.annotation.Nullable; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * Tests for TIME_FORMAT */ @@ -51,7 +53,7 @@ public class TimeFormatOperatorConversionTest extends CalciteTestBase private TimeFormatOperatorConversion target; private ExpressionTestHelper testHelper; - @Before + @BeforeEach public void setUp() { target = new TimeFormatOperatorConversion(); @@ -91,15 +93,17 @@ public class TimeFormatOperatorConversionTest extends CalciteTestBase ); } - @Test(expected = IAE.class) + @Test public void testConversionToUnknownTimezoneShouldThrowException() { - testExpression( - "2000-02-02 20:05:06", - "timestamp_format(\"t\",'yyyy-MM-dd HH:mm:ss','America/NO_TZ')", - "yyyy-MM-dd HH:mm:ss", - "America/NO_TZ" - ); + assertThrows(IAE.class, () -> { + testExpression( + "2000-02-02 20:05:06", + "timestamp_format(\"t\",'yyyy-MM-dd HH:mm:ss','America/NO_TZ')", + "yyyy-MM-dd HH:mm:ss", + "America/NO_TZ" + ); + }); } private void testExpression( diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/filtration/CombineAndSimplifyBoundsTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/filtration/CombineAndSimplifyBoundsTest.java index 3192dc052df..6088ffb6454 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/filtration/CombineAndSimplifyBoundsTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/filtration/CombineAndSimplifyBoundsTest.java @@ -25,16 +25,13 @@ import org.apache.druid.query.filter.DimFilter; import org.apache.druid.query.filter.RangeFilter; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.List; import static org.junit.Assert.assertEquals; -@RunWith(Parameterized.class) public class CombineAndSimplifyBoundsTest extends BaseCalciteQueryTest { @@ -100,7 +97,6 @@ public class CombineAndSimplifyBoundsTest extends BaseCalciteQueryTest public abstract DimFilter range(String lit1, boolean gte, String name, boolean lte, String lit2); } - @Parameters public static List getParameters() { return ImmutableList.of( @@ -109,15 +105,9 @@ public class CombineAndSimplifyBoundsTest extends BaseCalciteQueryTest ); } - final RangeFilterType rangeFilter; - - public CombineAndSimplifyBoundsTest(RangeFilterType rangeFilter) - { - this.rangeFilter = rangeFilter; - } - - @Test - public void testNotAZ() + @MethodSource("getParameters") + @ParameterizedTest + public void testNotAZ(RangeFilterType rangeFilter) { String dim1 = "dim1"; DimFilter inputFilter = or( @@ -129,8 +119,9 @@ public class CombineAndSimplifyBoundsTest extends BaseCalciteQueryTest check(inputFilter, expected); } - @Test - public void testAZ() + @MethodSource("getParameters") + @ParameterizedTest + public void testAZ(RangeFilterType rangeFilter) { String dim1 = "dim1"; DimFilter inputFilter = and( @@ -142,8 +133,9 @@ public class CombineAndSimplifyBoundsTest extends BaseCalciteQueryTest check(inputFilter, expected); } - @Test - public void testNot2() + @MethodSource("getParameters") + @ParameterizedTest + public void testNot2(RangeFilterType rangeFilter) { String dim1 = "dim1"; DimFilter inputFilter = or( diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/filtration/FiltrationTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/filtration/FiltrationTest.java index 901ab17a712..b88c520e522 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/filtration/FiltrationTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/filtration/FiltrationTest.java @@ -28,7 +28,7 @@ import org.apache.druid.segment.column.ColumnType; import org.apache.druid.segment.column.RowSignature; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class FiltrationTest extends CalciteTestBase { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java index 8d0507b4752..f9c083864f3 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/http/SqlQueryTest.java @@ -30,7 +30,7 @@ import org.apache.druid.sql.http.ResultFormat; import org.apache.druid.sql.http.SqlParameter; import org.apache.druid.sql.http.SqlQuery; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SqlQueryTest extends CalciteTestBase { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtilsTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtilsTest.java index 5165f75785d..bc9d6997536 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtilsTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtilsTest.java @@ -50,13 +50,11 @@ import org.joda.time.DateTimeZone; import org.joda.time.Period; import org.junit.Assert; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.util.Arrays; -@RunWith(Enclosed.class) public class DruidSqlParserUtilsTest { /** diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/planner/CalcitePlannerModuleTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/planner/CalcitePlannerModuleTest.java index 12db32d4f01..06d8cf761ab 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/planner/CalcitePlannerModuleTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/planner/CalcitePlannerModuleTest.java @@ -50,22 +50,23 @@ import org.apache.druid.sql.calcite.schema.NamedSchema; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.apache.druid.sql.calcite.util.CalciteTests; import org.easymock.EasyMock; -import org.easymock.EasyMockRunner; +import org.easymock.EasyMockExtension; import org.easymock.Mock; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import javax.validation.Validation; import javax.validation.Validator; + import java.util.Collections; import java.util.Set; import static org.apache.calcite.plan.RelOptRule.any; import static org.apache.calcite.plan.RelOptRule.operand; -@RunWith(EasyMockRunner.class) +@ExtendWith(EasyMockExtension.class) public class CalcitePlannerModuleTest extends CalciteTestBase { private static final String SCHEMA_1 = "SCHEMA_1"; @@ -98,9 +99,10 @@ public class CalcitePlannerModuleTest extends CalciteTestBase private Injector injector; private RelOptRule customRule; - @Before + @BeforeEach public void setUp() { + EasyMock.expect(druidSchema1.getSchema()).andStubReturn(schema1); EasyMock.expect(druidSchema2.getSchema()).andStubReturn(schema2); EasyMock.expect(druidSchema1.getSchemaName()).andStubReturn(SCHEMA_1); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/planner/CalcitesTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/planner/CalcitesTest.java index 576a57cc937..cc033162d08 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/planner/CalcitesTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/planner/CalcitesTest.java @@ -24,7 +24,7 @@ import org.apache.druid.query.ordering.StringComparators; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class CalcitesTest extends CalciteTestBase { diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/rule/DruidLogicalValuesRuleTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/rule/DruidLogicalValuesRuleTest.java index 2ad83563e9e..5a6db426d29 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/rule/DruidLogicalValuesRuleTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/rule/DruidLogicalValuesRuleTest.java @@ -41,7 +41,6 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; -import org.junit.experimental.runners.Enclosed; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -50,7 +49,6 @@ import org.mockito.Mockito; import java.math.BigDecimal; -@RunWith(Enclosed.class) public class DruidLogicalValuesRuleTest { private static final PlannerContext DEFAULT_CONTEXT = Mockito.mock(PlannerContext.class); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidCalciteSchemaModuleTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidCalciteSchemaModuleTest.java index 0b5fb609fa2..0616dd2a3a3 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidCalciteSchemaModuleTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidCalciteSchemaModuleTest.java @@ -56,17 +56,17 @@ import org.apache.druid.sql.calcite.planner.PlannerConfig; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.apache.druid.sql.calcite.view.ViewManager; import org.easymock.EasyMock; -import org.easymock.EasyMockRunner; +import org.easymock.EasyMockExtension; import org.easymock.Mock; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import java.util.Set; import java.util.stream.Collectors; -@RunWith(EasyMockRunner.class) +@ExtendWith(EasyMockExtension.class) public class DruidCalciteSchemaModuleTest extends CalciteTestBase { private static final String DRUID_SCHEMA_NAME = "druid"; @@ -103,7 +103,7 @@ public class DruidCalciteSchemaModuleTest extends CalciteTestBase private DruidCalciteSchemaModule target; private Injector injector; - @Before + @BeforeEach public void setUp() { EasyMock.replay(plannerConfig); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidSchemaNoDataInitTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidSchemaNoDataInitTest.java index a1ad4201c6d..7dec56c81f2 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidSchemaNoDataInitTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/DruidSchemaNoDataInitTest.java @@ -37,7 +37,7 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestTimelineServerView; import org.easymock.EasyMock; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/InformationSchemaTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/InformationSchemaTest.java index f2ac64826ee..06e02fe1ae6 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/InformationSchemaTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/InformationSchemaTest.java @@ -46,8 +46,8 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.QueryFrameworkUtils; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; @@ -62,7 +62,7 @@ public class InformationSchemaTest extends BaseCalciteQueryTest private InformationSchema informationSchema; private SqlTestFramework qf; - @Before + @BeforeEach public void setUp() { qf = queryFramework(); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedDruidSchemaTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedDruidSchemaTest.java index f4af22be088..15e4e429ef4 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedDruidSchemaTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedDruidSchemaTest.java @@ -20,14 +20,14 @@ package org.apache.druid.sql.calcite.schema; import org.apache.druid.sql.calcite.util.CalciteTestBase; -import org.easymock.EasyMockRunner; +import org.easymock.EasyMockExtension; import org.easymock.Mock; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -@RunWith(EasyMockRunner.class) +@ExtendWith(EasyMockExtension.class) public class NamedDruidSchemaTest extends CalciteTestBase { private static final String SCHEMA_NAME = "SCHEMA_NAME"; @@ -37,7 +37,7 @@ public class NamedDruidSchemaTest extends CalciteTestBase private NamedDruidSchema target; - @Before + @BeforeEach public void setUp() { target = new NamedDruidSchema(druidSchema, SCHEMA_NAME); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedLookupSchemaTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedLookupSchemaTest.java index 22aa9e9f638..1e4bd396b92 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedLookupSchemaTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedLookupSchemaTest.java @@ -20,14 +20,14 @@ package org.apache.druid.sql.calcite.schema; import org.apache.druid.sql.calcite.util.CalciteTestBase; -import org.easymock.EasyMockRunner; +import org.easymock.EasyMockExtension; import org.easymock.Mock; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -@RunWith(EasyMockRunner.class) +@ExtendWith(EasyMockExtension.class) public class NamedLookupSchemaTest extends CalciteTestBase { private static final String SCHEMA_NAME = "lookup"; @@ -37,7 +37,7 @@ public class NamedLookupSchemaTest extends CalciteTestBase private NamedLookupSchema target; - @Before + @BeforeEach public void setUp() { target = new NamedLookupSchema(lookupSchema); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedSystemSchemaTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedSystemSchemaTest.java index 17e83a78994..31cdf8d710c 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedSystemSchemaTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/NamedSystemSchemaTest.java @@ -25,8 +25,8 @@ import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.easymock.EasyMock; import org.easymock.Mock; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class NamedSystemSchemaTest extends CalciteTestBase { @@ -39,7 +39,7 @@ public class NamedSystemSchemaTest extends CalciteTestBase private NamedSystemSchema target; - @Before + @BeforeEach public void setUp() { plannerConfig = EasyMock.createMock(PlannerConfig.class); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/RootSchemaProviderTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/RootSchemaProviderTest.java index 6cfe3f2c81a..a43a3f24f4f 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/RootSchemaProviderTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/RootSchemaProviderTest.java @@ -24,16 +24,18 @@ import org.apache.calcite.schema.Schema; import org.apache.druid.java.util.common.ISE; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.easymock.EasyMock; -import org.easymock.EasyMockRunner; +import org.easymock.EasyMockExtension; import org.easymock.Mock; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import java.util.Set; -@RunWith(EasyMockRunner.class) +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(EasyMockExtension.class) public class RootSchemaProviderTest extends CalciteTestBase { private static final String SCHEMA_1 = "SCHEMA_1"; @@ -54,7 +56,7 @@ public class RootSchemaProviderTest extends CalciteTestBase private RootSchemaProvider target; - @Before + @BeforeEach public void setUp() { EasyMock.expect(druidSchema1.getSchema()).andStubReturn(schema1); @@ -81,10 +83,12 @@ public class RootSchemaProviderTest extends CalciteTestBase Assert.assertEquals(schema2, rootSchema.getSubSchema(SCHEMA_2).unwrap(schema2.getClass())); } - @Test(expected = ISE.class) + @Test public void testGetWithDuplicateSchemasShouldThrowISE() { - target = new RootSchemaProvider(ImmutableSet.of(druidSchema1, druidSchema2, duplicateSchema1)); - target.get(); + assertThrows(ISE.class, () -> { + target = new RootSchemaProvider(ImmutableSet.of(druidSchema1, druidSchema2, duplicateSchema1)); + target.get(); + }); } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/schema/SystemSchemaTest.java b/sql/src/test/java/org/apache/druid/sql/calcite/schema/SystemSchemaTest.java index 40772374537..bc44809b69f 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/schema/SystemSchemaTest.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/schema/SystemSchemaTest.java @@ -110,14 +110,12 @@ import org.apache.druid.timeline.partition.NumberedShardSpec; import org.easymock.EasyMock; import org.jboss.netty.handler.codec.http.HttpResponse; import org.joda.time.DateTime; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.IOException; import java.net.URI; @@ -170,24 +168,21 @@ public class SystemSchemaTest extends CalciteTestBase private DruidNodeDiscoveryProvider druidNodeDiscoveryProvider; private FilteredServerInventoryView serverInventoryView; - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @BeforeClass + @BeforeAll public static void setUpClass() { resourceCloser = Closer.create(); conglomerate = QueryStackTests.createQueryRunnerFactoryConglomerate(resourceCloser); } - @AfterClass + @AfterAll public static void tearDownClass() throws IOException { resourceCloser.close(); } - @Before - public void setUp() throws Exception + @BeforeEach + public void setUp(@TempDir File tmpDir) throws Exception { serverView = EasyMock.createNiceMock(TimelineServerView.class); client = EasyMock.createMock(DruidLeaderClient.class); @@ -207,7 +202,6 @@ public class SystemSchemaTest extends CalciteTestBase request = EasyMock.createMock(Request.class); authMapper = createAuthMapper(); - final File tmpDir = temporaryFolder.newFolder(); final QueryableIndex index1 = IndexBuilder.create() .tmpDir(new File(tmpDir, "1")) .segmentWriteOutMediumFactory(OffHeapMemorySegmentWriteOutMediumFactory.instance()) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java index a10a56d31e3..9ec71acc2d9 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTestBase.java @@ -21,6 +21,7 @@ package org.apache.druid.sql.calcite.util; import com.google.common.collect.ImmutableList; import org.apache.druid.common.config.NullHandling; +import org.apache.druid.java.util.common.FileUtils; import org.apache.druid.math.expr.ExpressionProcessing; import org.apache.druid.segment.column.ColumnType; import org.apache.druid.server.security.Action; @@ -30,8 +31,15 @@ import org.apache.druid.server.security.ResourceType; import org.apache.druid.sql.calcite.expression.DruidExpression; import org.apache.druid.sql.calcite.expression.SimpleExtraction; import org.apache.druid.sql.http.SqlParameter; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.io.TempDir; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.Collections; import java.util.List; @@ -39,13 +47,71 @@ public abstract class CalciteTestBase { public static final List DEFAULT_PARAMETERS = ImmutableList.of(); - @BeforeClass + @BeforeAll public static void setupCalciteProperties() { NullHandling.initializeForTests(); ExpressionProcessing.initializeForTests(); } + /** + * Temporary folder(s). + * + * Due to some possible reuse of configuration in the next case; there is only one real temporary path; + * but every case gets a separate folder in it. + * + * note: {@link #rootTempPath} and {@link #casetempPath} are made private to ensure that + */ + @TempDir + private static Path rootTempPath; + private Path casetempPath; + + @BeforeEach + public void setCaseTempDir(TestInfo testInfo) + { + String methodName = testInfo.getTestMethod().get().getName(); + casetempPath = FileUtils.createTempDirInLocation(rootTempPath, methodName).toPath(); + } + + + public File newTempFolder() + { + return newTempFolder(null); + } + + public File newTempFolder(String prefix) + { + return FileUtils.createTempDirInLocation(casetempPath, prefix); + } + + public File newTempFile(String prefix) + { + try { + return Files.createTempFile(casetempPath, prefix, null).toFile(); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + + // FIXME remove + public TempFolderOverTempDir temXMEXAXISporaryFolder = new TempFolderOverTempDir(); + + public class TempFolderOverTempDir + { + + public File newFolder() + { + return newTempFolder("unknown"); + } + + public File newFolder(String string) + { + return newTempFolder(string); + } + } + + /** * @deprecated prefer to make {@link DruidExpression} directly to ensure expression tests accurately test the full * expression structure, this method is just to have a convenient way to fix a very large number of existing tests diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryLogHook.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryLogHook.java index c95e2e60920..3e00d170181 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryLogHook.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryLogHook.java @@ -23,47 +23,23 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; import org.apache.calcite.runtime.Hook; -import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.logger.Logger; import org.apache.druid.query.Query; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Consumer; -import java.util.function.Supplier; /** - * JUnit Rule that adds a Calcite hook to log and remember Druid queries. + * Class to log Druid queries. */ -public class QueryLogHook implements TestRule +public class QueryLogHook { private static final Logger log = new Logger(QueryLogHook.class); - private final Supplier objectMapperSupplier; + private final ObjectMapper objectMapper; private final List> recordedQueries = Lists.newCopyOnWriteArrayList(); - private final AtomicBoolean skipLog = new AtomicBoolean(false); - public QueryLogHook(final Supplier objectMapperSupplier) + public QueryLogHook(ObjectMapper objectMapper) { - this.objectMapperSupplier = objectMapperSupplier; - } - - public static QueryLogHook create() - { - return new QueryLogHook(() -> DefaultObjectMapper.INSTANCE); - } - - public static QueryLogHook create(final ObjectMapper objectMapper) - { - return new QueryLogHook(() -> objectMapper); - } - - public void clearRecordedQueries() - { - recordedQueries.clear(); + this.objectMapper = objectMapper; } public List> getRecordedQueries() @@ -71,48 +47,24 @@ public class QueryLogHook implements TestRule return ImmutableList.copyOf(recordedQueries); } - public void withSkippedLog(Consumer consumer) + protected void accept(Object query) { try { - skipLog.set(true); - consumer.accept(null); + recordedQueries.add((Query) query); + log.info( + "Issued query: %s", + objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(query) + ); } - finally { - skipLog.set(false); + catch (Exception e) { + log.warn(e, "Failed to serialize query: %s", query); } } - @Override - public Statement apply(final Statement base, final Description description) + public void logQueriesFor(Runnable r) { - return new Statement() - { - @Override - public void evaluate() throws Throwable - { - clearRecordedQueries(); - - final Consumer function = query -> { - if (skipLog.get()) { - return; - } - - try { - recordedQueries.add((Query) query); - log.info( - "Issued query: %s", - objectMapperSupplier.get().writerWithDefaultPrettyPrinter().writeValueAsString(query) - ); - } - catch (Exception e) { - log.warn(e, "Failed to serialize query: %s", query); - } - }; - - try (final Hook.Closeable unhook = Hook.QUERY_PLAN.add(function)) { - base.evaluate(); - } - } - }; + try (final Hook.Closeable unhook = Hook.QUERY_PLAN.addThread(this::accept)) { + r.run(); + } } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java index 8ec1f30fafc..1506a5c2001 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java @@ -151,7 +151,7 @@ public class SqlTestFramework QueryRunnerFactoryConglomerate conglomerate, JoinableFactoryWrapper joinableFactory, Injector injector - ) throws IOException; + ); SqlEngine createEngine( QueryLifecycleFactory qlf, @@ -527,18 +527,13 @@ public class SqlTestFramework @LazySingleton public SpecificSegmentsQuerySegmentWalker segmentsQuerySegmentWalker(final Injector injector) { - try { - SpecificSegmentsQuerySegmentWalker walker = componentSupplier.createQuerySegmentWalker( - injector.getInstance(QueryRunnerFactoryConglomerate.class), - injector.getInstance(JoinableFactoryWrapper.class), - injector - ); - resourceCloser.register(walker); - return walker; - } - catch (IOException e) { - throw new RE(e); - } + SpecificSegmentsQuerySegmentWalker walker = componentSupplier.createQuerySegmentWalker( + injector.getInstance(QueryRunnerFactoryConglomerate.class), + injector.getInstance(JoinableFactoryWrapper.class), + injector + ); + resourceCloser.register(walker); + return walker; } @Provides diff --git a/sql/src/test/java/org/apache/druid/sql/http/SqlResourceTest.java b/sql/src/test/java/org/apache/druid/sql/http/SqlResourceTest.java index 921be219b2a..fa3c1edcea2 100644 --- a/sql/src/test/java/org/apache/druid/sql/http/SqlResourceTest.java +++ b/sql/src/test/java/org/apache/druid/sql/http/SqlResourceTest.java @@ -102,18 +102,14 @@ import org.apache.druid.sql.calcite.run.NativeSqlEngine; import org.apache.druid.sql.calcite.schema.DruidSchemaCatalog; import org.apache.druid.sql.calcite.util.CalciteTestBase; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.apache.druid.sql.calcite.util.QueryLogHook; import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; -import org.junit.After; -import org.junit.AfterClass; import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -122,7 +118,9 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.StreamingOutput; + import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.AbstractList; @@ -144,6 +142,8 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; + @SuppressWarnings("ALL") public class SqlResourceTest extends CalciteTestBase { @@ -168,14 +168,10 @@ public class SqlResourceTest extends CalciteTestBase private static Closer staticCloser = Closer.create(); private static QueryRunnerFactoryConglomerate conglomerate; - @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); + private static SpecificSegmentsQuerySegmentWalker walker; private static QueryScheduler scheduler; - @Rule - public QueryLogHook queryLogHook = QueryLogHook.create(); - private Closer resourceCloser; private TestRequestLogger testRequestLogger; private SqlResource resource; @@ -196,8 +192,8 @@ public class SqlResourceTest extends CalciteTestBase private static final AtomicReference> SCHEDULER_BAGGAGE = new AtomicReference<>(); - @BeforeClass - public static void setupClass() throws Exception + @BeforeAll + public static void setupClass(@TempDir File tempDir) { conglomerate = QueryStackTests.createQueryRunnerFactoryConglomerate(staticCloser); scheduler = new QueryScheduler( @@ -220,17 +216,17 @@ public class SqlResourceTest extends CalciteTestBase ); } }; - walker = CalciteTests.createMockWalker(conglomerate, temporaryFolder.newFolder(), scheduler); + walker = CalciteTests.createMockWalker(conglomerate, tempDir, scheduler); staticCloser.register(walker); } - @AfterClass + @AfterAll public static void teardownClass() throws Exception { staticCloser.close(); } - @Before + @BeforeEach public void setUp() throws Exception { SCHEDULER_BAGGAGE.set(() -> null); @@ -341,7 +337,7 @@ public class SqlResourceTest extends CalciteTestBase return makeExpectedReq(CalciteTests.REGULAR_USER_AUTH_RESULT); } - @After + @AfterEach public void tearDown() throws Exception { SCHEDULER_BAGGAGE.set(() -> null); @@ -1603,7 +1599,7 @@ public class SqlResourceTest extends CalciteTestBase Status.BAD_REQUEST.getStatusCode() ); - MatcherAssert.assertThat( + assertThat( exception.getUnderlyingException(), DruidExceptionMatcher .invalidSqlInput() @@ -2302,7 +2298,7 @@ public class SqlResourceTest extends CalciteTestBase if (messageContainsString == null) { Assert.assertNull(exception.getMessage()); } else { - MatcherAssert.assertThat(exception.getMessage(), CoreMatchers.containsString(messageContainsString)); + assertThat(exception.getMessage(), CoreMatchers.containsString(messageContainsString)); } return exception;