From 8f3dccf82f2dbde31c6661386760951fc769ca14 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 7 Aug 2026 18:14:58 +0800 Subject: [PATCH 01/15] test: migrate initial extensions-contrib tests to JUnit 5 --- .../compressed-bigdecimal/pom.xml | 50 +-- .../ArrayCompressedBigDecimalTest.java | 159 +++---- .../ByteBufferCompressedBigDecimalTest.java | 6 +- .../CompressedBigDecimalCachingTest.java | 6 +- .../CompressedBigDecimalColumnTest.java | 12 +- .../CompressedBigDecimalFactoryTestBase.java | 62 +-- .../CompressedBigDecimalMaxFactoryTest.java | 32 +- .../CompressedBigDecimalMinFactoryTest.java | 32 +- .../CompressedBigDecimalSumFactoryTest.java | 40 +- ...edBigDecimalAggregatorGroupByTestBase.java | 150 ++++--- ...ompressedBigDecimalAggregatorTestBase.java | 6 +- ...igDecimalAggregatorTimeseriesTestBase.java | 59 ++- ...sedBigDecimalMaxAggregatorGroupByTest.java | 15 +- ...CompressedBigDecimalMaxAggregatorTest.java | 2 + ...BigDecimalMaxAggregatorTimeseriesTest.java | 3 + ...sedBigDecimalMinAggregatorGroupByTest.java | 17 +- ...CompressedBigDecimalMinAggregatorTest.java | 2 + ...BigDecimalMinAggregatorTimeseriesTest.java | 3 + ...pressedBigDecimalMinSqlAggregatorTest.java | 2 +- ...sedBigDecimalSumAggregatorGroupByTest.java | 15 +- ...CompressedBigDecimalSumAggregatorTest.java | 2 + ...BigDecimalSumAggregatorTimeseriesTest.java | 3 + ...pressedBigDecimalSumSqlAggregatorTest.java | 2 +- .../druid-exact-count-bitmap/pom.xml | 11 +- extensions-contrib/grpc-query/pom.xml | 25 +- .../org/apache/druid/grpc/BasicAuthTest.java | 11 +- .../org/apache/druid/grpc/DriverTest.java | 9 +- .../org/apache/druid/grpc/GrpcQueryTest.java | 9 +- .../org/apache/druid/grpc/TestServer.java | 14 +- .../grpc/client/GrpcResponseHandlerTest.java | 6 +- .../spectator-histogram/pom.xml | 50 +-- .../histogram/NullableOffsetsHeaderTest.java | 190 ++++---- ...SpectatorHistogramAggregateHelperTest.java | 76 ++-- .../SpectatorHistogramAggregatorTest.java | 333 ++++++++------ ...rHistogramIndexBasedComplexColumnTest.java | 8 +- ...togramNumericVectorizedAggregatorTest.java | 62 +-- .../histogram/SpectatorHistogramTest.java | 240 +++++----- ...atorHistogramVectorizedAggregatorTest.java | 66 +-- .../SpectatorHistogramSqlAggregatorTest.java | 10 +- extensions-contrib/tdigestsketch/pom.xml | 45 +- .../TDigestSketchAggregatorFactoryTest.java | 14 +- .../TDigestSketchAggregatorTest.java | 142 ++++-- .../TDigestSketchObjectStrategyTest.java | 4 +- ...estSketchToQuantilePostAggregatorTest.java | 16 +- ...stSketchToQuantilesPostAggregatorTest.java | 36 +- .../aggregation/AggregationTestHelper.java | 3 +- .../groupby/GroupByQueryRunnerTestHelper.java | 164 +++++++ .../query/groupby/TestGroupByBuffers.java | 2 +- .../org/apache/druid/segment/TestHelper.java | 88 ++-- .../apache/druid/sql/SqlQueryPlusTest.java | 30 +- .../apache/druid/sql/SqlStatementTest.java | 88 ++-- .../sql/calcite/BaseCalciteQueryTest.java | 110 +++-- .../druid/sql/calcite/CalciteExportTest.java | 41 +- .../sql/calcite/CalciteIngestionDmlTest.java | 43 +- .../sql/calcite/CalciteInsertDmlTest.java | 73 ++-- .../sql/calcite/CalciteJoinQueryTest.java | 24 +- .../CalciteMultiValueStringQueryTest.java | 7 +- .../calcite/CalciteNestedDataQueryTest.java | 94 ++-- .../calcite/CalciteParameterQueryTest.java | 14 +- .../druid/sql/calcite/CalciteQueryTest.java | 91 ++-- .../sql/calcite/CalciteReplaceDmlTest.java | 16 +- .../sql/calcite/CalciteSelectQueryTest.java | 5 +- .../sql/calcite/CalciteSubqueryTest.java | 10 +- .../sql/calcite/CalciteTableAppendTest.java | 24 +- .../sql/calcite/CalciteUnionQueryTest.java | 20 +- .../sql/calcite/DruidExceptionAssertions.java | 114 +++++ .../sql/calcite/IngestTableFunctionTest.java | 18 +- .../druid/sql/calcite/QueryTestRunner.java | 50 +-- .../sql/calcite/SqlTestFrameworkConfig.java | 4 +- .../parser/DruidSqlParserUtilsTest.java | 154 +++---- .../rule/DruidLogicalValuesRuleTest.java | 115 ++--- .../druid/sql/calcite/util/CalciteTests.java | 3 +- .../sql/calcite/util/QueryFrameworkUtils.java | 5 +- .../sql/calcite/util/SqlTestFramework.java | 9 +- .../sql/calcite/util/SqlTestQueryStack.java | 310 +++++++++++++ .../sql/calcite/util/TestDataBuilder.java | 5 +- .../druid/sql/http/SqlResourceTest.java | 411 +++++++++--------- 77 files changed, 2466 insertions(+), 1736 deletions(-) create mode 100644 sql/src/test/java/org/apache/druid/sql/calcite/DruidExceptionAssertions.java create mode 100644 sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestQueryStack.java diff --git a/extensions-contrib/compressed-bigdecimal/pom.xml b/extensions-contrib/compressed-bigdecimal/pom.xml index 9d5388c110ad..417bd0ccde3e 100644 --- a/extensions-contrib/compressed-bigdecimal/pom.xml +++ b/extensions-contrib/compressed-bigdecimal/pom.xml @@ -38,6 +38,21 @@ + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + org.apache.druid druid-processing @@ -63,36 +78,6 @@ - - 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 @@ -121,11 +106,6 @@ test-jar test - - org.hamcrest - hamcrest - test - com.fasterxml.jackson.core jackson-databind diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/ArrayCompressedBigDecimalTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/ArrayCompressedBigDecimalTest.java index 82e435ea21c7..a49e0bbd0e43 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/ArrayCompressedBigDecimalTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/ArrayCompressedBigDecimalTest.java @@ -21,17 +21,18 @@ import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalAggregatorFactoryBase; import org.apache.druid.java.util.common.IAE; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.math.BigInteger; import java.nio.ByteBuffer; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Unit tests for CompressedBigDecimal. @@ -171,35 +172,37 @@ public void testCompareToOptimization() d3.accumulateSum(Utils.scale(new ArrayCompressedBigDecimal(new BigDecimal(8L * Integer.MAX_VALUE)), d3.getScale())); d4.accumulateSum(Utils.scale(new ArrayCompressedBigDecimal(new BigDecimal(8L * Integer.MAX_VALUE)), d4.getScale())); - Assert.assertEquals(-1, d2.compareTo(d1, true)); - Assert.assertEquals(1, d1.compareTo(d2, true)); - Assert.assertEquals(0, d3.compareTo(d4, true)); - Assert.assertEquals(0, d4.compareTo(d3, true)); - Assert.assertEquals(-1, d1.compareTo + Assertions.assertEquals(-1, d2.compareTo(d1, true)); + Assertions.assertEquals(1, d1.compareTo(d2, true)); + Assertions.assertEquals(0, d3.compareTo(d4, true)); + Assertions.assertEquals(0, d4.compareTo(d3, true)); + Assertions.assertEquals(-1, d1.compareTo (d3, true)); - Assert.assertEquals(1, d3.compareTo(d1, true)); - Assert.assertEquals(-1, d2.compareTo(d3, true)); - Assert.assertEquals(1, d3.compareTo(d2, true)); - Assert.assertEquals(1, d5.compareTo(d2, true)); - Assert.assertEquals(-1, d2.compareTo(d5, true)); - Assert.assertEquals(-1, d5.compareTo(d3, true)); - Assert.assertEquals(1, d3.compareTo(d5, true)); + Assertions.assertEquals(1, d3.compareTo(d1, true)); + Assertions.assertEquals(-1, d2.compareTo(d3, true)); + Assertions.assertEquals(1, d3.compareTo(d2, true)); + Assertions.assertEquals(1, d5.compareTo(d2, true)); + Assertions.assertEquals(-1, d2.compareTo(d5, true)); + Assertions.assertEquals(-1, d5.compareTo(d3, true)); + Assertions.assertEquals(1, d3.compareTo(d5, true)); } - @Test(expected = IAE.class) + @Test public void testCompareToFailOptimized() { - ArrayCompressedBigDecimal d1 = ArrayCompressedBigDecimal.allocateZero( - CompressedBigDecimalAggregatorFactoryBase.DEFAULT_SIZE, - CompressedBigDecimalAggregatorFactoryBase.DEFAULT_SCALE - ); - ArrayCompressedBigDecimal d2 = ArrayCompressedBigDecimal.allocateZero( - CompressedBigDecimalAggregatorFactoryBase.DEFAULT_SIZE, - CompressedBigDecimalAggregatorFactoryBase.DEFAULT_SCALE + 1 - ); + assertThrows(IAE.class, () -> { + ArrayCompressedBigDecimal d1 = ArrayCompressedBigDecimal.allocateZero( + CompressedBigDecimalAggregatorFactoryBase.DEFAULT_SIZE, + CompressedBigDecimalAggregatorFactoryBase.DEFAULT_SCALE + ); + ArrayCompressedBigDecimal d2 = ArrayCompressedBigDecimal.allocateZero( + CompressedBigDecimalAggregatorFactoryBase.DEFAULT_SIZE, + CompressedBigDecimalAggregatorFactoryBase.DEFAULT_SCALE + 1 + ); - // size doesn't match, so an IAE will be thrown - d1.compareTo(d2, true); + // size doesn't match, so an IAE will be thrown + d1.compareTo(d2, true); + }); } @Test @@ -232,18 +235,18 @@ public void testCompareToOptimizedUnequalSizes() d3.accumulateSum(Utils.scale(new ArrayCompressedBigDecimal(new BigDecimal(8L * Integer.MAX_VALUE)), d3.getScale())); d4.accumulateSum(Utils.scale(new ArrayCompressedBigDecimal(new BigDecimal(8L * Integer.MAX_VALUE)), d4.getScale())); - Assert.assertEquals(-1, d2.compareTo(d1, true)); - Assert.assertEquals(1, d1.compareTo(d2, true)); - Assert.assertEquals(0, d3.compareTo(d4, true)); - Assert.assertEquals(0, d4.compareTo(d3, true)); - Assert.assertEquals(-1, d1.compareTo(d3, true)); - Assert.assertEquals(1, d3.compareTo(d1, true)); - Assert.assertEquals(-1, d2.compareTo(d3, true)); - Assert.assertEquals(1, d3.compareTo(d2, true)); - Assert.assertEquals(1, d5.compareTo(d2, true)); - Assert.assertEquals(-1, d2.compareTo(d5, true)); - Assert.assertEquals(-1, d5.compareTo(d3, true)); - Assert.assertEquals(1, d3.compareTo(d5, true)); + Assertions.assertEquals(-1, d2.compareTo(d1, true)); + Assertions.assertEquals(1, d1.compareTo(d2, true)); + Assertions.assertEquals(0, d3.compareTo(d4, true)); + Assertions.assertEquals(0, d4.compareTo(d3, true)); + Assertions.assertEquals(-1, d1.compareTo(d3, true)); + Assertions.assertEquals(1, d3.compareTo(d1, true)); + Assertions.assertEquals(-1, d2.compareTo(d3, true)); + Assertions.assertEquals(1, d3.compareTo(d2, true)); + Assertions.assertEquals(1, d5.compareTo(d2, true)); + Assertions.assertEquals(-1, d2.compareTo(d5, true)); + Assertions.assertEquals(-1, d5.compareTo(d3, true)); + Assertions.assertEquals(1, d3.compareTo(d5, true)); } @Test @@ -255,10 +258,10 @@ public void testCompareToOverflow() CompressedBigDecimal negativeOne = ArrayCompressedBigDecimal.wrap(new int[]{-1, -1}, 0); // compareTo skips subtraction in overflow cases - Assert.assertEquals(1, maxPositive.compareTo(minNegative)); - Assert.assertEquals(-1, minNegative.compareTo(maxPositive)); - Assert.assertEquals(1, maxPositive.compareTo(negativeOne)); - Assert.assertEquals(-1, minNegative.compareTo(one)); + Assertions.assertEquals(1, maxPositive.compareTo(minNegative)); + Assertions.assertEquals(-1, minNegative.compareTo(maxPositive)); + Assertions.assertEquals(1, maxPositive.compareTo(negativeOne)); + Assertions.assertEquals(-1, minNegative.compareTo(one)); } /** @@ -438,25 +441,29 @@ public void testUnevenAccumulateOverflow() /** * Test method for {@link ArrayCompressedBigDecimal#accumulateSum(CompressedBigDecimal)}. */ - @Test(expected = IllegalArgumentException.class) + @Test public void testUnevenAccumulateOverflowWithTruncate() { - ArrayCompressedBigDecimal bd = ArrayCompressedBigDecimal.wrap(new int[]{Integer.MAX_VALUE}, 0); + assertThrows(IllegalArgumentException.class, () -> { + ArrayCompressedBigDecimal bd = ArrayCompressedBigDecimal.wrap(new int[]{Integer.MAX_VALUE}, 0); - ArrayCompressedBigDecimal add = ArrayCompressedBigDecimal.wrap(new int[]{1, 1}, 0); + ArrayCompressedBigDecimal add = ArrayCompressedBigDecimal.wrap(new int[]{1, 1}, 0); - bd.accumulateSum(add); + bd.accumulateSum(add); + }); } /** * Test method for {@link ArrayCompressedBigDecimal#accumulateSum(CompressedBigDecimal)}. */ - @Test(expected = IllegalArgumentException.class) + @Test public void testAccumulateSumScaleMismatch() { - ArrayCompressedBigDecimal bd = ArrayCompressedBigDecimal.allocateZero(2, 1); - ArrayCompressedBigDecimal add = new ArrayCompressedBigDecimal(1, 0); - bd.accumulateSum(add); + assertThrows(IllegalArgumentException.class, () -> { + ArrayCompressedBigDecimal bd = ArrayCompressedBigDecimal.allocateZero(2, 1); + ArrayCompressedBigDecimal add = new ArrayCompressedBigDecimal(1, 0); + bd.accumulateSum(add); + }); } /** @@ -524,22 +531,26 @@ public void testCopyToBuffer() /** * Test method for {@link Utils#accumulateSum(ByteBuffer, int, int, int, CompressedBigDecimal)} */ - @Test(expected = IllegalArgumentException.class) + @Test public void testUtilsAccumulateSumByteBuf() { - ByteBuffer buf = ByteBuffer.allocate(4); - Utils.accumulateSum(buf, 0, 1, 2, new ArrayCompressedBigDecimal(new BigDecimal(Long.MAX_VALUE))); + assertThrows(IllegalArgumentException.class, () -> { + ByteBuffer buf = ByteBuffer.allocate(4); + Utils.accumulateSum(buf, 0, 1, 2, new ArrayCompressedBigDecimal(new BigDecimal(Long.MAX_VALUE))); + }); } /** * Test method for {@link Utils#accumulateSum(CompressedBigDecimal, long, int)} */ - @Test(expected = IllegalArgumentException.class) + @Test public void testUtilsAccumulateSumCbdWithExeception() { - BigDecimal bd = new BigDecimal(new BigInteger("1")); - ArrayCompressedBigDecimal d = new ArrayCompressedBigDecimal(bd); - Utils.accumulateSum(d, 0L, 1); + assertThrows(IllegalArgumentException.class, () -> { + BigDecimal bd = new BigDecimal(new BigInteger("1")); + ArrayCompressedBigDecimal d = new ArrayCompressedBigDecimal(bd); + Utils.accumulateSum(d, 0L, 1); + }); } /** @@ -565,7 +576,7 @@ public void testScaleDown() { CompressedBigDecimal bd = new ArrayCompressedBigDecimal(new BigDecimal("1.1234567890")); CompressedBigDecimal scaled = Utils.scale(bd, 9); - Assert.assertEquals("1.123456789", scaled.toString()); + Assertions.assertEquals("1.123456789", scaled.toString()); } /** @@ -595,7 +606,7 @@ public void testSetMinValue() ArrayCompressedBigDecimal bd = ArrayCompressedBigDecimal.allocateZero(2, 0); bd.setMinValue(); - Assert.assertEquals("-9223372036854775808", bd.toString()); + Assertions.assertEquals("-9223372036854775808", bd.toString()); } @Test @@ -604,7 +615,7 @@ public void testSetMaxValue() ArrayCompressedBigDecimal bd = ArrayCompressedBigDecimal.allocateZero(2, 0); bd.setMaxValue(); - Assert.assertEquals("9223372036854775807", bd.toString()); + Assertions.assertEquals("9223372036854775807", bd.toString()); } @Test @@ -618,13 +629,13 @@ public void testAccumulateMaxInteger() ArrayCompressedBigDecimal bd4 = new ArrayCompressedBigDecimal(new BigDecimal(Integer.MAX_VALUE)); bdBase.accumulateMax(bd1); - Assert.assertEquals(Long.toString(Long.MIN_VALUE), bdBase.toString()); + Assertions.assertEquals(Long.toString(Long.MIN_VALUE), bdBase.toString()); bdBase.accumulateMax(bd2); - Assert.assertEquals("-1", bdBase.toString()); + Assertions.assertEquals("-1", bdBase.toString()); bdBase.accumulateMax(bd3); - Assert.assertEquals(Long.toString(Long.MAX_VALUE), bdBase.toString()); + Assertions.assertEquals(Long.toString(Long.MAX_VALUE), bdBase.toString()); bdBase.accumulateMax(bd4); - Assert.assertEquals(Long.toString(Long.MAX_VALUE), bdBase.toString()); + Assertions.assertEquals(Long.toString(Long.MAX_VALUE), bdBase.toString()); } @Test @@ -642,20 +653,20 @@ public void testAccumulateMinInteger() ArrayCompressedBigDecimal bd7 = ArrayCompressedBigDecimal.wrap(new int[]{0, 0, 0, 0, 0, 1}, 0); bdBase.accumulateMin(bd1); - Assert.assertEquals("-1", bdBase.toString()); + Assertions.assertEquals("-1", bdBase.toString()); bdBase.accumulateMin(bd2); - Assert.assertEquals("-1", bdBase.toString()); + Assertions.assertEquals("-1", bdBase.toString()); bdBase.accumulateMin(bd3); - Assert.assertEquals("-1", bdBase.toString()); + Assertions.assertEquals("-1", bdBase.toString()); bdBase.accumulateMin(bd4); - Assert.assertEquals(Integer.toString(Integer.MIN_VALUE), bdBase.toString()); + Assertions.assertEquals(Integer.toString(Integer.MIN_VALUE), bdBase.toString()); bdBase.accumulateMin(bd5); - Assert.assertEquals(Long.toString(Long.MIN_VALUE), bdBase.toString()); + Assertions.assertEquals(Long.toString(Long.MIN_VALUE), bdBase.toString()); // smallest possible 6-int[] number bdBase.accumulateMin(bd6); - Assert.assertEquals("-3138550867693340381917894711603833208051177722232017256448", bdBase.toString()); + Assertions.assertEquals("-3138550867693340381917894711603833208051177722232017256448", bdBase.toString()); // this tests that we don't do the subtraction and overflow bdBase.accumulateMin(bd7); - Assert.assertEquals("-3138550867693340381917894711603833208051177722232017256448", bdBase.toString()); + Assertions.assertEquals("-3138550867693340381917894711603833208051177722232017256448", bdBase.toString()); } } diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/ByteBufferCompressedBigDecimalTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/ByteBufferCompressedBigDecimalTest.java index dfa1c1b46048..45ee3086537d 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/ByteBufferCompressedBigDecimalTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/ByteBufferCompressedBigDecimalTest.java @@ -19,8 +19,8 @@ package org.apache.druid.compressedbigdecimal; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.nio.ByteBuffer; @@ -83,6 +83,6 @@ public void testBufferValue(String expectedValue) SCALE ); - Assert.assertEquals(expectedValue, compressedBigDecimal.toString()); + Assertions.assertEquals(expectedValue, compressedBigDecimal.toString()); } } diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalCachingTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalCachingTest.java index 305e28a3e999..bf26e221c41f 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalCachingTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalCachingTest.java @@ -23,8 +23,8 @@ import org.apache.druid.compressedbigdecimal.aggregator.min.CompressedBigDecimalMinAggregatorFactory; import org.apache.druid.compressedbigdecimal.aggregator.sum.CompressedBigDecimalSumAggregatorFactory; import org.apache.druid.query.aggregation.AggregatorFactory; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.util.Base64; import java.util.HashMap; @@ -70,6 +70,6 @@ public void testCrossFactory() cache.put(Base64.getEncoder().encodeToString(aggregatorFactory2.getCacheKey()), FLAG); cache.put(Base64.getEncoder().encodeToString(aggregatorFactory3.getCacheKey()), FLAG); - Assert.assertEquals(3, cache.size()); + Assertions.assertEquals(3, cache.size()); } } diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalColumnTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalColumnTest.java index d9a3f6e97141..b0eb2faafac9 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalColumnTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalColumnTest.java @@ -23,8 +23,8 @@ import org.apache.druid.segment.data.ColumnarMultiInts; import org.apache.druid.segment.data.ReadableOffset; import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class CompressedBigDecimalColumnTest { @@ -39,13 +39,13 @@ public void testCompressedBigDecimalColumn() columnarInts, columnarMultiInts ); - Assert.assertEquals( + Assertions.assertEquals( CompressedBigDecimalModule.COMPRESSED_BIG_DECIMAL, compressedBigDecimalColumn.getTypeName() ); - Assert.assertEquals(12345, compressedBigDecimalColumn.getLength()); - Assert.assertEquals(CompressedBigDecimalColumn.class, compressedBigDecimalColumn.getClazz()); - Assert.assertNotNull(compressedBigDecimalColumn.makeColumnValueSelector(readableOffset)); + Assertions.assertEquals(12345, compressedBigDecimalColumn.getLength()); + Assertions.assertEquals(CompressedBigDecimalColumn.class, compressedBigDecimalColumn.getClazz()); + Assertions.assertNotNull(compressedBigDecimalColumn.makeColumnValueSelector(readableOffset)); } } diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalFactoryTestBase.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalFactoryTestBase.java index ab17224a6e38..8cd93c5f6135 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalFactoryTestBase.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalFactoryTestBase.java @@ -28,8 +28,8 @@ import org.apache.druid.query.aggregation.AggregatorFactory; import org.apache.druid.query.aggregation.BufferAggregator; import org.apache.druid.segment.selector.TestColumnValueSelector; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.math.BigDecimal; @@ -61,25 +61,25 @@ public abstract class CompressedBigDecimalFactoryTestBase @Test public abstract void testCompressedBigDecimalAggregateCombinerGetObject(); - @Test(expected = UnsupportedOperationException.class) + @Test public abstract void testCompressedBigDecimalAggregateCombinerGetLong(); - @Test(expected = UnsupportedOperationException.class) + @Test public abstract void testCompressedBigDecimalAggregateCombinerGetFloat(); - @Test(expected = UnsupportedOperationException.class) + @Test public abstract void testCompressedBigDecimalAggregateCombinerGetDouble(); - @Test(expected = UnsupportedOperationException.class) + @Test public abstract void testCompressedBigDecimalAggregatorGetFloat(); - @Test(expected = UnsupportedOperationException.class) + @Test public abstract void testCompressedBigDecimalAggregatorGetLong(); - @Test(expected = UnsupportedOperationException.class) + @Test public abstract void testCompressedBigDecimalBufferAggregatorGetFloat(); - @Test(expected = UnsupportedOperationException.class) + @Test public abstract void testCompressedBigDecimalBufferAggregatorGetLong(); @Test @@ -99,7 +99,7 @@ protected void testJsonSerializeHelper(Class clazz, T aggregatorFactory) String jsonString = objectMapper.writeValueAsString(aggregatorFactory); T deserializedAggregatorFactory = objectMapper.readValue(jsonString, clazz); - Assert.assertEquals(aggregatorFactory, deserializedAggregatorFactory); + Assertions.assertEquals(aggregatorFactory, deserializedAggregatorFactory); } @SuppressWarnings("ConstantConditions") @@ -109,42 +109,42 @@ protected void testFinalizeComputationHelper(AggregatorFactory aggregatorFactory new ArrayCompressedBigDecimal(new BigDecimal("100.3141592")) ); - Assert.assertEquals("100.3141592", result1.toString()); + Assertions.assertEquals("100.3141592", result1.toString()); ArrayCompressedBigDecimal result2 = (ArrayCompressedBigDecimal) aggregatorFactory.finalizeComputation( new ArrayCompressedBigDecimal(new BigDecimal("0.000000000")) ); - Assert.assertEquals("0", result2.toString()); + Assertions.assertEquals("0", result2.toString()); Object result3 = aggregatorFactory.finalizeComputation(null); - Assert.assertNull(result3); + Assertions.assertNull(result3); ArrayCompressedBigDecimal result4 = (ArrayCompressedBigDecimal) aggregatorFactory.finalizeComputation( new ArrayCompressedBigDecimal(new BigDecimal("1.000000000")) ); - Assert.assertEquals("1.000000000", result4.toString()); + Assertions.assertEquals("1.000000000", result4.toString()); } protected void testCompressedBigDecimalAggregatorFactoryDeserializeHelper(AggregatorFactory aggregatorFactory) { CompressedBigDecimal compressedBigDecimal = (CompressedBigDecimal) aggregatorFactory.deserialize(5); - Assert.assertEquals("5", compressedBigDecimal.toString()); + Assertions.assertEquals("5", compressedBigDecimal.toString()); } protected void testCompressedBigDecimalBufferAggregatorGetFloatHelper(BufferAggregator aggregator) { ByteBuffer byteBuffer = ByteBuffer.allocate(10); - aggregator.getFloat(byteBuffer, 0); + Assertions.assertThrows(UnsupportedOperationException.class, () -> aggregator.getFloat(byteBuffer, 0)); } protected void testCompressedBigDecimalBufferAggregatorGetLongHelper(BufferAggregator aggregator) { ByteBuffer byteBuffer = ByteBuffer.allocate(10); - aggregator.getLong(byteBuffer, 0); + Assertions.assertThrows(UnsupportedOperationException.class, () -> aggregator.getLong(byteBuffer, 0)); } protected void testCombinerResetHelper(AggregateCombiner combiner) @@ -156,7 +156,7 @@ protected void testCombinerResetHelper(AggregateCombiner combiner) columnValueSelector.advance(); combiner.reset(columnValueSelector); - Assert.assertEquals("67", combiner.getObject().toString()); + Assertions.assertEquals("67", combiner.getObject().toString()); } protected void testCombinerFoldHelper(AggregateCombiner combiner, String result1, String result2) @@ -171,41 +171,41 @@ protected void testCombinerFoldHelper(AggregateCombiner combiner, String columnValueSelector.advance(); combiner.fold(columnValueSelector); - Assert.assertEquals(result1, combiner.getObject().toString()); + Assertions.assertEquals(result1, combiner.getObject().toString()); columnValueSelector.advance(); combiner.fold(columnValueSelector); - Assert.assertEquals(result2, combiner.getObject().toString()); + Assertions.assertEquals(result2, combiner.getObject().toString()); } protected void testCompressedBigDecimalAggregateCombinerGetObjectHelper(AggregateCombiner combiner) { T compressedBigDecimal = combiner.getObject(); - Assert.assertSame(null, compressedBigDecimal); + Assertions.assertSame(null, compressedBigDecimal); } protected void testCompressedBigDecimalAggregateCombinerGetLongHelper(AggregateCombiner combiner) { - combiner.getLong(); + Assertions.assertThrows(UnsupportedOperationException.class, combiner::getLong); } protected void testCompressedBigDecimalAggregateCombinerGetFloatHelper(AggregateCombiner combiner) { - combiner.getFloat(); + Assertions.assertThrows(UnsupportedOperationException.class, combiner::getFloat); } protected void testCompressedBigDecimalAggregateCombinerGetDoubleHelper(AggregateCombiner combiner) { - combiner.getDouble(); + Assertions.assertThrows(UnsupportedOperationException.class, combiner::getDouble); } protected void testCompressedBigDecimalAggregatorGetFloatHelper(Aggregator aggregator) { - aggregator.getFloat(); + Assertions.assertThrows(UnsupportedOperationException.class, aggregator::getFloat); } protected void testCompressedBigDecimalAggregatorGetLongHelper(Aggregator aggregator) { - aggregator.getLong(); + Assertions.assertThrows(UnsupportedOperationException.class, aggregator::getLong); } /** @@ -214,7 +214,7 @@ protected void testCompressedBigDecimalAggregatorGetLongHelper(Aggregator aggreg */ protected void testCacheKeyEqualityHelper(CompressedBigDecimalAggregatorFactoryCreator factoryCreator) { - Assert.assertEquals( + Assertions.assertEquals( Base64.getEncoder().encodeToString( factoryCreator.create( "name1", @@ -234,7 +234,7 @@ protected void testCacheKeyEqualityHelper(CompressedBigDecimalAggregatorFactoryC ).getCacheKey() ) ); - Assert.assertNotEquals( + Assertions.assertNotEquals( Base64.getEncoder().encodeToString( factoryCreator.create( "name1", @@ -254,7 +254,7 @@ protected void testCacheKeyEqualityHelper(CompressedBigDecimalAggregatorFactoryC ).getCacheKey() ) ); - Assert.assertNotEquals( + Assertions.assertNotEquals( Base64.getEncoder().encodeToString( factoryCreator.create( "name1", @@ -274,7 +274,7 @@ protected void testCacheKeyEqualityHelper(CompressedBigDecimalAggregatorFactoryC ).getCacheKey() ) ); - Assert.assertNotEquals( + Assertions.assertNotEquals( Base64.getEncoder().encodeToString( factoryCreator.create( "name1", @@ -294,7 +294,7 @@ protected void testCacheKeyEqualityHelper(CompressedBigDecimalAggregatorFactoryC ).getCacheKey() ) ); - Assert.assertNotEquals( + Assertions.assertNotEquals( Base64.getEncoder().encodeToString( factoryCreator.create( "name1", diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMaxFactoryTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMaxFactoryTest.java index e3dbdc258a02..3bc43e58a135 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMaxFactoryTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMaxFactoryTest.java @@ -25,8 +25,8 @@ import org.apache.druid.compressedbigdecimal.aggregator.max.CompressedBigDecimalMaxBufferAggregator; import org.apache.druid.segment.ColumnValueSelector; import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.math.BigDecimal; @@ -44,19 +44,19 @@ public void testCompressedBigDecimalMaxAggregatorFactory() 0, false ); - Assert.assertEquals( + Assertions.assertEquals( "CompressedBigDecimalMaxAggregatorFactory{name='name', type='COMPLEX', fieldName='fieldName', requiredFields='[fieldName]', size='9', scale='0', strictNumberParsing='false'}", aggregatorFactory.toString() ); - Assert.assertNotNull(aggregatorFactory.getCacheKey()); - Assert.assertNull(aggregatorFactory.deserialize(null)); - Assert.assertEquals("5", aggregatorFactory.deserialize(new BigDecimal(5)).toString()); - Assert.assertEquals("5.0", aggregatorFactory.deserialize(5d).toString()); - Assert.assertEquals("5", aggregatorFactory.deserialize("5").toString()); - Assert.assertNull(aggregatorFactory.combine(null, null)); - Assert.assertEquals("4", aggregatorFactory.combine(new BigDecimal(4), null).toString()); - Assert.assertEquals("4", aggregatorFactory.combine(null, new BigDecimal(4)).toString()); - Assert.assertEquals( + Assertions.assertNotNull(aggregatorFactory.getCacheKey()); + Assertions.assertNull(aggregatorFactory.deserialize(null)); + Assertions.assertEquals("5", aggregatorFactory.deserialize(new BigDecimal(5)).toString()); + Assertions.assertEquals("5.0", aggregatorFactory.deserialize(5d).toString()); + Assertions.assertEquals("5", aggregatorFactory.deserialize("5").toString()); + Assertions.assertNull(aggregatorFactory.combine(null, null)); + Assertions.assertEquals("4", aggregatorFactory.combine(new BigDecimal(4), null).toString()); + Assertions.assertEquals("4", aggregatorFactory.combine(null, new BigDecimal(4)).toString()); + Assertions.assertEquals( "-4", aggregatorFactory.combine( new ArrayCompressedBigDecimal(new BigDecimal(-4)), @@ -111,6 +111,7 @@ public void testCompressedBigDecimalAggregatorFactoryDeserialize() } @Override + @Test public void testCompressedBigDecimalBufferAggregatorGetFloat() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -125,6 +126,7 @@ public void testCompressedBigDecimalBufferAggregatorGetFloat() } @Override + @Test public void testCompressedBigDecimalBufferAggregatorGetLong() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -166,6 +168,7 @@ public void testCompressedBigDecimalAggregateCombinerGetObject() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetLong() { CompressedBigDecimalMaxAggregateCombiner combiner = new CompressedBigDecimalMaxAggregateCombiner(); @@ -174,6 +177,7 @@ public void testCompressedBigDecimalAggregateCombinerGetLong() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetFloat() { CompressedBigDecimalMaxAggregateCombiner combiner = new CompressedBigDecimalMaxAggregateCombiner(); @@ -182,6 +186,7 @@ public void testCompressedBigDecimalAggregateCombinerGetFloat() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetDouble() { CompressedBigDecimalMaxAggregateCombiner combiner = new CompressedBigDecimalMaxAggregateCombiner(); @@ -190,6 +195,7 @@ public void testCompressedBigDecimalAggregateCombinerGetDouble() } @Override + @Test public void testCompressedBigDecimalAggregatorGetFloat() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -199,6 +205,7 @@ public void testCompressedBigDecimalAggregatorGetFloat() } @Override + @Test public void testCompressedBigDecimalAggregatorGetLong() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -208,6 +215,7 @@ public void testCompressedBigDecimalAggregatorGetLong() } @Override + @Test public void testCacheKeyEquality() { testCacheKeyEqualityHelper(CompressedBigDecimalMaxAggregatorFactory::new); diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMinFactoryTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMinFactoryTest.java index b4cc8e544816..862626c2f0ba 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMinFactoryTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalMinFactoryTest.java @@ -26,8 +26,8 @@ import org.apache.druid.compressedbigdecimal.aggregator.min.CompressedBigDecimalMinBufferAggregator; import org.apache.druid.segment.ColumnValueSelector; import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.math.BigDecimal; @@ -45,21 +45,21 @@ public void testCompressedBigDecimalMinAggregatorFactory() 0, false ); - Assert.assertEquals( + Assertions.assertEquals( "CompressedBigDecimalMinAggregatorFactory{name='name', type='COMPLEX', fieldName='fieldName', requiredFields='[fieldName]', size='9', scale='0', strictNumberParsing='false'}", aggregatorFactory.toString() ); - Assert.assertNotNull(aggregatorFactory.getCacheKey()); - Assert.assertNull(aggregatorFactory.deserialize(null)); - Assert.assertEquals("5", aggregatorFactory.deserialize(new BigDecimal(5)).toString()); - Assert.assertEquals("5.0", aggregatorFactory.deserialize(5d).toString()); - Assert.assertEquals("5", aggregatorFactory.deserialize("5").toString()); + Assertions.assertNotNull(aggregatorFactory.getCacheKey()); + Assertions.assertNull(aggregatorFactory.deserialize(null)); + Assertions.assertEquals("5", aggregatorFactory.deserialize(new BigDecimal(5)).toString()); + Assertions.assertEquals("5.0", aggregatorFactory.deserialize(5d).toString()); + Assertions.assertEquals("5", aggregatorFactory.deserialize("5").toString()); // default is to initialize to - Assert.assertNull(aggregatorFactory.combine(null, null)); - Assert.assertEquals("4", aggregatorFactory.combine(new BigDecimal(4), null).toString()); - Assert.assertEquals("4", aggregatorFactory.combine(null, new BigDecimal(4)).toString()); - Assert.assertEquals( + Assertions.assertNull(aggregatorFactory.combine(null, null)); + Assertions.assertEquals("4", aggregatorFactory.combine(new BigDecimal(4), null).toString()); + Assertions.assertEquals("4", aggregatorFactory.combine(null, new BigDecimal(4)).toString()); + Assertions.assertEquals( "4", aggregatorFactory.combine( new ArrayCompressedBigDecimal(new BigDecimal(4)), @@ -114,6 +114,7 @@ public void testCompressedBigDecimalAggregatorFactoryDeserialize() } @Override + @Test public void testCompressedBigDecimalBufferAggregatorGetFloat() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -128,6 +129,7 @@ public void testCompressedBigDecimalBufferAggregatorGetFloat() } @Override + @Test public void testCompressedBigDecimalBufferAggregatorGetLong() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -169,6 +171,7 @@ public void testCompressedBigDecimalAggregateCombinerGetObject() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetLong() { CompressedBigDecimalMinAggregateCombiner combiner = new CompressedBigDecimalMinAggregateCombiner(); @@ -177,6 +180,7 @@ public void testCompressedBigDecimalAggregateCombinerGetLong() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetFloat() { CompressedBigDecimalMinAggregateCombiner combiner = new CompressedBigDecimalMinAggregateCombiner(); @@ -185,6 +189,7 @@ public void testCompressedBigDecimalAggregateCombinerGetFloat() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetDouble() { CompressedBigDecimalMinAggregateCombiner combiner = new CompressedBigDecimalMinAggregateCombiner(); @@ -193,6 +198,7 @@ public void testCompressedBigDecimalAggregateCombinerGetDouble() } @Override + @Test public void testCompressedBigDecimalAggregatorGetFloat() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -202,6 +208,7 @@ public void testCompressedBigDecimalAggregatorGetFloat() } @Override + @Test public void testCompressedBigDecimalAggregatorGetLong() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -211,6 +218,7 @@ public void testCompressedBigDecimalAggregatorGetLong() } @Override + @Test public void testCacheKeyEquality() { testCacheKeyEqualityHelper(CompressedBigDecimalMinAggregatorFactory::new); diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSumFactoryTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSumFactoryTest.java index 5998e2e11f27..2ddfb5168fa1 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSumFactoryTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/CompressedBigDecimalSumFactoryTest.java @@ -26,8 +26,8 @@ import org.apache.druid.compressedbigdecimal.aggregator.sum.CompressedBigDecimalSumBufferAggregator; import org.apache.druid.segment.ColumnValueSelector; import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.math.BigDecimal; @@ -47,20 +47,20 @@ public void testCompressedBigDecimalAggregatorFactory() 0, false ); - Assert.assertEquals( + Assertions.assertEquals( "CompressedBigDecimalSumAggregatorFactory{name='name', type='COMPLEX', fieldName='fieldName', requiredFields='[fieldName]', size='9', scale='0', strictNumberParsing='false'}", aggregatorFactory.toString() ); - Assert.assertNotNull(aggregatorFactory.getCacheKey()); - Assert.assertNull(aggregatorFactory.deserialize(null)); - Assert.assertEquals("5", aggregatorFactory.deserialize(new BigDecimal(5)).toString()); - Assert.assertEquals("5.0", aggregatorFactory.deserialize(5d).toString()); - Assert.assertEquals("5", aggregatorFactory.deserialize("5").toString()); - - Assert.assertEquals("0", aggregatorFactory.combine(null, null).toString()); - Assert.assertEquals("4", aggregatorFactory.combine(new BigDecimal(4), null).toString()); - Assert.assertEquals("4", aggregatorFactory.combine(null, new BigDecimal(4)).toString()); - Assert.assertEquals( + Assertions.assertNotNull(aggregatorFactory.getCacheKey()); + Assertions.assertNull(aggregatorFactory.deserialize(null)); + Assertions.assertEquals("5", aggregatorFactory.deserialize(new BigDecimal(5)).toString()); + Assertions.assertEquals("5.0", aggregatorFactory.deserialize(5d).toString()); + Assertions.assertEquals("5", aggregatorFactory.deserialize("5").toString()); + + Assertions.assertEquals("0", aggregatorFactory.combine(null, null).toString()); + Assertions.assertEquals("4", aggregatorFactory.combine(new BigDecimal(4), null).toString()); + Assertions.assertEquals("4", aggregatorFactory.combine(null, new BigDecimal(4)).toString()); + Assertions.assertEquals( "8", aggregatorFactory.combine( new ArrayCompressedBigDecimal(new BigDecimal(4)), @@ -70,6 +70,7 @@ public void testCompressedBigDecimalAggregatorFactory() } @Override + @Test public void testJsonSerialize() throws IOException { CompressedBigDecimalSumAggregatorFactory aggregatorFactory = new CompressedBigDecimalSumAggregatorFactory( @@ -84,6 +85,7 @@ public void testJsonSerialize() throws IOException } @Override + @Test public void testFinalizeComputation() { CompressedBigDecimalMaxAggregatorFactory aggregatorFactory = new CompressedBigDecimalMaxAggregatorFactory( @@ -98,6 +100,7 @@ public void testFinalizeComputation() } @Override + @Test public void testCompressedBigDecimalAggregatorFactoryDeserialize() { CompressedBigDecimalSumAggregatorFactory aggregatorFactory = new CompressedBigDecimalSumAggregatorFactory( @@ -112,6 +115,7 @@ public void testCompressedBigDecimalAggregatorFactoryDeserialize() } @Override + @Test public void testCompressedBigDecimalBufferAggregatorGetFloat() { ColumnValueSelector columnValueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -126,6 +130,7 @@ public void testCompressedBigDecimalBufferAggregatorGetFloat() } @Override + @Test public void testCompressedBigDecimalBufferAggregatorGetLong() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -140,6 +145,7 @@ public void testCompressedBigDecimalBufferAggregatorGetLong() } @Override + @Test public void testCombinerReset() { CompressedBigDecimalSumAggregateCombiner combiner = new CompressedBigDecimalSumAggregateCombiner(); @@ -148,6 +154,7 @@ public void testCombinerReset() } @Override + @Test public void testCombinerFold() { CompressedBigDecimalSumAggregateCombiner combiner = new CompressedBigDecimalSumAggregateCombiner(); @@ -156,6 +163,7 @@ public void testCombinerFold() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetObject() { CompressedBigDecimalSumAggregateCombiner combiner = new CompressedBigDecimalSumAggregateCombiner(); @@ -164,6 +172,7 @@ public void testCompressedBigDecimalAggregateCombinerGetObject() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetLong() { CompressedBigDecimalSumAggregateCombiner combiner = new CompressedBigDecimalSumAggregateCombiner(); @@ -172,6 +181,7 @@ public void testCompressedBigDecimalAggregateCombinerGetLong() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetFloat() { CompressedBigDecimalSumAggregateCombiner combiner = new CompressedBigDecimalSumAggregateCombiner(); @@ -180,6 +190,7 @@ public void testCompressedBigDecimalAggregateCombinerGetFloat() } @Override + @Test public void testCompressedBigDecimalAggregateCombinerGetDouble() { CompressedBigDecimalSumAggregateCombiner combiner = new CompressedBigDecimalSumAggregateCombiner(); @@ -188,6 +199,7 @@ public void testCompressedBigDecimalAggregateCombinerGetDouble() } @Override + @Test public void testCompressedBigDecimalAggregatorGetFloat() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -197,6 +209,7 @@ public void testCompressedBigDecimalAggregatorGetFloat() } @Override + @Test public void testCompressedBigDecimalAggregatorGetLong() { ColumnValueSelector valueSelector = EasyMock.createMock(ColumnValueSelector.class); @@ -206,6 +219,7 @@ public void testCompressedBigDecimalAggregatorGetLong() } @Override + @Test public void testCacheKeyEquality() { testCacheKeyEqualityHelper(CompressedBigDecimalSumAggregatorFactory::new); diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java index 908957c786ee..2e97675010e0 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java @@ -23,79 +23,118 @@ import org.apache.druid.compressedbigdecimal.CompressedBigDecimalGroupByQueryConfig; import org.apache.druid.compressedbigdecimal.CompressedBigDecimalModule; import org.apache.druid.data.input.MapBasedRow; +import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.aggregation.AggregationTestHelper; import org.apache.druid.query.groupby.GroupByQueryConfig; import org.apache.druid.query.groupby.ResultRow; -import org.hamcrest.MatcherAssert; -import org.hamcrest.collection.IsCollectionWithSize; -import org.hamcrest.collection.IsMapContaining; -import org.hamcrest.collection.IsMapWithSize; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.io.TempDir; import java.io.File; -import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.Map; import java.util.TimeZone; -@RunWith(Parameterized.class) public abstract class CompressedBigDecimalAggregatorGroupByTestBase { - private final AggregationTestHelper helper; - - @Rule - public final TemporaryFolder tempFolder = new TemporaryFolder(new File("target")); - - private final CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig; - - /** - * Constructor. - * - * @param config config object - */ - public CompressedBigDecimalAggregatorGroupByTestBase( - GroupByQueryConfig config, - CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig - ) - { - this.cbdGroupByQueryConfig = cbdGroupByQueryConfig; - CompressedBigDecimalModule module = new CompressedBigDecimalModule(); - CompressedBigDecimalModule.registerSerde(); - helper = AggregationTestHelper.createGroupByQueryAggregationTestHelper( - module.getJacksonModules(), config, tempFolder); - } + @TempDir + public File tempFolder; /** * Default setup of UTC timezone. */ - @BeforeClass + @BeforeAll public static void setupClass() { System.setProperty("user.timezone", "UTC"); } + public static List testConfigs() + { + return List.of( + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperInitialBuckets() + { + return 4; + } + + @Override + public String toString() + { + return "v2"; + } + }, + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperMaxSize() + { + return 2; + } + + @Override + public HumanReadableBytes getMaxOnDiskStorage() + { + return HumanReadableBytes.valueOf(10L * 1024 * 1024); + } + + @Override + public String toString() + { + return "v2SmallBuffer"; + } + }, + new org.apache.druid.jackson.DefaultObjectMapper().convertValue( + java.util.Map.of( + "maxSelectorDictionarySize", 20, + "maxMergingDictionarySize", 400, + "maxOnDiskStorage", 10L * 1024 * 1024 + ), + GroupByQueryConfig.class + ), + new GroupByQueryConfig() + { + @Override + public int getNumParallelCombineThreads() + { + return 2; + } + + @Override + public String toString() + { + return "v2ParallelCombine"; + } + } + ); + } + /** * ingetion method for all groupBy query. * * @throws IOException IOException * @throws Exception Exception */ - @Test - public void testIngestAndGroupByAllQuery() throws IOException, Exception + protected void testIngestAndGroupByAllQuery( + GroupByQueryConfig config, + CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig + ) throws Exception { + final CompressedBigDecimalModule module = new CompressedBigDecimalModule(); + CompressedBigDecimalModule.registerSerde(); + final AggregationTestHelper helper = AggregationTestHelper.createGroupByQueryAggregationTestHelperWithTempDir( + module.getJacksonModules(), config, tempFolder + ); Sequence seq = helper.createIndexAndRunQueryOnSegment( this.getClass().getResourceAsStream("/" + "bd_test_data.csv"), CompressedBigDecimalAggregatorTimeseriesTestBase.SCHEMA, @@ -108,37 +147,28 @@ public void testIngestAndGroupByAllQuery() throws IOException, Exception ); List results = seq.toList(); - MatcherAssert.assertThat(results, IsCollectionWithSize.hasSize(1)); + Assertions.assertEquals(1, results.size()); ResultRow row = results.get(0); MapBasedRow mapBasedRow = row.toMapBasedRow(cbdGroupByQueryConfig.getQuery()); Map event = mapBasedRow.getEvent(); - Assert.assertEquals( + Assertions.assertEquals( new DateTime("2017-01-01T00:00:00Z", DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))), mapBasedRow.getTimestamp() ); - MatcherAssert.assertThat(event, IsMapWithSize.aMapWithSize(3)); - MatcherAssert.assertThat( - event, - IsMapContaining.hasEntry( - "cbdRevenueFromString", - new ArrayCompressedBigDecimal(new BigDecimal(cbdGroupByQueryConfig.getStringRevenue())) - ) + Assertions.assertEquals(3, event.size()); + Assertions.assertEquals( + new ArrayCompressedBigDecimal(new BigDecimal(cbdGroupByQueryConfig.getStringRevenue())), + event.get("cbdRevenueFromString") ); // long conversion of 5000000000.000000005 results in null/0 value - MatcherAssert.assertThat( - event, - IsMapContaining.hasEntry( - "cbdRevenueFromLong", - new ArrayCompressedBigDecimal(new BigDecimal(cbdGroupByQueryConfig.getLongRevenue())) - ) + Assertions.assertEquals( + new ArrayCompressedBigDecimal(new BigDecimal(cbdGroupByQueryConfig.getLongRevenue())), + event.get("cbdRevenueFromLong") ); // double input changes 5000000000.000000005 to 5000000000.5 to fit in double mantissa space - MatcherAssert.assertThat( - event, - IsMapContaining.hasEntry( - "cbdRevenueFromDouble", - new ArrayCompressedBigDecimal(new BigDecimal(cbdGroupByQueryConfig.getDoubleRevenue())) - ) + Assertions.assertEquals( + new ArrayCompressedBigDecimal(new BigDecimal(cbdGroupByQueryConfig.getDoubleRevenue())), + event.get("cbdRevenueFromDouble") ); } } diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorTestBase.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorTestBase.java index b35e55210fe4..88d8dfc9e334 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorTestBase.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorTestBase.java @@ -20,8 +20,8 @@ package org.apache.druid.compressedbigdecimal.aggregator; import org.apache.druid.query.aggregation.Aggregator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public abstract class CompressedBigDecimalAggregatorTestBase { @@ -30,6 +30,6 @@ public abstract class CompressedBigDecimalAggregatorTestBase protected void testNoDataHelper(Aggregator aggregator, Object expectedValue) { - Assert.assertEquals(expectedValue, aggregator.get()); + Assertions.assertEquals(expectedValue, aggregator.get()); } } diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorTimeseriesTestBase.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorTimeseriesTestBase.java index f9f2073622d5..532b3c35b349 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorTimeseriesTestBase.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorTimeseriesTestBase.java @@ -31,6 +31,7 @@ import org.apache.druid.data.input.impl.LongDimensionSchema; import org.apache.druid.data.input.impl.StringDimensionSchema; import org.apache.druid.data.input.impl.TimestampSpec; +import org.apache.druid.java.util.common.FileUtils; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.Result; @@ -41,10 +42,10 @@ import org.apache.druid.testing.InitializedNullHandlingTest; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +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.math.BigDecimal; @@ -53,10 +54,7 @@ import java.util.Map; import java.util.TimeZone; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsMapContaining.hasEntry; -import static org.hamcrest.collection.IsMapWithSize.aMapWithSize; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public abstract class CompressedBigDecimalAggregatorTimeseriesTestBase extends InitializedNullHandlingTest { @@ -90,27 +88,25 @@ public abstract class CompressedBigDecimalAggregatorTimeseriesTestBase extends I null ); - private final AggregationTestHelper helper; + private AggregationTestHelper helper; - @Rule - public final TemporaryFolder tempFolder = new TemporaryFolder(new File("target")); + @TempDir + public File tempFolder; - /** - * Constructor. - * * - */ - public CompressedBigDecimalAggregatorTimeseriesTestBase() + @BeforeEach + public void setUp() { - CompressedBigDecimalModule module = new CompressedBigDecimalModule(); + final CompressedBigDecimalModule module = new CompressedBigDecimalModule(); CompressedBigDecimalModule.registerSerde(); - helper = AggregationTestHelper.createTimeseriesQueryAggregationTestHelper( - module.getJacksonModules(), tempFolder); + helper = AggregationTestHelper.createTimeseriesQueryAggregationTestHelperWithTempDir( + module.getJacksonModules(), tempFolder + ); } /** * Default setup of UTC timezone. */ - @BeforeClass + @BeforeAll public static void setupClass() { System.setProperty("user.timezone", "UTC"); @@ -143,10 +139,10 @@ protected void testIngestAndTimeseriesQueryHelper( new DateTime("2017-01-01T00:00:00Z", DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))), ((Result) Iterables.getOnlyElement(seq.toList())).getTimestamp() ); - assertThat(event, aMapWithSize(1)); - assertThat( - event, - hasEntry("cbdStringRevenue", new ArrayCompressedBigDecimal(new BigDecimal(expected))) + assertEquals(1, event.size()); + assertEquals( + new ArrayCompressedBigDecimal(new BigDecimal(expected)), + event.get("cbdStringRevenue") ); } @@ -164,7 +160,8 @@ protected void testIngestMultipleSegmentsAndTimeseriesQueryHelper( String expected ) throws Exception { - File segmentDir1 = tempFolder.newFolder(); + final File segmentDir1 = new File(tempFolder, "segment1"); + FileUtils.mkdirp(segmentDir1); helper.createIndex( new File(this.getClass().getResource("/" + "bd_test_data.csv").getFile()), SCHEMA, @@ -175,7 +172,8 @@ protected void testIngestMultipleSegmentsAndTimeseriesQueryHelper( Granularities.NONE, 5 ); - File segmentDir2 = tempFolder.newFolder(); + final File segmentDir2 = new File(tempFolder, "segment2"); + FileUtils.mkdirp(segmentDir2); helper.createIndex( new File(this.getClass().getResource("/" + "bd_test_zero_data.csv").getFile()), SCHEMA, @@ -198,11 +196,10 @@ protected void testIngestMultipleSegmentsAndTimeseriesQueryHelper( new DateTime("2017-01-01T00:00:00Z", DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))), ((Result) Iterables.getOnlyElement(seq.toList())).getTimestamp() ); - assertThat(event, aMapWithSize(1)); - assertThat( - event, - hasEntry("cbdStringRevenue", new ArrayCompressedBigDecimal(new BigDecimal(expected))) + assertEquals(1, event.size()); + assertEquals( + new ArrayCompressedBigDecimal(new BigDecimal(expected)), + event.get("cbdStringRevenue") ); - } } diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java index e34ee644b3ae..47bac7d0bd3e 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java @@ -24,8 +24,8 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; -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.Collection; @@ -34,12 +34,14 @@ public class CompressedBigDecimalMaxAggregatorGroupByTest extends CompressedBigDecimalAggregatorGroupByTestBase { - public CompressedBigDecimalMaxAggregatorGroupByTest( + @ParameterizedTest + @MethodSource("constructorFeeder") + public void testIngestAndGroupByAllQuery( GroupByQueryConfig config, CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig - ) + ) throws Exception { - super(config, cbdGroupByQueryConfig); + super.testIngestAndGroupByAllQuery(config, cbdGroupByQueryConfig); } /** @@ -47,7 +49,6 @@ public CompressedBigDecimalMaxAggregatorGroupByTest( * * @return constructors */ - @Parameterized.Parameters(name = "{0}") public static Collection constructorFeeder() { List constructors = new ArrayList<>(); @@ -67,7 +68,7 @@ public static Collection constructorFeeder() "9999999999.000000000", "9999999999.000000000" ); - for (GroupByQueryConfig config : GroupByQueryRunnerTest.testConfigs()) { + for (GroupByQueryConfig config : testConfigs()) { constructors.add(new Object[]{config, cbdGroupByQueryConfig}); } return constructors; diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorTest.java index d4839c83054f..90422df17bf6 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorTest.java @@ -22,10 +22,12 @@ import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalAggregatorTestBase; import org.apache.druid.segment.ColumnValueSelector; import org.easymock.EasyMock; +import org.junit.jupiter.api.Test; public class CompressedBigDecimalMaxAggregatorTest extends CompressedBigDecimalAggregatorTestBase { @Override + @Test public void testNoData() { CompressedBigDecimalMaxAggregator aggregator = new CompressedBigDecimalMaxAggregator( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorTimeseriesTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorTimeseriesTest.java index e084dcde6a0d..c2b8333cecf0 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorTimeseriesTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorTimeseriesTest.java @@ -25,6 +25,7 @@ import org.apache.druid.query.filter.NotDimFilter; import org.apache.druid.query.filter.SelectorDimFilter; import org.apache.druid.query.timeseries.TimeseriesQuery; +import org.junit.jupiter.api.Test; import java.util.List; @@ -39,6 +40,7 @@ public class CompressedBigDecimalMaxAggregatorTimeseriesTest extends CompressedB .build(); @Override + @Test public void testIngestAndTimeseriesQuery() throws Exception { testIngestAndTimeseriesQueryHelper( @@ -49,6 +51,7 @@ public void testIngestAndTimeseriesQuery() throws Exception } @Override + @Test public void testIngestMultipleSegmentsAndTimeseriesQuery() throws Exception { testIngestMultipleSegmentsAndTimeseriesQueryHelper( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java index 86d126583af0..daad3f7f82c9 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java @@ -24,24 +24,24 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; -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.Collection; import java.util.List; -@RunWith(Parameterized.class) public class CompressedBigDecimalMinAggregatorGroupByTest extends CompressedBigDecimalAggregatorGroupByTestBase { - public CompressedBigDecimalMinAggregatorGroupByTest( + @ParameterizedTest + @MethodSource("constructorFeeder") + public void testIngestAndGroupByAllQuery( GroupByQueryConfig config, CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig - ) + ) throws Exception { - super(config, cbdGroupByQueryConfig); + super.testIngestAndGroupByAllQuery(config, cbdGroupByQueryConfig); } /** @@ -49,7 +49,6 @@ public CompressedBigDecimalMinAggregatorGroupByTest( * * @return constructors */ - @Parameterized.Parameters(name = "{0}") public static Collection constructorFeeder() { List constructors = new ArrayList<>(); @@ -69,7 +68,7 @@ public static Collection constructorFeeder() "-1.000000000", "-1.000000000" ); - for (GroupByQueryConfig config : GroupByQueryRunnerTest.testConfigs()) { + for (GroupByQueryConfig config : testConfigs()) { constructors.add(new Object[]{config, cbdGroupByQueryConfig}); } return constructors; diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorTest.java index fbf82672616d..421ce5f9e82a 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorTest.java @@ -22,10 +22,12 @@ import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalAggregatorTestBase; import org.apache.druid.segment.ColumnValueSelector; import org.easymock.EasyMock; +import org.junit.jupiter.api.Test; public class CompressedBigDecimalMinAggregatorTest extends CompressedBigDecimalAggregatorTestBase { @Override + @Test public void testNoData() { CompressedBigDecimalMinAggregator aggregator = new CompressedBigDecimalMinAggregator( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorTimeseriesTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorTimeseriesTest.java index 67914a113acd..ec56dc8360c3 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorTimeseriesTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorTimeseriesTest.java @@ -25,6 +25,7 @@ import org.apache.druid.query.filter.NotDimFilter; import org.apache.druid.query.filter.SelectorDimFilter; import org.apache.druid.query.timeseries.TimeseriesQuery; +import org.junit.jupiter.api.Test; import java.util.List; @@ -39,6 +40,7 @@ public class CompressedBigDecimalMinAggregatorTimeseriesTest extends CompressedB .build(); @Override + @Test public void testIngestAndTimeseriesQuery() throws Exception { testIngestAndTimeseriesQueryHelper( @@ -49,6 +51,7 @@ public void testIngestAndTimeseriesQuery() throws Exception } @Override + @Test public void testIngestMultipleSegmentsAndTimeseriesQuery() throws Exception { testIngestMultipleSegmentsAndTimeseriesQueryHelper( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinSqlAggregatorTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinSqlAggregatorTest.java index 693fa984aae6..0c7331eeeca1 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinSqlAggregatorTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinSqlAggregatorTest.java @@ -22,7 +22,7 @@ import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalSqlAggregatorTestBase; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; public class CompressedBigDecimalMinSqlAggregatorTest extends CompressedBigDecimalSqlAggregatorTestBase { diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java index e765497d74a8..2a3efbaa803b 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java @@ -24,8 +24,8 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; -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.Collection; @@ -34,12 +34,14 @@ public class CompressedBigDecimalSumAggregatorGroupByTest extends CompressedBigDecimalAggregatorGroupByTestBase { - public CompressedBigDecimalSumAggregatorGroupByTest( + @ParameterizedTest + @MethodSource("constructorFeeder") + public void testIngestAndGroupByAllQuery( GroupByQueryConfig config, CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig - ) + ) throws Exception { - super(config, cbdGroupByQueryConfig); + super.testIngestAndGroupByAllQuery(config, cbdGroupByQueryConfig); } /** @@ -47,7 +49,6 @@ public CompressedBigDecimalSumAggregatorGroupByTest( * * @return constructors */ - @Parameterized.Parameters(name = "{0}") public static Collection constructorFeeder() { List constructors = new ArrayList<>(); @@ -67,7 +68,7 @@ public static Collection constructorFeeder() "10000000010.000000000", "15000000010.500000000" ); - for (GroupByQueryConfig config : GroupByQueryRunnerTest.testConfigs()) { + for (GroupByQueryConfig config : testConfigs()) { constructors.add(new Object[]{config, cbdGroupByQueryConfig}); } return constructors; diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorTest.java index d90b0549aaa5..57388faaf2fc 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorTest.java @@ -23,12 +23,14 @@ import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalAggregatorTestBase; import org.apache.druid.segment.ColumnValueSelector; import org.easymock.EasyMock; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; public class CompressedBigDecimalSumAggregatorTest extends CompressedBigDecimalAggregatorTestBase { @Override + @Test public void testNoData() { CompressedBigDecimalSumAggregator aggregator = new CompressedBigDecimalSumAggregator( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorTimeseriesTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorTimeseriesTest.java index 29b11f70cf79..487a023ccc18 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorTimeseriesTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorTimeseriesTest.java @@ -25,6 +25,7 @@ import org.apache.druid.query.filter.NotDimFilter; import org.apache.druid.query.filter.SelectorDimFilter; import org.apache.druid.query.timeseries.TimeseriesQuery; +import org.junit.jupiter.api.Test; import java.util.List; @@ -39,6 +40,7 @@ public class CompressedBigDecimalSumAggregatorTimeseriesTest extends CompressedB .build(); @Override + @Test public void testIngestAndTimeseriesQuery() throws Exception { testIngestAndTimeseriesQueryHelper( @@ -49,6 +51,7 @@ public void testIngestAndTimeseriesQuery() throws Exception } @Override + @Test public void testIngestMultipleSegmentsAndTimeseriesQuery() throws Exception { testIngestMultipleSegmentsAndTimeseriesQueryHelper( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumSqlAggregatorTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumSqlAggregatorTest.java index 3f2bc448b554..1f1973a157ab 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumSqlAggregatorTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumSqlAggregatorTest.java @@ -22,7 +22,7 @@ import org.apache.druid.compressedbigdecimal.aggregator.CompressedBigDecimalSqlAggregatorTestBase; import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; public class CompressedBigDecimalSumSqlAggregatorTest extends CompressedBigDecimalSqlAggregatorTestBase { diff --git a/extensions-contrib/druid-exact-count-bitmap/pom.xml b/extensions-contrib/druid-exact-count-bitmap/pom.xml index d7470f6ea425..e137a0341962 100644 --- a/extensions-contrib/druid-exact-count-bitmap/pom.xml +++ b/extensions-contrib/druid-exact-count-bitmap/pom.xml @@ -101,13 +101,13 @@ - junit - junit + org.junit.jupiter + junit-jupiter-api test org.junit.jupiter - junit-jupiter-api + junit-jupiter-engine test @@ -136,11 +136,6 @@ test-jar test - - org.hamcrest - hamcrest - test - org.reflections reflections diff --git a/extensions-contrib/grpc-query/pom.xml b/extensions-contrib/grpc-query/pom.xml index 703c7466f0f9..6a2f70039e29 100644 --- a/extensions-contrib/grpc-query/pom.xml +++ b/extensions-contrib/grpc-query/pom.xml @@ -58,6 +58,21 @@ + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + org.apache.druid druid-server @@ -215,16 +230,6 @@ test-jar test - - junit - junit - test - - - org.junit.jupiter - junit-jupiter-api - test - org.apache.druid druid-server diff --git a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/BasicAuthTest.java b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/BasicAuthTest.java index 167bef17f54f..c5806102995c 100644 --- a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/BasicAuthTest.java +++ b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/BasicAuthTest.java @@ -34,23 +34,22 @@ import org.apache.druid.query.DefaultQueryConfig; import org.apache.druid.security.basic.authentication.BasicHTTPAuthenticator; import org.apache.druid.security.basic.authentication.validator.CredentialsValidator; -import org.apache.druid.server.QueryStackTests; import org.apache.druid.server.security.AuthConfig; import org.apache.druid.server.security.AuthenticationResult; import org.apache.druid.server.security.AuthenticatorMapper; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.SqlTestFramework; -import org.junit.Assert; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; /** * Simple test that runs the gRPC server, on top of a test SQL stack. @@ -75,7 +74,7 @@ public void setup() throws IOException plannerFixture.statementFactory(), new DefaultQueryConfig(Map.of("forbiddenKey", "system-default-value")), // system default forbidden key, only superuser can change it sqlTestFramework.queryLifecycleFactory(), - QueryStackTests.DEFAULT_NOOP_SCHEDULER + TestServer.NOOP_SCHEDULER ); CredentialsValidator validator = new CredentialsValidator() @@ -220,7 +219,7 @@ public void testAccessToForbiddenKey() assertEquals(QueryStatus.OK, response.getStatus()); } try (TestClient client = new TestClient(TestClient.DEFAULT_HOST, "regular", "pwd")) { - StatusRuntimeException e = Assert.assertThrows(StatusRuntimeException.class, () -> client.getQueryClient().submitQuery(request)); + StatusRuntimeException e = Assertions.assertThrows(StatusRuntimeException.class, () -> client.getQueryClient().submitQuery(request)); assertEquals(Status.PERMISSION_DENIED, e.getStatus()); } } diff --git a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/DriverTest.java b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/DriverTest.java index 8e2e99406a97..167a3f67af02 100644 --- a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/DriverTest.java +++ b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/DriverTest.java @@ -28,7 +28,6 @@ import org.apache.druid.grpc.proto.QueryOuterClass.QueryStatus; import org.apache.druid.grpc.server.QueryDriver; import org.apache.druid.query.DefaultQueryConfig; -import org.apache.druid.server.QueryStackTests; import org.apache.druid.server.security.AuthConfig; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; import org.apache.druid.sql.calcite.util.CalciteTests; @@ -40,9 +39,9 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DriverTest extends BaseCalciteQueryTest { @@ -61,7 +60,7 @@ public void setup() plannerFixture.statementFactory(), new DefaultQueryConfig(Map.of()), sqlTestFramework.queryLifecycleFactory(), - QueryStackTests.DEFAULT_NOOP_SCHEDULER + TestServer.NOOP_SCHEDULER ); } diff --git a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/GrpcQueryTest.java b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/GrpcQueryTest.java index 46c2df5a7b52..a152e60b59f9 100644 --- a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/GrpcQueryTest.java +++ b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/GrpcQueryTest.java @@ -35,7 +35,6 @@ import org.apache.druid.grpc.server.QueryDriver; import org.apache.druid.grpc.server.QueryServer; import org.apache.druid.query.DefaultQueryConfig; -import org.apache.druid.server.QueryStackTests; import org.apache.druid.server.security.AllowAllAuthenticator; import org.apache.druid.server.security.AuthConfig; import org.apache.druid.server.security.AuthenticatorMapper; @@ -51,9 +50,9 @@ import java.util.Map; import java.util.concurrent.Executors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Simple test that runs the gRPC server, on top of a test SQL stack. @@ -80,7 +79,7 @@ public void setup() throws IOException plannerFixture.statementFactory(), new DefaultQueryConfig(Map.of()), sqlTestFramework.queryLifecycleFactory(), - QueryStackTests.DEFAULT_NOOP_SCHEDULER + TestServer.NOOP_SCHEDULER ); AuthenticatorMapper authMapper = new AuthenticatorMapper( ImmutableMap.of( diff --git a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/TestServer.java b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/TestServer.java index faad4fa8a393..3d8cb1edbad5 100644 --- a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/TestServer.java +++ b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/TestServer.java @@ -23,7 +23,10 @@ import org.apache.druid.grpc.server.GrpcEndpointInitializer; import org.apache.druid.grpc.server.GrpcQueryConfig; import org.apache.druid.query.DefaultQueryConfig; -import org.apache.druid.server.QueryStackTests; +import org.apache.druid.server.QueryScheduler; +import org.apache.druid.server.initialization.ServerConfig; +import org.apache.druid.server.scheduling.ManualQueryPrioritizationStrategy; +import org.apache.druid.server.scheduling.NoQueryLaningStrategy; import org.apache.druid.server.security.AllowAllAuthenticator; import org.apache.druid.server.security.AuthConfig; import org.apache.druid.server.security.AuthenticatorMapper; @@ -37,6 +40,13 @@ */ public class TestServer extends BaseCalciteQueryTest { + static final QueryScheduler NOOP_SCHEDULER = new QueryScheduler( + 0, + ManualQueryPrioritizationStrategy.INSTANCE, + NoQueryLaningStrategy.INSTANCE, + new ServerConfig() + ); + private GrpcEndpointInitializer serverInit; @Test @@ -62,7 +72,7 @@ public void run() null, DefaultQueryConfig.NIL, authMapper, - QueryStackTests.DEFAULT_NOOP_SCHEDULER + NOOP_SCHEDULER ); serverInit.start(); Runtime.getRuntime().addShutdownHook(new Thread() diff --git a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/client/GrpcResponseHandlerTest.java b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/client/GrpcResponseHandlerTest.java index 1f3ba79814c4..f0d955bec60d 100644 --- a/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/client/GrpcResponseHandlerTest.java +++ b/extensions-contrib/grpc-query/src/test/java/org/apache/druid/grpc/client/GrpcResponseHandlerTest.java @@ -22,15 +22,15 @@ import com.google.protobuf.ByteString; import org.apache.druid.grpc.proto.QueryOuterClass.QueryResponse; import org.apache.druid.grpc.proto.TestResults.QueryResult; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class GrpcResponseHandlerTest { diff --git a/extensions-contrib/spectator-histogram/pom.xml b/extensions-contrib/spectator-histogram/pom.xml index e97225c13523..374885156bde 100644 --- a/extensions-contrib/spectator-histogram/pom.xml +++ b/extensions-contrib/spectator-histogram/pom.xml @@ -35,6 +35,21 @@ Druid extension for generating histograms based on Netflix's Spectator library + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + com.netflix.spectator spectator-api @@ -115,36 +130,6 @@ - - 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.reflections reflections @@ -181,5 +166,10 @@ mockito-core test + + org.mockito + mockito-junit-jupiter + test + diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/NullableOffsetsHeaderTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/NullableOffsetsHeaderTest.java index add0d88efceb..cae933ef05c4 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/NullableOffsetsHeaderTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/NullableOffsetsHeaderTest.java @@ -21,8 +21,8 @@ import com.google.common.collect.ImmutableList; import org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -42,14 +42,14 @@ public void testShouldAcceptNullWrites() throws IOException header.writeNull(); header.writeNull(); - Assert.assertEquals("Size should be count of entries", 3, header.size()); + Assertions.assertEquals(3, header.size(), "Size should be count of entries"); header = serde(header); - Assert.assertEquals("Size should be count of entries", 3, header.size()); + Assertions.assertEquals(3, header.size(), "Size should be count of entries"); - Assert.assertNull("Should return null for null entries by index", header.get(0)); - Assert.assertNull("Should return null for null entries by index", header.get(1)); - Assert.assertNull("Should return null for null entries by index", header.get(2)); + Assertions.assertNull(header.get(0), "Should return null for null entries by index"); + Assertions.assertNull(header.get(1), "Should return null for null entries by index"); + Assertions.assertNull(header.get(2), "Should return null for null entries by index"); } @Test @@ -59,18 +59,18 @@ public void testShouldAcceptOffsetWrites() throws IOException header.writeOffset(123); header.writeOffset(456); - Assert.assertEquals("Size should be count of entries", 2, header.size()); + Assertions.assertEquals(2, header.size(), "Size should be count of entries"); header = serde(header); - Assert.assertEquals("Size should be count of entries", 2, header.size()); + Assertions.assertEquals(2, header.size(), "Size should be count of entries"); - Assert.assertNotNull("Should flag nulls by index", header.get(0)); - Assert.assertNotNull("Should flag nulls by index", header.get(1)); + Assertions.assertNotNull(header.get(0), "Should flag nulls by index"); + Assertions.assertNotNull(header.get(1), "Should flag nulls by index"); - Assert.assertEquals("Should return value for entries by index", 0, header.get(0).getStart()); - Assert.assertEquals("Should return value for entries by index", 123, header.get(0).getEnd()); - Assert.assertEquals("Should return value for entries by index", 123, header.get(1).getStart()); - Assert.assertEquals("Should return value for entries by index", 456, header.get(1).getEnd()); + Assertions.assertEquals(0, header.get(0).getStart(), "Should return value for entries by index"); + Assertions.assertEquals(123, header.get(0).getEnd(), "Should return value for entries by index"); + Assertions.assertEquals(123, header.get(1).getStart(), "Should return value for entries by index"); + Assertions.assertEquals(456, header.get(1).getEnd(), "Should return value for entries by index"); } @Test @@ -84,24 +84,24 @@ public void testShouldAcceptMixedWrites() throws IOException header.writeOffset(789); header.writeNull(); - Assert.assertEquals("Size should be count of entries", 6, header.size()); + Assertions.assertEquals(6, header.size(), "Size should be count of entries"); header = serde(header); - Assert.assertEquals("Size should be count of entries", 6, header.size()); - - Assert.assertNotNull("Should flag nulls by index", header.get(0)); - Assert.assertNull("Should flag nulls by index", header.get(1)); - Assert.assertNull("Should flag nulls by index", header.get(2)); - Assert.assertNotNull("Should flag nulls by index", header.get(3)); - Assert.assertNotNull("Should flag nulls by index", header.get(4)); - Assert.assertNull("Should flag nulls by index", header.get(5)); - - Assert.assertEquals("Should return value for entries by index", 0, header.get(0).getStart()); - Assert.assertEquals("Should return value for entries by index", 123, header.get(0).getEnd()); - Assert.assertEquals("Should return value for entries by index", 123, header.get(3).getStart()); - Assert.assertEquals("Should return value for entries by index", 456, header.get(3).getEnd()); - Assert.assertEquals("Should return value for entries by index", 456, header.get(4).getStart()); - Assert.assertEquals("Should return value for entries by index", 789, header.get(4).getEnd()); + Assertions.assertEquals(6, header.size(), "Size should be count of entries"); + + Assertions.assertNotNull(header.get(0), "Should flag nulls by index"); + Assertions.assertNull(header.get(1), "Should flag nulls by index"); + Assertions.assertNull(header.get(2), "Should flag nulls by index"); + Assertions.assertNotNull(header.get(3), "Should flag nulls by index"); + Assertions.assertNotNull(header.get(4), "Should flag nulls by index"); + Assertions.assertNull(header.get(5), "Should flag nulls by index"); + + Assertions.assertEquals(0, header.get(0).getStart(), "Should return value for entries by index"); + Assertions.assertEquals(123, header.get(0).getEnd(), "Should return value for entries by index"); + Assertions.assertEquals(123, header.get(3).getStart(), "Should return value for entries by index"); + Assertions.assertEquals(456, header.get(3).getEnd(), "Should return value for entries by index"); + Assertions.assertEquals(456, header.get(4).getStart(), "Should return value for entries by index"); + Assertions.assertEquals(789, header.get(4).getEnd(), "Should return value for entries by index"); } @Test @@ -117,22 +117,22 @@ public void testGiveAccessToOffsets() throws IOException header = serde(header); - Assert.assertNull("Should return null for 6", header.get(6)); + Assertions.assertNull(header.get(6), "Should return null for 6"); - Assert.assertNull("Should return null for 5", header.get(5)); + Assertions.assertNull(header.get(5), "Should return null for 5"); - Assert.assertEquals("Offset at 4", 789, header.get(4).getEnd()); - Assert.assertEquals("Offset prior to 4", 456, header.get(4).getStart()); + Assertions.assertEquals(789, header.get(4).getEnd(), "Offset at 4"); + Assertions.assertEquals(456, header.get(4).getStart(), "Offset prior to 4"); - Assert.assertEquals("Offset at 3", 456, header.get(3).getEnd()); - Assert.assertEquals("Offset prior to 3", 123, header.get(3).getStart()); + Assertions.assertEquals(456, header.get(3).getEnd(), "Offset at 3"); + Assertions.assertEquals(123, header.get(3).getStart(), "Offset prior to 3"); - Assert.assertNull("Should return null for 2", header.get(2)); + Assertions.assertNull(header.get(2), "Should return null for 2"); - Assert.assertNull("Should return null for 1", header.get(1)); + Assertions.assertNull(header.get(1), "Should return null for 1"); - Assert.assertEquals("Offset at 0", 123, header.get(0).getEnd()); - Assert.assertEquals("Offset prior to 0", 0, header.get(0).getStart()); + Assertions.assertEquals(123, header.get(0).getEnd(), "Offset at 0"); + Assertions.assertEquals(0, header.get(0).getStart(), "Offset prior to 0"); } @Test @@ -147,13 +147,13 @@ public void testGiveAccessToSingleOffsetNulls() throws IOException header = serde(header); - Assert.assertEquals("Offset at 1", 123, header.get(1).getEnd()); - Assert.assertEquals("Offset prior to 1", 0, header.get(1).getStart()); + Assertions.assertEquals(123, header.get(1).getEnd(), "Offset at 1"); + Assertions.assertEquals(0, header.get(1).getStart(), "Offset prior to 1"); - Assert.assertNull("Nulls for anything not set", header.get(0)); - Assert.assertNull("Nulls for anything not set", header.get(-1)); - Assert.assertNull("Nulls for anything not set", header.get(3)); - Assert.assertNull("Nulls for anything not set", header.get(100)); + Assertions.assertNull(header.get(0), "Nulls for anything not set"); + Assertions.assertNull(header.get(-1), "Nulls for anything not set"); + Assertions.assertNull(header.get(3), "Nulls for anything not set"); + Assertions.assertNull(header.get(100), "Nulls for anything not set"); } @Test @@ -169,7 +169,7 @@ public void testShouldSerializeAndDeserialize() throws IOException // Length + BitmapLength + Bitmap + Offsets // 4 + 4 + 1 + 12 = 21 bytes - Assert.assertEquals("Serialized size should be minimal", 21, header.getSerializedSize()); + Assertions.assertEquals(21, header.getSerializedSize(), "Serialized size should be minimal"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final WritableByteChannel channel = Channels.newChannel(baos); @@ -177,16 +177,16 @@ public void testShouldSerializeAndDeserialize() throws IOException channel.close(); final ByteBuffer byteBuffer = ByteBuffer.wrap(baos.toByteArray()); - Assert.assertEquals( - "Reported size and actual size should match", + Assertions.assertEquals( header.getSerializedSize(), - byteBuffer.remaining() + byteBuffer.remaining(), + "Reported size and actual size should match" ); NullableOffsetsHeader deserialized = NullableOffsetsHeader.read(byteBuffer); - Assert.assertEquals(0, byteBuffer.remaining()); + Assertions.assertEquals(0, byteBuffer.remaining()); - Assert.assertEquals("Deserialized should match pre-serialized size", header.size(), deserialized.size()); + Assertions.assertEquals(header.size(), deserialized.size(), "Deserialized should match pre-serialized size"); // Nulls should return the previous offset List expected = Arrays.asList( @@ -199,7 +199,7 @@ public void testShouldSerializeAndDeserialize() throws IOException ); for (int i = 0; i < header.size(); i++) { - Assert.assertEquals("Deserialized should match pre-serialized values", expected.get(i), deserialized.get(i)); + Assertions.assertEquals(expected.get(i), deserialized.get(i), "Deserialized should match pre-serialized values"); } } @@ -213,7 +213,7 @@ public void testShouldSerializeAndDeserializeAllNulls() throws IOException // Length + BitmapLength + Bitmap + Offsets // 4 + 4 + 0 + 0 = 8 bytes - Assert.assertEquals("Serialized size should be minimal", 8, header.getSerializedSize()); + Assertions.assertEquals(8, header.getSerializedSize(), "Serialized size should be minimal"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final WritableByteChannel channel = Channels.newChannel(baos); @@ -221,19 +221,19 @@ public void testShouldSerializeAndDeserializeAllNulls() throws IOException channel.close(); final ByteBuffer byteBuffer = ByteBuffer.wrap(baos.toByteArray()); - Assert.assertEquals( - "Reported size and actual size should match", + Assertions.assertEquals( header.getSerializedSize(), - byteBuffer.remaining() + byteBuffer.remaining(), + "Reported size and actual size should match" ); NullableOffsetsHeader deserialized = NullableOffsetsHeader.read(byteBuffer); - Assert.assertEquals(0, byteBuffer.remaining()); + Assertions.assertEquals(0, byteBuffer.remaining()); - Assert.assertEquals("Deserialized should match pre-serialized size", header.size(), deserialized.size()); + Assertions.assertEquals(header.size(), deserialized.size(), "Deserialized should match pre-serialized size"); for (int i = 0; i < header.size(); i++) { - Assert.assertNull("Deserialized should be null", deserialized.get(i)); + Assertions.assertNull(deserialized.get(i), "Deserialized should be null"); } } @@ -248,7 +248,7 @@ public void testShouldSerializeAndDeserializeAllValues() throws IOException // Length + BitmapLength + Bitmap + Offsets // 4 + 4 + 0 + 40000 = 40008 bytes // Bitmap is omitted if all values are set - Assert.assertEquals("Serialized size should be minimal", 40008, header.getSerializedSize()); + Assertions.assertEquals(40008, header.getSerializedSize(), "Serialized size should be minimal"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final WritableByteChannel channel = Channels.newChannel(baos); @@ -256,20 +256,20 @@ public void testShouldSerializeAndDeserializeAllValues() throws IOException channel.close(); final ByteBuffer byteBuffer = ByteBuffer.wrap(baos.toByteArray()); - Assert.assertEquals( - "Reported size and actual size should match", + Assertions.assertEquals( header.getSerializedSize(), - byteBuffer.remaining() + byteBuffer.remaining(), + "Reported size and actual size should match" ); NullableOffsetsHeader deserialized = NullableOffsetsHeader.read(byteBuffer); - Assert.assertEquals(0, byteBuffer.remaining()); + Assertions.assertEquals(0, byteBuffer.remaining()); - Assert.assertEquals("Deserialized should match pre-serialized size", header.size(), deserialized.size()); + Assertions.assertEquals(header.size(), deserialized.size(), "Deserialized should match pre-serialized size"); for (int i = 0; i < header.size(); i++) { - Assert.assertNotNull("Deserialized should be set " + i, deserialized.get(i)); - Assert.assertEquals("Deserialized should match pre-serialized nulls " + i, i + 1, deserialized.get(i).getEnd()); + Assertions.assertNotNull(deserialized.get(i), "Deserialized should be set " + i); + Assertions.assertEquals(i + 1, deserialized.get(i).getEnd(), "Deserialized should match pre-serialized nulls " + i); } } @@ -279,13 +279,13 @@ public void testShouldFindOffsetFromIndexSingleWord() throws IOException // Should return the exact index of the offset to read, or negative if not present List expectedOffsetIndexes = ImmutableList.of(15, 21, 30, 31); NullableOffsetsHeader header = createHeaderWithIndexesSet(expectedOffsetIndexes); - Assert.assertEquals("Size should be count of entries", 32, header.size()); + Assertions.assertEquals(32, header.size(), "Size should be count of entries"); header = serde(header); for (int i = 0; i < header.size(); i++) { int offsetIndex = header.getOffsetIndex(i); int expected = expectedOffsetIndexes.indexOf(i); - Assert.assertEquals("Offset " + i, expected, offsetIndex); + Assertions.assertEquals(expected, offsetIndex, "Offset " + i); } } @@ -295,13 +295,13 @@ public void testShouldFindOffsetFromIndexMultipleWords() throws IOException // Should return the exact index of the offset to read, or negative if not present List expectedOffsetIndexes = ImmutableList.of(15, 21, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 70, 100); NullableOffsetsHeader header = createHeaderWithIndexesSet(expectedOffsetIndexes); - Assert.assertEquals("Size should be count of entries", 101, header.size()); + Assertions.assertEquals(101, header.size(), "Size should be count of entries"); header = serde(header); for (int i = 0; i < header.size(); i++) { int offsetIndex = header.getOffsetIndex(i); int expected = expectedOffsetIndexes.indexOf(i); - Assert.assertEquals("Offset " + i, expected, offsetIndex); + Assertions.assertEquals(expected, offsetIndex, "Offset " + i); } } @@ -315,12 +315,12 @@ public void testShouldFindOffsetFromIndexFull() throws IOException for (int i = 0; i < size; i++) { header.writeOffset(i + 1); } - Assert.assertEquals("Size should be count of entries", size, header.size()); + Assertions.assertEquals(size, header.size(), "Size should be count of entries"); header = serde(header); for (int i = 0; i < size; i++) { int offsetIndex = header.getOffsetIndex(i); - Assert.assertEquals("Offset " + i, i, offsetIndex); + Assertions.assertEquals(i, offsetIndex, "Offset " + i); } } @@ -334,12 +334,12 @@ public void testShouldFindOffsetFromIndexEmpty() throws IOException for (int i = 0; i < size; i++) { header.writeNull(); } - Assert.assertEquals("Size should be count of entries", size, header.size()); + Assertions.assertEquals(size, header.size(), "Size should be count of entries"); header = serde(header); for (int i = 0; i < size; i++) { int offsetIndex = header.getOffsetIndex(i); - Assert.assertEquals("Offset " + i, -1, offsetIndex); + Assertions.assertEquals(-1, offsetIndex, "Offset " + i); } } @@ -348,25 +348,25 @@ public void testShouldWorkWithBitsSetAfter64bitBoundary() throws IOException { List expectedOffsetIndexes = ImmutableList.of(0, 1, 2, 3, 4, 256, 257); NullableOffsetsHeader header = createHeaderWithIndexesSet(expectedOffsetIndexes); - Assert.assertEquals("Size should be count of entries", 258, header.size()); + Assertions.assertEquals(258, header.size(), "Size should be count of entries"); header = serde(header); - Assert.assertEquals("Size should be count of entries", 258, header.size()); - Assert.assertEquals("Cardinality should be count of non-nulls", expectedOffsetIndexes.size(), header.getCardinality()); + Assertions.assertEquals(258, header.size(), "Size should be count of entries"); + Assertions.assertEquals(expectedOffsetIndexes.size(), header.getCardinality(), "Cardinality should be count of non-nulls"); for (int i = 0; i < header.size(); i++) { int offsetIndex = header.getOffsetIndex(i); int expectedOffset = expectedOffsetIndexes.indexOf(i); - Assert.assertEquals("Offset " + i, expectedOffset, offsetIndex); + Assertions.assertEquals(expectedOffset, offsetIndex, "Offset " + i); NullableOffsetsHeader.Offset offset = header.get(i); if (expectedOffset < 0) { - Assert.assertNull("Null Offset " + i, offset); + Assertions.assertNull(offset, "Null Offset " + i); } else { int expectedOffsetStart = expectedOffset; int expectedOffsetEnd = expectedOffset + 1; - Assert.assertEquals("Offset Start " + i, expectedOffsetStart, offset.getStart()); - Assert.assertEquals("Offset End " + i, expectedOffsetEnd, offset.getEnd()); - Assert.assertEquals("Offset Length " + i, 1, offset.getLength()); + Assertions.assertEquals(expectedOffsetStart, offset.getStart(), "Offset Start " + i); + Assertions.assertEquals(expectedOffsetEnd, offset.getEnd(), "Offset End " + i); + Assertions.assertEquals(1, offset.getLength(), "Offset Length " + i); } } } @@ -378,29 +378,29 @@ public void testShouldWorkOnLongByteBoundaries() throws IOException int boundary = ((int) Math.pow(2, x)) - 1; List expectedOffsetIndexes = ImmutableList.of(boundary - 1); NullableOffsetsHeader header = createHeaderWithIndexesSet(expectedOffsetIndexes); - Assert.assertEquals("Size should be count of entries", boundary, header.size()); + Assertions.assertEquals(boundary, header.size(), "Size should be count of entries"); header = serde(header); - Assert.assertEquals("Size should be count of entries", boundary, header.size()); - Assert.assertEquals( - "Cardinality should be count of non-nulls", + Assertions.assertEquals(boundary, header.size(), "Size should be count of entries"); + Assertions.assertEquals( expectedOffsetIndexes.size(), - header.getCardinality() + header.getCardinality(), + "Cardinality should be count of non-nulls" ); for (int i = 0; i < header.size(); i++) { int offsetIndex = header.getOffsetIndex(i); int expectedOffset = expectedOffsetIndexes.indexOf(i); - Assert.assertEquals("Offset " + i, expectedOffset, offsetIndex); + Assertions.assertEquals(expectedOffset, offsetIndex, "Offset " + i); NullableOffsetsHeader.Offset offset = header.get(i); if (expectedOffset < 0) { - Assert.assertNull("Null Offset " + i, offset); + Assertions.assertNull(offset, "Null Offset " + i); } else { int expectedOffsetStart = expectedOffset; int expectedOffsetEnd = expectedOffset + 1; - Assert.assertEquals("Offset Start " + i, expectedOffsetStart, offset.getStart()); - Assert.assertEquals("Offset End " + i, expectedOffsetEnd, offset.getEnd()); - Assert.assertEquals("Offset Length " + i, 1, offset.getLength()); + Assertions.assertEquals(expectedOffsetStart, offset.getStart(), "Offset Start " + i); + Assertions.assertEquals(expectedOffsetEnd, offset.getEnd(), "Offset End " + i); + Assertions.assertEquals(1, offset.getLength(), "Offset Length " + i); } } } diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregateHelperTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregateHelperTest.java index 77e76e959ae2..1ef61ab5626f 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregateHelperTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregateHelperTest.java @@ -23,13 +23,15 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import org.apache.druid.java.util.common.IAE; import org.apache.druid.testing.InitializedNullHandlingTest; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class SpectatorHistogramAggregateHelperTest extends InitializedNullHandlingTest { private static final int POSITION = 0; @@ -38,14 +40,14 @@ public class SpectatorHistogramAggregateHelperTest extends InitializedNullHandli private SpectatorHistogramAggregateHelper helper; private ByteBuffer buffer; - @Before + @BeforeEach public void setUp() { helper = new SpectatorHistogramAggregateHelper(); buffer = ByteBuffer.allocate(1024); } - @After + @AfterEach public void tearDown() { helper.close(); @@ -57,8 +59,8 @@ public void testInitCreatesEmptyHistogram() helper.init(buffer, POSITION); SpectatorHistogram result = helper.get(buffer, POSITION); - Assert.assertNotNull(result); - Assert.assertTrue(result.isEmpty()); + Assertions.assertNotNull(result); + Assertions.assertTrue(result.isEmpty()); } @Test @@ -73,8 +75,8 @@ public void testMergeWithSpectatorHistogramObject() helper.merge(histogram, other); SpectatorHistogram result = helper.get(buffer, POSITION); - Assert.assertNotNull(result); - Assert.assertEquals(other, result); + Assertions.assertNotNull(result); + Assertions.assertEquals(other, result); } @Test @@ -92,8 +94,8 @@ public void testMergeWithLongValues() expected.insert(100L); SpectatorHistogram result = helper.get(buffer, POSITION); - Assert.assertNotNull(result); - Assert.assertEquals(expected, result); + Assertions.assertNotNull(result); + Assertions.assertEquals(expected, result); } @Test @@ -112,7 +114,7 @@ public void testMergeWithSpectatorHistogram() expected.add(PercentileBuckets.indexOf(100), 8L); expected.add(PercentileBuckets.indexOf(200), 2L); - Assert.assertEquals(expected, histogram); + Assertions.assertEquals(expected, histogram); } @Test @@ -129,7 +131,7 @@ public void testMergeWithNumber() expected.insert(Long.valueOf(200)); expected.insert(Float.valueOf(300.0f)); - Assert.assertEquals(expected, histogram); + Assertions.assertEquals(expected, histogram); } @Test @@ -137,7 +139,7 @@ public void testMergeWithInvalidType() { SpectatorHistogram histogram = new SpectatorHistogram(); - Assert.assertThrows(IAE.class, () -> helper.merge(histogram, "invalid")); + Assertions.assertThrows(IAE.class, () -> helper.merge(histogram, "invalid")); } @Test @@ -154,7 +156,7 @@ public void testMergeLongValue() expected.insert(100L); expected.insert(200L); - Assert.assertEquals(expected, histogram); + Assertions.assertEquals(expected, histogram); } @Test @@ -171,7 +173,7 @@ public void testGetFromCache() SpectatorHistogram result1 = helper.get(buffer, POSITION); SpectatorHistogram result2 = helper.get(buffer, POSITION); - Assert.assertSame(result1, result2); + Assertions.assertSame(result1, result2); } @Test @@ -187,10 +189,10 @@ public void testGetBufferMap() hist2.add(PercentileBuckets.indexOf(200), 2L); Int2ObjectMap map = helper.get(buffer); - Assert.assertNotNull(map); - Assert.assertEquals(2, map.size()); - Assert.assertSame(hist1, map.get(POSITION)); - Assert.assertSame(hist2, map.get(POSITION_2)); + Assertions.assertNotNull(map); + Assertions.assertEquals(2, map.size()); + Assertions.assertSame(hist1, map.get(POSITION)); + Assertions.assertSame(hist2, map.get(POSITION_2)); } @Test @@ -214,8 +216,8 @@ public void testMultiplePositions() SpectatorHistogram result1 = helper.get(buffer, POSITION); SpectatorHistogram result2 = helper.get(buffer, POSITION_2); - Assert.assertEquals(other1, result1); - Assert.assertEquals(other2, result2); + Assertions.assertEquals(other1, result1); + Assertions.assertEquals(other2, result2); } @Test @@ -236,7 +238,7 @@ public void testRelocate() helper.relocate(oldPosition, newPosition, oldBuffer, newBuffer); SpectatorHistogram result = helper.get(newBuffer, newPosition); - Assert.assertEquals(other, result); + Assertions.assertEquals(other, result); } @Test @@ -257,7 +259,7 @@ public void testRelocateRemovesOldEntry() helper.relocate(oldPosition, newPosition, oldBuffer, newBuffer); // Old position should no longer have the histogram - Assert.assertNull(helper.get(oldBuffer, oldPosition)); + Assertions.assertNull(helper.get(oldBuffer, oldPosition)); } @Test @@ -270,21 +272,25 @@ public void testClose() helper.close(); // After close, the cache should be cleared - Assert.assertNull(helper.get(buffer, POSITION)); + Assertions.assertNull(helper.get(buffer, POSITION)); } - @Test(expected = UnsupportedOperationException.class) + @Test public void testGetFloatThrowsUnsupportedOperationException() { - helper.init(buffer, POSITION); - helper.getFloat(buffer, POSITION); + assertThrows(UnsupportedOperationException.class, () -> { + helper.init(buffer, POSITION); + helper.getFloat(buffer, POSITION); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void testGetLongThrowsUnsupportedOperationException() { - helper.init(buffer, POSITION); - helper.getLong(buffer, POSITION); + assertThrows(UnsupportedOperationException.class, () -> { + helper.init(buffer, POSITION); + helper.getLong(buffer, POSITION); + }); } @Test @@ -313,14 +319,14 @@ public void testMergeMultipleHistograms() expected.add(PercentileBuckets.indexOf(300), 3L); SpectatorHistogram result = helper.get(buffer, POSITION); - Assert.assertEquals(expected, result); + Assertions.assertEquals(expected, result); } @Test public void testGetNonExistentBuffer() { ByteBuffer otherBuffer = ByteBuffer.allocate(1024); - Assert.assertNull(helper.get(otherBuffer, POSITION)); - Assert.assertNull(helper.get(otherBuffer)); + Assertions.assertNull(helper.get(otherBuffer, POSITION)); + Assertions.assertNull(helper.get(otherBuffer)); } } diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java index 31aff8fb272e..92c8a8a47991 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java @@ -32,6 +32,7 @@ import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.Druids; @@ -52,7 +53,6 @@ import org.apache.druid.query.filter.SelectorDimFilter; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.query.metadata.SegmentMetadataQueryConfig; import org.apache.druid.query.metadata.SegmentMetadataQueryQueryToolChest; @@ -75,14 +75,13 @@ import org.apache.druid.testing.InitializedNullHandlingTest; import org.apache.druid.timeline.SegmentId; import org.joda.time.DateTime; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -90,7 +89,6 @@ import java.util.List; import java.util.Map; -@RunWith(Parameterized.class) public class SpectatorHistogramAggregatorTest extends InitializedNullHandlingTest { private static final InputRowSchema INPUT_ROW_SCHEMA = new InputRowSchema( @@ -102,8 +100,8 @@ public class SpectatorHistogramAggregatorTest extends InitializedNullHandlingTes private static final DelimitedInputFormat INPUT_FORMAT = DelimitedInputFormat.forColumns( List.of("timestamp", "product", "cost") ); - @Rule - public final TemporaryFolder tempFolder = new TemporaryFolder(); + @TempDir + public File tempFolder; private static final SegmentMetadataQueryRunnerFactory METADATA_QR_FACTORY = new SegmentMetadataQueryRunnerFactory( new SegmentMetadataQueryQueryToolChest(new SegmentMetadataQueryConfig()), @@ -125,35 +123,80 @@ public class SpectatorHistogramAggregatorTest extends InitializedNullHandlingTes EXPECTED_HISTOGRAMS.put("C", histogram); } - private final AggregationTestHelper helper; - private final AggregationTestHelper timeSeriesHelper; + private AggregationTestHelper helper; + private AggregationTestHelper timeSeriesHelper; - public SpectatorHistogramAggregatorTest(final GroupByQueryConfig config) + public void initSpectatorHistogramAggregatorTest(final GroupByQueryConfig config) { SpectatorHistogramModule.registerSerde(); SpectatorHistogramModule module = new SpectatorHistogramModule(); - helper = AggregationTestHelper.createGroupByQueryAggregationTestHelper( + helper = AggregationTestHelper.createGroupByQueryAggregationTestHelperWithTempDir( module.getJacksonModules(), config, tempFolder); - timeSeriesHelper = AggregationTestHelper.createTimeseriesQueryAggregationTestHelper( + timeSeriesHelper = AggregationTestHelper.createTimeseriesQueryAggregationTestHelperWithTempDir( module.getJacksonModules(), tempFolder ); } - @Parameterized.Parameters(name = "{0}") + private static List testConfigs() + { + return List.of( + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperInitialBuckets() + { + return 4; + } + }, + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperMaxSize() + { + return 2; + } + + @Override + public HumanReadableBytes getMaxOnDiskStorage() + { + return HumanReadableBytes.valueOf(10L * 1024 * 1024); + } + }, + new org.apache.druid.jackson.DefaultObjectMapper().convertValue( + java.util.Map.of( + "maxSelectorDictionarySize", 20, + "maxMergingDictionarySize", 400, + "maxOnDiskStorage", 10L * 1024 * 1024 + ), + GroupByQueryConfig.class + ), + new GroupByQueryConfig() + { + @Override + public int getNumParallelCombineThreads() + { + return 2; + } + } + ); + } + public static Collection constructorFeeder() { final List constructors = new ArrayList<>(); - for (GroupByQueryConfig config : GroupByQueryRunnerTest.testConfigs()) { + for (GroupByQueryConfig config : testConfigs()) { constructors.add(new Object[]{config}); } return constructors; } // this is to test Json properties and equals - @Test - public void serializeDeserializeFactoryWithFieldName() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void serializeDeserializeFactoryWithFieldName(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); new SpectatorHistogramModule().getJacksonModules().forEach(objectMapper::registerModule); SpectatorHistogramAggregatorFactory factory = new SpectatorHistogramAggregatorFactory( @@ -166,12 +209,14 @@ public void serializeDeserializeFactoryWithFieldName() throws Exception AggregatorFactory.class ); - Assert.assertEquals(factory, other); + Assertions.assertEquals(factory, other); } - @Test - public void testBuildingHistogramQueryTime() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testBuildingHistogramQueryTime(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -194,9 +239,11 @@ public void testBuildingHistogramQueryTime() throws Exception assertResultsMatch(results, 2, "C"); } - @Test - public void testBuildingAndMergingHistograms() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testBuildingAndMergingHistograms(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -220,13 +267,15 @@ public void testBuildingAndMergingHistograms() throws Exception expected.add(PercentileBuckets.indexOf(20000), 1L); List results = seq.toList(); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(expected, results.get(0).get(0)); + Assertions.assertEquals(1, results.size()); + Assertions.assertEquals(expected, results.get(0).get(0)); } - @Test - public void testBuildingAndMergingHistogramsTimeseriesQuery() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testBuildingAndMergingHistogramsTimeseriesQuery(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); TimeseriesQuery tsQuery = Druids.newTimeseriesQueryBuilder() .dataSource("test_datasource") .granularity(Granularities.ALL) @@ -251,14 +300,16 @@ public void testBuildingAndMergingHistogramsTimeseriesQuery() throws Exception expected.add(PercentileBuckets.indexOf(20000), 1L); List> results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); SpectatorHistogram value = (SpectatorHistogram) results.get(0).getValue().getMetric("merged_cost_histogram"); - Assert.assertEquals(expected, value); + Assertions.assertEquals(expected, value); } - @Test - public void testBuildingAndMergingGroupbyHistograms() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testBuildingAndMergingGroupbyHistograms(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -277,31 +328,33 @@ public void testBuildingAndMergingGroupbyHistograms() throws Exception ); List results = seq.toList(); - Assert.assertEquals(6, results.size()); + Assertions.assertEquals(6, results.size()); SpectatorHistogram expectedA = new SpectatorHistogram(); expectedA.add(PercentileBuckets.indexOf(10), 1L); - Assert.assertEquals(expectedA, results.get(0).get(1)); + Assertions.assertEquals(expectedA, results.get(0).get(1)); SpectatorHistogram expectedB = new SpectatorHistogram(); expectedB.add(PercentileBuckets.indexOf(30), 1L); expectedB.add(PercentileBuckets.indexOf(40), 3L); expectedB.add(PercentileBuckets.indexOf(50), 2L); - Assert.assertEquals(expectedB, results.get(1).get(1)); + Assertions.assertEquals(expectedB, results.get(1).get(1)); SpectatorHistogram expectedC = new SpectatorHistogram(); expectedC.add(PercentileBuckets.indexOf(50), 1L); expectedC.add(PercentileBuckets.indexOf(20000), 1L); - Assert.assertEquals(expectedC, results.get(2).get(1)); + Assertions.assertEquals(expectedC, results.get(2).get(1)); - Assert.assertNull(results.get(3).get(1)); - Assert.assertNull(results.get(4).get(1)); - Assert.assertNull(results.get(5).get(1)); + Assertions.assertNull(results.get(3).get(1)); + Assertions.assertNull(results.get(4).get(1)); + Assertions.assertNull(results.get(5).get(1)); } - @Test - public void testBuildingAndCountingHistograms() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testBuildingAndCountingHistograms(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -322,16 +375,18 @@ public void testBuildingAndCountingHistograms() throws Exception ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); // Check longSum - Assert.assertEquals(9L, results.get(0).get(0)); + Assertions.assertEquals(9L, results.get(0).get(0)); // Check doubleSum - Assert.assertEquals(9.0, (Double) results.get(0).get(1), 0.001); + Assertions.assertEquals(9.0, (Double) results.get(0).get(1), 0.001); } - @Test - public void testBuildingAndCountingHistogramsWithNullFilter() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testBuildingAndCountingHistogramsWithNullFilter(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -356,16 +411,18 @@ public void testBuildingAndCountingHistogramsWithNullFilter() throws Exception ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); // Check longSum - Assert.assertEquals(9L, results.get(0).get(0)); + Assertions.assertEquals(9L, results.get(0).get(0)); // Check doubleSum - Assert.assertEquals(9.0, (Double) results.get(0).get(1), 0.001); + Assertions.assertEquals(9.0, (Double) results.get(0).get(1), 0.001); } - @Test - public void testIngestAsHistogramDistribution() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testIngestAsHistogramDistribution(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -389,13 +446,15 @@ public void testIngestAsHistogramDistribution() throws Exception expected.add(PercentileBuckets.indexOf(20000), 1L); List results = seq.toList(); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(expected, results.get(0).get(0)); + Assertions.assertEquals(1, results.size()); + Assertions.assertEquals(expected, results.get(0).get(0)); } - @Test - public void testIngestHistogramsTimer() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testIngestHistogramsTimer(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -419,13 +478,15 @@ public void testIngestHistogramsTimer() throws Exception expected.add(PercentileBuckets.indexOf(20000), 1L); List results = seq.toList(); - Assert.assertEquals(1, results.size()); - Assert.assertEquals(expected, results.get(0).get(0)); + Assertions.assertEquals(1, results.size()); + Assertions.assertEquals(expected, results.get(0).get(0)); } - @Test - public void testIngestingPreaggregatedHistograms() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testIngestingPreaggregatedHistograms(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); TimeseriesQuery preAggTsQuery = Druids.newTimeseriesQueryBuilder() .dataSource("test_datasource") .granularity(Granularities.ALL) @@ -450,15 +511,17 @@ public void testIngestingPreaggregatedHistograms() throws Exception expected.add(PercentileBuckets.indexOf(20000), 1L); List> results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); SpectatorHistogram value = (SpectatorHistogram) results.get(0).getValue().getMetric("merged_cost_histogram"); - Assert.assertEquals(expected, value); + Assertions.assertEquals(expected, value); } - @Test - public void testMetadataQueryTimer() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testMetadataQueryTimer(final GroupByQueryConfig config) throws Exception { - File segmentDir = tempFolder.newFolder(); + initSpectatorHistogramAggregatorTest(config); + File segmentDir = newFolder(tempFolder, "junit"); helper.createIndex( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -495,16 +558,18 @@ public void testMetadataQueryTimer() throws Exception .build(); List results = runner.run(QueryPlus.wrap(segmentMetadataQuery)).toList(); System.out.println(results); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); Map columns = results.get(0).getColumns(); - Assert.assertNotNull(columns.get("histogram")); - Assert.assertEquals("spectatorHistogramTimer", columns.get("histogram").getType()); + Assertions.assertNotNull(columns.get("histogram")); + Assertions.assertEquals("spectatorHistogramTimer", columns.get("histogram").getType()); } - @Test - public void testMetadataQueryDistribution() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testMetadataQueryDistribution(final GroupByQueryConfig config) throws Exception { - File segmentDir = tempFolder.newFolder(); + initSpectatorHistogramAggregatorTest(config); + File segmentDir = newFolder(tempFolder, "junit"); helper.createIndex( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -541,15 +606,17 @@ public void testMetadataQueryDistribution() throws Exception .build(); List results = runner.run(QueryPlus.wrap(segmentMetadataQuery)).toList(); System.out.println(results); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); Map columns = results.get(0).getColumns(); - Assert.assertNotNull(columns.get("histogram")); - Assert.assertEquals("spectatorHistogramDistribution", columns.get("histogram").getType()); + Assertions.assertNotNull(columns.get("histogram")); + Assertions.assertEquals("spectatorHistogramDistribution", columns.get("histogram").getType()); } - @Test - public void testPercentilePostAggregator() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testPercentilePostAggregator(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -585,9 +652,9 @@ public void testPercentilePostAggregator() throws Exception expected.add(PercentileBuckets.indexOf(20000), 1L); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); // Check on Median (true median is 40) - Assert.assertEquals(40.0, (double) results.get(0).get(1), 0.2); + Assertions.assertEquals(40.0, (double) results.get(0).get(1), 0.2); // True percentiles for 25, 50, 75, 99 double[] expectedPercentiles = new double[]{40.0, 40.0, 50.0, 18404.0}; double[] resultPercentiles = (double[]) results.get(0).get(2); @@ -597,13 +664,15 @@ public void testPercentilePostAggregator() throws Exception double resultPercentile = resultPercentiles[i]; double error18pcnt = expectedPercentile * 0.18; // Should be within 18% - Assert.assertEquals(expectedPercentile, resultPercentile, error18pcnt); + Assertions.assertEquals(expectedPercentile, resultPercentile, error18pcnt); } } - @Test - public void testBuildingAndCountingHistogramsIncrementalIndex() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testBuildingAndCountingHistogramsIncrementalIndex(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); List dimensions = Collections.singletonList("d"); int n = 10; DateTime startOfDay = DateTimes.of("2000-01-01"); @@ -652,16 +721,18 @@ public void testBuildingAndCountingHistogramsIncrementalIndex() throws Exception Sequence seq = helper.runQueryOnSegmentsObjs(segments, query); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); // Check timestamp - Assert.assertEquals(startOfDay.getMillis(), results.get(0).get(0)); + Assertions.assertEquals(startOfDay.getMillis(), results.get(0).get(0)); // Check doubleSum - Assert.assertEquals(n * segments.size(), (Double) results.get(0).get(1), 0.001); + Assertions.assertEquals(n * segments.size(), (Double) results.get(0).get(1), 0.001); } - @Test - public void testPercentilePostAggregatorWithNullSketch() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testPercentilePostAggregatorWithNullSketch(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -687,22 +758,24 @@ public void testPercentilePostAggregatorWithNullSketch() throws Exception ); List results = seq.toList(); - Assert.assertEquals(6, results.size()); + Assertions.assertEquals(6, results.size()); // First three rows should have valid histograms and percentile values - Assert.assertNotNull("Row [0] should have non-null percentile", results.get(0).get(2)); - Assert.assertNotNull("Row [1] should have non-null percentile", results.get(1).get(2)); - Assert.assertNotNull("Row [2] should have non-null percentile", results.get(2).get(2)); + Assertions.assertNotNull(results.get(0).get(2), "Row [0] should have non-null percentile"); + Assertions.assertNotNull(results.get(1).get(2), "Row [1] should have non-null percentile"); + Assertions.assertNotNull(results.get(2).get(2), "Row [2] should have non-null percentile"); // Last three rows have null histograms, so percentile should also be null - Assert.assertNull("Row [3] should have null percentile when histogram is null", results.get(3).get(2)); - Assert.assertNull("Row [4] should have null percentile when histogram is null", results.get(4).get(2)); - Assert.assertNull("Row [5] should have null percentile when histogram is null", results.get(5).get(2)); + Assertions.assertNull(results.get(3).get(2), "Row [3] should have null percentile when histogram is null"); + Assertions.assertNull(results.get(4).get(2), "Row [4] should have null percentile when histogram is null"); + Assertions.assertNull(results.get(5).get(2), "Row [5] should have null percentile when histogram is null"); } - @Test - public void testPercentilesPostAggregatorWithNullSketch() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testPercentilesPostAggregatorWithNullSketch(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -728,25 +801,27 @@ public void testPercentilesPostAggregatorWithNullSketch() throws Exception ); List results = seq.toList(); - Assert.assertEquals(6, results.size()); + Assertions.assertEquals(6, results.size()); // First three rows should have valid histograms and percentiles arrays - Assert.assertNotNull("Row [0] should have non-null percentiles array", results.get(0).get(2)); - Assert.assertTrue("Row [0] percentiles should be double array", results.get(0).get(2) instanceof double[]); - Assert.assertNotNull("Row [1] should have non-null percentiles array", results.get(1).get(2)); - Assert.assertTrue("Row [1] percentiles should be double array", results.get(1).get(2) instanceof double[]); - Assert.assertNotNull("Row [2] should have non-null percentiles array", results.get(2).get(2)); - Assert.assertTrue("Row [2] percentiles should be double array", results.get(2).get(2) instanceof double[]); + Assertions.assertNotNull(results.get(0).get(2), "Row [0] should have non-null percentiles array"); + Assertions.assertTrue(results.get(0).get(2) instanceof double[], "Row [0] percentiles should be double array"); + Assertions.assertNotNull(results.get(1).get(2), "Row [1] should have non-null percentiles array"); + Assertions.assertTrue(results.get(1).get(2) instanceof double[], "Row [1] percentiles should be double array"); + Assertions.assertNotNull(results.get(2).get(2), "Row [2] should have non-null percentiles array"); + Assertions.assertTrue(results.get(2).get(2) instanceof double[], "Row [2] percentiles should be double array"); // Last three rows have null histograms, so percentiles should also be null - Assert.assertNull("Row [3] should have null percentiles when histogram is null", results.get(3).get(2)); - Assert.assertNull("Row [4] should have null percentiles when histogram is null", results.get(4).get(2)); - Assert.assertNull("Row [5] should have null percentiles when histogram is null", results.get(5).get(2)); + Assertions.assertNull(results.get(3).get(2), "Row [3] should have null percentiles when histogram is null"); + Assertions.assertNull(results.get(4).get(2), "Row [4] should have null percentiles when histogram is null"); + Assertions.assertNull(results.get(5).get(2), "Row [5] should have null percentiles when histogram is null"); } - @Test - public void testCountPostAggregator() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testCountPostAggregator(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -770,14 +845,16 @@ public void testCountPostAggregator() throws Exception ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); // The merged histogram has 9 total observations (1+1+3+3+1 from the buckets) - Assert.assertEquals(9L, results.get(0).get(1)); + Assertions.assertEquals(9L, results.get(0).get(1)); } - @Test - public void testCountPostAggregatorWithNullSketch() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testCountPostAggregatorWithNullSketch(final GroupByQueryConfig config) throws Exception { + initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -802,34 +879,44 @@ public void testCountPostAggregatorWithNullSketch() throws Exception ); List results = seq.toList(); - Assert.assertEquals(6, results.size()); + Assertions.assertEquals(6, results.size()); // First three rows should have valid histograms and count values // Product A: 1 observation - Assert.assertEquals(1L, results.get(0).get(2)); + Assertions.assertEquals(1L, results.get(0).get(2)); // Product B: 6 observations (1+3+2 from buckets at indices 30, 40, 50) - Assert.assertEquals(6L, results.get(1).get(2)); + Assertions.assertEquals(6L, results.get(1).get(2)); // Product C: 2 observations (1+1 from buckets at indices 50, 20000) - Assert.assertEquals(2L, results.get(2).get(2)); + Assertions.assertEquals(2L, results.get(2).get(2)); // Last three rows have null histograms, so count should also be null - Assert.assertNull("Row [3] should have null count when histogram is null", results.get(3).get(2)); - Assert.assertNull("Row [4] should have null count when histogram is null", results.get(4).get(2)); - Assert.assertNull("Row [5] should have null count when histogram is null", results.get(5).get(2)); + Assertions.assertNull(results.get(3).get(2), "Row [3] should have null count when histogram is null"); + Assertions.assertNull(results.get(4).get(2), "Row [4] should have null count when histogram is null"); + Assertions.assertNull(results.get(5).get(2), "Row [5] should have null count when histogram is null"); } private static void assertResultsMatch(List results, int rowNum, String expectedProduct) { ResultRow row = results.get(rowNum); Object product = row.get(0); - Assert.assertTrue("Expected dimension of type String", product instanceof String); - Assert.assertEquals("Product values didn't match", expectedProduct, product); + Assertions.assertTrue(product instanceof String, "Expected dimension of type String"); + Assertions.assertEquals(expectedProduct, product, "Product values didn't match"); Object histogram = row.get(1); - Assert.assertTrue( - "Expected histogram metric of type SpectatorHistogramUtils.HistogramMap", - histogram instanceof SpectatorHistogram + Assertions.assertTrue( + histogram instanceof SpectatorHistogram, + "Expected histogram metric of type SpectatorHistogramUtils.HistogramMap" ); - Assert.assertEquals("Count values didn't match", EXPECTED_HISTOGRAMS.get(product), histogram); + Assertions.assertEquals(EXPECTED_HISTOGRAMS.get(product), histogram, "Count values didn't match"); + } + + private static File newFolder(File root, String... subDirs) throws IOException + { + final String subFolder = String.join("/", subDirs); + final File result = new File(root, subFolder); + if (!result.mkdirs()) { + throw new IOException("Couldn't create folders " + root); + } + return result; } } diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramIndexBasedComplexColumnTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramIndexBasedComplexColumnTest.java index 643e2e57cc56..0a71d5308470 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramIndexBasedComplexColumnTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramIndexBasedComplexColumnTest.java @@ -20,8 +20,8 @@ package org.apache.druid.spectator.histogram; import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class SpectatorHistogramIndexBasedComplexColumnTest { @@ -34,8 +34,8 @@ public void testComplexColumn() final String typeName = "type"; final SpectatorHistogramIndexBasedComplexColumn column = new SpectatorHistogramIndexBasedComplexColumn("type", mockIndexed); - Assert.assertEquals(typeName, column.getTypeName()); - Assert.assertEquals(-1, column.getLength()); + Assertions.assertEquals(typeName, column.getTypeName()); + Assertions.assertEquals(-1, column.getLength()); EasyMock.verify(mockIndexed); } diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramNumericVectorizedAggregatorTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramNumericVectorizedAggregatorTest.java index a659f28cb706..a5fb3528428b 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramNumericVectorizedAggregatorTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramNumericVectorizedAggregatorTest.java @@ -22,17 +22,17 @@ import com.netflix.spectator.api.histogram.PercentileBuckets; import org.apache.druid.segment.vector.VectorValueSelector; import org.apache.druid.testing.InitializedNullHandlingTest; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.nio.ByteBuffer; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SpectatorHistogramNumericVectorizedAggregatorTest extends InitializedNullHandlingTest { private static final int POSITION = 0; @@ -44,7 +44,7 @@ public class SpectatorHistogramNumericVectorizedAggregatorTest extends Initializ private SpectatorHistogramNumericVectorizedAggregator aggregator; private ByteBuffer buffer; - @Before + @BeforeEach public void setUp() { aggregator = new SpectatorHistogramNumericVectorizedAggregator(selector); @@ -58,7 +58,7 @@ public void testInitCreatesEmptyHistogram() Object result = aggregator.get(buffer, POSITION); // Empty histogram returns null - Assert.assertNull(result); + Assertions.assertNull(result); } @Test @@ -77,8 +77,8 @@ public void testAggregateWithLongValues() expected.insert(300L); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertNotNull(result); - Assert.assertEquals(expected, result); + Assertions.assertNotNull(result); + Assertions.assertEquals(expected, result); } @Test @@ -98,8 +98,8 @@ public void testAggregateWithNullValues() expected.insert(300L); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertNotNull(result); - Assert.assertEquals(expected, result); + Assertions.assertNotNull(result); + Assertions.assertEquals(expected, result); } @Test @@ -115,7 +115,7 @@ public void testAggregateWithAllNulls() aggregator.aggregate(buffer, POSITION, 0, 3); // Should still be empty/null - Assert.assertNull(aggregator.get(buffer, POSITION)); + Assertions.assertNull(aggregator.get(buffer, POSITION)); } @Test @@ -143,8 +143,8 @@ public void testAggregateWithPositions() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(expected1, result1); - Assert.assertEquals(expected2, result2); + Assertions.assertEquals(expected1, result1); + Assertions.assertEquals(expected2, result2); } @Test @@ -170,8 +170,8 @@ public void testAggregateWithPositionsNoRows() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(expected1, result1); - Assert.assertEquals(expected2, result2); + Assertions.assertEquals(expected1, result1); + Assertions.assertEquals(expected2, result2); } @Test @@ -193,7 +193,7 @@ public void testAggregateWithPositionOffset() expected.insert(100L); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, actualPosition); - Assert.assertEquals(expected, result); + Assertions.assertEquals(expected, result); } @Test @@ -221,8 +221,8 @@ public void testAggregateWithPositionsAndNulls() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(expected1, result1); - Assert.assertNull(result2); + Assertions.assertEquals(expected1, result1); + Assertions.assertNull(result2); } @Test @@ -240,7 +240,7 @@ public void testAggregatePartialRange() expected.insert(200L); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertEquals(expected, result); + Assertions.assertEquals(expected, result); } @Test @@ -267,7 +267,7 @@ public void testAggregateMultipleBatches() expected.insert(400L); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertEquals(expected, result); + Assertions.assertEquals(expected, result); } @Test @@ -281,13 +281,13 @@ public void testClose() aggregator.aggregate(buffer, POSITION, 0, 1); // Verify aggregation worked - Assert.assertNotNull(aggregator.get(buffer, POSITION)); + Assertions.assertNotNull(aggregator.get(buffer, POSITION)); // Close should clear the cache aggregator.close(); // After close, get should return null - Assert.assertNull(aggregator.get(buffer, POSITION)); + Assertions.assertNull(aggregator.get(buffer, POSITION)); } @Test @@ -302,7 +302,7 @@ public void testValuesGoToCorrectBuckets() aggregator.aggregate(buffer, POSITION, 0, 4); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertNotNull(result); + Assertions.assertNotNull(result); // Verify each value went to its correct bucket SpectatorHistogram expected = new SpectatorHistogram(); @@ -311,7 +311,7 @@ public void testValuesGoToCorrectBuckets() expected.add(PercentileBuckets.indexOf(1000L), 1L); expected.add(PercentileBuckets.indexOf(10000L), 1L); - Assert.assertEquals(expected, result); + Assertions.assertEquals(expected, result); } @Test @@ -335,7 +335,7 @@ public void testRelocate() expected.insert(100L); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(newBuffer, newPosition); - Assert.assertEquals(expected, result); + Assertions.assertEquals(expected, result); } @Test @@ -365,9 +365,9 @@ public void testAggregateWithNonSequentialRowsAndNulls() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(expected1, result1); + Assertions.assertEquals(expected1, result1); // POSITION_2 should be null/empty because nullVector[rows[1]]=nullVector[1]=true - Assert.assertNull(result2); + Assertions.assertNull(result2); } @Test @@ -395,7 +395,7 @@ public void testAggregateWithNonSequentialRows() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(expected1, result1); - Assert.assertEquals(expected2, result2); + Assertions.assertEquals(expected1, result1); + Assertions.assertEquals(expected2, result2); } } diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramTest.java index ac0d59189dbd..8ca91dcd07c9 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramTest.java @@ -25,8 +25,8 @@ import org.apache.druid.segment.ColumnValueSelector; import org.apache.druid.segment.writeout.OnHeapMemorySegmentWriteOutMedium; import org.apache.druid.segment.writeout.SegmentWriteOutMedium; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -34,6 +34,8 @@ import java.nio.channels.Channels; import java.nio.channels.WritableByteChannel; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class SpectatorHistogramTest { @Test @@ -51,23 +53,23 @@ public void testToBytesSmallValues() long bigValue = PercentileBuckets.get(270); histogram.insert(bigValue); - Assert.assertEquals("Should have size matching number of buckets", 5, histogram.size()); - Assert.assertEquals("Should have sum matching number entries", 8, histogram.getSum()); + Assertions.assertEquals(5, histogram.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(8, histogram.getSum(), "Should have sum matching number entries"); byte[] bytes = histogram.toBytes(); int keySize = Short.BYTES; int valSize = 0; - Assert.assertEquals("Should compact small values within key bytes", 5 * (keySize + valSize), bytes.length); + Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should compact small values within key bytes"); SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes); - Assert.assertEquals(1L, deserialized.get(PercentileBuckets.indexOf(10))); - Assert.assertEquals(1L, deserialized.get(PercentileBuckets.indexOf(30))); - Assert.assertEquals(3L, deserialized.get(PercentileBuckets.indexOf(40))); - Assert.assertEquals(2L, deserialized.get(PercentileBuckets.indexOf(50))); - Assert.assertEquals(1L, deserialized.get(PercentileBuckets.indexOf(bigValue))); - - Assert.assertEquals("Should have size matching number of buckets", 5, deserialized.size()); - Assert.assertEquals("Should have sum matching number entries", 8, deserialized.getSum()); + Assertions.assertEquals(1L, deserialized.get(PercentileBuckets.indexOf(10))); + Assertions.assertEquals(1L, deserialized.get(PercentileBuckets.indexOf(30))); + Assertions.assertEquals(3L, deserialized.get(PercentileBuckets.indexOf(40))); + Assertions.assertEquals(2L, deserialized.get(PercentileBuckets.indexOf(50))); + Assertions.assertEquals(1L, deserialized.get(PercentileBuckets.indexOf(bigValue))); + + Assertions.assertEquals(5, deserialized.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(8, deserialized.getSum(), "Should have sum matching number entries"); } @Test @@ -80,23 +82,23 @@ public void testToBytesSmallishValues() histogram.add(PercentileBuckets.indexOf(50), 99L); histogram.add(270, 100L); - Assert.assertEquals("Should have size matching number of buckets", 5, histogram.size()); - Assert.assertEquals("Should have sum matching number entries", 501, histogram.getSum()); + Assertions.assertEquals(5, histogram.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(501, histogram.getSum(), "Should have sum matching number entries"); byte[] bytes = histogram.toBytes(); int keySize = Short.BYTES; int valSize = Byte.BYTES; - Assert.assertEquals("Should compact small values to a byte", 5 * (keySize + valSize), bytes.length); + Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should compact small values to a byte"); SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes); - Assert.assertEquals(64L, deserialized.get(PercentileBuckets.indexOf(10))); - Assert.assertEquals(127L, deserialized.get(PercentileBuckets.indexOf(30))); - Assert.assertEquals(111L, deserialized.get(PercentileBuckets.indexOf(40))); - Assert.assertEquals(99L, deserialized.get(PercentileBuckets.indexOf(50))); - Assert.assertEquals(100L, deserialized.get(270)); - - Assert.assertEquals("Should have size matching number of buckets", 5, deserialized.size()); - Assert.assertEquals("Should have sum matching number entries", 501, deserialized.getSum()); + Assertions.assertEquals(64L, deserialized.get(PercentileBuckets.indexOf(10))); + Assertions.assertEquals(127L, deserialized.get(PercentileBuckets.indexOf(30))); + Assertions.assertEquals(111L, deserialized.get(PercentileBuckets.indexOf(40))); + Assertions.assertEquals(99L, deserialized.get(PercentileBuckets.indexOf(50))); + Assertions.assertEquals(100L, deserialized.get(270)); + + Assertions.assertEquals(5, deserialized.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(501, deserialized.getSum(), "Should have sum matching number entries"); } @Test @@ -109,23 +111,23 @@ public void testToBytesMedValues() histogram.add(PercentileBuckets.indexOf(50), 4096L); histogram.add(270, 8192L); - Assert.assertEquals("Should have size matching number of buckets", 5, histogram.size()); - Assert.assertEquals("Should have sum matching number entries", 15872, histogram.getSum()); + Assertions.assertEquals(5, histogram.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(15872, histogram.getSum(), "Should have sum matching number entries"); byte[] bytes = histogram.toBytes(); int keySize = Short.BYTES; int valSize = Short.BYTES; - Assert.assertEquals("Should compact medium values to short", 5 * (keySize + valSize), bytes.length); + Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should compact medium values to short"); SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes); - Assert.assertEquals(512L, deserialized.get(PercentileBuckets.indexOf(10))); - Assert.assertEquals(1024L, deserialized.get(PercentileBuckets.indexOf(30))); - Assert.assertEquals(2048L, deserialized.get(PercentileBuckets.indexOf(40))); - Assert.assertEquals(4096L, deserialized.get(PercentileBuckets.indexOf(50))); - Assert.assertEquals(8192L, deserialized.get(270)); - - Assert.assertEquals("Should have size matching number of buckets", 5, deserialized.size()); - Assert.assertEquals("Should have sum matching number entries", 15872, deserialized.getSum()); + Assertions.assertEquals(512L, deserialized.get(PercentileBuckets.indexOf(10))); + Assertions.assertEquals(1024L, deserialized.get(PercentileBuckets.indexOf(30))); + Assertions.assertEquals(2048L, deserialized.get(PercentileBuckets.indexOf(40))); + Assertions.assertEquals(4096L, deserialized.get(PercentileBuckets.indexOf(50))); + Assertions.assertEquals(8192L, deserialized.get(270)); + + Assertions.assertEquals(5, deserialized.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(15872, deserialized.getSum(), "Should have sum matching number entries"); } @Test @@ -138,23 +140,23 @@ public void testToBytesLargerValues() histogram.add(PercentileBuckets.indexOf(50), 10000000L); histogram.add(270, 50000000L); - Assert.assertEquals("Should have size matching number of buckets", 5, histogram.size()); - Assert.assertEquals("Should have sum matching number entries", 60800000, histogram.getSum()); + Assertions.assertEquals(5, histogram.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(60800000, histogram.getSum(), "Should have sum matching number entries"); byte[] bytes = histogram.toBytes(); int keySize = Short.BYTES; int valSize = Integer.BYTES; - Assert.assertEquals("Should compact larger values to integer", 5 * (keySize + valSize), bytes.length); + Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should compact larger values to integer"); SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes); - Assert.assertEquals(100000L, deserialized.get(PercentileBuckets.indexOf(10))); - Assert.assertEquals(200000L, deserialized.get(PercentileBuckets.indexOf(30))); - Assert.assertEquals(500000L, deserialized.get(PercentileBuckets.indexOf(40))); - Assert.assertEquals(10000000L, deserialized.get(PercentileBuckets.indexOf(50))); - Assert.assertEquals(50000000L, deserialized.get(270)); - - Assert.assertEquals("Should have size matching number of buckets", 5, deserialized.size()); - Assert.assertEquals("Should have sum matching number entries", 60800000, deserialized.getSum()); + Assertions.assertEquals(100000L, deserialized.get(PercentileBuckets.indexOf(10))); + Assertions.assertEquals(200000L, deserialized.get(PercentileBuckets.indexOf(30))); + Assertions.assertEquals(500000L, deserialized.get(PercentileBuckets.indexOf(40))); + Assertions.assertEquals(10000000L, deserialized.get(PercentileBuckets.indexOf(50))); + Assertions.assertEquals(50000000L, deserialized.get(270)); + + Assertions.assertEquals(5, deserialized.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(60800000, deserialized.getSum(), "Should have sum matching number entries"); } @Test @@ -167,23 +169,23 @@ public void testToBytesBiggestValues() histogram.add(PercentileBuckets.indexOf(50), 100000000000L); histogram.add(270, 5000000000000L); - Assert.assertEquals("Should have size matching number of buckets", 5, histogram.size()); - Assert.assertEquals("Should have sum matching number entries", 5180000000000L, histogram.getSum()); + Assertions.assertEquals(5, histogram.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(5180000000000L, histogram.getSum(), "Should have sum matching number entries"); byte[] bytes = histogram.toBytes(); int keySize = Short.BYTES; int valSize = Long.BYTES; - Assert.assertEquals("Should not compact larger values", 5 * (keySize + valSize), bytes.length); + Assertions.assertEquals(5 * (keySize + valSize), bytes.length, "Should not compact larger values"); SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes); - Assert.assertEquals(10000000000L, deserialized.get(PercentileBuckets.indexOf(10))); - Assert.assertEquals(20000000000L, deserialized.get(PercentileBuckets.indexOf(30))); - Assert.assertEquals(50000000000L, deserialized.get(PercentileBuckets.indexOf(40))); - Assert.assertEquals(100000000000L, deserialized.get(PercentileBuckets.indexOf(50))); - Assert.assertEquals(5000000000000L, deserialized.get(270)); - - Assert.assertEquals("Should have size matching number of buckets", 5, deserialized.size()); - Assert.assertEquals("Should have sum matching number entries", 5180000000000L, deserialized.getSum()); + Assertions.assertEquals(10000000000L, deserialized.get(PercentileBuckets.indexOf(10))); + Assertions.assertEquals(20000000000L, deserialized.get(PercentileBuckets.indexOf(30))); + Assertions.assertEquals(50000000000L, deserialized.get(PercentileBuckets.indexOf(40))); + Assertions.assertEquals(100000000000L, deserialized.get(PercentileBuckets.indexOf(50))); + Assertions.assertEquals(5000000000000L, deserialized.get(270)); + + Assertions.assertEquals(5, deserialized.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(5180000000000L, deserialized.getSum(), "Should have sum matching number entries"); } @Test @@ -196,22 +198,22 @@ public void testToBytesMixedValues() histogram.add(PercentileBuckets.indexOf(50), 100000000000L); histogram.add(270, 5000000000000L); - Assert.assertEquals("Should have size matching number of buckets", 5, histogram.size()); - Assert.assertEquals("Should have sum matching number entries", 5100000200301L, histogram.getSum()); + Assertions.assertEquals(5, histogram.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(5100000200301L, histogram.getSum(), "Should have sum matching number entries"); byte[] bytes = histogram.toBytes(); int keySize = Short.BYTES; - Assert.assertEquals("Should not compact larger values", (5 * keySize) + 0 + 2 + 4 + 8 + 8, bytes.length); + Assertions.assertEquals((5 * keySize) + 0 + 2 + 4 + 8 + 8, bytes.length, "Should not compact larger values"); SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes); - Assert.assertEquals(1L, deserialized.get(PercentileBuckets.indexOf(10))); - Assert.assertEquals(300L, deserialized.get(PercentileBuckets.indexOf(30))); - Assert.assertEquals(200000L, deserialized.get(PercentileBuckets.indexOf(40))); - Assert.assertEquals(100000000000L, deserialized.get(PercentileBuckets.indexOf(50))); - Assert.assertEquals(5000000000000L, deserialized.get(270)); - - Assert.assertEquals("Should have size matching number of buckets", 5, deserialized.size()); - Assert.assertEquals("Should have sum matching number entries", 5100000200301L, deserialized.getSum()); + Assertions.assertEquals(1L, deserialized.get(PercentileBuckets.indexOf(10))); + Assertions.assertEquals(300L, deserialized.get(PercentileBuckets.indexOf(30))); + Assertions.assertEquals(200000L, deserialized.get(PercentileBuckets.indexOf(40))); + Assertions.assertEquals(100000000000L, deserialized.get(PercentileBuckets.indexOf(50))); + Assertions.assertEquals(5000000000000L, deserialized.get(270)); + + Assertions.assertEquals(5, deserialized.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(5100000200301L, deserialized.getSum(), "Should have sum matching number entries"); } @Test @@ -227,39 +229,43 @@ public void testToBytesBoundaryValues() histogram.add(32, 4294967295L); histogram.add(33, 4294967296L); - Assert.assertEquals("Should have size matching number of buckets", 8, histogram.size()); - Assert.assertEquals("Should have sum matching number entries", 8590066300L, histogram.getSum()); + Assertions.assertEquals(8, histogram.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(8590066300L, histogram.getSum(), "Should have sum matching number entries"); byte[] bytes = histogram.toBytes(); int keySize = Short.BYTES; - Assert.assertEquals("Should compact", (8 * keySize) + 0 + 1 + 1 + 2 + 2 + 4 + 4 + 8, bytes.length); + Assertions.assertEquals((8 * keySize) + 0 + 1 + 1 + 2 + 2 + 4 + 4 + 8, bytes.length, "Should compact"); SpectatorHistogram deserialized = SpectatorHistogram.deserialize(bytes); - Assert.assertEquals(63L, deserialized.get(6)); - Assert.assertEquals(64L, deserialized.get(7)); - Assert.assertEquals(255L, deserialized.get(8)); - Assert.assertEquals(256L, deserialized.get(9)); - Assert.assertEquals(65535L, deserialized.get(16)); - Assert.assertEquals(65536L, deserialized.get(17)); - Assert.assertEquals(4294967295L, deserialized.get(32)); - Assert.assertEquals(4294967296L, deserialized.get(33)); - - Assert.assertEquals("Should have size matching number of buckets", 8, deserialized.size()); - Assert.assertEquals("Should have sum matching number entries", 8590066300L, deserialized.getSum()); + Assertions.assertEquals(63L, deserialized.get(6)); + Assertions.assertEquals(64L, deserialized.get(7)); + Assertions.assertEquals(255L, deserialized.get(8)); + Assertions.assertEquals(256L, deserialized.get(9)); + Assertions.assertEquals(65535L, deserialized.get(16)); + Assertions.assertEquals(65536L, deserialized.get(17)); + Assertions.assertEquals(4294967295L, deserialized.get(32)); + Assertions.assertEquals(4294967296L, deserialized.get(33)); + + Assertions.assertEquals(8, deserialized.size(), "Should have size matching number of buckets"); + Assertions.assertEquals(8590066300L, deserialized.getSum(), "Should have sum matching number entries"); } - @Test(expected = IAE.class) - public void testBucketOutOfRangeMax() throws IAE + @Test + public void testBucketOutOfRangeMax() { - SpectatorHistogram histogram = new SpectatorHistogram(); - histogram.add(500, 1); + assertThrows(IAE.class, () -> { + SpectatorHistogram histogram = new SpectatorHistogram(); + histogram.add(500, 1); + }); } - @Test(expected = IAE.class) - public void testBucketOutOfRangeNegative() throws IAE + @Test + public void testBucketOutOfRangeNegative() { - SpectatorHistogram histogram = new SpectatorHistogram(); - histogram.add(-2, 1); + assertThrows(IAE.class, () -> { + SpectatorHistogram histogram = new SpectatorHistogram(); + histogram.add(-2, 1); + }); } @Test @@ -267,7 +273,7 @@ public void testSerializeAndDeserialize() throws IOException { SegmentWriteOutMedium medium = new OnHeapMemorySegmentWriteOutMedium(); SpectatorHistogramObjectStrategy strategy = new SpectatorHistogramObjectStrategy(); - Assert.assertFalse(strategy.readRetainsBufferReference()); + Assertions.assertFalse(strategy.readRetainsBufferReference()); SpectatorHistogramSerializer serializer = SpectatorHistogramSerializer.create(medium, "test", strategy); serializer.open(); @@ -354,7 +360,7 @@ public Class classOfObject() // 4 values = 152 bytes // each value = 38 bytes // Total = 6 + 25 + 152 = 183 - Assert.assertEquals("Expect serialized size", 183L, serializedSize); + Assertions.assertEquals(183L, serializedSize, "Expect serialized size"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); final WritableByteChannel channel = Channels.newChannel(baos); @@ -362,26 +368,26 @@ public Class classOfObject() channel.close(); final ByteBuffer byteBuffer = ByteBuffer.wrap(baos.toByteArray()); - Assert.assertEquals(serializer.getSerializedSize(), byteBuffer.remaining()); + Assertions.assertEquals(serializer.getSerializedSize(), byteBuffer.remaining()); SpectatorHistogramIndexed indexedDeserialized = SpectatorHistogramIndexed.read(byteBuffer, strategy); - Assert.assertEquals(0, byteBuffer.remaining()); + Assertions.assertEquals(0, byteBuffer.remaining()); - Assert.assertEquals("Count of entries should match", count, indexedDeserialized.size()); + Assertions.assertEquals(count, indexedDeserialized.size(), "Count of entries should match"); for (int i = 0; i < count; i++) { SpectatorHistogram deserialized = indexedDeserialized.get(i); if ((i + 1) % 3 == 0 || i >= 6) { // Expect null - Assert.assertNull(deserialized); + Assertions.assertNull(deserialized); } else { - Assert.assertEquals(63L, deserialized.get(6)); - Assert.assertEquals(64L, deserialized.get(7)); - Assert.assertEquals(255L, deserialized.get(8)); - Assert.assertEquals(256L, deserialized.get(9)); - Assert.assertEquals(65535L, deserialized.get(16)); - Assert.assertEquals(65536L, deserialized.get(17)); - Assert.assertEquals(4294967295L, deserialized.get(32)); - Assert.assertEquals(4294967296L, deserialized.get(33)); + Assertions.assertEquals(63L, deserialized.get(6)); + Assertions.assertEquals(64L, deserialized.get(7)); + Assertions.assertEquals(255L, deserialized.get(8)); + Assertions.assertEquals(256L, deserialized.get(9)); + Assertions.assertEquals(65535L, deserialized.get(16)); + Assertions.assertEquals(65536L, deserialized.get(17)); + Assertions.assertEquals(4294967295L, deserialized.get(32)); + Assertions.assertEquals(4294967296L, deserialized.get(33)); } } } @@ -391,10 +397,10 @@ public void testPercentileComputation0() { SpectatorHistogram h = new SpectatorHistogram(); h.insert(0); - Assert.assertEquals(0.1, h.getPercentileValue(10.0), 0.01); - Assert.assertEquals(0.5, h.getPercentileValue(50.0), 0.01); - Assert.assertEquals(0.99, h.getPercentileValue(99.0), 0.01); - Assert.assertEquals(1.0, h.getPercentileValue(100.0), 0.01); + Assertions.assertEquals(0.1, h.getPercentileValue(10.0), 0.01); + Assertions.assertEquals(0.5, h.getPercentileValue(50.0), 0.01); + Assertions.assertEquals(0.99, h.getPercentileValue(99.0), 0.01); + Assertions.assertEquals(1.0, h.getPercentileValue(100.0), 0.01); } @Test @@ -405,10 +411,10 @@ public void testPercentileComputation1_100() h.insert(i); } // Precision assigned to half of the bucket width - Assert.assertEquals(10.0, h.getPercentileValue(10.0), 0.5); - Assert.assertEquals(50.0, h.getPercentileValue(50.0), 2.5); - Assert.assertEquals(99.0, h.getPercentileValue(99.0), 10.5); - Assert.assertEquals(100.0, h.getPercentileValue(100.0), 10.5); + Assertions.assertEquals(10.0, h.getPercentileValue(10.0), 0.5); + Assertions.assertEquals(50.0, h.getPercentileValue(50.0), 2.5); + Assertions.assertEquals(99.0, h.getPercentileValue(99.0), 10.5); + Assertions.assertEquals(100.0, h.getPercentileValue(100.0), 10.5); } @Test @@ -424,10 +430,10 @@ public void testPercentileComputation0_Big() long widthOfBucket = upperBoundOfBucket200 - lowerBoundOfBucket200; // P1 should be pulled towards the very low value // P >1 should be pulled towards the very big value - Assert.assertEquals(upperBoundOfBucket0, h.getPercentileValue(1.0), 0.01); - Assert.assertEquals(lowerBoundOfBucket200, h.getPercentileValue(50.0), widthOfBucket / 2.0); - Assert.assertEquals(upperBoundOfBucket200, h.getPercentileValue(99.0), widthOfBucket / 2.0); - Assert.assertEquals(upperBoundOfBucket200, h.getPercentileValue(100.0), widthOfBucket / 2.0); + Assertions.assertEquals(upperBoundOfBucket0, h.getPercentileValue(1.0), 0.01); + Assertions.assertEquals(lowerBoundOfBucket200, h.getPercentileValue(50.0), widthOfBucket / 2.0); + Assertions.assertEquals(upperBoundOfBucket200, h.getPercentileValue(99.0), widthOfBucket / 2.0); + Assertions.assertEquals(upperBoundOfBucket200, h.getPercentileValue(100.0), widthOfBucket / 2.0); } @Test @@ -447,6 +453,6 @@ public void testMedianOfSequence() long halfBucketWidth = ((upperBoundOfFifteenPointFiveBucket - lowerBoundOfFifteenPointFiveBucket) / 2); long middleOfFifteenPointFiveBucket = lowerBoundOfFifteenPointFiveBucket + halfBucketWidth; - Assert.assertEquals(middleOfFifteenPointFiveBucket, h.getPercentileValue(50.0), 0.01); + Assertions.assertEquals(middleOfFifteenPointFiveBucket, h.getPercentileValue(50.0), 0.01); } } diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramVectorizedAggregatorTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramVectorizedAggregatorTest.java index 0f6970d50c44..8581c40ec417 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramVectorizedAggregatorTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramVectorizedAggregatorTest.java @@ -22,17 +22,17 @@ import com.netflix.spectator.api.histogram.PercentileBuckets; import org.apache.druid.segment.vector.VectorObjectSelector; import org.apache.druid.testing.InitializedNullHandlingTest; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.nio.ByteBuffer; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SpectatorHistogramVectorizedAggregatorTest extends InitializedNullHandlingTest { private static final int POSITION = 0; @@ -44,7 +44,7 @@ public class SpectatorHistogramVectorizedAggregatorTest extends InitializedNullH private SpectatorHistogramVectorizedAggregator aggregator; private ByteBuffer buffer; - @Before + @BeforeEach public void setUp() { aggregator = new SpectatorHistogramVectorizedAggregator(selector); @@ -58,7 +58,7 @@ public void testInitCreatesEmptyHistogram() Object result = aggregator.get(buffer, POSITION); // Empty histogram returns null - Assert.assertNull(result); + Assertions.assertNull(result); } @Test @@ -82,8 +82,8 @@ public void testAggregateWithSpectatorHistograms() expected.add(PercentileBuckets.indexOf(200), 2L); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertNotNull(result); - Assert.assertEquals(expected, result); + Assertions.assertNotNull(result); + Assertions.assertEquals(expected, result); } @Test @@ -99,8 +99,8 @@ public void testAggregateWithNullValues() aggregator.aggregate(buffer, POSITION, 0, 3); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertNotNull(result); - Assert.assertEquals(hist1, result); + Assertions.assertNotNull(result); + Assertions.assertEquals(hist1, result); } @Test @@ -113,7 +113,7 @@ public void testAggregateWithAllNulls() aggregator.aggregate(buffer, POSITION, 0, 3); // Should still be empty/null - Assert.assertNull(aggregator.get(buffer, POSITION)); + Assertions.assertNull(aggregator.get(buffer, POSITION)); } @Test @@ -132,8 +132,8 @@ public void testAggregateWithNumberValues() expected.insert(300L); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertNotNull(result); - Assert.assertEquals(expected, result); + Assertions.assertNotNull(result); + Assertions.assertEquals(expected, result); } @Test @@ -169,8 +169,8 @@ public void testAggregateWithPositions() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(expected1, result1); - Assert.assertEquals(expected2, result2); + Assertions.assertEquals(expected1, result1); + Assertions.assertEquals(expected2, result2); } @Test @@ -195,8 +195,8 @@ public void testAggregateWithPositionsNoRows() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(hist1, result1); - Assert.assertEquals(hist2, result2); + Assertions.assertEquals(hist1, result1); + Assertions.assertEquals(hist2, result2); } @Test @@ -217,7 +217,7 @@ public void testAggregateWithPositionOffset() aggregator.aggregate(buffer, 1, positions, null, positionOffset); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, actualPosition); - Assert.assertEquals(hist1, result); + Assertions.assertEquals(hist1, result); } @Test @@ -240,7 +240,7 @@ public void testRelocate() aggregator.relocate(oldPosition, newPosition, oldBuffer, newBuffer); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(newBuffer, newPosition); - Assert.assertEquals(hist, result); + Assertions.assertEquals(hist, result); } @Test @@ -263,7 +263,7 @@ public void testAggregatePartialRange() aggregator.aggregate(buffer, POSITION, 1, 2); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertEquals(hist2, result); + Assertions.assertEquals(hist2, result); } @Test @@ -279,13 +279,13 @@ public void testClose() aggregator.aggregate(buffer, POSITION, 0, 1); // Verify aggregation worked - Assert.assertNotNull(aggregator.get(buffer, POSITION)); + Assertions.assertNotNull(aggregator.get(buffer, POSITION)); // Close should clear the cache aggregator.close(); // After close, get should return null - Assert.assertNull(aggregator.get(buffer, POSITION)); + Assertions.assertNull(aggregator.get(buffer, POSITION)); } @Test @@ -314,7 +314,7 @@ public void testAggregateMultipleBatches() expected.add(PercentileBuckets.indexOf(200), 2L); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertEquals(expected, result); + Assertions.assertEquals(expected, result); } @Test @@ -350,8 +350,8 @@ public void testAggregateWithPositionsMultipleToSamePosition() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(expected1, result1); - Assert.assertEquals(expected2, result2); + Assertions.assertEquals(expected1, result1); + Assertions.assertEquals(expected2, result2); } @Test @@ -373,8 +373,8 @@ public void testAggregateWithMixedTypesInVector() expected.insert(300); SpectatorHistogram result = (SpectatorHistogram) aggregator.get(buffer, POSITION); - Assert.assertNotNull(result); - Assert.assertEquals(expected, result); + Assertions.assertNotNull(result); + Assertions.assertEquals(expected, result); } @Test @@ -408,9 +408,9 @@ public void testAggregateWithNonSequentialRowsAndNulls() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(expected1, result1); + Assertions.assertEquals(expected1, result1); // POSITION_2 should be null/empty because vector[rows[1]]=vector[1]=null - Assert.assertNull(result2); + Assertions.assertNull(result2); } @Test @@ -446,7 +446,7 @@ public void testAggregateWithNonSequentialRows() SpectatorHistogram result1 = (SpectatorHistogram) aggregator.get(buffer, POSITION); SpectatorHistogram result2 = (SpectatorHistogram) aggregator.get(buffer, POSITION_2); - Assert.assertEquals(expected1, result1); - Assert.assertEquals(expected2, result2); + Assertions.assertEquals(expected1, result1); + Assertions.assertEquals(expected2, result2); } } diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/sql/SpectatorHistogramSqlAggregatorTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/sql/SpectatorHistogramSqlAggregatorTest.java index 138c91259cb2..f38b4a27a683 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/sql/SpectatorHistogramSqlAggregatorTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/sql/SpectatorHistogramSqlAggregatorTest.java @@ -57,7 +57,7 @@ import org.apache.druid.sql.calcite.util.SqlTestFramework.StandardComponentSupplier; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -561,12 +561,12 @@ public void testSpectatorPercentileWithStringLiteral() try { testQuery(query, List.of(), List.of()); - Assert.fail("Expected DruidException but query succeeded"); + Assertions.fail("Expected DruidException but query succeeded"); } catch (DruidException e) { - Assert.assertEquals(DruidException.Persona.USER, e.getTargetPersona()); - Assert.assertEquals(DruidException.Category.INVALID_INPUT, e.getCategory()); - Assert.assertTrue(e.getMessage().contains("must be a numeric literal")); + Assertions.assertEquals(DruidException.Persona.USER, e.getTargetPersona()); + Assertions.assertEquals(DruidException.Category.INVALID_INPUT, e.getCategory()); + Assertions.assertTrue(e.getMessage().contains("must be a numeric literal")); } } } diff --git a/extensions-contrib/tdigestsketch/pom.xml b/extensions-contrib/tdigestsketch/pom.xml index ddf32ec718e2..56fafc4e8ada 100644 --- a/extensions-contrib/tdigestsketch/pom.xml +++ b/extensions-contrib/tdigestsketch/pom.xml @@ -33,6 +33,21 @@ Druid extension for generating tdigest backed sketches + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + com.tdunning t-digest @@ -133,36 +148,6 @@ - - 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.reflections reflections diff --git a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorFactoryTest.java b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorFactoryTest.java index 80ef6c8ecb58..1e618d48ff50 100644 --- a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorFactoryTest.java +++ b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorFactoryTest.java @@ -28,8 +28,8 @@ import org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest; 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.Assertions; +import org.junit.jupiter.api.Test; public class TDigestSketchAggregatorFactoryTest { @@ -51,7 +51,7 @@ public void testResultArraySignature() ) .build(); - Assert.assertEquals( + Assertions.assertEquals( RowSignature.builder() .addTimeColumn() .add("count", ColumnType.LONG) @@ -67,8 +67,8 @@ public void testResultArraySignature() public void testWithName() { TDigestSketchAggregatorFactory factory = new TDigestSketchAggregatorFactory("tdigest", "col", null, TDigestConfig.builder().maxCompression(200).build()); - Assert.assertEquals(factory, factory.withName("tdigest")); - Assert.assertEquals("newTest", factory.withName("newTest").getName()); + Assertions.assertEquals(factory, factory.withName("tdigest")); + Assertions.assertEquals("newTest", factory.withName("newTest").getName()); } @Test @@ -76,7 +76,7 @@ public void testCompressionCappedAtMaxCompression() { TDigestConfig config = TDigestConfig.builder().maxCompression(150).build(); TDigestSketchAggregatorFactory factory = new TDigestSketchAggregatorFactory("tdigest", "col", 300, config); - Assert.assertEquals(150, factory.getCompression()); + Assertions.assertEquals(150, factory.getCompression()); } @Test @@ -84,6 +84,6 @@ public void testCompressionBelowMaxCompressionUnchanged() { TDigestConfig config = TDigestConfig.builder().maxCompression(150).build(); TDigestSketchAggregatorFactory factory = new TDigestSketchAggregatorFactory("tdigest", "col", 100, config); - Assert.assertEquals(100, factory.getCompression()); + Assertions.assertEquals(100, factory.getCompression()); } } diff --git a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java index c95b8a7068e0..ac3f454d2b6b 100644 --- a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java +++ b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java @@ -27,6 +27,7 @@ import org.apache.druid.data.input.impl.DimensionsSpec; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.jackson.DefaultObjectMapper; +import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; @@ -36,15 +37,12 @@ import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.testing.InitializedNullHandlingTest; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.util.ArrayList; @@ -52,19 +50,18 @@ import java.util.Collections; import java.util.List; -@RunWith(Parameterized.class) public class TDigestSketchAggregatorTest extends InitializedNullHandlingTest { - private final AggregationTestHelper helper; + private AggregationTestHelper helper; - @Rule - public final TemporaryFolder tempFolder = new TemporaryFolder(); + @TempDir + public File tempFolder; - public TDigestSketchAggregatorTest(final GroupByQueryConfig config) + public void initTDigestSketchAggregatorTest(final GroupByQueryConfig config) { TDigestSketchModule.registerSerde(); TDigestSketchModule module = new TDigestSketchModule(); - helper = AggregationTestHelper.createGroupByQueryAggregationTestHelper( + helper = AggregationTestHelper.createGroupByQueryAggregationTestHelperWithTempDir( module.getJacksonModules(), config, tempFolder); InjectableValues currentInjectableValues = helper.getObjectMapper().getInjectableValues(); InjectableValues.Std currentInjectableValuesStd = (InjectableValues.Std) currentInjectableValues; @@ -72,20 +69,65 @@ public TDigestSketchAggregatorTest(final GroupByQueryConfig config) helper.getObjectMapper().setInjectableValues(currentInjectableValuesStd); } - @Parameterized.Parameters(name = "{0}") + private static List testConfigs() + { + return List.of( + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperInitialBuckets() + { + return 4; + } + }, + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperMaxSize() + { + return 2; + } + + @Override + public HumanReadableBytes getMaxOnDiskStorage() + { + return HumanReadableBytes.valueOf(10L * 1024 * 1024); + } + }, + new org.apache.druid.jackson.DefaultObjectMapper().convertValue( + java.util.Map.of( + "maxSelectorDictionarySize", 20, + "maxMergingDictionarySize", 400, + "maxOnDiskStorage", 10L * 1024 * 1024 + ), + GroupByQueryConfig.class + ), + new GroupByQueryConfig() + { + @Override + public int getNumParallelCombineThreads() + { + return 2; + } + } + ); + } + public static Collection constructorFeeder() { final List constructors = new ArrayList<>(); - for (GroupByQueryConfig config : GroupByQueryRunnerTest.testConfigs()) { + for (GroupByQueryConfig config : testConfigs()) { constructors.add(new Object[]{config}); } return constructors; } // this is to test Json properties and equals - @Test - public void serializeDeserializeFactoryWithFieldName() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void serializeDeserializeFactoryWithFieldName(final GroupByQueryConfig config) throws Exception { + initTDigestSketchAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); objectMapper.setInjectableValues( new InjectableValues.Std() @@ -99,12 +141,14 @@ public void serializeDeserializeFactoryWithFieldName() throws Exception AggregatorFactory.class ); - Assert.assertEquals(factory, other); + Assertions.assertEquals(factory, other); } - @Test - public void deserializedFactoryCompressionCappedAtMaxCompression() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void deserializedFactoryCompressionCappedAtMaxCompression(final GroupByQueryConfig config) throws Exception { + initTDigestSketchAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); objectMapper.setInjectableValues( new InjectableValues.Std() @@ -118,12 +162,14 @@ public void deserializedFactoryCompressionCappedAtMaxCompression() throws Except AggregatorFactory.class ); - Assert.assertEquals(150, deserialized.getCompression()); + Assertions.assertEquals(150, deserialized.getCompression()); } - @Test - public void deserializedFactoryCompressionBelowMaxCompressionUnchanged() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void deserializedFactoryCompressionBelowMaxCompressionUnchanged(final GroupByQueryConfig config) throws Exception { + initTDigestSketchAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); objectMapper.setInjectableValues( new InjectableValues.Std() @@ -137,12 +183,14 @@ public void deserializedFactoryCompressionBelowMaxCompressionUnchanged() throws AggregatorFactory.class ); - Assert.assertEquals(100, deserialized.getCompression()); + Assertions.assertEquals(100, deserialized.getCompression()); } - @Test - public void buildingSketchesAtIngestionTime() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void buildingSketchesAtIngestionTime(final GroupByQueryConfig config) throws Exception { + initTDigestSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -176,21 +224,23 @@ public void buildingSketchesAtIngestionTime() throws Exception .build() ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); ResultRow row = results.get(0); // post agg Object quantilesObject = row.get(1); // "quantiles" - Assert.assertTrue(quantilesObject instanceof double[]); + Assertions.assertTrue(quantilesObject instanceof double[]); double[] quantiles = (double[]) quantilesObject; - Assert.assertEquals(0.001, quantiles[0], 0.0006); // min value - Assert.assertEquals(0.5, quantiles[1], 0.05); // median value - Assert.assertEquals(1, quantiles[2], 0.05); // max value + Assertions.assertEquals(0.001, quantiles[0], 0.0006); // min value + Assertions.assertEquals(0.5, quantiles[1], 0.05); // median value + Assertions.assertEquals(1, quantiles[2], 0.05); // max value } - @Test - public void buildingSketchesAtQueryTime() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void buildingSketchesAtQueryTime(final GroupByQueryConfig config) throws Exception { + initTDigestSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -221,22 +271,24 @@ public void buildingSketchesAtQueryTime() throws Exception .build() ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); ResultRow row = results.get(0); // post agg Object quantilesObject = row.get(1); // "quantiles" - Assert.assertTrue(quantilesObject instanceof double[]); + Assertions.assertTrue(quantilesObject instanceof double[]); double[] quantiles = (double[]) quantilesObject; - Assert.assertEquals(0.001, quantiles[0], 0.0006); // min value - Assert.assertEquals(0.5, quantiles[1], 0.05); // median value - Assert.assertEquals(1, quantiles[2], 0.05); // max value + Assertions.assertEquals(0.001, quantiles[0], 0.0006); // min value + Assertions.assertEquals(0.5, quantiles[1], 0.05); // median value + Assertions.assertEquals(1, quantiles[2], 0.05); // max value } - @Test - public void testIngestingSketches() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void testIngestingSketches(final GroupByQueryConfig config) throws Exception { + initTDigestSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_sketch_data.tsv").getFile()), new InputRowSchema( @@ -269,15 +321,15 @@ public void testIngestingSketches() throws Exception .build() ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); ResultRow row = results.get(0); // post agg Object quantilesObject = row.get(1); // "quantiles" - Assert.assertTrue(quantilesObject instanceof double[]); + Assertions.assertTrue(quantilesObject instanceof double[]); double[] quantiles = (double[]) quantilesObject; - Assert.assertEquals(0.001, quantiles[0], 0.0006); // min value - Assert.assertEquals(0.5, quantiles[1], 0.05); // median value - Assert.assertEquals(1, quantiles[2], 0.05); // max value + Assertions.assertEquals(0.001, quantiles[0], 0.0006); // min value + Assertions.assertEquals(0.5, quantiles[1], 0.05); // median value + Assertions.assertEquals(1, quantiles[2], 0.05); // max value } } diff --git a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchObjectStrategyTest.java b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchObjectStrategyTest.java index e91809506e9d..7823f7856caf 100644 --- a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchObjectStrategyTest.java +++ b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchObjectStrategyTest.java @@ -19,7 +19,7 @@ package org.apache.druid.query.aggregation.tdigestsketch; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class TDigestSketchObjectStrategyTest @@ -28,6 +28,6 @@ public class TDigestSketchObjectStrategyTest public void testReadRetainsBufferReference() { TDigestSketchObjectStrategy strategy = new TDigestSketchObjectStrategy(); - Assert.assertFalse(strategy.readRetainsBufferReference()); + Assertions.assertFalse(strategy.readRetainsBufferReference()); } } diff --git a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchToQuantilePostAggregatorTest.java b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchToQuantilePostAggregatorTest.java index db85a4cbe297..f19d42b899f9 100644 --- a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchToQuantilePostAggregatorTest.java +++ b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchToQuantilePostAggregatorTest.java @@ -23,15 +23,11 @@ import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.ConstantPostAggregator; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class TDigestSketchToQuantilePostAggregatorTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); @Test public void testSerde() throws Exception @@ -45,9 +41,9 @@ public void testSerde() throws Exception TDigestSketchToQuantilePostAggregator.class ); - Assert.assertEquals(there, andBackAgain); - Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); - Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); + Assertions.assertEquals(there, andBackAgain); + Assertions.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); + Assertions.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); } @Test @@ -56,7 +52,7 @@ public void testToString() PostAggregator postAgg = new TDigestSketchToQuantilePostAggregator("post", new ConstantPostAggregator("", 100), 0.5); - Assert.assertEquals( + Assertions.assertEquals( "TDigestSketchToQuantilePostAggregator{name='post', field=ConstantPostAggregator{name='', constantValue=100}, fraction=0.5}", postAgg.toString() ); diff --git a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchToQuantilesPostAggregatorTest.java b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchToQuantilesPostAggregatorTest.java index 7660a3b10125..5bd62af4c8bd 100644 --- a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchToQuantilesPostAggregatorTest.java +++ b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchToQuantilesPostAggregatorTest.java @@ -24,15 +24,14 @@ import org.apache.druid.java.util.common.IAE; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.ConstantPostAggregator; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TDigestSketchToQuantilesPostAggregatorTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); @Test public void testSerde() throws Exception @@ -46,9 +45,9 @@ public void testSerde() throws Exception TDigestSketchToQuantilesPostAggregator.class ); - Assert.assertEquals(there, andBackAgain); - Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); - Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); + Assertions.assertEquals(there, andBackAgain); + Assertions.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); + Assertions.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); } @Test @@ -60,7 +59,7 @@ public void testToString() new double[]{0.25, 0.75} ); - Assert.assertEquals( + Assertions.assertEquals( "TDigestSketchToQuantilesPostAggregator{name='post', field=ConstantPostAggregator{name='', constantValue=100}, fractions=[0.25, 0.75]}", postAgg.toString() ); @@ -69,14 +68,15 @@ public void testToString() @Test public void testComparator() { - expectedException.expect(IAE.class); - expectedException.expectMessage("Comparing arrays of quantiles is not supported"); - PostAggregator postAgg = new TDigestSketchToQuantilesPostAggregator( - "post", - new ConstantPostAggregator("", 100), - new double[]{0.25, 0.75} - ); - postAgg.getComparator(); + Throwable exception = assertThrows(IAE.class, () -> { + PostAggregator postAgg = new TDigestSketchToQuantilesPostAggregator( + "post", + new ConstantPostAggregator("", 100), + new double[]{0.25, 0.75} + ); + postAgg.getComparator(); + }); + assertTrue(exception.getMessage().contains("Comparing arrays of quantiles is not supported")); } @Test diff --git a/processing/src/test/java/org/apache/druid/query/aggregation/AggregationTestHelper.java b/processing/src/test/java/org/apache/druid/query/aggregation/AggregationTestHelper.java index 11d0c4a00c40..6ac02614b2cf 100644 --- a/processing/src/test/java/org/apache/druid/query/aggregation/AggregationTestHelper.java +++ b/processing/src/test/java/org/apache/druid/query/aggregation/AggregationTestHelper.java @@ -55,7 +55,6 @@ import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; import org.apache.druid.query.groupby.GroupByQueryRunnerFactory; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; import org.apache.druid.query.groupby.GroupingEngine; import org.apache.druid.query.groupby.ResultRow; @@ -193,7 +192,7 @@ private static AggregationTestHelper createGroupByQueryAggregationTestHelper( for (Module mod : jsonModulesToRegister) { mapper.registerModule(mod); } - final GroupByQueryRunnerFactory factory = GroupByQueryRunnerTest.makeQueryRunnerFactory( + final GroupByQueryRunnerFactory factory = GroupByQueryRunnerTestHelper.makeQueryRunnerFactory( mapper, config, groupByBuffers diff --git a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTestHelper.java b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTestHelper.java index 049b00ca1159..9b6c22d4e63e 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTestHelper.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/GroupByQueryRunnerTestHelper.java @@ -19,10 +19,16 @@ package org.apache.druid.query.groupby; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Preconditions; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableList; import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.java.util.common.HumanReadableBytes; +import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.java.util.emitter.service.ServiceEmitter; +import org.apache.druid.query.DruidProcessingConfig; import org.apache.druid.query.FinalizeResultsQueryRunner; import org.apache.druid.query.MetricsEmittingQueryRunner; import org.apache.druid.query.Query; @@ -30,6 +36,7 @@ import org.apache.druid.query.QueryPlus; import org.apache.druid.query.QueryRunner; import org.apache.druid.query.QueryRunnerFactory; +import org.apache.druid.query.QueryRunnerTestHelper; import org.apache.druid.query.QueryToolChest; import org.apache.druid.segment.column.ColumnHolder; import org.joda.time.DateTime; @@ -47,6 +54,163 @@ */ public class GroupByQueryRunnerTestHelper { + public static final DruidProcessingConfig DEFAULT_PROCESSING_CONFIG = new DruidProcessingConfig() + { + @Override + public String getFormatString() + { + return null; + } + + @Override + public int intermediateComputeSizeBytes() + { + return 10 * 1024 * 1024; + } + + @Override + public int getNumMergeBuffers() + { + return 4; + } + + @Override + public int getNumThreads() + { + return 2; + } + }; + + private static final GroupByQueryConfig V2_CONFIG = new GroupByQueryConfig() + { + @Override + public int getBufferGrouperInitialBuckets() + { + return 4; + } + + @Override + public String toString() + { + return "v2"; + } + }; + + private static final GroupByQueryConfig V2_SMALL_BUFFER_CONFIG = new GroupByQueryConfig() + { + @Override + public int getBufferGrouperMaxSize() + { + return 2; + } + + @Override + public HumanReadableBytes getMaxOnDiskStorage() + { + return HumanReadableBytes.valueOf(10L * 1024 * 1024); + } + + @Override + public String toString() + { + return "v2SmallBuffer"; + } + }; + + private static final GroupByQueryConfig V2_SMALL_DICTIONARY_CONFIG = new GroupByQueryConfig() + { + @Override + public long getConfiguredMaxSelectorDictionarySize() + { + return 20; + } + + @Override + public long getConfiguredMaxMergingDictionarySize() + { + return 400; + } + + @Override + public HumanReadableBytes getMaxOnDiskStorage() + { + return HumanReadableBytes.valueOf(10L * 1024 * 1024); + } + + @Override + public String toString() + { + return "v2SmallDictionary"; + } + }; + + private static final GroupByQueryConfig V2_PARALLEL_COMBINE_CONFIG = new GroupByQueryConfig() + { + @Override + public int getNumParallelCombineThreads() + { + return DEFAULT_PROCESSING_CONFIG.getNumThreads(); + } + + @Override + public String toString() + { + return "v2ParallelCombine"; + } + }; + + public static List testConfigs() + { + return ImmutableList.of( + V2_CONFIG, + V2_SMALL_BUFFER_CONFIG, + V2_SMALL_DICTIONARY_CONFIG, + V2_PARALLEL_COMBINE_CONFIG + ); + } + + public static GroupByQueryRunnerFactory makeQueryRunnerFactory( + final ObjectMapper mapper, + final GroupByQueryConfig config, + final TestGroupByBuffers bufferPools + ) + { + if (bufferPools.getBufferSize() != DEFAULT_PROCESSING_CONFIG.intermediateComputeSizeBytes()) { + throw new ISE( + "Provided buffer size [%,d] does not match configured size [%,d]", + bufferPools.getBufferSize(), + DEFAULT_PROCESSING_CONFIG.intermediateComputeSizeBytes() + ); + } + if (bufferPools.getNumMergeBuffers() != DEFAULT_PROCESSING_CONFIG.getNumMergeBuffers()) { + throw new ISE( + "Provided merge buffer count [%,d] does not match configured count [%,d]", + bufferPools.getNumMergeBuffers(), + DEFAULT_PROCESSING_CONFIG.getNumMergeBuffers() + ); + } + final GroupByStatsProvider statsProvider = new GroupByStatsProvider(); + final GroupByResourcesReservationPool groupByResourcesReservationPool = + new GroupByResourcesReservationPool(bufferPools.getMergePool(), config); + final GroupingEngine groupingEngine = new GroupingEngine( + DEFAULT_PROCESSING_CONFIG, + Suppliers.ofInstance(config), + groupByResourcesReservationPool, + mapper, + mapper, + QueryRunnerTestHelper.NOOP_QUERYWATCHER, + statsProvider + ); + final GroupByQueryQueryToolChest toolChest = new GroupByQueryQueryToolChest( + groupingEngine, + () -> config, + DefaultGroupByQueryMetricsFactory.instance(), + groupByResourcesReservationPool, + statsProvider + ); + return new GroupByQueryRunnerFactory(groupingEngine, toolChest, bufferPools.getProcessingPool()); + } + public static Iterable runQuery(QueryRunnerFactory factory, QueryRunner runner, Query query) { QueryToolChest toolChest = factory.getToolchest(); diff --git a/processing/src/test/java/org/apache/druid/query/groupby/TestGroupByBuffers.java b/processing/src/test/java/org/apache/druid/query/groupby/TestGroupByBuffers.java index 82378a0d7984..63d2a5985501 100644 --- a/processing/src/test/java/org/apache/druid/query/groupby/TestGroupByBuffers.java +++ b/processing/src/test/java/org/apache/druid/query/groupby/TestGroupByBuffers.java @@ -53,7 +53,7 @@ public static TestGroupByBuffers createFromProcessingConfig(final DruidProcessin public static TestGroupByBuffers createDefault() { - return createFromProcessingConfig(GroupByQueryRunnerTest.DEFAULT_PROCESSING_CONFIG); + return createFromProcessingConfig(GroupByQueryRunnerTestHelper.DEFAULT_PROCESSING_CONFIG); } public int getBufferSize() diff --git a/processing/src/test/java/org/apache/druid/segment/TestHelper.java b/processing/src/test/java/org/apache/druid/segment/TestHelper.java index 23af82a48040..f846db3c98d3 100644 --- a/processing/src/test/java/org/apache/druid/segment/TestHelper.java +++ b/processing/src/test/java/org/apache/druid/segment/TestHelper.java @@ -46,7 +46,7 @@ import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.DataSegment.PruneSpecsHolder; import org.apache.druid.timeline.partition.ShardSpec; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import java.io.IOException; import java.io.UncheckedIOException; @@ -240,7 +240,7 @@ private static void assertResults( } if (resultsIter.hasNext()) { - Assert.fail( + Assertions.fail( StringUtils.format( "%s: Expected resultsIter to be exhausted, next element was %s", failMsg, @@ -250,7 +250,7 @@ private static void assertResults( } if (resultsIter2.hasNext()) { - Assert.fail( + Assertions.fail( StringUtils.format( "%s: Expected resultsIter2 to be exhausted, next element was %s", failMsg, @@ -260,7 +260,7 @@ private static void assertResults( } if (expectedResultsIter.hasNext()) { - Assert.fail( + Assertions.fail( StringUtils.format( "%s: Expected expectedResultsIter to be exhausted, next element was %s", failMsg, @@ -293,25 +293,25 @@ private static void assertObjects(Iterable expectedResults, Iterable a assertRow(failMsg, (ResultRow) expectedNext, (ResultRow) next); assertRow(failMsg2, (ResultRow) expectedNext, (ResultRow) next2); } else { - Assert.assertEquals(failMsg, expectedNext, next); - Assert.assertEquals(failMsg2, expectedNext, next2); + Assertions.assertEquals(expectedNext, next, failMsg); + Assertions.assertEquals(expectedNext, next2, failMsg2); } } if (resultsIter.hasNext()) { - Assert.fail( + Assertions.fail( StringUtils.format("%s: Expected resultsIter to be exhausted, next element was %s", msg, resultsIter.next()) ); } if (resultsIter2.hasNext()) { - Assert.fail( + Assertions.fail( StringUtils.format("%s: Expected resultsIter2 to be exhausted, next element was %s", msg, resultsIter.next()) ); } if (expectedResultsIter.hasNext()) { - Assert.fail( + Assertions.fail( StringUtils.format( "%s: Expected expectedResultsIter to be exhausted, next element was %s", msg, @@ -323,14 +323,18 @@ private static void assertObjects(Iterable expectedResults, Iterable a private static void assertResult(String msg, Result expected, Result actual) { - Assert.assertEquals(msg, expected, actual); + Assertions.assertEquals(expected, actual, msg); } private static void assertTimeseriesResultValue(String msg, Result expected, Result actual) { // Custom equals check to get fuzzy comparison of numerics, useful because different groupBy strategies don't // always generate exactly the same results (different merge ordering / float vs double) - Assert.assertEquals(StringUtils.format("%s: timestamp", msg), expected.getTimestamp(), actual.getTimestamp()); + Assertions.assertEquals( + expected.getTimestamp(), + actual.getTimestamp(), + StringUtils.format("%s: timestamp", msg) + ); TimeseriesResultValue expectedVal = (TimeseriesResultValue) expected.getValue(); TimeseriesResultValue actualVal = (TimeseriesResultValue) actual.getValue(); @@ -365,7 +369,7 @@ private static void assertTopNResultValue(String msg, Result expected, Result ac dimensionAndMetricValueExtractor.getBaseObject() )) .collect(Collectors.toList()); - Assert.assertEquals("Size of list must match", listExpectedRows.size(), listActualRows.size()); + Assertions.assertEquals(listExpectedRows.size(), listActualRows.size(), "Size of list must match"); IntStream.range(0, listExpectedRows.size()).forEach(value -> assertRow( StringUtils.format("%s, on value number [%s]", msg, value), @@ -378,10 +382,10 @@ private static void assertRow(String msg, Row expected, Row actual) { // Custom equals check to get fuzzy comparison of numerics, useful because different groupBy strategies don't // always generate exactly the same results (different merge ordering / float vs double) - Assert.assertEquals( - StringUtils.format("%s: timestamp", msg), + Assertions.assertEquals( expected.getTimestamp(), - actual.getTimestamp() + actual.getTimestamp(), + StringUtils.format("%s: timestamp", msg) ); final Map expectedMap = ((MapBasedRow) expected).getEvent(); @@ -390,7 +394,7 @@ private static void assertRow(String msg, Row expected, Row actual) for (final String key : expectedMap.keySet()) { final Object expectedValue = expectedMap.get(key); if (!actualMap.containsKey(key)) { - Assert.fail( + Assertions.fail( StringUtils.format("%s: Expected key [%s] to exist, but it did not [%s]", msg, key, actualMap.keySet()) ); } @@ -398,35 +402,35 @@ private static void assertRow(String msg, Row expected, Row actual) final Object actualValue = actualMap.get(key); if ((expectedValue != null && actualValue == null) || (expectedValue == null && actualValue != null)) { - Assert.assertEquals(StringUtils.format("%s: key[%s]", msg, key), expectedValue, actualValue); + Assertions.assertEquals(expectedValue, actualValue, StringUtils.format("%s: key[%s]", msg, key)); } else if (expectedValue != null && expectedValue.getClass().isArray()) { - Assert.assertArrayEquals((Object[]) expectedValue, (Object[]) actualValue); + Assertions.assertArrayEquals((Object[]) expectedValue, (Object[]) actualValue); } else if (expectedValue instanceof Float || expectedValue instanceof Double) { - Assert.assertEquals( - StringUtils.format("%s: key[%s]", msg, key), + Assertions.assertEquals( ((Number) expectedValue).doubleValue(), ((Number) actualValue).doubleValue(), - Math.abs(((Number) expectedValue).doubleValue() * 1e-6) + Math.abs(((Number) expectedValue).doubleValue() * 1e-6), + StringUtils.format("%s: key[%s]", msg, key) ); } else { - Assert.assertEquals( - StringUtils.format("%s: key[%s]", msg, key), + Assertions.assertEquals( expectedValue, - actualValue + actualValue, + StringUtils.format("%s: key[%s]", msg, key) ); } } // Given that we iterated through all of the keys in one, checking that the key exists in the other, then if they // have the same size, they must have the same keyset. - Assert.assertEquals(expectedMap.size(), actualMap.size()); + Assertions.assertEquals(expectedMap.size(), actualMap.size()); } public static void assertRow(String msg, ResultRow expected, ResultRow actual) { - Assert.assertEquals( - StringUtils.format("%s: row length", msg), + Assertions.assertEquals( expected.length(), - actual.length() + actual.length(), + StringUtils.format("%s: row length", msg) ); for (int i = 0; i < expected.length(); i++) { @@ -438,33 +442,33 @@ public static void assertRow(String msg, ResultRow expected, ResultRow actual) if (expectedValue != null && expectedValue.getClass().isArray()) { // spilled results will materialize into lists, coerce them back to arrays if we expected arrays if (actualValue instanceof List) { - Assert.assertEquals( - message, + Assertions.assertEquals( (Object[]) expectedValue, - (Object[]) ExprEval.coerceListToArray((List) actualValue, true).rhs + (Object[]) ExprEval.coerceListToArray((List) actualValue, true).rhs, + message ); } else { - Assert.assertArrayEquals( - message, + Assertions.assertArrayEquals( (Object[]) expectedValue, - (Object[]) actualValue + (Object[]) actualValue, + message ); } } else if (expectedValue instanceof Float || expectedValue instanceof Double) { if (actualValue == null) { - Assert.fail(message + ": failed because expected numeric value is actually null"); + Assertions.fail(message + ": failed because expected numeric value is actually null"); } - Assert.assertEquals( - message, + Assertions.assertEquals( ((Number) expectedValue).doubleValue(), ((Number) actualValue).doubleValue(), - Math.abs(((Number) expectedValue).doubleValue() * 1e-6) + Math.abs(((Number) expectedValue).doubleValue() * 1e-6), + message ); } else { - Assert.assertEquals( - message, + Assertions.assertEquals( expectedValue, - actualValue + actualValue, + message ); } } @@ -509,7 +513,7 @@ public static void testSerializesDeserializes(ObjectMapper objectMapper, Object try { String serialized = objectMapper.writeValueAsString(object); Object deserialized = objectMapper.readValue(serialized, object.getClass()); - Assert.assertEquals(serialized, objectMapper.writeValueAsString(deserialized)); + Assertions.assertEquals(serialized, objectMapper.writeValueAsString(deserialized)); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/sql/src/test/java/org/apache/druid/sql/SqlQueryPlusTest.java b/sql/src/test/java/org/apache/druid/sql/SqlQueryPlusTest.java index 1c793b9ef559..4888e7be7b55 100644 --- a/sql/src/test/java/org/apache/druid/sql/SqlQueryPlusTest.java +++ b/sql/src/test/java/org/apache/druid/sql/SqlQueryPlusTest.java @@ -20,11 +20,11 @@ package org.apache.druid.sql; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; +import org.apache.druid.sql.calcite.BaseCalciteQueryTest; +import org.apache.druid.sql.calcite.DruidExceptionAssertions; 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.Assertions; +import org.junit.jupiter.api.Test; import java.util.Map; @@ -34,16 +34,16 @@ public class SqlQueryPlusTest public void testSyntaxError() { // SqlQueryPlus throws parse errors on build() if the statement is invalid - final DruidException e = Assert.assertThrows( + final DruidException e = Assertions.assertThrows( DruidException.class, () -> SqlQueryPlus.builder("SELECT COUNT(*) AS cnt, 'foo' AS") .auth(CalciteTests.REGULAR_USER_AUTH_RESULT) .build() ); - MatcherAssert.assertThat( + BaseCalciteQueryTest.assertDruidException( e, - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageContains("Incorrect syntax near the keyword 'AS' at line 1, column 31") ); @@ -59,14 +59,14 @@ public void testSyntaxErrorJdbc() .buildJdbc(); // It does throw exceptions on freshCopy(), though. - final DruidException e = Assert.assertThrows( + final DruidException e = Assertions.assertThrows( DruidException.class, sqlQueryPlus::freshCopy ); - MatcherAssert.assertThat( + BaseCalciteQueryTest.assertDruidException( e, - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageContains("Incorrect syntax near the keyword 'AS' at line 1, column 31") ); @@ -83,24 +83,24 @@ public void testUserProvidedContextOverridesSystemDefault() .queryContext(userProvidedContext) .auth(CalciteTests.REGULAR_USER_AUTH_RESULT); - Assert.assertEquals( + Assertions.assertEquals( Map.of("key", "user-provided-value", "key2", "system-default2"), sqlQueryPlusBuilder.build().context() ); - Assert.assertEquals( + Assertions.assertEquals( Map.of("key", "user-provided-value", "key2", "system-default2"), sqlQueryPlusBuilder.buildJdbc().context() ); - Assert.assertEquals( + Assertions.assertEquals( Map.of("key", "user-provided-value", "key2", "system-default2"), sqlQueryPlusBuilder.build().withContext(systemDefaultContext, userProvidedContext).context() ); - Assert.assertEquals( + Assertions.assertEquals( Map.of("key", "system-default", "key2", "system-default2"), sqlQueryPlusBuilder.build().withContext(systemDefaultContext, Map.of()).context() ); - Assert.assertEquals( + Assertions.assertEquals( Map.of("key", "user-provided-value"), sqlQueryPlusBuilder.build().withContext(Map.of(), userProvidedContext).context() ); 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 8856a19331f3..924f95046511 100644 --- a/sql/src/test/java/org/apache/druid/sql/SqlStatementTest.java +++ b/sql/src/test/java/org/apache/druid/sql/SqlStatementTest.java @@ -27,7 +27,6 @@ import org.apache.calcite.rel.type.RelDataType; import org.apache.calcite.rel.type.RelDataTypeField; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.concurrent.Execs; import org.apache.druid.java.util.common.guava.LazySequence; @@ -54,6 +53,8 @@ import org.apache.druid.server.security.AuthenticationResult; import org.apache.druid.server.security.ForbiddenException; import org.apache.druid.sql.DirectStatement.ResultSet; +import org.apache.druid.sql.calcite.BaseCalciteQueryTest; +import org.apache.druid.sql.calcite.DruidExceptionAssertions; import org.apache.druid.sql.calcite.planner.CalciteRulesManager; import org.apache.druid.sql.calcite.planner.CatalogResolver; import org.apache.druid.sql.calcite.planner.DruidOperatorTable; @@ -62,19 +63,20 @@ 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.SqlTestQueryStack; import org.apache.druid.sql.hook.DruidHookDispatcher; import org.easymock.EasyMock; -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.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +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.servlet.http.HttpServletRequest; + +import java.io.File; import java.io.IOException; import java.util.Collections; import java.util.List; @@ -82,19 +84,19 @@ import java.util.concurrent.TimeUnit; import static org.apache.druid.sql.calcite.BaseCalciteQueryTest.assertResultsEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class SqlStatementTest { private static QueryRunnerFactoryConglomerate conglomerate; private static SpecificSegmentsQuerySegmentWalker walker; private static Closer resourceCloser; - @ClassRule - public static TemporaryFolder temporaryFolder = new TemporaryFolder(); + @TempDir + public static File temporaryFolder; private ListeningExecutorService executorService; private final DefaultQueryConfig defaultQueryConfig = new DefaultQueryConfig( ImmutableMap.of("DEFAULT_KEY", "DEFAULT_VALUE")); @@ -102,11 +104,11 @@ public class SqlStatementTest private PolicyEnforcer policyEnforcer; private SqlStatementFactory sqlStatementFactory; - @BeforeClass - public static void setUpClass() throws Exception + @BeforeAll + public static void setUpClass() { resourceCloser = Closer.create(); - conglomerate = QueryStackTests.createQueryRunnerFactoryConglomerate(resourceCloser); + conglomerate = SqlTestQueryStack.createQueryRunnerFactoryConglomerate(resourceCloser); final QueryScheduler scheduler = new QueryScheduler( 5, @@ -125,17 +127,17 @@ public Sequence run(Query query, Sequence resultSequence) } }; - walker = CalciteTests.createMockWalker(conglomerate, temporaryFolder.newFolder(), scheduler); + walker = CalciteTests.createMockWalker(conglomerate, temporaryFolder, scheduler); resourceCloser.register(walker); } - @AfterClass + @AfterAll public static void tearDownClass() throws IOException { resourceCloser.close(); } - @Before + @BeforeEach public void setUp() { executorService = MoreExecutors.listeningDecorator(Execs.multiThreaded(8, "test_sql_resource_%s")); @@ -144,7 +146,7 @@ public void setUp() this.sqlStatementFactory = buildSqlStatementFactory(); } - @After + @AfterEach public void tearDown() throws Exception { executorService.shutdownNow(); @@ -254,11 +256,11 @@ public void testDirectPolicyEnforcerThrowsForNoPolicy() ); DirectStatement stmt = sqlStatementFactory.directStatement(sqlReq); ResultSet resultSet = stmt.plan(); - DruidException e = Assert.assertThrows(DruidException.class, () -> resultSet.run()); + DruidException e = Assertions.assertThrows(DruidException.class, () -> resultSet.run()); - Assert.assertEquals(DruidException.Category.FORBIDDEN, e.getCategory()); - Assert.assertEquals(DruidException.Persona.OPERATOR, e.getTargetPersona()); - Assert.assertEquals("Failed security validation with dataSource [foo]", e.getMessage()); + Assertions.assertEquals(DruidException.Category.FORBIDDEN, e.getCategory()); + Assertions.assertEquals(DruidException.Persona.OPERATOR, e.getTargetPersona()); + Assertions.assertEquals("Failed security validation with dataSource [foo]", e.getMessage()); } @Test @@ -292,9 +294,9 @@ public void testDirectValidationError() fail(); } catch (DruidException e) { - MatcherAssert.assertThat( + BaseCalciteQueryTest.assertDruidException( e, - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageContains("Object 'bogus' not found within 'druid'") ); @@ -355,9 +357,9 @@ public void testHttpValidationError() fail(); } catch (DruidException e) { - MatcherAssert.assertThat( + BaseCalciteQueryTest.assertDruidException( e, - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageContains("Object 'bogus' not found within 'druid'") ); @@ -390,11 +392,11 @@ public void testHttpPolicyEnforcerThrowsForNoPolicy() throws Exception request(true) ); ResultSet resultSet = stmt.plan(); - DruidException e = Assert.assertThrows(DruidException.class, () -> resultSet.run()); + DruidException e = Assertions.assertThrows(DruidException.class, () -> resultSet.run()); - Assert.assertEquals(DruidException.Category.FORBIDDEN, e.getCategory()); - Assert.assertEquals(DruidException.Persona.OPERATOR, e.getTargetPersona()); - Assert.assertEquals("Failed security validation with dataSource [foo]", e.getMessage()); + Assertions.assertEquals(DruidException.Category.FORBIDDEN, e.getCategory()); + Assertions.assertEquals(DruidException.Persona.OPERATOR, e.getTargetPersona()); + Assertions.assertEquals("Failed security validation with dataSource [foo]", e.getMessage()); } @Test @@ -459,9 +461,9 @@ public void testPrepareValidationError() fail(); } catch (DruidException e) { - MatcherAssert.assertThat( + BaseCalciteQueryTest.assertDruidException( e, - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageContains("Object 'bogus' not found within 'druid'") ); @@ -495,11 +497,11 @@ public void testPreparePolicyEnforcerThrowsForNoPolicy() CalciteTests.REGULAR_USER_AUTH_RESULT ); PreparedStatement stmt = sqlStatementFactory.preparedStatement(sqlReq); - DruidException e = Assert.assertThrows(DruidException.class, () -> stmt.execute(Collections.emptyList(), null).execute()); + DruidException e = Assertions.assertThrows(DruidException.class, () -> stmt.execute(Collections.emptyList(), null).execute()); - Assert.assertEquals(DruidException.Category.FORBIDDEN, e.getCategory()); - Assert.assertEquals(DruidException.Persona.OPERATOR, e.getTargetPersona()); - Assert.assertEquals("Failed security validation with dataSource [foo]", e.getMessage()); + Assertions.assertEquals(DruidException.Category.FORBIDDEN, e.getCategory()); + Assertions.assertEquals(DruidException.Persona.OPERATOR, e.getTargetPersona()); + Assertions.assertEquals("Failed security validation with dataSource [foo]", e.getMessage()); } @Test @@ -532,7 +534,7 @@ public void testIgnoredQueryContextParametersAreIgnored() DirectStatement stmt = sqlStatementFactory.directStatement(sqlReq); Map context = stmt.context(); // should contain only query id, not bySegment since it is not valid for SQL - Assert.assertEquals(Collections.singleton(QueryContexts.CTX_SQL_QUERY_ID), context.keySet()); + Assertions.assertEquals(Collections.singleton(QueryContexts.CTX_SQL_QUERY_ID), context.keySet()); } private SqlStatementFactory buildSqlStatementFactory() 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 8f65b4328432..0dd5cb4a6b72 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 @@ -31,7 +31,6 @@ import org.apache.druid.error.DruidException; import org.apache.druid.error.DruidException.Category; import org.apache.druid.error.DruidException.Persona; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.Intervals; @@ -96,18 +95,16 @@ import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerFixture; import org.apache.druid.sql.http.SqlParameter; -import org.hamcrest.CoreMatchers; -import org.hamcrest.Matcher; 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.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Named; import org.junit.jupiter.api.extension.RegisterExtension; import javax.annotation.Nullable; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -119,12 +116,12 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Consumer; 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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assumptions.assumeFalse; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -519,14 +516,14 @@ public static Druids.ScanQueryBuilder newScanQueryBuilder() return new Druids.ScanQueryBuilder().resultFormat(ScanQuery.ResultFormat.RESULT_FORMAT_COMPACTED_LIST); } - protected static DruidExceptionMatcher invalidSqlIs(String s) + protected static DruidExceptionAssertions invalidSqlIs(String s) { - return DruidExceptionMatcher.invalidSqlInput().expectMessageIs(s); + return DruidExceptionAssertions.invalidSqlInput().expectMessageIs(s); } - protected static DruidExceptionMatcher invalidSqlContains(String s) + protected static DruidExceptionAssertions invalidSqlContains(String s) { - return DruidExceptionMatcher.invalidSqlInput().expectMessageContains(s); + return DruidExceptionAssertions.invalidSqlInput().expectMessageContains(s); } @RegisterExtension @@ -559,7 +556,7 @@ public void assertQueryIsUnplannable(final PlannerConfig plannerConfig, final St testQuery(plannerConfig, sql, CalciteTests.REGULAR_USER_AUTH_RESULT, ImmutableList.of(), ImmutableList.of()); } catch (DruidException e) { - assertThat( + assertDruidException( e, buildUnplannableExceptionMatcher().expectMessageContains(expectedError) ); @@ -570,17 +567,17 @@ public void assertQueryIsUnplannable(final PlannerConfig plannerConfig, final St } } - private DruidExceptionMatcher buildUnplannableExceptionMatcher() + private DruidExceptionAssertions buildUnplannableExceptionMatcher() { if (testBuilder().isDecoupledMode()) { - return new DruidExceptionMatcher(Persona.USER, Category.INVALID_INPUT, "invalidInput"); + return new DruidExceptionAssertions(Persona.USER, Category.INVALID_INPUT, "invalidInput"); } else { - return new DruidExceptionMatcher(Persona.USER, Category.INVALID_INPUT, "general"); + return new DruidExceptionAssertions(Persona.USER, Category.INVALID_INPUT, "general"); } } /** - * Provided for tests that wish to check multiple queries instead of relying on ExpectedException. + * Provided for tests that wish to check multiple queries instead of relying on a rule-based expected exception. */ public void assertQueryIsForbidden(final String sql, final AuthenticationResult authenticationResult) { @@ -603,7 +600,7 @@ public void assertQueryIsForbidden( if (!(e instanceof ForbiddenException)) { log.error(e, "Expected ForbiddenException for query: %s with authResult: %s", sql, authenticationResult); - Assert.fail(sql); + Assertions.fail(sql); } } @@ -870,9 +867,9 @@ public enum ResultMatchMode void validate(int row, int column, ValueType type, Object expectedCell, Object resultCell) { assertEquals( - mismatchMessage(row, column), expectedCell, - resultCell); + resultCell, + mismatchMessage(row, column)); } }, RELAX_NULLS { @@ -893,17 +890,17 @@ void validate(int row, int column, ValueType type, Object expectedCell, Object r { if (expectedCell instanceof Float) { assertEquals( - mismatchMessage(row, column), (Float) expectedCell, (Float) resultCell, - ASSERTION_EPSILON + ASSERTION_EPSILON, + mismatchMessage(row, column) ); } else if (expectedCell instanceof Double) { assertEquals( - mismatchMessage(row, column), (Double) expectedCell, (Double) resultCell, - ASSERTION_EPSILON + ASSERTION_EPSILON, + mismatchMessage(row, column) ); } else if (expectedCell instanceof Object[] || expectedCell instanceof List) { final Object[] expectedCellCasted = homogenizeArray(expectedCell); @@ -951,18 +948,18 @@ void validate(int row, int column, ValueType type, Object expectedCell, Object r if (expectedCell instanceof Float) { float eps = ASSERTION_ERROR_ULPS * Math.ulp((Float) expectedCell); assertEquals( - mismatchMessage(row, column), (Float) expectedCell, (Float) resultCell, - eps + eps, + mismatchMessage(row, column) ); } else if (expectedCell instanceof Double) { double eps = ASSERTION_ERROR_ULPS * Math.ulp((Double) expectedCell); assertEquals( - mismatchMessage(row, column), (Double) expectedCell, (Double) resultCell, - eps + eps, + mismatchMessage(row, column) ); } else if (expectedCell instanceof Object[] || expectedCell instanceof List) { final Object[] expectedCellCasted = homogenizeArray(expectedCell); @@ -1023,7 +1020,7 @@ private static Object[] homogenizeArray(Object array) public static void assertResultsValid(final ResultMatchMode matchMode, final List expected, final QueryResults queryResults) { final List results = queryResults.results; - Assert.assertEquals("Result count mismatch", expected.size(), results.size()); + Assertions.assertEquals(expected.size(), results.size(), "Result count mismatch"); final List types = new ArrayList<>(); @@ -1040,7 +1037,7 @@ public static void assertResultsValid(final ResultMatchMode matchMode, final Lis for (int row = 0; row < numRows; row++) { final Object[] expectedRow = expected.get(row); final Object[] resultRow = results.get(row); - assertEquals("column count mismatch; at row#" + row, expectedRow.length, resultRow.length); + assertEquals(expectedRow.length, resultRow.length, "column count mismatch; at row#" + row); for (int i = 0; i < resultRow.length; i++) { final Object resultCell = resultRow[i]; @@ -1061,21 +1058,40 @@ public static void assertResultsEquals(String sql, List expectedResult { int minSize = Math.min(results.size(), expectedResults.size()); for (int i = 0; i < minSize; i++) { - Assert.assertArrayEquals( - StringUtils.format("result #%d: %s", i + 1, sql), + Assertions.assertArrayEquals( expectedResults.get(i), - results.get(i) + results.get(i), + StringUtils.format("result #%d: %s", i + 1, sql) ); } - Assert.assertEquals(expectedResults.size(), results.size()); + Assertions.assertEquals(expectedResults.size(), results.size()); + } + + public void testQueryThrows( + final String sql, + final DruidExceptionAssertions exceptionMatcher + ) + { + testQueryThrows(sql, null, DruidException.class, e -> assertDruidException(e, exceptionMatcher)); + } + + public void testQueryThrows( + final String sql, + final Class exceptionType, + final DruidExceptionAssertions exceptionMatcher + ) + { + testQueryThrows(sql, null, exceptionType, e -> assertDruidException(e, exceptionMatcher)); } - public void testQueryThrows( + public void testQueryThrows( final String sql, - final DruidExceptionMatcher exceptionMatcher + final Map queryContext, + final Class exceptionType, + final DruidExceptionAssertions exceptionMatcher ) { - testQueryThrows(sql, null, DruidException.class, exceptionMatcher); + testQueryThrows(sql, queryContext, exceptionType, e -> assertDruidException(e, exceptionMatcher)); } public void testQueryThrows( @@ -1088,24 +1104,24 @@ public void testQueryThrows( sql, null, exceptionType, - ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo(exceptionMessage)) + e -> assertEquals(exceptionMessage, e.getMessage()) ); } public void testQueryThrows( final String sql, final Class exceptionType, - final Matcher exceptionMatcher + final Consumer exceptionVerifier ) { - testQueryThrows(sql, null, exceptionType, exceptionMatcher); + testQueryThrows(sql, null, exceptionType, exceptionVerifier); } public void testQueryThrows( final String sql, final Map queryContext, final Class exceptionType, - final Matcher exceptionMatcher + final Consumer exceptionVerifier ) { T e = assertThrows( @@ -1116,7 +1132,15 @@ public void testQueryThrows( .build() .run() ); - assertThat(e, exceptionMatcher); + exceptionVerifier.accept(e); + } + + public static void assertDruidException( + final DruidException exception, + final DruidExceptionAssertions exceptionMatcher + ) + { + exceptionMatcher.assertMatches(exception); } public void analyzeResources( @@ -1412,7 +1436,7 @@ public DefaultResultsVerifier(List expectedResults, RowSignature expec public void verifyRowSignature(RowSignature rowSignature) { if (expectedResultRowSignature != null) { - Assert.assertEquals(expectedResultRowSignature, rowSignature); + Assertions.assertEquals(expectedResultRowSignature, rowSignature); } } 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 8467e4e9b06b..273cec8ce246 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,8 +44,7 @@ import org.apache.druid.storage.StorageConnectorProvider; import org.apache.druid.storage.local.LocalFileExportStorageProvider; import org.apache.druid.storage.local.LocalFileStorageConnectorProvider; -import org.hamcrest.CoreMatchers; -import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -134,16 +133,14 @@ public void testReplaceIntoExternShouldThrowUnsupportedException() + "AS CSV " + "OVERWRITE ALL " + "SELECT dim2 FROM foo", LocalFileExportStorageProvider.TYPE_NAME)) - .expectValidationError( - CoreMatchers.allOf( - CoreMatchers.instanceOf(DruidException.class), - ThrowableMessageMatcher.hasMessage( - CoreMatchers.containsString( - "REPLACE operations do no support EXTERN destinations. Use INSERT statements to write to an external destination." - ) - ) - ) - ) + .expectValidationError(e -> { + Assertions.assertInstanceOf(DruidException.class, e); + Assertions.assertTrue( + e.getMessage().contains( + "REPLACE operations do no support EXTERN destinations. Use INSERT statements to write to an external destination." + ) + ); + }) .verify(); } @@ -154,12 +151,10 @@ public void testExportWithoutRequiredParameter() .sql(StringUtils.format("INSERT INTO EXTERN(%s()) " + "AS CSV " + "SELECT dim2 FROM foo", LocalFileExportStorageProvider.TYPE_NAME)) - .expectValidationError( - CoreMatchers.allOf( - CoreMatchers.instanceOf(IllegalArgumentException.class), - ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString("Missing required creator property 'exportPath'")) - ) - ) + .expectValidationError(e -> { + Assertions.assertInstanceOf(IllegalArgumentException.class, e); + Assertions.assertTrue(e.getMessage().contains("Missing required creator property 'exportPath'")); + }) .verify(); } @@ -271,12 +266,10 @@ public void testWithUnsupportedStorageConnector() { testIngestionQuery() .sql("insert into extern(nonExistent()) as csv select __time, dim1 from foo") - .expectValidationError( - CoreMatchers.allOf( - CoreMatchers.instanceOf(IllegalArgumentException.class), - ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString("Could not resolve type id 'nonExistent' as a subtype")) - ) - ) + .expectValidationError(e -> { + Assertions.assertInstanceOf(IllegalArgumentException.class, e); + Assertions.assertTrue(e.getMessage().contains("Could not resolve type id 'nonExistent' as a subtype")); + }) .verify(); } 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 507da7c43142..ab3684ef9d98 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 @@ -37,6 +37,7 @@ import org.apache.druid.data.input.impl.CsvInputFormat; import org.apache.druid.data.input.impl.InlineInputSource; import org.apache.druid.data.input.impl.SplittableInputSource; +import org.apache.druid.error.DruidException; import org.apache.druid.initialization.DruidModule; import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.StringUtils; @@ -66,11 +67,8 @@ import org.apache.druid.sql.calcite.util.SqlTestFramework.StandardComponentSupplier; import org.apache.druid.sql.guice.SqlBindings; import org.apache.druid.sql.http.SqlParameter; -import org.hamcrest.CoreMatchers; -import org.hamcrest.Matcher; -import org.junit.Assert; -import org.junit.internal.matchers.ThrowableMessageMatcher; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -83,10 +81,9 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.function.Consumer; import java.util.stream.Stream; -import static org.hamcrest.MatcherAssert.assertThat; - @SqlTestFrameworkConfig.ComponentSupplier(IngestionDmlComponentSupplier.class) public class CalciteIngestionDmlTest extends BaseCalciteQueryTest { @@ -233,7 +230,7 @@ protected Map queryContextWithGranularity(Granularity granularit granularityString = queryJsonMapper.writeValueAsString(granularity); } catch (JsonProcessingException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } return ImmutableMap.of(DruidSqlInsert.SQL_INSERT_SEGMENT_GRANULARITY, granularityString); } @@ -253,7 +250,7 @@ public class IngestionDmlTester private RowSignature expectedTargetSignature; private List expectedResources; private Query expectedQuery; - private Matcher validationErrorMatcher; + private Consumer validationErrorVerifier; private String expectedLogicalPlanResource; private List parameters; private AuthConfig authConfig; @@ -325,25 +322,31 @@ public IngestionDmlTester expectQuery(final Query expectedQuery) return this; } - public IngestionDmlTester expectValidationError(Matcher validationErrorMatcher) + public IngestionDmlTester expectValidationError(Consumer validationErrorVerifier) { - this.validationErrorMatcher = validationErrorMatcher; + this.validationErrorVerifier = validationErrorVerifier; return this; } + public IngestionDmlTester expectValidationError(DruidExceptionAssertions exceptionMatcher) + { + return expectValidationError(e -> { + Assertions.assertInstanceOf(DruidException.class, e); + assertDruidException((DruidException) e, exceptionMatcher); + }); + } + public IngestionDmlTester expectValidationError(Class clazz) { - return expectValidationError(CoreMatchers.instanceOf(clazz)); + return expectValidationError(e -> Assertions.assertInstanceOf(clazz, e)); } public IngestionDmlTester expectValidationError(Class clazz, String message) { - return expectValidationError( - CoreMatchers.allOf( - CoreMatchers.instanceOf(clazz), - ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo(message)) - ) - ); + return expectValidationError(e -> { + Assertions.assertInstanceOf(clazz, e); + Assertions.assertEquals(message, e.getMessage()); + }); } public IngestionDmlTester expectLogicalPlanFrom(String resource) @@ -369,7 +372,7 @@ public void verify() try { log.info("SQL: %s", sql); - if (validationErrorMatcher != null) { + if (validationErrorVerifier != null) { verifyValidationError(); } else { verifySuccess(); @@ -397,14 +400,14 @@ private void verifyValidationError() throw new ISE("Test must not have expectedQuery"); } - final Throwable e = Assert.assertThrows( + final Throwable e = Assertions.assertThrows( Throwable.class, () -> { getSqlStatementFactory(plannerConfig, authConfig).directStatement(sqlQuery()).execute(); } ); - assertThat(e, validationErrorMatcher); + validationErrorVerifier.accept(e); } 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 7fffbc5216c3..8c2e34d5e4bd 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 @@ -27,7 +27,6 @@ import org.apache.druid.data.input.impl.CsvInputFormat; import org.apache.druid.data.input.impl.InlineInputSource; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.granularity.Granularity; @@ -52,9 +51,7 @@ 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.junit.Assert; -import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; @@ -68,7 +65,6 @@ 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 { @@ -216,7 +212,7 @@ public void testInsertIntoInvalidDataSourceName() testIngestionQuery() .sql("INSERT INTO \"in/valid\" SELECT dim1, dim2 FROM foo PARTITIONED BY ALL TIME") .expectValidationError( - DruidExceptionMatcher.invalidInput().expectMessageIs( + DruidExceptionAssertions.invalidInput().expectMessageIs( "Invalid value for field [table]: Value [in/valid] cannot contain '/'." ) ) @@ -581,12 +577,7 @@ public void testInsertFromExternalWithoutSecuritySupportWithInputsourceSecurityE .authentication(CalciteTests.SUPER_USER_AUTH_RESULT) .authConfig(AuthConfig.newBuilder().setEnableInputSourceSecurity(true).build()) .expectLogicalPlanFrom("insertFromExternal") - .expectValidationError( - CoreMatchers.allOf( - CoreMatchers.instanceOf(CalciteIngestDmlTestException.class), - ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo("getTypes()")) - ) - ) + .expectValidationError(CalciteIngestDmlTestException.class, "getTypes()") .verify(); } @@ -649,7 +640,7 @@ public void testPartitionedBySupportedClauses() } catch (JsonProcessingException e) { // Won't reach here - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } testIngestionQuery() @@ -696,7 +687,7 @@ public void testPartitionedBySupportedGranularityLiteralClauses() } catch (JsonProcessingException e) { // Won't reach here - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } testIngestionQuery() @@ -1136,10 +1127,10 @@ public void testInsertWithClusteredByAndOrderBy() ImmutableList.of(), ImmutableList.of() ); - Assert.fail("Exception should be thrown"); + Assertions.fail("Exception should be thrown"); } catch (DruidException e) { - assertThat(e, invalidSqlIs( + assertDruidException(e, invalidSqlIs( "Cannot use an ORDER BY clause on a Query of type [INSERT], use CLUSTERED BY instead" )); } @@ -1155,10 +1146,10 @@ public void testInsertWithPartitionedByContainingInvalidGranularity() ImmutableList.of(), ImmutableList.of() ); - Assert.fail("Exception should be thrown"); + Assertions.fail("Exception should be thrown"); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs( "Invalid granularity['invalid_granularity'] specified after PARTITIONED BY clause." @@ -1182,10 +1173,10 @@ public void testInsertWithOrderBy() ImmutableList.of(), ImmutableList.of() ); - Assert.fail("Exception should be thrown"); + Assertions.fail("Exception should be thrown"); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs("Cannot use an ORDER BY clause on a Query of type [INSERT], use CLUSTERED BY instead") ); @@ -1198,7 +1189,7 @@ public void testInsertWithOrderBy() @Test public void testInsertWithoutPartitionedBy() { - DruidException e = Assert.assertThrows( + DruidException e = Assertions.assertThrows( DruidException.class, () -> testQuery( @@ -1208,7 +1199,7 @@ public void testInsertWithoutPartitionedBy() ) ); - assertThat( + assertDruidException( e, invalidSqlIs("Operation [INSERT] requires a PARTITIONED BY to be explicitly defined, but none was found.") ); @@ -1322,7 +1313,7 @@ public void testExplainPlanForInsertWithClusteredBy() throws JsonProcessingExcep public void testExplainInsertFromExternalUnauthorized() { // Use testQuery for EXPLAIN (not testIngestionQuery). - Assert.assertThrows( + Assertions.assertThrows( ForbiddenException.class, () -> testQuery( @@ -1535,16 +1526,17 @@ public void testInsertQueryWithInvalidGranularity() { testIngestionQuery() .sql("insert into foo1 select __time, dim1 FROM foo partitioned by time_floor(__time, 'PT2H')") - .expectValidationError( - CoreMatchers.allOf( - CoreMatchers.instanceOf(DruidException.class), - ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString( + .expectValidationError(e -> { + Assertions.assertInstanceOf(DruidException.class, e); + Assertions.assertTrue( + e.getMessage().contains( "Invalid granularity[`time_floor`(`__time`, 'PT2H')] specified after PARTITIONED BY clause." + " Expected 'SECOND', 'MINUTE', 'FIVE_MINUTE', 'TEN_MINUTE', 'FIFTEEN_MINUTE', 'THIRTY_MINUTE'," + " 'HOUR', 'SIX_HOUR', 'EIGHT_HOUR', 'DAY', 'MONTH', 'QUARTER', 'YEAR', 'ALL'," - + " ALL TIME, FLOOR() or TIME_FLOOR()")) - ) - ) + + " ALL TIME, FLOOR() or TIME_FLOOR()" + ) + ); + }) .verify(); } @@ -1563,13 +1555,12 @@ public void testInsertOnExternalDataSourceWithIncompatibleTimeColumnSignature() "INSERT INTO dst SELECT __time FROM %s PARTITIONED BY ALL TIME", externSql(restrictedSignature) ) - .expectValidationError( - CoreMatchers.allOf( - CoreMatchers.instanceOf(DruidException.class), - ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString( - "EXTERN function with __time column can be used when __time column is of type long")) - ) - ) + .expectValidationError(e -> { + Assertions.assertInstanceOf(DruidException.class, e); + Assertions.assertTrue( + e.getMessage().contains("EXTERN function with __time column can be used when __time column is of type long") + ); + }) .verify(); } @@ -1605,7 +1596,7 @@ public void testErrorWithUnableToConstructColumnSignatureWithExtern() HashMap context = new HashMap<>(DEFAULT_CONTEXT); testIngestionQuery().context(context).sql(sqlString) .expectValidationError( - new DruidExceptionMatcher( + new DruidExceptionAssertions( DruidException.Persona.USER, DruidException.Category.INVALID_INPUT, "invalidInput" @@ -1633,7 +1624,7 @@ public void testErrorWhenBothRowSignatureAndExtendsProvidedToExtern() HashMap context = new HashMap<>(DEFAULT_CONTEXT); testIngestionQuery().context(context).sql(sqlString) .expectValidationError( - new DruidExceptionMatcher( + new DruidExceptionAssertions( DruidException.Persona.USER, DruidException.Category.INVALID_INPUT, "invalidInput" @@ -1660,7 +1651,7 @@ public void testErrorWhenNoneOfRowSignatureAndExtendsProvidedToExtern() HashMap context = new HashMap<>(DEFAULT_CONTEXT); testIngestionQuery().context(context).sql(sqlString) .expectValidationError( - new DruidExceptionMatcher( + new DruidExceptionAssertions( DruidException.Persona.USER, DruidException.Category.INVALID_INPUT, "invalidInput" @@ -1688,7 +1679,7 @@ public void testErrorWhenInputSourceInvalid() HashMap context = new HashMap<>(DEFAULT_CONTEXT); testIngestionQuery().context(context).sql(sqlString) .expectValidationError( - new DruidExceptionMatcher( + new DruidExceptionAssertions( DruidException.Persona.USER, DruidException.Category.INVALID_INPUT, "invalidInput" 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 d78aa5d24de3..87f10d8d860e 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 @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.JodaUtils; @@ -91,10 +90,9 @@ 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.CoreMatchers; import org.joda.time.DateTimeZone; import org.joda.time.Period; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -106,7 +104,6 @@ import java.util.List; import java.util.Map; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assumptions.assumeFalse; @@ -1574,12 +1571,12 @@ public void testTimeColumnAggregationsOnLookups(Map queryContext ImmutableList.of(), ImmutableList.of() ); - Assert.fail("Expected exception to be thrown."); + Assertions.fail("Expected exception to be thrown."); } catch (DruidException e) { - assertThat( + assertDruidException( e, - new DruidExceptionMatcher(DruidException.Persona.ADMIN, DruidException.Category.INVALID_INPUT, "general") + new DruidExceptionAssertions(DruidException.Persona.ADMIN, DruidException.Category.INVALID_INPUT, "general") .expectMessageIs( "Query could not be planned. A possible reason is " + "[LATEST and EARLIEST aggregators implicitly depend on the __time column, " @@ -5075,7 +5072,7 @@ public void testGroupByJoinAsNativeQueryWithUnoptimizedFilter(Map results = seq.toList(); - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of(ResultRow.of("def")), results ); @@ -5164,7 +5161,7 @@ public void testJoinOnRestrictedBroadcast(Map queryContext) ) ); - Exception e = Assert.assertThrows( + Exception e = Assertions.assertThrows( Exception.class, () -> testQuery( PLANNER_CONFIG_DEFAULT, @@ -5175,9 +5172,8 @@ public void testJoinOnRestrictedBroadcast(Map queryContext) ) ); - assertThat( - e.getMessage(), - CoreMatchers.containsString( + Assertions.assertTrue( + e.getMessage().contains( "Restricted data source [GlobalTableDataSource{name='restrictedBroadcastDatasource_m1_is_6'}] with policy [RowFilterPolicy{rowFilter=m1 = 6 (LONG)}] is not supported" ) ); @@ -5505,7 +5501,7 @@ public void testInnerJoinWithFilterPushdownAndManyFiltersEmptyResults(Map Assertions.assertTrue( + e.getMessage().contains( StringUtils.format( "org.apache.druid.query.groupby.epinephelinae.UnexpectedMultiValueDimensionException: " + "Encountered multi-value dimension [%s] that cannot be processed with '%s' set to false." 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 e5f1f375155f..408616e861a8 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 @@ -32,7 +32,6 @@ import org.apache.druid.data.input.impl.StringDimensionSchema; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.guice.BuiltInTypesModule; import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.granularity.Granularities; @@ -82,11 +81,7 @@ 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.Assert; -import org.junit.internal.matchers.ThrowableMessageMatcher; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -96,8 +91,6 @@ import java.util.Map; import java.util.stream.Collectors; -import static org.hamcrest.MatcherAssert.assertThat; - @SqlTestFrameworkConfig.ComponentSupplier(NestedComponentSupplier.class) public abstract class CalciteNestedDataQueryTest extends BaseCalciteQueryTest { @@ -160,43 +153,6 @@ public abstract class CalciteNestedDataQueryTest extends BaseCalciteQueryTest .build() ); - @Nested - public static class DefaultCalciteNestedDataQueryTest extends CalciteNestedDataQueryTest - { - } - - @Nested - public static class NoneObjectStorageCalciteNestedDataQueryTest extends CalciteNestedDataQueryTest - { - public NoneObjectStorageCalciteNestedDataQueryTest() - { - super(); - // Override with none object storage - NestedCommonFormatColumnFormatSpec noneObjectStorage = - NestedCommonFormatColumnFormatSpec.builder().setObjectStorageEncoding(ObjectStorageEncoding.NONE).build(); - Mockito.when(ALL_JSON_COLUMNS.getDimensionsSpec()).thenReturn( - DimensionsSpec.builder().setDimensions( - ImmutableList.builder() - .add(new AutoTypeColumnSchema("string", null, noneObjectStorage)) - .add(new AutoTypeColumnSchema("nest", null, noneObjectStorage)) - .add(new AutoTypeColumnSchema("nester", null, noneObjectStorage)) - .add(new AutoTypeColumnSchema("long", null, noneObjectStorage)) - .add(new AutoTypeColumnSchema("string_sparse", null, noneObjectStorage)) - .build() - ).build()); - Mockito.when(JSON_AND_SCALAR_MIX.getDimensionsSpec()).thenReturn( - DimensionsSpec.builder().setDimensions( - ImmutableList.builder() - .add(new StringDimensionSchema("string")) - .add(new AutoTypeColumnSchema("nest", null, noneObjectStorage)) - .add(new AutoTypeColumnSchema("nester", null, noneObjectStorage)) - .add(new LongDimensionSchema("long")) - .add(new StringDimensionSchema("string_sparse")) - .build() - ).build()); - } - } - public static final InputRowSchema ALL_JSON_COLUMNS = Mockito.mock(InputRowSchema.class); public static final InputRowSchema JSON_AND_SCALAR_MIX = Mockito.mock(InputRowSchema.class); @@ -4931,7 +4887,7 @@ public void testGroupByInvalidPath() + "JSON_VALUE(nester, '.array.[1]'), " + "SUM(cnt) " + "FROM druid.nested GROUP BY 1", - DruidExceptionMatcher + DruidExceptionAssertions .invalidInput() .expectMessageIs("JSONPath [.array.[1]] is invalid, it must start with '$'") ); @@ -5574,8 +5530,8 @@ public void testJsonValueUnsupportedOptions() + "SUM(JSON_VALUE(nest, '$.z' RETURNING BIGINT ERROR ON EMPTY ERROR ON ERROR)) " + "FROM druid.nested", IllegalArgumentException.class, - ThrowableMessageMatcher.hasMessage( - CoreMatchers.containsString( + e -> Assertions.assertTrue( + e.getMessage().contains( "Unsupported JSON_VALUE parameter 'ON EMPTY' defined - please re-issue this query without this argument" ) ) @@ -5783,9 +5739,8 @@ public void testJoinOnNestedColumnThrows() .run(); }); - assertThat( - e.getMessage(), - CoreMatchers.containsString("Cannot join when the join condition has column of type [COMPLEX]") + Assertions.assertTrue( + e.getMessage().contains("Cannot join when the join condition has column of type [COMPLEX]") ); } @@ -7426,7 +7381,7 @@ public void testApproxCountDistinctOnUnsupportedComplexColumn() @Test public void testApproxCountDistinctFunctionOnUnsupportedComplexColumn() { - DruidException druidException = Assert.assertThrows( + DruidException druidException = Assertions.assertThrows( DruidException.class, () -> testQuery( "SELECT APPROX_COUNT_DISTINCT(nester) FROM druid.nested", @@ -7434,7 +7389,7 @@ public void testApproxCountDistinctFunctionOnUnsupportedComplexColumn() ImmutableList.of() ) ); - Assert.assertTrue(druidException.getMessage().contains( + Assertions.assertTrue(druidException.getMessage().contains( "Cannot apply 'APPROX_COUNT_DISTINCT' to arguments of type 'APPROX_COUNT_DISTINCT(>)'" )); } @@ -8043,3 +7998,38 @@ public void testCountPathWithArraysReturningRealtime() ); } } + +class DefaultCalciteNestedDataQueryTest extends CalciteNestedDataQueryTest +{ +} + +class NoneObjectStorageCalciteNestedDataQueryTest extends CalciteNestedDataQueryTest +{ + NoneObjectStorageCalciteNestedDataQueryTest() + { + super(); + // Override with none object storage + final NestedCommonFormatColumnFormatSpec noneObjectStorage = + NestedCommonFormatColumnFormatSpec.builder().setObjectStorageEncoding(ObjectStorageEncoding.NONE).build(); + Mockito.when(ALL_JSON_COLUMNS.getDimensionsSpec()).thenReturn( + DimensionsSpec.builder().setDimensions( + ImmutableList.builder() + .add(new AutoTypeColumnSchema("string", null, noneObjectStorage)) + .add(new AutoTypeColumnSchema("nest", null, noneObjectStorage)) + .add(new AutoTypeColumnSchema("nester", null, noneObjectStorage)) + .add(new AutoTypeColumnSchema("long", null, noneObjectStorage)) + .add(new AutoTypeColumnSchema("string_sparse", null, noneObjectStorage)) + .build() + ).build()); + Mockito.when(JSON_AND_SCALAR_MIX.getDimensionsSpec()).thenReturn( + DimensionsSpec.builder().setDimensions( + ImmutableList.builder() + .add(new StringDimensionSchema("string")) + .add(new AutoTypeColumnSchema("nest", null, noneObjectStorage)) + .add(new AutoTypeColumnSchema("nester", null, noneObjectStorage)) + .add(new LongDimensionSchema("long")) + .add(new StringDimensionSchema("string_sparse")) + .build() + ).build()); + } +} 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 154c8bd41888..ad227af517a5 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 @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableList; import org.apache.calcite.avatica.SqlType; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; @@ -45,7 +44,6 @@ import java.util.ArrayList; import java.util.List; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; /** @@ -585,9 +583,9 @@ public void testMissingParameter() ImmutableList.of() ) ); - assertThat( + assertDruidException( exception, - DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value bound for parameter (position [1])") + DruidExceptionAssertions.invalidSqlInput().expectMessageIs("No value bound for parameter (position [1])") ); } @@ -605,9 +603,9 @@ public void testPartiallyMissingParameter() ImmutableList.of(new SqlParameter(SqlType.BIGINT, 3L)) ) ); - assertThat( + assertDruidException( exception, - DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value bound for parameter (position [2])") + DruidExceptionAssertions.invalidSqlInput().expectMessageIs("No value bound for parameter (position [2])") ); } @@ -627,9 +625,9 @@ public void testPartiallyMissingParameterInTheMiddle() ) ); - assertThat( + assertDruidException( exception, - DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value bound for parameter (position [1])") + DruidExceptionAssertions.invalidSqlInput().expectMessageIs("No value bound for parameter (position [1])") ); } 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 607c088bd6fe..ab9d1ef7f2e0 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 @@ -26,7 +26,6 @@ import org.apache.calcite.rel.RelNode; import org.apache.calcite.runtime.CalciteContextException; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.Intervals; @@ -133,13 +132,11 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.TestDataBuilder; import org.apache.druid.sql.calcite.util.datasets.TestDataSet; -import org.hamcrest.CoreMatchers; 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.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -151,7 +148,6 @@ import java.util.Map; import java.util.stream.Collectors; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -361,7 +357,7 @@ public void testInformationSchemaColumnsOnAnotherView() public void testCannotInsertWithNativeEngine() { msqIncompatible(); - final DruidException e = Assert.assertThrows( + final DruidException e = Assertions.assertThrows( DruidException.class, () -> testQuery( "INSERT INTO dst SELECT * FROM foo PARTITIONED BY ALL", @@ -370,7 +366,7 @@ public void testCannotInsertWithNativeEngine() ) ); - assertThat( + assertDruidException( e, invalidSqlIs("INSERT operations are not supported by requested SQL engine [native], consider using MSQ.") ); @@ -380,7 +376,7 @@ public void testCannotInsertWithNativeEngine() public void testCannotReplaceWithNativeEngine() { msqIncompatible(); - final DruidException e = Assert.assertThrows( + final DruidException e = Assertions.assertThrows( DruidException.class, () -> testQuery( "REPLACE INTO dst OVERWRITE ALL SELECT * FROM foo PARTITIONED BY ALL", @@ -389,7 +385,7 @@ public void testCannotReplaceWithNativeEngine() ) ); - assertThat( + assertDruidException( e, invalidSqlIs("REPLACE operations are not supported by the requested SQL engine [native]. Consider using MSQ.") ); @@ -6053,13 +6049,13 @@ public void testStringAggQueryOnComplexDatatypes() { try { testQuery("SELECT STRING_AGG(unique_dim1, ',') FROM druid.foo", ImmutableList.of(), ImmutableList.of()); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - Assert.assertTrue( + Assertions.assertTrue( e.getMessage().contains("Aggregation [STRING_AGG] does not support type [COMPLEX]") ); - Assert.assertEquals("invalidInput", e.getErrorCode()); + Assertions.assertEquals("invalidInput", e.getErrorCode()); } } @@ -6376,10 +6372,13 @@ public void testCountStarWithTimeInIntervalFilterInvalidInterval() "SELECT COUNT(*) FROM druid.foo " + "WHERE TIME_IN_INTERVAL(__time, '2000-01-01/X')", CalciteContextException.class, - ThrowableMessageMatcher.hasMessage(CoreMatchers.containsString( - "From line 1, column 38 to line 1, column 77: " - + "Function 'TIME_IN_INTERVAL' second argument is not a valid ISO8601 interval: " - + "Invalid format: \"X\"")) + e -> Assertions.assertTrue( + e.getMessage().contains( + "From line 1, column 38 to line 1, column 77: " + + "Function 'TIME_IN_INTERVAL' second argument is not a valid ISO8601 interval: " + + "Invalid format: \"X\"" + ) + ) ); } @@ -6419,8 +6418,8 @@ public void testCountStarWithTimeInIntervalFilterNonLiteral() "SELECT COUNT(*) FROM druid.foo " + "WHERE TIME_IN_INTERVAL(__time, dim1)", DruidException.class, - ThrowableMessageMatcher.hasMessage( - CoreMatchers.containsString( + e -> Assertions.assertTrue( + e.getMessage().contains( "Argument to function 'TIME_IN_INTERVAL' must be a literal (line [1], column [63])" ) ) @@ -6592,14 +6591,14 @@ public void testCountStarWithTimeFilterUsingStringLiteralsInvalid_isUnplannable( testBuilder().sql(sql).run(); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs("Illegal TIMESTAMP constant [CAST('z2000-01-01 00:00:00'):TIMESTAMP(3) NOT NULL]") ); } catch (Exception e) { log.error(e, "Expected DruidException for query: %s", sql); - Assert.fail(sql); + Assertions.fail(sql); } } @@ -8540,7 +8539,7 @@ public void testRegexpExtractWithBadRegexPattern() "SELECT DISTINCT\n" + " REGEXP_EXTRACT(dim1, '^(.))', 1)\n" + "FROM foo", - DruidExceptionMatcher.invalidInput().expectMessageContains( + DruidExceptionAssertions.invalidInput().expectMessageContains( "An invalid pattern [^(.))] was provided for the [regexp_extract] function, " + "error: [Unmatched closing ')' near index 3\n^(.))\n ^]" ) @@ -12049,10 +12048,10 @@ public void testTimeExtractWithTooFewArguments() // Regression test for https://github.com/apache/druid/pull/7710. try { testQuery("SELECT TIME_EXTRACT(__time) FROM druid.foo", ImmutableList.of(), ImmutableList.of()); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs( "Invalid number of arguments to function 'TIME_EXTRACT'. Was expecting 2 arguments (line [1], column [8])" @@ -14503,16 +14502,16 @@ public void testStringAnyAggArgValidation() .sql("SELECT ANY_VALUE(dim3, 1000, 'true') FROM foo") .queryContext(ImmutableMap.of()) .run()); - assertThat(e, invalidSqlIs( + assertDruidException(e, invalidSqlIs( "Cannot apply 'ANY_VALUE' to arguments of type 'ANY_VALUE(, , )'. Supported form(s): 'ANY_VALUE(, [, []])' (line [1], column [8])")); DruidException e1 = assertThrows(DruidException.class, () -> testBuilder() .sql("SELECT ANY_VALUE(dim3, 1000, null) FROM foo") .queryContext(ImmutableMap.of()).run()); - Assert.assertEquals("Illegal use of 'NULL' (line [1], column [30])", e1.getMessage()); + Assertions.assertEquals("Illegal use of 'NULL' (line [1], column [30])", e1.getMessage()); DruidException e2 = assertThrows(DruidException.class, () -> testBuilder() .sql("SELECT ANY_VALUE(dim3, null, true) FROM foo") .queryContext(ImmutableMap.of()).run()); - Assert.assertEquals("Illegal use of 'NULL' (line [1], column [24])", e2.getMessage()); + Assertions.assertEquals("Illegal use of 'NULL' (line [1], column [24])", e2.getMessage()); } @Test @@ -14585,12 +14584,12 @@ public void testStringAggWithStringMaxBytes() try { testQuery(query, ImmutableList.of(), ImmutableList.of()); - Assert.fail("Expected DruidException but query succeeded"); + Assertions.fail("Expected DruidException but query succeeded"); } catch (DruidException e) { - Assert.assertEquals(DruidException.Persona.USER, e.getTargetPersona()); - Assert.assertEquals(DruidException.Category.INVALID_INPUT, e.getCategory()); - Assert.assertTrue(e.getMessage().contains("parameter `maxBytes` must be a numeric literal")); + Assertions.assertEquals(DruidException.Persona.USER, e.getTargetPersona()); + Assertions.assertEquals(DruidException.Category.INVALID_INPUT, e.getCategory()); + Assertions.assertTrue(e.getMessage().contains("parameter `maxBytes` must be a numeric literal")); } } @@ -14602,12 +14601,12 @@ public void testArrayAggWithStringMaxBytes() try { testQuery(query, ImmutableList.of(), ImmutableList.of()); - Assert.fail("Expected DruidException but query succeeded"); + Assertions.fail("Expected DruidException but query succeeded"); } catch (DruidException e) { - Assert.assertEquals(DruidException.Persona.USER, e.getTargetPersona()); - Assert.assertEquals(DruidException.Category.INVALID_INPUT, e.getCategory()); - Assert.assertTrue(e.getMessage().contains("parameter `maxBytes` must be a numeric literal")); + Assertions.assertEquals(DruidException.Persona.USER, e.getTargetPersona()); + Assertions.assertEquals(DruidException.Category.INVALID_INPUT, e.getCategory()); + Assertions.assertTrue(e.getMessage().contains("parameter `maxBytes` must be a numeric literal")); } } @@ -14619,12 +14618,12 @@ public void testArrayConcatAggWithStringMaxBytes() try { testQuery(query, ImmutableList.of(), ImmutableList.of()); - Assert.fail("Expected DruidException but query succeeded"); + Assertions.fail("Expected DruidException but query succeeded"); } catch (DruidException e) { - Assert.assertEquals(DruidException.Persona.USER, e.getTargetPersona()); - Assert.assertEquals(DruidException.Category.INVALID_INPUT, e.getCategory()); - Assert.assertTrue(e.getMessage().contains("parameter `maxBytes` must be a numeric literal")); + Assertions.assertEquals(DruidException.Persona.USER, e.getTargetPersona()); + Assertions.assertEquals(DruidException.Category.INVALID_INPUT, e.getCategory()); + Assertions.assertTrue(e.getMessage().contains("parameter `maxBytes` must be a numeric literal")); } } @@ -15501,7 +15500,7 @@ public void testDistinctSumNotSupportedWithApproximation() .run() ); - assertThat(e, invalidSqlContains("Aggregation [SUM] with DISTINCT is not supported")); + assertDruidException(e, invalidSqlContains("Aggregation [SUM] with DISTINCT is not supported")); } @Test @@ -15511,7 +15510,7 @@ public void testUnSupportedNullsFirst() .sql("SELECT dim1,ROW_NUMBER() OVER (ORDER BY dim1 DESC NULLS FIRST) from druid.foo") .run()); - assertThat(e, invalidSqlIs("DESCENDING ordering with NULLS FIRST is not supported! (line [1], column [41])")); + assertDruidException(e, invalidSqlIs("DESCENDING ordering with NULLS FIRST is not supported! (line [1], column [41])")); } @Test @@ -15520,7 +15519,7 @@ public void testUnSupportedNullsLast() DruidException e = assertThrows(DruidException.class, () -> testBuilder() .sql("SELECT dim1,ROW_NUMBER() OVER (ORDER BY dim1 NULLS LAST) from druid.foo") .run()); - assertThat(e, invalidSqlIs("ASCENDING ordering with NULLS LAST is not supported! (line [1], column [41])")); + assertDruidException(e, invalidSqlIs("ASCENDING ordering with NULLS LAST is not supported! (line [1], column [41])")); } @Test @@ -15531,7 +15530,7 @@ public void testUnSupportedRangeBounds() DruidException e = assertThrows(DruidException.class, () -> testBuilder() .sql("SELECT dim1,ROW_NUMBER() OVER (ORDER BY dim1 RANGE BETWEEN 3 PRECEDING AND 2 FOLLOWING) from druid.foo") .run()); - assertThat(e, invalidSqlIs("Order By with RANGE clause currently supports only UNBOUNDED or CURRENT ROW. Use ROWS clause instead. (line [1], column [31])")); + assertDruidException(e, invalidSqlIs("Order By with RANGE clause currently supports only UNBOUNDED or CURRENT ROW. Use ROWS clause instead. (line [1], column [31])")); } @Test @@ -15542,7 +15541,7 @@ public void testUnSupportedWindowBoundExpressions() DruidException e = assertThrows(DruidException.class, () -> testBuilder() .sql("SELECT dim1,ROW_NUMBER() OVER (ORDER BY dim1 ROWS BETWEEN dim1 PRECEDING AND dim1 FOLLOWING) from druid.foo") .run()); - assertThat(e, invalidSqlIs("Window frames with expression based lower/upper bounds are not supported. (line [1], column [31])")); + assertDruidException(e, invalidSqlIs("Window frames with expression based lower/upper bounds are not supported. (line [1], column [31])")); } @Test @@ -15557,7 +15556,7 @@ public void testNtileNotSupportedWithFrame() .run() ); - assertThat(e, invalidSqlContains("Framing of NTILE is not supported")); + assertDruidException(e, invalidSqlContains("Framing of NTILE is not supported")); } @Test @@ -15572,7 +15571,7 @@ public void testDistinctNotSupportedWithWindow() .run() ); - assertThat(e, invalidSqlContains("DISTINCT is not supported for window functions")); + assertDruidException(e, invalidSqlContains("DISTINCT is not supported for window functions")); } @Test @@ -15588,7 +15587,7 @@ public void testUnSupportedAggInSelectWindow() .sql("SELECT dim1, ROW_NUMBER() OVER W from druid.foo WINDOW W as (ORDER BY max(length(dim1)))") .run()); - assertThat(e, invalidSqlContains("not supported with syntax WINDOW W AS ")); + assertDruidException(e, invalidSqlContains("not supported with syntax WINDOW W AS ")); } @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 1e544cfda28e..75f1e93100ba 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 @@ -24,7 +24,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.granularity.Granularity; @@ -46,7 +45,7 @@ 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.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.IOException; @@ -61,7 +60,6 @@ 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 { @@ -404,7 +402,7 @@ public void testReplaceIntoInvalidDataSourceName() testIngestionQuery() .sql("REPLACE INTO \"in/valid\" OVERWRITE ALL SELECT dim1, dim2 FROM foo PARTITIONED BY ALL TIME") .expectValidationError( - DruidExceptionMatcher + DruidExceptionAssertions .invalidInput() .expectMessageIs("Invalid value for field [table]: Value [in/valid] cannot contain '/'.") ) @@ -634,7 +632,7 @@ public void testPartitionedBySupportedGranularityLiteralClauses() } catch (JsonProcessingException e) { // Won't reach here - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } testIngestionQuery() @@ -668,10 +666,10 @@ public void testReplaceWithPartitionedByContainingInvalidGranularity() ImmutableList.of(), ImmutableList.of() ); - Assert.fail("Exception should be thrown"); + Assertions.fail("Exception should be thrown"); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs( "Invalid granularity['invalid_granularity'] specified after PARTITIONED BY clause." @@ -952,7 +950,7 @@ public void testExplainPlanReplaceWithClusteredByDescThrowsException() public void testExplainReplaceFromExternalUnauthorized() { // Use testQuery for EXPLAIN (not testIngestionQuery). - Assert.assertThrows( + Assertions.assertThrows( ForbiddenException.class, () -> testQuery( @@ -1107,7 +1105,7 @@ public void testReplaceWithSqlOuterLimit() testIngestionQuery() .context(context) .sql("REPLACE INTO dst OVERWRITE ALL SELECT * FROM foo PARTITIONED BY ALL TIME") - .expectValidationError(DruidExceptionMatcher.invalidInput().expectMessageIs( + .expectValidationError(DruidExceptionAssertions.invalidInput().expectMessageIs( "Context parameter [sqlOuterLimit] cannot be provided on operator [REPLACE]" )) .verify(); 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 59fef5a20a7a..5c54ccc04c47 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 @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; @@ -170,7 +169,7 @@ public void testTimeCeilExpressionContainingInvalidPeriod() { testQueryThrows( "SELECT TIME_CEIL(__time, 'PT1Y') FROM foo", - DruidExceptionMatcher.invalidInput().expectMessageContains( + DruidExceptionAssertions.invalidInput().expectMessageContains( "Invalid period['PT1Y'] specified for expression[timestamp_ceil(\"__time\", 'PT1Y', null, 'UTC')]" ) ); @@ -181,7 +180,7 @@ public void testTimeFloorExpressionContainingInvalidPeriod() { testQueryThrows( "SELECT TIME_FLOOR(TIMESTAMPADD(DAY, -1, __time), 'PT1D') FROM foo", - DruidExceptionMatcher.invalidInput().expectMessageContains( + DruidExceptionAssertions.invalidInput().expectMessageContains( "Invalid period['PT1D'] specified for expression[timestamp_floor((\"__time\" + -86400000), 'PT1D', null, 'UTC')]" ) ); 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 22a79a1fbd9b..d522f870a11b 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 @@ -81,10 +81,9 @@ import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.timeline.DataSegment; import org.apache.druid.timeline.partition.LinearShardSpec; -import org.hamcrest.CoreMatchers; import org.joda.time.DateTimeZone; import org.joda.time.Period; -import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -97,10 +96,9 @@ import java.util.Map; import java.util.stream.Collectors; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; - /** * Calcite tests which involve subqueries and materializing the intermediate results on {@link org.apache.druid.server.ClientQuerySegmentWalker} * The tests are run with two different codepaths: @@ -752,8 +750,8 @@ private void testMaxSubqueryRowsWithoutMemoryLimit(String testName, Map 0", modifiedQueryContext, ResourceLimitExceededException.class, - ThrowableMessageMatcher.hasMessage( - CoreMatchers.containsString( + e -> Assertions.assertTrue( + e.getMessage().contains( "Cannot issue the query, subqueries generated results beyond maximum[1] rows. Try setting the " + "'maxSubqueryBytes' in the query context to 'auto' for enabling byte based limit, which chooses an optimal " + "limit based on memory size and result's heap usage or manually configure the values of either 'maxSubqueryBytes' " 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 9fb11f88702b..53bd89571756 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 @@ -26,11 +26,9 @@ 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.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import static org.hamcrest.MatcherAssert.assertThat; - public class CalciteTableAppendTest extends BaseCalciteQueryTest { @Test @@ -221,10 +219,10 @@ public void testAppendNoTableIsInvalid() testBuilder() .sql("select dim1 from TABLE(APPEND()) u") .run(); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs("No match found for function signature APPEND() (line [1], column [24])") ); @@ -238,10 +236,10 @@ public void testAppendtInvalidIntegerArg() testBuilder() .sql("select dim1 from TABLE(APPEND('foo',111)) u") .run(); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs( "All arguments to APPEND should be literal strings. Argument #2 is not string (line [1], column [37])" @@ -257,10 +255,10 @@ public void testAppendtNullArg() testBuilder() .sql("select dim1 from TABLE(APPEND('foo',null)) u") .run(); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs( "All arguments to APPEND should be literal strings. Argument #2 is not string (line [1], column [37])" @@ -276,10 +274,10 @@ public void testAppendtNonExistentTable() testBuilder() .sql("select dim1 from TABLE(APPEND('foo','nonexistent')) u") .run(); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs("Table [nonexistent] not found (line [1], column [37])") ); @@ -294,10 +292,10 @@ public void testAppendCTE() testBuilder() .sql("with t0 as (select * from foo) select dim3 from TABLE(APPEND('t0','foo')) u") .run(); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat( + assertDruidException( e, invalidSqlIs("Table [t0] not found (line [1], column [62])") ); 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 173a43ccd45e..5d4cf402b2a1 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 @@ -30,11 +30,9 @@ import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.sql.calcite.filtration.Filtration; import org.apache.druid.sql.calcite.util.CalciteTests; -import org.junit.Assert; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import static org.hamcrest.MatcherAssert.assertThat; - public class CalciteUnionQueryTest extends BaseCalciteQueryTest { @Test @@ -134,10 +132,10 @@ public void testUnionAllTablesColumnCountMismatch() ImmutableList.of(), ImmutableList.of() ); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [42])")); + assertDruidException(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [42])")); } } @@ -461,10 +459,10 @@ public void testUnionAllThreeTablesColumnCountMismatch1() ImmutableList.of(), ImmutableList.of() ); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [45])")); + assertDruidException(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [45])")); } } @@ -481,10 +479,10 @@ public void testUnionAllThreeTablesColumnCountMismatch2() ImmutableList.of(), ImmutableList.of() ); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [45])")); + assertDruidException(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [45])")); } } @@ -501,10 +499,10 @@ public void testUnionAllThreeTablesColumnCountMismatch3() ImmutableList.of(), ImmutableList.of() ); - Assert.fail("query execution should fail"); + Assertions.fail("query execution should fail"); } catch (DruidException e) { - assertThat(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [70])")); + assertDruidException(e, invalidSqlIs("Column count mismatch in UNION ALL (line [3], column [70])")); } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DruidExceptionAssertions.java b/sql/src/test/java/org/apache/druid/sql/calcite/DruidExceptionAssertions.java new file mode 100644 index 000000000000..c743aded687d --- /dev/null +++ b/sql/src/test/java/org/apache/druid/sql/calcite/DruidExceptionAssertions.java @@ -0,0 +1,114 @@ +/* + * 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.sql.calcite; + +import org.apache.druid.error.DruidException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.function.Executable; + +import javax.annotation.Nullable; + +public class DruidExceptionAssertions +{ + private final DruidException.Persona persona; + private final DruidException.Category category; + private final String errorCode; + @Nullable + private String expectedMessage; + @Nullable + private String expectedMessagePart; + @Nullable + private String contextKey; + @Nullable + private String contextValue; + + public DruidExceptionAssertions( + final DruidException.Persona persona, + final DruidException.Category category, + final String errorCode + ) + { + this.persona = persona; + this.category = category; + this.errorCode = errorCode; + } + + public static DruidExceptionAssertions invalidInput() + { + return new DruidExceptionAssertions( + DruidException.Persona.USER, + DruidException.Category.INVALID_INPUT, + "invalidInput" + ); + } + + public static DruidExceptionAssertions invalidSqlInput() + { + return invalidInput().expectContext("sourceType", "sql"); + } + + public DruidExceptionAssertions expectMessageIs(final String message) + { + expectedMessage = message; + return this; + } + + public DruidExceptionAssertions expectMessageContains(final String messagePart) + { + expectedMessagePart = messagePart; + return this; + } + + public DruidExceptionAssertions expectContext(final String key, final String value) + { + contextKey = key; + contextValue = value; + return this; + } + + public void assertThrowsAndMatches(final Executable executable) + { + assertMatches(Assertions.assertThrows(DruidException.class, executable)); + } + + public void assertMatches(final DruidException exception) + { + Assertions.assertAll( + () -> Assertions.assertEquals(persona, exception.getTargetPersona()), + () -> Assertions.assertEquals(category, exception.getCategory()), + () -> Assertions.assertEquals(errorCode, exception.getErrorCode()), + () -> { + if (expectedMessage != null) { + Assertions.assertEquals(expectedMessage, exception.getMessage()); + } + }, + () -> { + if (expectedMessagePart != null) { + Assertions.assertTrue(exception.getMessage().contains(expectedMessagePart), exception.getMessage()); + } + }, + () -> { + if (contextKey != null) { + Assertions.assertEquals(contextValue, exception.getContext().get(contextKey)); + } + } + ); + } +} 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 47b220f71778..567534df6cda 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 @@ -52,8 +52,7 @@ import org.apache.druid.sql.calcite.util.CalciteTests; import org.apache.druid.sql.calcite.util.DruidModuleCollection; import org.apache.druid.sql.http.SqlParameter; -import org.hamcrest.CoreMatchers; -import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import java.io.File; @@ -62,7 +61,6 @@ import java.util.Arrays; import java.util.Collections; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; /** @@ -382,7 +380,7 @@ public void testExplainHttpFnUnauthorized() .authResult(CalciteTests.REGULAR_USER_AUTH_RESULT) .run() ); - assertThat(e, ThrowableMessageMatcher.hasMessage(CoreMatchers.equalTo(Access.DEFAULT_ERROR_MESSAGE))); + Assertions.assertEquals(Access.DEFAULT_ERROR_MESSAGE, e.getMessage()); } @Test @@ -520,14 +518,10 @@ public void testHttpJsonMalformedComplexTypeRejected() " EXTEND (x VARCHAR, z TYPE('complex { + Assertions.assertInstanceOf(DruidException.class, e); + Assertions.assertTrue(e.getMessage().contains("Column [z] has an unsupported type")); + }) .verify(); } 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 5a22635f1c2f..2959688c0cba 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 @@ -48,10 +48,7 @@ import org.apache.druid.sql.calcite.planner.PrepareResult; import org.apache.druid.sql.calcite.table.RowSignatures; import org.apache.druid.sql.calcite.util.QueryLogHook; -import org.hamcrest.CoreMatchers; -import org.hamcrest.MatcherAssert; -import org.junit.Assert; -import org.junit.internal.matchers.ThrowableMessageMatcher; +import org.junit.jupiter.api.Assertions; import java.util.ArrayList; import java.util.Arrays; @@ -442,32 +439,32 @@ private void verifyQuery(QueryResults queryResults) .map(q -> BaseCalciteQueryTest.recursivelyClearContext(q, queryJsonMapper)) .collect(Collectors.toList()); - Assert.assertEquals( - StringUtils.format("query count: %s", builder.sql), + Assertions.assertEquals( expectedQueries.size(), - recordedQueries.size() + recordedQueries.size(), + StringUtils.format("query count: %s", builder.sql) ); for (int i = 0; i < expectedQueries.size(); i++) { Query expectedQuery = expectedQueries.get(i); Query actualQuery = recordedQueries.get(i); - Assert.assertEquals( - StringUtils.format("query #%d: %s", i + 1, builder.sql), + Assertions.assertEquals( expectedQuery, - actualQuery + actualQuery, + StringUtils.format("query #%d: %s", i + 1, builder.sql) ); try { // go through some JSON serde and back, round tripping both queries and comparing them to each other, because - // Assert.assertEquals(recordedQueries.get(i), stringAndBack) is a failure due to a sorted map being present + // Assertions.assertEquals(recordedQueries.get(i), stringAndBack) is a failure due to a sorted map being present // in the recorded queries, but it is a regular map after deserialization final String recordedString = queryJsonMapper.writeValueAsString(actualQuery); final Query stringAndBack = queryJsonMapper.readValue(recordedString, Query.class); final String expectedString = queryJsonMapper.writeValueAsString(expectedQuery); final Query expectedStringAndBack = queryJsonMapper.readValue(expectedString, Query.class); - Assert.assertEquals(expectedStringAndBack, stringAndBack); + Assertions.assertEquals(expectedStringAndBack, stringAndBack); } catch (JsonProcessingException e) { - Assert.fail(e.getMessage()); + Assertions.fail(e.getMessage()); } } } @@ -489,7 +486,7 @@ public VerifyResources(PrepareQuery prepareStep) public void verify() { QueryTestBuilder builder = prepareStep.builder(); - Assert.assertEquals( + Assertions.assertEquals( ImmutableSet.copyOf(builder.expectedResources), prepareStep.resourceActions() ); @@ -512,7 +509,7 @@ public VerifyPrepareSignature(PrepareQuery prepareStep) public void verify() { QueryTestBuilder builder = prepareStep.builder(); - Assert.assertEquals( + Assertions.assertEquals( builder.expectedSqlSchema, SqlSchema.of(prepareStep.sqlSignature) ); @@ -537,7 +534,7 @@ public void verify() { QueryTestBuilder builder = execStep.builder(); for (QueryResults queryResults : execStep.results()) { - Assert.assertEquals( + Assertions.assertEquals( builder.expectedSqlSchema, SqlSchema.of(queryResults.sqlSignature) ); @@ -566,7 +563,7 @@ private void verifyLogicalPlan(QueryResults queryResults) { String expectedPlan = execStep.builder().expectedLogicalPlan; String actualPlan = visualizePlan(queryResults.capture); - Assert.assertEquals(expectedPlan, actualPlan); + Assertions.assertEquals(expectedPlan, actualPlan); } private String visualizePlan(PlannerCaptureHook hook) @@ -613,11 +610,11 @@ private String visualizePlan(PlannerCaptureHook hook) * runs, but that's an exercise for later. */ - public static class VerifyExpectedException implements QueryVerifyStep + public static class VerifyExpectedFailure implements QueryVerifyStep { protected final BaseExecuteQuery execStep; - public VerifyExpectedException(BaseExecuteQuery execStep) + public VerifyExpectedFailure(BaseExecuteQuery execStep) { this.execStep = execStep; } @@ -634,21 +631,14 @@ public void verify() // Delayed exception checking to let other verify steps run before running vectorized checks if (builder.queryCannotVectorize && "force".equals(queryResults.vectorizeOption)) { if (queryResults.exception == null) { - Assert.fail( + Assertions.fail( "Expected vectorized execution to fail, but it did not. " + "Please remove cannotVectorize() from this test case." ); } - MatcherAssert.assertThat( - queryResults.exception, - CoreMatchers.allOf( - CoreMatchers.instanceOf(RuntimeException.class), - ThrowableMessageMatcher.hasMessage( - CoreMatchers.containsString("Cannot vectorize!") - ) - ) - ); + Assertions.assertInstanceOf(RuntimeException.class, queryResults.exception); + Assertions.assertTrue(queryResults.exception.getMessage().contains("Cannot vectorize!")); } else if (queryResults.exception != null) { throw queryResults.exception; } @@ -760,7 +750,7 @@ public QueryTestRunner(QueryTestBuilder builder) // The exception is always verified: either there should be no exception // (the other steps ran), or there should be the defined exception. - verifySteps.add(new VerifyExpectedException(finalExecStep)); + verifySteps.add(new VerifyExpectedFailure(finalExecStep)); } } 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 f950f933a7bd..5fac056c2faa 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 @@ -30,12 +30,12 @@ import org.apache.druid.error.DruidException; import org.apache.druid.java.util.common.IAE; import org.apache.druid.java.util.common.StringUtils; -import org.apache.druid.server.QueryStackTests; import org.apache.druid.sql.calcite.util.CacheTestHelperModule.ResultCacheMode; import org.apache.druid.sql.calcite.util.FakeIndexTaskUtil; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.QueryComponentSupplier; import org.apache.druid.sql.calcite.util.SqlTestFramework.StandardComponentSupplier; +import org.apache.druid.sql.calcite.util.SqlTestQueryStack; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URLEncodedUtils; @@ -95,7 +95,7 @@ public class SqlTestFrameworkConfig { @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) - @NumMergeBuffers(QueryStackTests.DEFAULT_NUM_MERGE_BUFFERS) + @NumMergeBuffers(SqlTestQueryStack.DEFAULT_NUM_MERGE_BUFFERS) public @interface NumMergeBuffers { ConfigOptionProcessor PROCESSOR = new ConfigOptionProcessor<>(NumMergeBuffers.class) 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 b51a106aef93..2d44e471a3ad 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 @@ -36,22 +36,23 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.granularity.Granularity; +import org.apache.druid.sql.calcite.BaseCalciteQueryTest; +import org.apache.druid.sql.calcite.DruidExceptionAssertions; import org.apache.druid.sql.calcite.expression.TimeUnits; import org.apache.druid.sql.calcite.expression.builtin.TimeFloorOperatorConversion; import org.apache.druid.sql.calcite.planner.Calcites; import org.apache.druid.sql.calcite.planner.DruidTypeSystem; -import org.hamcrest.MatcherAssert; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Period; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.Arrays; @@ -60,10 +61,9 @@ public class DruidSqlParserUtilsTest /** * Sanity checking that the formats of TIME_FLOOR(__time, Period) work as expected */ - @RunWith(Parameterized.class) - public static class TimeFloorToGranularityConversionTest + @Nested + public class TimeFloorToGranularityConversionTest { - @Parameterized.Parameters(name = "{1}") public static Iterable constructorFeeder() { return ImmutableList.of( @@ -71,35 +71,26 @@ public static Iterable constructorFeeder() ); } - String periodString; - Granularity expectedGranularity; - - public TimeFloorToGranularityConversionTest(String periodString, Granularity expectedGranularity) - { - this.periodString = periodString; - this.expectedGranularity = expectedGranularity; - } - - @Test - public void testGranularityFromTimeFloor() + @ParameterizedTest(name = "{1}") + @MethodSource("constructorFeeder") + public void testGranularityFromTimeFloor(String periodString, Granularity expectedGranularity) { final SqlNodeList args = new SqlNodeList(SqlParserPos.ZERO); args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); - args.add(SqlLiteral.createCharString(this.periodString, SqlParserPos.ZERO)); + args.add(SqlLiteral.createCharString(periodString, SqlParserPos.ZERO)); final SqlNode timeFloorCall = TimeFloorOperatorConversion.SQL_FUNCTION.createCall(args); Granularity actualGranularity = DruidSqlParserUtils.convertSqlNodeToGranularity( timeFloorCall); - Assert.assertEquals(expectedGranularity, actualGranularity); + Assertions.assertEquals(expectedGranularity, actualGranularity); } } /** * Sanity checking that FLOOR(__time TO TimeUnit()) works as intended with the supported granularities */ - @RunWith(Parameterized.class) - public static class FloorToGranularityConversionTest + @Nested + public class FloorToGranularityConversionTest { - @Parameterized.Parameters(name = "{1}") public static Iterable constructorFeeder() { return ImmutableList.of( @@ -114,72 +105,78 @@ public static Iterable constructorFeeder() ); } - TimeUnit timeUnit; - Period period; - Granularity expectedGranularity; - - public FloorToGranularityConversionTest(TimeUnit timeUnit, Period period, Granularity expectedGranularity) - { - this.timeUnit = timeUnit; - this.period = period; - this.expectedGranularity = expectedGranularity; - } - - @Test - public void testGetGranularityFromFloor() + @ParameterizedTest(name = "{1}") + @MethodSource("constructorFeeder") + public void testGetGranularityFromFloor(TimeUnit timeUnit, Period period, Granularity expectedGranularity) { // parserPos doesn't matter final SqlNodeList args = new SqlNodeList(SqlParserPos.ZERO); args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); - args.add(new SqlIntervalQualifier(this.timeUnit, null, SqlParserPos.ZERO)); + args.add(new SqlIntervalQualifier(timeUnit, null, SqlParserPos.ZERO)); final SqlNode floorCall = SqlStdOperatorTable.FLOOR.createCall(args); Granularity actualGranularity = DruidSqlParserUtils.convertSqlNodeToGranularity(floorCall); - Assert.assertEquals(expectedGranularity, actualGranularity); + Assertions.assertEquals(expectedGranularity, actualGranularity); } /** * Tests clause like "PARTITIONED BY 'day'" */ - @Test - public void testConvertSqlNodeToGranularityAsLiteral() + @ParameterizedTest(name = "{1}") + @MethodSource("constructorFeeder") + public void testConvertSqlNodeToGranularityAsLiteral( + TimeUnit timeUnit, + Period period, + Granularity expectedGranularity + ) { SqlNode sqlNode = SqlLiteral.createCharString(timeUnit.name(), SqlParserPos.ZERO); Granularity actualGranularity = DruidSqlParserUtils.convertSqlNodeToGranularity(sqlNode); - Assert.assertEquals(expectedGranularity, actualGranularity); + Assertions.assertEquals(expectedGranularity, actualGranularity); } /** * Tests clause like "PARTITIONED BY PT1D" */ - @Test - public void testConvertSqlNodeToPeriodFormGranularityAsIdentifier() + @ParameterizedTest(name = "{1}") + @MethodSource("constructorFeeder") + public void testConvertSqlNodeToPeriodFormGranularityAsIdentifier( + TimeUnit timeUnit, + Period period, + Granularity expectedGranularity + ) { SqlNode sqlNode = new SqlIdentifier(period.toString(), SqlParserPos.ZERO); Granularity actualGranularity = DruidSqlParserUtils.convertSqlNodeToGranularity(sqlNode); - Assert.assertEquals(expectedGranularity, actualGranularity); + Assertions.assertEquals(expectedGranularity, actualGranularity); } /** * Tests clause like "PARTITIONED BY 'PT1D'" */ - @Test - public void testConvertSqlNodeToPeriodFormGranularityAsLiteral() + @ParameterizedTest(name = "{1}") + @MethodSource("constructorFeeder") + public void testConvertSqlNodeToPeriodFormGranularityAsLiteral( + TimeUnit timeUnit, + Period period, + Granularity expectedGranularity + ) { SqlNode sqlNode = SqlLiteral.createCharString(period.toString(), SqlParserPos.ZERO); Granularity actualGranularity = DruidSqlParserUtils.convertSqlNodeToGranularity(sqlNode); - Assert.assertEquals(expectedGranularity, actualGranularity); + Assertions.assertEquals(expectedGranularity, actualGranularity); } } /** * Test class that validates the resolution of "CLUSTERED BY" columns to output columns. */ - public static class ResolveClusteredByColumnsTest + @Nested + public class ResolveClusteredByColumnsTest { @Test public void testNullClusteredByAndSource() { - Assert.assertNull(DruidSqlParserUtils.resolveClusteredByColumnsToOutputColumns(null, null)); + Assertions.assertNull(DruidSqlParserUtils.resolveClusteredByColumnsToOutputColumns(null, null)); } @Test @@ -191,7 +188,7 @@ public void testNullClusteredBy() .add(3, "bar") .build(); - Assert.assertNull( + Assertions.assertNull( DruidSqlParserUtils.resolveClusteredByColumnsToOutputColumns( null, fields @@ -214,7 +211,7 @@ public void testSimpledClusteredByWithNullSource() new SqlParserPos(0, 3) ); args.add(sqlBasicCall1); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("__time", "FOO", "DIM3_ALIAS"), DruidSqlParserUtils.resolveClusteredByColumnsToOutputColumns(args, null) ); @@ -234,7 +231,7 @@ public void testSimpleClusteredBy() clusteredByArgs.add(new SqlIdentifier("FOO", SqlParserPos.ZERO)); clusteredByArgs.add(SqlLiteral.createExactNumeric("3", SqlParserPos.ZERO)); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("__time", "FOO", "BOO"), DruidSqlParserUtils.resolveClusteredByColumnsToOutputColumns(clusteredByArgs, sourceFieldMappings) ); @@ -261,14 +258,15 @@ public void testClusteredByOrdinalsAndAliases() clusteredByArgs.add(SqlLiteral.createExactNumeric("5", SqlParserPos.ZERO)); clusteredByArgs.add(SqlLiteral.createExactNumeric("7", SqlParserPos.ZERO)); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList("DIM3_ALIAS", "floor_dim4_time", "DIM5", "TIME_FLOOR(\"timestamps\", 'PT1H')"), DruidSqlParserUtils.resolveClusteredByColumnsToOutputColumns(clusteredByArgs, sourceFieldMappings) ); } } - public static class ClusteredByColumnsValidationTest + @Nested + public class ClusteredByColumnsValidationTest { /** * Tests an empty CLUSTERED BY clause @@ -315,7 +313,7 @@ public void testClusteredByColumnsWithDescThrowsException() ); clusteredByArgs.add(sqlBasicCall); - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageIs("Invalid CLUSTERED BY clause [`DIM4` DESC]: cannot sort in descending order.") .assertThrowsAndMatches(() -> DruidSqlParserUtils.validateClusteredByColumns(clusteredByArgs)); @@ -333,14 +331,15 @@ public void testClusteredByColumnsWithNegativeOrdinalThrowsException() clusteredByArgs.add(new SqlIdentifier("3", SqlParserPos.ZERO)); clusteredByArgs.add(SqlLiteral.createExactNumeric("-10", SqlParserPos.ZERO)); - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageIs("Ordinal [-10] specified in the CLUSTERED BY clause is invalid. It must be a positive integer.") .assertThrowsAndMatches(() -> DruidSqlParserUtils.validateClusteredByColumns(clusteredByArgs)); } } - public static class FloorToGranularityConversionErrorsTest + @Nested + public class FloorToGranularityConversionErrorsTest { /** * Tests clause like "PARTITIONED BY CEIL(__time TO DAY)" @@ -352,7 +351,7 @@ public void testConvertSqlNodeToGranularityWithIncorrectFunctionCall() args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); args.add(new SqlIntervalQualifier(TimeUnit.DAY, null, SqlParserPos.ZERO)); final SqlNode sqlNode = SqlStdOperatorTable.CEIL.createCall(args); - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageIs( "Invalid operator[CEIL] specified. PARTITIONED BY clause only supports FLOOR(__time TO )" @@ -370,7 +369,7 @@ public void testConvertSqlNodeToGranularityWithIncorrectNumberOfArguments() final SqlNodeList args = new SqlNodeList(SqlParserPos.ZERO); args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); final SqlNode sqlNode = SqlStdOperatorTable.FLOOR.createCall(args); - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageIs( "FLOOR in PARTITIONED BY clause must have 2 arguments, but only [1] provided." @@ -388,7 +387,7 @@ public void testConvertSqlNodeToGranularityWithWrongIdentifierInFloorFunction() args.add(new SqlIdentifier("timestamps", SqlParserPos.ZERO)); args.add(new SqlIntervalQualifier(TimeUnit.DAY, null, SqlParserPos.ZERO)); final SqlNode sqlNode = SqlStdOperatorTable.FLOOR.createCall(args); - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageIs( "Invalid argument[timestamps] provided. The first argument to FLOOR in PARTITIONED BY" @@ -407,7 +406,7 @@ public void testConvertSqlNodeToGranularityWithWrongIdentifierInTimeFloorFunctio args.add(new SqlIdentifier("timestamps", SqlParserPos.ZERO)); args.add(SqlLiteral.createCharString("PT1H", SqlParserPos.ZERO)); final SqlNode sqlNode = TimeFloorOperatorConversion.SQL_FUNCTION.createCall(args); - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageIs( "Invalid argument[timestamps] provided. The first argument to TIME_FLOOR in" @@ -426,7 +425,7 @@ public void testConvertSqlNodeToGranularityWithIncorrectIngestionGranularityInFl args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); args.add(new SqlIntervalQualifier(TimeUnit.ISOYEAR, null, SqlParserPos.ZERO)); final SqlNode sqlNode = SqlStdOperatorTable.FLOOR.createCall(args); - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageIs( "ISOYEAR is not a valid period granularity for ingestion." @@ -444,7 +443,7 @@ public void testConvertSqlNodeToGranularityWithIncorrectIngestionGranularityInTi args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); args.add(SqlLiteral.createCharString("abc", SqlParserPos.ZERO)); final SqlNode sqlNode = TimeFloorOperatorConversion.SQL_FUNCTION.createCall(args); - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageIs( "granularity['abc'] is an invalid period literal." @@ -453,7 +452,8 @@ public void testConvertSqlNodeToGranularityWithIncorrectIngestionGranularityInTi } } - public static class NonParameterizedTests + @Nested + public class NonParameterizedTests { private static final DateTimeZone TZ_LOS_ANGELES = DateTimes.inferTzFromString("America/Los_Angeles"); @@ -472,7 +472,7 @@ public void test_parseTimeStampWithTimeZone_timestamp_utc() DateTimeZone.UTC ); - Assert.assertEquals(String.valueOf(ts.getMillis()), s); + Assertions.assertEquals(String.valueOf(ts.getMillis()), s); } @Test @@ -490,7 +490,7 @@ public void test_parseTimeStampWithTimeZone_timestamp_losAngeles() TZ_LOS_ANGELES ); - Assert.assertEquals(String.valueOf(ts.getMillis()), s); + Assertions.assertEquals(String.valueOf(ts.getMillis()), s); } @Test @@ -508,7 +508,7 @@ public void test_parseTimeStampWithTimeZone_timestampWithLocalTimeZone() DateTimeZone.UTC ); - Assert.assertEquals(String.valueOf(ts.getMillis()), s); + Assertions.assertEquals(String.valueOf(ts.getMillis()), s); } @Test @@ -526,7 +526,7 @@ public void test_parseTimeStampWithTimeZone_timestampWithLocalTimeZone_losAngele TZ_LOS_ANGELES ); - Assert.assertEquals(String.valueOf(ts.getMillis()), s); + Assertions.assertEquals(String.valueOf(ts.getMillis()), s); } @Test @@ -543,7 +543,7 @@ public void test_parseTimeStampWithTimeZone_unknownTimestamp() DateTimeZone.UTC ); - Assert.assertEquals(String.valueOf(ts.getMillis()), s); + Assertions.assertEquals(String.valueOf(ts.getMillis()), s); } @Test @@ -560,7 +560,7 @@ public void test_parseTimeStampWithTimeZone_unknownTimestampWithLocalTimeZone() DateTimeZone.UTC ); - Assert.assertEquals(String.valueOf(ts.getMillis()), s); + Assertions.assertEquals(String.valueOf(ts.getMillis()), s); } @Test @@ -577,7 +577,7 @@ public void test_parseTimeStampWithTimeZone_unknownTimestamp_losAngeles() TZ_LOS_ANGELES ); - Assert.assertEquals(String.valueOf(ts.getMillis()), s); + Assertions.assertEquals(String.valueOf(ts.getMillis()), s); } @Test @@ -594,13 +594,13 @@ public void test_parseTimeStampWithTimeZone_unknownTimestampWithLocalTimeZone_lo TZ_LOS_ANGELES ); - Assert.assertEquals(String.valueOf(ts.getMillis()), s); + Assertions.assertEquals(String.valueOf(ts.getMillis()), s); } @Test public void test_parseTimeStampWithTimeZone_unknownTimestamp_invalid() { - final DruidException e = Assert.assertThrows( + final DruidException e = Assertions.assertThrows( DruidException.class, () -> DruidSqlParserUtils.parseTimeStampWithTimeZone( SqlLiteral.createUnknown( @@ -612,9 +612,9 @@ public void test_parseTimeStampWithTimeZone_unknownTimestamp_invalid() ) ); - MatcherAssert.assertThat( + BaseCalciteQueryTest.assertDruidException( e, - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageContains("Cannot get a timestamp from sql expression") ); 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 54619b5b10bd..6c53cf5ce330 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 @@ -29,21 +29,20 @@ import org.apache.calcite.util.DateString; import org.apache.calcite.util.TimeString; import org.apache.calcite.util.TimestampString; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.sql.calcite.DruidExceptionAssertions; import org.apache.druid.sql.calcite.planner.DruidTypeSystem; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.testing.InitializedNullHandlingTest; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mockito; import java.math.BigDecimal; @@ -52,10 +51,9 @@ public class DruidLogicalValuesRuleTest { private static final PlannerContext DEFAULT_CONTEXT = Mockito.mock(PlannerContext.class); - @RunWith(Parameterized.class) - public static class GetValueFromLiteralSimpleTypesTest extends InitializedNullHandlingTest + @Nested + public class GetValueFromLiteralSimpleTypesTest extends InitializedNullHandlingTest { - @Parameters(name = "{1}, {2}") public static Iterable constructorFeeder() { return ImmutableList.of( @@ -71,24 +69,14 @@ public static Iterable constructorFeeder() ); } - private final Comparable val; - private final SqlTypeName sqlTypeName; - private final Class javaType; - - public GetValueFromLiteralSimpleTypesTest(Comparable val, SqlTypeName sqlTypeName, Class javaType) - { - this.val = val; - this.sqlTypeName = sqlTypeName; - this.javaType = javaType; - } - - @Test - public void testGetValueFromLiteral() + @ParameterizedTest(name = "{1}, {2}") + @MethodSource("constructorFeeder") + public void testGetValueFromLiteral(Comparable val, SqlTypeName sqlTypeName, Class javaType) { final RexLiteral literal = Mockito.spy(makeLiteral(val, sqlTypeName, javaType)); final Object fromLiteral = DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); - Assert.assertSame(javaType, fromLiteral.getClass()); - Assert.assertEquals(val, fromLiteral); + Assertions.assertSame(javaType, fromLiteral.getClass()); + Assertions.assertEquals(val, fromLiteral); Mockito.verify(literal, Mockito.times(1)).getType(); } @@ -106,18 +94,17 @@ private static RexLiteral makeLiteral(Comparable val, SqlTypeName typeName, C } } - public static class GetValueFromLiteralOtherTypesTest + @Nested + @TestInstance(TestInstance.Lifecycle.PER_CLASS) + public class GetValueFromLiteralOtherTypesTest { private static final PlannerContext DEFAULT_CONTEXT = Mockito.mock(PlannerContext.class); private static final DateTimeZone TIME_ZONE = DateTimes.inferTzFromString("Asia/Seoul"); private static final RelDataTypeFactory TYPE_FACTORY = new SqlTypeFactoryImpl(DruidTypeSystem.INSTANCE); private static final RexBuilder REX_BUILDER = new RexBuilder(TYPE_FACTORY); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @BeforeClass - public static void setup() + @BeforeAll + public void setup() { Mockito.when(DEFAULT_CONTEXT.getTimeZone()).thenReturn(TIME_ZONE); } @@ -128,8 +115,8 @@ public void testGetValueFromTrueLiteral() RexLiteral literal = REX_BUILDER.makeLiteral(true); final Object fromLiteral = DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); - Assert.assertSame(Long.class, fromLiteral.getClass()); - Assert.assertEquals(1L, fromLiteral); + Assertions.assertSame(Long.class, fromLiteral.getClass()); + Assertions.assertEquals(1L, fromLiteral); } @Test @@ -138,8 +125,8 @@ public void testGetValueFromFalseLiteral() RexLiteral literal = REX_BUILDER.makeLiteral(false); final Object fromLiteral = DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); - Assert.assertSame(Long.class, fromLiteral.getClass()); - Assert.assertEquals(0L, fromLiteral); + Assertions.assertSame(Long.class, fromLiteral.getClass()); + Assertions.assertEquals(0L, fromLiteral); } @Test @@ -148,7 +135,7 @@ public void testGetValueFromNullBooleanLiteral() RexLiteral literal = REX_BUILDER.makeLiteral(null, REX_BUILDER.getTypeFactory().createSqlType(SqlTypeName.BOOLEAN)); final Object fromLiteral = DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); - Assert.assertNull(fromLiteral); + Assertions.assertNull(fromLiteral); } @Test @@ -157,8 +144,8 @@ public void testGetValueFromTimestampLiteral() RexLiteral literal = REX_BUILDER.makeTimestampLiteral(new TimestampString("2021-04-01 16:54:31"), 0); final Object fromLiteral = DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); - Assert.assertSame(Long.class, fromLiteral.getClass()); - Assert.assertEquals(new DateTime("2021-04-01T16:54:31", TIME_ZONE).getMillis(), fromLiteral); + Assertions.assertSame(Long.class, fromLiteral.getClass()); + Assertions.assertEquals(new DateTime("2021-04-01T16:54:31", TIME_ZONE).getMillis(), fromLiteral); } @Test @@ -167,8 +154,8 @@ public void testGetValueFromDateLiteral() RexLiteral literal = REX_BUILDER.makeDateLiteral(new DateString("2021-04-01")); final Object fromLiteral = DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); - Assert.assertSame(Long.class, fromLiteral.getClass()); - Assert.assertEquals(new DateTime("2021-04-01", TIME_ZONE).getMillis(), fromLiteral); + Assertions.assertSame(Long.class, fromLiteral.getClass()); + Assertions.assertEquals(new DateTime("2021-04-01", TIME_ZONE).getMillis(), fromLiteral); } @Test @@ -178,42 +165,36 @@ public void testGetValueFromTimestampWithLocalTimeZoneLiteral() new TimestampString("2021-04-01 16:54:31"), 0 ); - expectedException.expect( - DruidExceptionMatcher - .invalidSqlInput() - .expectMessageIs( - "Cannot handle literal [2021-04-01 16:54:31:TIMESTAMP_WITH_LOCAL_TIME_ZONE(0)] " - + "of unsupported type [TIMESTAMP_WITH_LOCAL_TIME_ZONE]." - ) - ); - DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); + DruidExceptionAssertions + .invalidSqlInput() + .expectMessageIs( + "Cannot handle literal [2021-04-01 16:54:31:TIMESTAMP_WITH_LOCAL_TIME_ZONE(0)] " + + "of unsupported type [TIMESTAMP_WITH_LOCAL_TIME_ZONE]." + ) + .assertThrowsAndMatches(() -> DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT)); } @Test public void testGetValueFromTimeLiteral() { RexLiteral literal = REX_BUILDER.makeTimeLiteral(new TimeString("16:54:31"), 0); - expectedException.expect( - DruidExceptionMatcher - .invalidSqlInput() - .expectMessageIs("Cannot handle literal [16:54:31] of unsupported type [TIME].") - ); - DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); + DruidExceptionAssertions + .invalidSqlInput() + .expectMessageIs("Cannot handle literal [16:54:31] of unsupported type [TIME].") + .assertThrowsAndMatches(() -> DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT)); } @Test public void testGetValueFromTimeWithLocalTimeZoneLiteral() { RexLiteral literal = REX_BUILDER.makeTimeWithLocalTimeZoneLiteral(new TimeString("16:54:31"), 0); - expectedException.expect( - DruidExceptionMatcher - .invalidSqlInput() - .expectMessageIs( - "Cannot handle literal [16:54:31:TIME_WITH_LOCAL_TIME_ZONE(0)] " - + "of unsupported type [TIME_WITH_LOCAL_TIME_ZONE]." - ) - ); - DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); + DruidExceptionAssertions + .invalidSqlInput() + .expectMessageIs( + "Cannot handle literal [16:54:31:TIME_WITH_LOCAL_TIME_ZONE(0)] " + + "of unsupported type [TIME_WITH_LOCAL_TIME_ZONE]." + ) + .assertThrowsAndMatches(() -> DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT)); } @Test @@ -224,7 +205,7 @@ public void testGetCastedValuesFromFloatToNumeric() TYPE_FACTORY.createSqlType(SqlTypeName.INTEGER) ); Object value = DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT); - Assert.assertEquals(value, 123L); + Assertions.assertEquals(value, 123L); } } } diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTests.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTests.java index b0e72b2af9c9..463faf15a2bd 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTests.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTests.java @@ -66,7 +66,6 @@ import org.apache.druid.server.DruidNode; import org.apache.druid.server.QueryLifecycleFactory; import org.apache.druid.server.QueryScheduler; -import org.apache.druid.server.QueryStackTests; import org.apache.druid.server.SpecificSegmentsQuerySegmentWalker; import org.apache.druid.server.coordination.DruidServerMetadata; import org.apache.druid.server.security.AllowAllAuthenticator; @@ -199,7 +198,7 @@ public AuthenticationResult createEscalatedAuthenticationResult() null ); - public static final Injector INJECTOR = QueryStackTests.defaultInjectorBuilder() + public static final Injector INJECTOR = SqlTestQueryStack.defaultInjectorBuilder() .addModule(new LookylooModule()) .addModule(new SqlAggregationModule()) .addModule(new CalciteTestOperatorModule()) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java index b48743a6d258..12fc6a8a3f3c 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java @@ -38,7 +38,6 @@ import org.apache.druid.segment.loading.SegmentCacheManager; import org.apache.druid.segment.metadata.CentralizedDatasourceSchemaConfig; import org.apache.druid.server.QueryLifecycleFactory; -import org.apache.druid.server.QueryStackTests; import org.apache.druid.server.SegmentManager; import org.apache.druid.server.SpecificSegmentsQuerySegmentWalker; import org.apache.druid.server.log.NoopRequestLogger; @@ -139,7 +138,7 @@ private static SqlToolbox createTestToolbox(SqlEngine engine, PlannerFactory pla plannerFactory, NoopServiceEmitter.instance(), NoopRequestLogger.instance(), - QueryStackTests.DEFAULT_NOOP_SCHEDULER, + SqlTestQueryStack.DEFAULT_NOOP_SCHEDULER, new SqlLifecycleManager() ); } @@ -314,7 +313,7 @@ public Set getDataSourceNames() public static JoinableFactory createDefaultJoinableFactory(Injector injector) { - return QueryStackTests.makeJoinableFactoryFromDefault( + return SqlTestQueryStack.makeJoinableFactoryFromDefault( injector.getInstance(LookupExtractorFactoryContainerProvider.class), ImmutableSet.of(TestDataBuilder.CUSTOM_ROW_TABLE_JOINABLE), ImmutableMap.of(TestDataBuilder.CUSTOM_ROW_TABLE_JOINABLE.getClass(), GlobalTableDataSource.class) 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 487c50570f3b..8085aa5c7835 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 @@ -86,7 +86,6 @@ import org.apache.druid.server.LocalQuerySegmentWalker; import org.apache.druid.server.QueryLifecycle; import org.apache.druid.server.QueryLifecycleFactory; -import org.apache.druid.server.QueryStackTests; import org.apache.druid.server.SpecificSegmentsQuerySegmentWalker; import org.apache.druid.server.SubqueryGuardrailHelper; import org.apache.druid.server.TestClusterQuerySegmentWalker; @@ -621,7 +620,7 @@ public Class getSqlEngineClass() public JoinableFactoryWrapper createJoinableFactoryWrapper(LookupExtractorFactoryContainerProvider lookupProvider) { return new JoinableFactoryWrapper( - QueryStackTests.makeJoinableFactoryFromDefault( + SqlTestQueryStack.makeJoinableFactoryFromDefault( lookupProvider, ImmutableSet.of(TestDataBuilder.CUSTOM_ROW_TABLE_JOINABLE), ImmutableMap.of(TestDataBuilder.CUSTOM_ROW_TABLE_JOINABLE.getClass(), GlobalTableDataSource.class) @@ -986,21 +985,21 @@ GroupByResourcesReservationPool makeMergingGroupByResourcesReservationPool( @LazySingleton public DruidProcessingConfig makeProcessingConfig(Builder builder) { - return QueryStackTests.getProcessingConfig(builder.mergeBufferCount); + return SqlTestQueryStack.getProcessingConfig(builder.mergeBufferCount); } @Provides @LazySingleton public TestBufferPool makeTestBufferPool(Builder builder) { - return QueryStackTests.makeTestBufferPool(builder.resourceCloser); + return SqlTestQueryStack.makeTestBufferPool(builder.resourceCloser); } @Provides @LazySingleton public TestGroupByBuffers makeTestGroupByBuffers(DruidProcessingConfig processingConfig, Builder builder) { - return QueryStackTests.makeGroupByBuffers(builder.resourceCloser, processingConfig); + return SqlTestQueryStack.makeGroupByBuffers(builder.resourceCloser, processingConfig); } @Provides diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestQueryStack.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestQueryStack.java new file mode 100644 index 000000000000..7166784743d6 --- /dev/null +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestQueryStack.java @@ -0,0 +1,310 @@ +/* + * 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.sql.calcite.util; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import com.google.inject.Injector; +import org.apache.druid.guice.DruidInjectorBuilder; +import org.apache.druid.guice.ExpressionModule; +import org.apache.druid.guice.SegmentWranglerModule; +import org.apache.druid.guice.StartupInjectorBuilder; +import org.apache.druid.initialization.CoreInjectorBuilder; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.io.Closer; +import org.apache.druid.query.DataSource; +import org.apache.druid.query.DefaultGenericQueryMetricsFactory; +import org.apache.druid.query.DefaultQueryRunnerFactoryConglomerate; +import org.apache.druid.query.DruidProcessingConfig; +import org.apache.druid.query.Query; +import org.apache.druid.query.QueryRunnerFactory; +import org.apache.druid.query.QueryRunnerFactoryConglomerate; +import org.apache.druid.query.QueryRunnerTestHelper; +import org.apache.druid.query.TestBufferPool; +import org.apache.druid.query.groupby.DefaultGroupByQueryMetricsFactory; +import org.apache.druid.query.groupby.GroupByQuery; +import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryQueryToolChest; +import org.apache.druid.query.groupby.GroupByQueryRunnerFactory; +import org.apache.druid.query.groupby.GroupByResourcesReservationPool; +import org.apache.druid.query.groupby.GroupByStatsProvider; +import org.apache.druid.query.groupby.GroupingEngine; +import org.apache.druid.query.groupby.TestGroupByBuffers; +import org.apache.druid.query.lookup.LookupExtractorFactoryContainerProvider; +import org.apache.druid.query.metadata.SegmentMetadataQueryConfig; +import org.apache.druid.query.metadata.SegmentMetadataQueryQueryToolChest; +import org.apache.druid.query.metadata.SegmentMetadataQueryRunnerFactory; +import org.apache.druid.query.metadata.metadata.SegmentMetadataQuery; +import org.apache.druid.query.operator.WindowOperatorQuery; +import org.apache.druid.query.operator.WindowOperatorQueryQueryRunnerFactory; +import org.apache.druid.query.operator.WindowOperatorQueryQueryToolChest; +import org.apache.druid.query.scan.ScanQuery; +import org.apache.druid.query.scan.ScanQueryConfig; +import org.apache.druid.query.scan.ScanQueryEngine; +import org.apache.druid.query.scan.ScanQueryQueryToolChest; +import org.apache.druid.query.scan.ScanQueryRunnerFactory; +import org.apache.druid.query.search.SearchQuery; +import org.apache.druid.query.search.SearchQueryConfig; +import org.apache.druid.query.search.SearchQueryQueryToolChest; +import org.apache.druid.query.search.SearchQueryRunnerFactory; +import org.apache.druid.query.search.SearchStrategySelector; +import org.apache.druid.query.timeboundary.TimeBoundaryQuery; +import org.apache.druid.query.timeboundary.TimeBoundaryQueryRunnerFactory; +import org.apache.druid.query.timeseries.TimeseriesQuery; +import org.apache.druid.query.timeseries.TimeseriesQueryEngine; +import org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest; +import org.apache.druid.query.timeseries.TimeseriesQueryRunnerFactory; +import org.apache.druid.query.topn.TopNQuery; +import org.apache.druid.query.topn.TopNQueryConfig; +import org.apache.druid.query.topn.TopNQueryQueryToolChest; +import org.apache.druid.query.topn.TopNQueryRunnerFactory; +import org.apache.druid.query.union.UnionQuery; +import org.apache.druid.query.union.UnionQueryLogic; +import org.apache.druid.segment.TestHelper; +import org.apache.druid.segment.join.FrameBasedInlineJoinableFactory; +import org.apache.druid.segment.join.InlineJoinableFactory; +import org.apache.druid.segment.join.JoinableFactory; +import org.apache.druid.segment.join.LookupJoinableFactory; +import org.apache.druid.segment.join.MapJoinableFactory; +import org.apache.druid.server.QueryScheduler; +import org.apache.druid.server.initialization.ServerConfig; +import org.apache.druid.server.scheduling.ManualQueryPrioritizationStrategy; +import org.apache.druid.server.scheduling.NoQueryLaningStrategy; +import org.apache.druid.sql.calcite.util.CacheTestHelperModule.ResultCacheMode; +import org.junit.jupiter.api.Assertions; + +import javax.annotation.Nullable; + +import java.util.Map; +import java.util.Set; + +public class SqlTestQueryStack +{ + private static final int COMPUTE_BUFFER_SIZE = 10 * 1024 * 1024; + + public static final int DEFAULT_NUM_MERGE_BUFFERS = -1; + + public static final QueryScheduler DEFAULT_NOOP_SCHEDULER = new QueryScheduler( + 0, + ManualQueryPrioritizationStrategy.INSTANCE, + NoQueryLaningStrategy.INSTANCE, + new ServerConfig() + ); + + private SqlTestQueryStack() + { + } + + public static DruidProcessingConfig getProcessingConfig(final int mergeBuffers) + { + return new DruidProcessingConfig() + { + @Override + public String getFormatString() + { + return null; + } + + @Override + public int intermediateComputeSizeBytes() + { + return COMPUTE_BUFFER_SIZE; + } + + @Override + public int getNumThreads() + { + return 1; + } + + @Override + public int getNumMergeBuffers() + { + return mergeBuffers < 0 ? 2 : mergeBuffers; + } + }; + } + + public static TestBufferPool makeTestBufferPool(final Closer closer) + { + final TestBufferPool testBufferPool = TestBufferPool.offHeap(COMPUTE_BUFFER_SIZE, Integer.MAX_VALUE); + closer.register(() -> Assertions.assertEquals(0, testBufferPool.getOutstandingObjectCount())); + return testBufferPool; + } + + public static TestGroupByBuffers makeGroupByBuffers( + final Closer closer, + final DruidProcessingConfig processingConfig + ) + { + return closer.register(TestGroupByBuffers.createFromProcessingConfig(processingConfig)); + } + + public static QueryRunnerFactoryConglomerate createQueryRunnerFactoryConglomerate(final Closer closer) + { + final DruidProcessingConfig processingConfig = getProcessingConfig(-1); + final TestBufferPool testBufferPool = makeTestBufferPool(closer); + final TestGroupByBuffers groupByBuffers = makeGroupByBuffers(closer, processingConfig); + final ObjectMapper jsonMapper = TestHelper.makeJsonMapper(); + + final ImmutableMap, QueryRunnerFactory> factories = ImmutableMap + ., QueryRunnerFactory>builder() + .put( + SegmentMetadataQuery.class, + new SegmentMetadataQueryRunnerFactory( + new SegmentMetadataQueryQueryToolChest(new SegmentMetadataQueryConfig("P1W")), + QueryRunnerTestHelper.NOOP_QUERYWATCHER + ) + ) + .put( + SearchQuery.class, + new SearchQueryRunnerFactory( + new SearchStrategySelector(Suppliers.ofInstance(new SearchQueryConfig())), + new SearchQueryQueryToolChest(new SearchQueryConfig()), + QueryRunnerTestHelper.NOOP_QUERYWATCHER + ) + ) + .put( + ScanQuery.class, + new ScanQueryRunnerFactory( + new ScanQueryQueryToolChest(DefaultGenericQueryMetricsFactory.instance()), + new ScanQueryEngine(), + new ScanQueryConfig() + ) + ) + .put( + TimeseriesQuery.class, + new TimeseriesQueryRunnerFactory( + new TimeseriesQueryQueryToolChest(), + new TimeseriesQueryEngine(), + QueryRunnerTestHelper.NOOP_QUERYWATCHER + ) + ) + .put( + TopNQuery.class, + new TopNQueryRunnerFactory( + testBufferPool, + new TopNQueryQueryToolChest(new TopNQueryConfig()), + QueryRunnerTestHelper.NOOP_QUERYWATCHER + ) + ) + .put(GroupByQuery.class, makeGroupByQueryRunnerFactory(jsonMapper, groupByBuffers, processingConfig)) + .put(TimeBoundaryQuery.class, new TimeBoundaryQueryRunnerFactory(QueryRunnerTestHelper.NOOP_QUERYWATCHER)) + .put( + WindowOperatorQuery.class, + new WindowOperatorQueryQueryRunnerFactory( + new WindowOperatorQueryQueryToolChest(DefaultGenericQueryMetricsFactory.instance()) + ) + ) + .build(); + final UnionQueryLogic unionQueryLogic = new UnionQueryLogic(); + final QueryRunnerFactoryConglomerate conglomerate = new DefaultQueryRunnerFactoryConglomerate( + factories, + Maps.transformValues(factories, QueryRunnerFactory::getToolchest), + ImmutableMap.of(UnionQuery.class, unionQueryLogic) + ); + unionQueryLogic.initialize(conglomerate); + return conglomerate; + } + + public static JoinableFactory makeJoinableFactoryForLookup( + final LookupExtractorFactoryContainerProvider lookupProvider + ) + { + return makeJoinableFactoryFromDefault(lookupProvider, null, null); + } + + public static JoinableFactory makeJoinableFactoryFromDefault( + @Nullable final LookupExtractorFactoryContainerProvider lookupProvider, + @Nullable final Set customFactories, + @Nullable final Map, Class> customMappings + ) + { + final ImmutableSet.Builder setBuilder = ImmutableSet.builder(); + final ImmutableMap.Builder, Class> mapBuilder = + ImmutableMap.builder(); + setBuilder.add(new InlineJoinableFactory(), new FrameBasedInlineJoinableFactory()); + mapBuilder.put(InlineJoinableFactory.class, org.apache.druid.query.InlineDataSource.class); + mapBuilder.put(FrameBasedInlineJoinableFactory.class, org.apache.druid.query.FrameBasedInlineDataSource.class); + if (lookupProvider != null) { + setBuilder.add(new LookupJoinableFactory(lookupProvider)); + mapBuilder.put(LookupJoinableFactory.class, org.apache.druid.query.LookupDataSource.class); + } + if (customFactories != null) { + setBuilder.addAll(customFactories); + } + if (customMappings != null) { + mapBuilder.putAll(customMappings); + } + return new MapJoinableFactory(setBuilder.build(), mapBuilder.build()); + } + + public static DruidInjectorBuilder defaultInjectorBuilder() + { + final Injector startupInjector = new StartupInjectorBuilder().build(); + return new CoreInjectorBuilder(startupInjector) + .ignoreLoadScopes() + .addModule(new ExpressionModule()) + .addModule(new SegmentWranglerModule()) + .addModule(new CacheTestHelperModule(ResultCacheMode.DISABLED)); + } + + private static GroupByQueryRunnerFactory makeGroupByQueryRunnerFactory( + final ObjectMapper mapper, + final TestGroupByBuffers bufferPools, + final DruidProcessingConfig processingConfig + ) + { + if (bufferPools.getBufferSize() != processingConfig.intermediateComputeSizeBytes()) { + throw new ISE("Provided buffer size [%,d] does not match configured size [%,d]", + bufferPools.getBufferSize(), processingConfig.intermediateComputeSizeBytes()); + } + if (bufferPools.getNumMergeBuffers() != processingConfig.getNumMergeBuffers()) { + throw new ISE("Provided merge buffer count [%,d] does not match configured count [%,d]", + bufferPools.getNumMergeBuffers(), processingConfig.getNumMergeBuffers()); + } + final GroupByQueryConfig config = new GroupByQueryConfig(); + final Supplier configSupplier = Suppliers.ofInstance(config); + final GroupByStatsProvider statsProvider = new GroupByStatsProvider(); + final GroupByResourcesReservationPool reservationPool = + new GroupByResourcesReservationPool(bufferPools.getMergePool(), config); + final GroupingEngine groupingEngine = new GroupingEngine( + processingConfig, + configSupplier, + reservationPool, + mapper, + mapper, + QueryRunnerTestHelper.NOOP_QUERYWATCHER, + statsProvider + ); + final GroupByQueryQueryToolChest toolChest = new GroupByQueryQueryToolChest( + groupingEngine, + configSupplier, + DefaultGroupByQueryMetricsFactory.instance(), + reservationPool, + statsProvider + ); + return new GroupByQueryRunnerFactory(groupingEngine, toolChest, bufferPools.getProcessingPool()); + } +} diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/TestDataBuilder.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/TestDataBuilder.java index ddb13708fa81..ed41c165740b 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/TestDataBuilder.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/TestDataBuilder.java @@ -88,7 +88,6 @@ import org.apache.druid.segment.transform.TransformSpec; import org.apache.druid.segment.writeout.OffHeapMemorySegmentWriteOutMediumFactory; import org.apache.druid.server.QueryScheduler; -import org.apache.druid.server.QueryStackTests; import org.apache.druid.server.SpecificSegmentsQuerySegmentWalker; import org.apache.druid.sql.calcite.util.datasets.TestDataSet; import org.apache.druid.timeline.DataSegment; @@ -662,7 +661,7 @@ public static SpecificSegmentsQuerySegmentWalker createMockWalker( injector, conglomerate, tmpDir, - QueryStackTests.DEFAULT_NOOP_SCHEDULER, + SqlTestQueryStack.DEFAULT_NOOP_SCHEDULER, QueryFrameworkUtils.createDefaultJoinableFactory(injector) ); } @@ -693,7 +692,7 @@ public static SpecificSegmentsQuerySegmentWalker createMockWalker( { final JoinableFactory joinableFactoryToUse; if (joinableFactory == null) { - joinableFactoryToUse = QueryStackTests.makeJoinableFactoryForLookup( + joinableFactoryToUse = SqlTestQueryStack.makeJoinableFactoryForLookup( injector.getInstance(LookupExtractorFactoryContainerProvider.class) ); } else { 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 6fb974a527cd..e54ddc89a9c8 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 @@ -35,7 +35,6 @@ import org.apache.druid.common.exception.ErrorResponseTransformStrategy; import org.apache.druid.common.guava.SettableSupplier; import org.apache.druid.error.DruidException; -import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.error.ErrorResponse; import org.apache.druid.error.QueryExceptionCompat; import org.apache.druid.jackson.DefaultObjectMapper; @@ -70,7 +69,6 @@ import org.apache.druid.server.QueryResource; import org.apache.druid.server.QueryResponse; import org.apache.druid.server.QueryScheduler; -import org.apache.druid.server.QueryStackTests; import org.apache.druid.server.ResponseContextConfig; import org.apache.druid.server.SpecificSegmentsQuerySegmentWalker; import org.apache.druid.server.initialization.ServerConfig; @@ -91,6 +89,8 @@ import org.apache.druid.sql.SqlQueryPlus; import org.apache.druid.sql.SqlStatementFactory; import org.apache.druid.sql.SqlToolbox; +import org.apache.druid.sql.calcite.BaseCalciteQueryTest; +import org.apache.druid.sql.calcite.DruidExceptionAssertions; import org.apache.druid.sql.calcite.parser.DruidSqlInsert; import org.apache.druid.sql.calcite.planner.CalciteRulesManager; import org.apache.druid.sql.calcite.planner.CatalogResolver; @@ -104,11 +104,11 @@ 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.SqlTestQueryStack; import org.apache.druid.sql.hook.DruidHookDispatcher; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -121,6 +121,7 @@ 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; @@ -144,8 +145,6 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -import static org.hamcrest.MatcherAssert.assertThat; - @SuppressWarnings("ALL") public class SqlResourceTest extends CalciteTestBase { @@ -197,7 +196,7 @@ public class SqlResourceTest extends CalciteTestBase @BeforeAll public static void setupClass(@TempDir File tempDir) { - conglomerate = QueryStackTests.createQueryRunnerFactoryConglomerate(staticCloser); + conglomerate = SqlTestQueryStack.createQueryRunnerFactoryConglomerate(staticCloser); scheduler = new QueryScheduler( 5, ManualQueryPrioritizationStrategy.INSTANCE, @@ -357,12 +356,12 @@ public void tearDown() throws Exception @Test public void testUnauthorized() { - ForbiddenException e = Assert.assertThrows(ForbiddenException.class, () -> { + ForbiddenException e = Assertions.assertThrows(ForbiddenException.class, () -> { postForAsyncResponse(createSimpleQueryWithId("id", "select count(*) from forbiddenDatasource"), request()); }); - Assert.assertEquals("Unauthorized", e.getMessage()); - Assert.assertEquals(1, testRequestLogger.getSqlQueryLogs().size()); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertEquals("Unauthorized", e.getMessage()); + Assertions.assertEquals(1, testRequestLogger.getSqlQueryLogs().size()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); } @Test @@ -373,21 +372,21 @@ public void testRestricted() throws Exception "id", "select count(*) as cnt from restrictedDatasource_m1_is_6" )).rhs; - Assert.assertEquals(ImmutableList.of(ImmutableMap.of("cnt", 6)), resultAsSuperUser); + Assertions.assertEquals(ImmutableList.of(ImmutableMap.of("cnt", 6)), resultAsSuperUser); checkSqlRequestLog(true, CalciteTests.TEST_SUPERUSER_NAME); testRequestLogger.clear(); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); req = makeRegularUserReq(); final List> resultAsRegularUser = doPost(createSimpleQueryWithId( "id", "select count(*) as cnt from restrictedDatasource_m1_is_6" )).rhs; - Assert.assertEquals(ImmutableList.of(ImmutableMap.of("cnt", 1)), resultAsRegularUser); + Assertions.assertEquals(ImmutableList.of(ImmutableMap.of("cnt", 1)), resultAsRegularUser); checkSqlRequestLog(true); testRequestLogger.clear(); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); } @Test @@ -397,16 +396,16 @@ public void testCountStar() throws Exception createSimpleQueryWithId("id", "SELECT COUNT(*) AS cnt, 'foo' AS TheFoo FROM druid.foo") ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("cnt", 6, "TheFoo", "foo") ), rows ); checkSqlRequestLog(true); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(200, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(200, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } @Test @@ -414,7 +413,7 @@ public void test_getEnabled() { Response response = resource.getSupportedEngines(req); Set supportedEngines = ((SupportedEnginesResponse) response.getEntity()).getEngines(); - Assert.assertTrue(supportedEngines.contains(new EngineInfo(NativeSqlEngine.NAME))); + Assertions.assertTrue(supportedEngines.contains(new EngineInfo(NativeSqlEngine.NAME))); } @Test @@ -462,18 +461,18 @@ public void testCountStarWithMissingIntervalsContext() throws Exception }) .collect(Collectors.toList()); - Assert.assertEquals(expectedMissingHeaders, observedMissingHeaders); + Assertions.assertEquals(expectedMissingHeaders, observedMissingHeaders); Object results = JSON_MAPPER.readValue(response.baos.toByteArray(), Object.class); - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("cnt", 6, "TheFoo", "foo") ), results ); checkSqlRequestLog(true); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); } @Test @@ -483,18 +482,18 @@ public void testSqlLifecycleMetrics() throws Exception createSimpleQueryWithId("id", "SELECT COUNT(*) AS cnt, 'foo' AS TheFoo FROM druid.foo") ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("cnt", 6, "TheFoo", "foo") ), rows ); checkSqlRequestLog(true); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); stubServiceEmitter.verifyValue("sqlQuery/bytes", 27L); stubServiceEmitter.verifyEmitted("sqlQuery/planningTimeMs", 1); - Assert.assertEquals(200, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(200, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } @@ -508,14 +507,14 @@ public void testCountStarExtendedCharacters() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("cnt", 1) ), rows ); checkSqlRequestLog(true); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); } @Test @@ -533,7 +532,7 @@ public void testTimestampsInResponse() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("__time", "2000-01-01T00:00:00.000Z", "t2", "2000-01-01T00:00:00.000Z") ), @@ -556,7 +555,7 @@ public void testTimestampsInResponseWithParameterizedLimit() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("__time", "2000-01-01T00:00:00.000Z", "t2", "2000-01-01T00:00:00.000Z") ), @@ -579,7 +578,7 @@ public void testTimestampsInResponseLosAngelesTimeZone() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("__time", "1999-12-31T16:00:00.000-08:00", "t2", "1999-12-31T00:00:00.000-08:00") ), @@ -622,7 +621,7 @@ public void testTimestampsInResponseLosAngelesTimeZone_setViaDefaultQueryConfig( ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("__time", "1999-12-31T16:00:00.000-08:00", "t2", "1999-12-31T00:00:00.000-08:00") ), @@ -645,7 +644,7 @@ public void testTimestampsInResponseWithNulls() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( Maps.transformValues( ImmutableMap.of("t1", "2001-01-03T00:00:00.000Z", "t2", ""), @@ -671,7 +670,7 @@ public void testFieldAliasingSelect() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("x", "a", "y", "a") ), @@ -694,7 +693,7 @@ public void testFieldAliasingGroupBy() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( // x and y both should be null instead of empty string Maps.transformValues(ImmutableMap.of("x", "", "y", ""), (val) -> null), @@ -746,7 +745,7 @@ public void testPivotRowTypePreservedInDecoupledPlanner() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("Age", "18-19", "Women", 0.040737148399612025, "Men", 0.1052376333656644), ImmutableMap.of("Age", "20-29", "Women", 0.1556741028128031, "Men", 0.3976721629485936), @@ -797,7 +796,7 @@ public void testPivotRowTypePreservedInCoupledPlanner() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of("Age", "18-19", "Women", 0.040737148399612025, "Men", 0.1052376333656644), ImmutableMap.of("Age", "20-29", "Women", 0.1556741028128031, "Men", 0.3976721629485936), @@ -814,7 +813,7 @@ public void testArrayResultFormat() throws Exception { final String query = "SELECT *, CASE dim2 WHEN '' THEN dim2 END FROM foo LIMIT 2"; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( Arrays.asList( "2000-01-01T00:00:00.000Z", @@ -858,8 +857,8 @@ public void testArrayResultFormatWithErrorAfterSecondRow() throws Exception doPostRaw(new SqlQuery(query, ResultFormat.ARRAY, false, false, false, null, null), req); // Truncated response: missing final ] - Assert.assertNull(response.lhs); - Assert.assertEquals("[[1],[1]", response.rhs); + Assertions.assertNull(response.lhs); + Assertions.assertEquals("[[1],[1]", response.rhs); } @Test @@ -872,8 +871,8 @@ public void testObjectResultFormatWithErrorAfterFirstRow() throws Exception doPostRaw(new SqlQuery(query, ResultFormat.OBJECT, false, false, false, null, null), req); // Truncated response: missing final ] - Assert.assertNull(response.lhs); - Assert.assertEquals("[{\"cnt\":1},{\"cnt\":1}", response.rhs); + Assertions.assertNull(response.lhs); + Assertions.assertEquals("[{\"cnt\":1},{\"cnt\":1}", response.rhs); } @Test @@ -886,8 +885,8 @@ public void testArrayLinesResultFormatWithErrorAfterFirstRow() throws Exception doPostRaw(new SqlQuery(query, ResultFormat.ARRAYLINES, false, false, false, null, null), req); // Truncated response: missing final LFLF - Assert.assertNull(response.lhs); - Assert.assertEquals("[1]\n[1]", response.rhs); + Assertions.assertNull(response.lhs); + Assertions.assertEquals("[1]\n[1]", response.rhs); } @Test @@ -900,8 +899,8 @@ public void testObjectLinesResultFormatWithErrorAfterFirstRow() throws Exception doPostRaw(new SqlQuery(query, ResultFormat.OBJECTLINES, false, false, false, null, null), req); // Truncated response: missing final LFLF - Assert.assertNull(response.lhs); - Assert.assertEquals("{\"cnt\":1}\n{\"cnt\":1}", response.rhs); + Assertions.assertNull(response.lhs); + Assertions.assertEquals("{\"cnt\":1}\n{\"cnt\":1}", response.rhs); } @Test @@ -914,8 +913,8 @@ public void testCsvResultFormatWithErrorAfterFirstRow() throws Exception doPostRaw(new SqlQuery(query, ResultFormat.CSV, false, false, false, null, null), req); // Truncated response: missing final LFLF - Assert.assertNull(response.lhs); - Assert.assertEquals("1\n1\n", response.rhs); + Assertions.assertNull(response.lhs); + Assertions.assertEquals("1\n1\n", response.rhs); } @Test @@ -934,9 +933,9 @@ public void testArrayResultFormatWithHeader() throws Exception req.mimic() ); - Assert.assertEquals(200, response.getStatus()); - Assert.assertEquals("yes", response.getHeader("X-Druid-SQL-Header-Included")); - Assert.assertEquals( + Assertions.assertEquals(200, response.getStatus()); + Assertions.assertEquals("yes", response.getHeader("X-Druid-SQL-Header-Included")); + Assertions.assertEquals( ImmutableList.builder() .add(EXPECTED_COLUMNS_FOR_RESULT_FORMAT_TESTS) .add(EXPECTED_TYPES_FOR_RESULT_FORMAT_TESTS) @@ -951,9 +950,9 @@ public void testArrayResultFormatWithHeader() throws Exception req.mimic() ); - Assert.assertEquals(200, responseNoSqlTypesHeader.getStatus()); - Assert.assertEquals("yes", responseNoSqlTypesHeader.getHeader("X-Druid-SQL-Header-Included")); - Assert.assertEquals( + Assertions.assertEquals(200, responseNoSqlTypesHeader.getStatus()); + Assertions.assertEquals("yes", responseNoSqlTypesHeader.getHeader("X-Druid-SQL-Header-Included")); + Assertions.assertEquals( ImmutableList.builder() .add(EXPECTED_COLUMNS_FOR_RESULT_FORMAT_TESTS) .add(EXPECTED_TYPES_FOR_RESULT_FORMAT_TESTS) @@ -967,9 +966,9 @@ public void testArrayResultFormatWithHeader() throws Exception req.mimic() ); - Assert.assertEquals(200, responseNoTypesHeader.getStatus()); - Assert.assertEquals("yes", responseNoTypesHeader.getHeader("X-Druid-SQL-Header-Included")); - Assert.assertEquals( + Assertions.assertEquals(200, responseNoTypesHeader.getStatus()); + Assertions.assertEquals("yes", responseNoTypesHeader.getHeader("X-Druid-SQL-Header-Included")); + Assertions.assertEquals( ImmutableList.builder() .add(EXPECTED_COLUMNS_FOR_RESULT_FORMAT_TESTS) .add(EXPECTED_SQL_TYPES_FOR_RESULT_FORMAT_TESTS) @@ -983,9 +982,9 @@ public void testArrayResultFormatWithHeader() throws Exception req.mimic() ); - Assert.assertEquals(200, responseNoTypes.getStatus()); - Assert.assertEquals("yes", responseNoTypes.getHeader("X-Druid-SQL-Header-Included")); - Assert.assertEquals( + Assertions.assertEquals(200, responseNoTypes.getStatus()); + Assertions.assertEquals("yes", responseNoTypes.getHeader("X-Druid-SQL-Header-Included")); + Assertions.assertEquals( ImmutableList.builder() .add(EXPECTED_COLUMNS_FOR_RESULT_FORMAT_TESTS) .addAll(Arrays.asList(expectedQueryResults)) @@ -998,9 +997,9 @@ public void testArrayResultFormatWithHeader() throws Exception req.mimic() ); - Assert.assertEquals(200, responseNoHeader.getStatus()); - Assert.assertNull(responseNoHeader.getHeader("X-Druid-SQL-Header-Included")); - Assert.assertEquals( + Assertions.assertEquals(200, responseNoHeader.getStatus()); + Assertions.assertNull(responseNoHeader.getHeader("X-Druid-SQL-Header-Included")); + Assertions.assertEquals( Arrays.asList(expectedQueryResults), JSON_MAPPER.readValue(responseNoHeader.baos.toByteArray(), Object.class) ); @@ -1018,10 +1017,10 @@ public void testArrayResultFormatWithHeader_nullColumnType() throws Exception req ); - Assert.assertEquals(200, response.getStatus()); - Assert.assertEquals("yes", response.getHeader("X-Druid-SQL-Header-Included")); + Assertions.assertEquals(200, response.getStatus()); + Assertions.assertEquals("yes", response.getHeader("X-Druid-SQL-Header-Included")); - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( Collections.singletonList("EXPR$0"), Collections.singletonList(null), @@ -1044,12 +1043,12 @@ public void testArrayLinesResultFormat() throws Exception final Pair pair = doPostRaw( new SqlQuery(query, ResultFormat.ARRAYLINES, false, false, false, null, null) ); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final List lines = Splitter.on('\n').splitToList(response); - Assert.assertEquals(4, lines.size()); - Assert.assertEquals( + Assertions.assertEquals(4, lines.size()); + Assertions.assertEquals( Arrays.asList( "2000-01-01T00:00:00.000Z", "", @@ -1063,7 +1062,7 @@ public void testArrayLinesResultFormat() throws Exception ), JSON_MAPPER.readValue(lines.get(0), List.class) ); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList( "2000-01-02T00:00:00.000Z", "10.1", @@ -1077,8 +1076,8 @@ public void testArrayLinesResultFormat() throws Exception ), JSON_MAPPER.readValue(lines.get(1), List.class) ); - Assert.assertEquals("", lines.get(2)); - Assert.assertEquals("", lines.get(3)); + Assertions.assertEquals("", lines.get(2)); + Assertions.assertEquals("", lines.get(3)); } @Test @@ -1088,15 +1087,15 @@ public void testArrayLinesResultFormatWithHeader() throws Exception final Pair pair = doPostRaw( new SqlQuery(query, ResultFormat.ARRAYLINES, true, true, true, null, null) ); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final List lines = Splitter.on('\n').splitToList(response); - Assert.assertEquals(7, lines.size()); - Assert.assertEquals(EXPECTED_COLUMNS_FOR_RESULT_FORMAT_TESTS, JSON_MAPPER.readValue(lines.get(0), List.class)); - Assert.assertEquals(EXPECTED_TYPES_FOR_RESULT_FORMAT_TESTS, JSON_MAPPER.readValue(lines.get(1), List.class)); - Assert.assertEquals(EXPECTED_SQL_TYPES_FOR_RESULT_FORMAT_TESTS, JSON_MAPPER.readValue(lines.get(2), List.class)); - Assert.assertEquals( + Assertions.assertEquals(7, lines.size()); + Assertions.assertEquals(EXPECTED_COLUMNS_FOR_RESULT_FORMAT_TESTS, JSON_MAPPER.readValue(lines.get(0), List.class)); + Assertions.assertEquals(EXPECTED_TYPES_FOR_RESULT_FORMAT_TESTS, JSON_MAPPER.readValue(lines.get(1), List.class)); + Assertions.assertEquals(EXPECTED_SQL_TYPES_FOR_RESULT_FORMAT_TESTS, JSON_MAPPER.readValue(lines.get(2), List.class)); + Assertions.assertEquals( Arrays.asList( "2000-01-01T00:00:00.000Z", "", @@ -1110,7 +1109,7 @@ public void testArrayLinesResultFormatWithHeader() throws Exception ), JSON_MAPPER.readValue(lines.get(3), List.class) ); - Assert.assertEquals( + Assertions.assertEquals( Arrays.asList( "2000-01-02T00:00:00.000Z", "10.1", @@ -1124,8 +1123,8 @@ public void testArrayLinesResultFormatWithHeader() throws Exception ), JSON_MAPPER.readValue(lines.get(4), List.class) ); - Assert.assertEquals("", lines.get(5)); - Assert.assertEquals("", lines.get(6)); + Assertions.assertEquals("", lines.get(5)); + Assertions.assertEquals("", lines.get(6)); } @Test @@ -1135,15 +1134,15 @@ public void testArrayLinesResultFormatWithHeader_nullColumnType() throws Excepti final Pair pair = doPostRaw( new SqlQuery(query, ResultFormat.ARRAYLINES, true, true, true, null, null) ); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final List lines = Splitter.on('\n').splitToList(response); - Assert.assertEquals(6, lines.size()); - Assert.assertEquals(Collections.singletonList("EXPR$0"), JSON_MAPPER.readValue(lines.get(0), List.class)); - Assert.assertEquals(Collections.singletonList(null), JSON_MAPPER.readValue(lines.get(1), List.class)); - Assert.assertEquals(Collections.singletonList("ROW"), JSON_MAPPER.readValue(lines.get(2), List.class)); - Assert.assertEquals( + Assertions.assertEquals(6, lines.size()); + Assertions.assertEquals(Collections.singletonList("EXPR$0"), JSON_MAPPER.readValue(lines.get(0), List.class)); + Assertions.assertEquals(Collections.singletonList(null), JSON_MAPPER.readValue(lines.get(1), List.class)); + Assertions.assertEquals(Collections.singletonList("ROW"), JSON_MAPPER.readValue(lines.get(2), List.class)); + Assertions.assertEquals( Collections.singletonList( Arrays.asList( 1, @@ -1152,8 +1151,8 @@ public void testArrayLinesResultFormatWithHeader_nullColumnType() throws Excepti ), JSON_MAPPER.readValue(lines.get(3), List.class) ); - Assert.assertEquals("", lines.get(4)); - Assert.assertEquals("", lines.get(5)); + Assertions.assertEquals("", lines.get(4)); + Assertions.assertEquals("", lines.get(5)); } @Test @@ -1165,7 +1164,7 @@ public void testObjectResultFormat() throws Exception (k, v) -> "EXPR$8".equals(k) || ("dim2".equals(k) && v.toString().isEmpty()) ? null : v ); - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap .builder() @@ -1208,7 +1207,7 @@ public void testObjectLinesResultFormat() throws Exception final Pair pair = doPostRaw( new SqlQuery(query, ResultFormat.OBJECTLINES, false, false, false, null, null) ); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final Function, Map> transformer = m -> { return Maps.transformEntries( @@ -1218,8 +1217,8 @@ public void testObjectLinesResultFormat() throws Exception }; final List lines = Splitter.on('\n').splitToList(response); - Assert.assertEquals(4, lines.size()); - Assert.assertEquals( + Assertions.assertEquals(4, lines.size()); + Assertions.assertEquals( transformer.apply( ImmutableMap .builder() @@ -1236,7 +1235,7 @@ public void testObjectLinesResultFormat() throws Exception ), JSON_MAPPER.readValue(lines.get(0), Object.class) ); - Assert.assertEquals( + Assertions.assertEquals( transformer.apply( ImmutableMap .builder() @@ -1253,8 +1252,8 @@ public void testObjectLinesResultFormat() throws Exception ), JSON_MAPPER.readValue(lines.get(1), Object.class) ); - Assert.assertEquals("", lines.get(2)); - Assert.assertEquals("", lines.get(3)); + Assertions.assertEquals("", lines.get(2)); + Assertions.assertEquals("", lines.get(3)); } @Test @@ -1263,7 +1262,7 @@ public void testObjectLinesResultFormatWithMinimalHeader() throws Exception final String query = "SELECT *, CASE dim2 WHEN '' THEN dim2 END FROM foo LIMIT 2"; final Pair pair = doPostRaw(new SqlQuery(query, ResultFormat.OBJECTLINES, true, false, false, null, null)); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final Function, Map> transformer = m -> Maps.transformEntries( m, @@ -1276,9 +1275,9 @@ public void testObjectLinesResultFormatWithMinimalHeader() throws Exception expectedHeader.put(column, null); } - Assert.assertEquals(5, lines.size()); - Assert.assertEquals(expectedHeader, JSON_MAPPER.readValue(lines.get(0), Object.class)); - Assert.assertEquals( + Assertions.assertEquals(5, lines.size()); + Assertions.assertEquals(expectedHeader, JSON_MAPPER.readValue(lines.get(0), Object.class)); + Assertions.assertEquals( transformer.apply( ImmutableMap .builder() @@ -1295,7 +1294,7 @@ public void testObjectLinesResultFormatWithMinimalHeader() throws Exception ), JSON_MAPPER.readValue(lines.get(1), Object.class) ); - Assert.assertEquals( + Assertions.assertEquals( transformer.apply( ImmutableMap .builder() @@ -1312,8 +1311,8 @@ public void testObjectLinesResultFormatWithMinimalHeader() throws Exception ), JSON_MAPPER.readValue(lines.get(2), Object.class) ); - Assert.assertEquals("", lines.get(3)); - Assert.assertEquals("", lines.get(4)); + Assertions.assertEquals("", lines.get(3)); + Assertions.assertEquals("", lines.get(4)); } @Test @@ -1322,7 +1321,7 @@ public void testObjectLinesResultFormatWithFullHeader() throws Exception final String query = "SELECT *, CASE dim2 WHEN '' THEN dim2 END FROM foo LIMIT 2"; final Pair pair = doPostRaw(new SqlQuery(query, ResultFormat.OBJECTLINES, true, true, true, null, null)); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final Function, Map> transformer = m -> Maps.transformEntries( m, @@ -1341,9 +1340,9 @@ public void testObjectLinesResultFormatWithFullHeader() throws Exception ); } - Assert.assertEquals(5, lines.size()); - Assert.assertEquals(expectedHeader, JSON_MAPPER.readValue(lines.get(0), Object.class)); - Assert.assertEquals( + Assertions.assertEquals(5, lines.size()); + Assertions.assertEquals(expectedHeader, JSON_MAPPER.readValue(lines.get(0), Object.class)); + Assertions.assertEquals( transformer.apply( ImmutableMap .builder() @@ -1360,7 +1359,7 @@ public void testObjectLinesResultFormatWithFullHeader() throws Exception ), JSON_MAPPER.readValue(lines.get(1), Object.class) ); - Assert.assertEquals( + Assertions.assertEquals( transformer.apply( ImmutableMap .builder() @@ -1377,8 +1376,8 @@ public void testObjectLinesResultFormatWithFullHeader() throws Exception ), JSON_MAPPER.readValue(lines.get(2), Object.class) ); - Assert.assertEquals("", lines.get(3)); - Assert.assertEquals("", lines.get(4)); + Assertions.assertEquals("", lines.get(3)); + Assertions.assertEquals("", lines.get(4)); } @Test @@ -1387,7 +1386,7 @@ public void testObjectLinesResultFormatWithFullHeader_nullColumnType() throws Ex final String query = "SELECT (1, 2) FROM INFORMATION_SCHEMA.COLUMNS LIMIT 1"; final Pair pair = doPostRaw(new SqlQuery(query, ResultFormat.OBJECTLINES, true, true, true, null, null)); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final List lines = Splitter.on('\n').splitToList(response); @@ -1396,9 +1395,9 @@ public void testObjectLinesResultFormatWithFullHeader_nullColumnType() throws Ex typeMap.put(ObjectWriter.SQL_TYPE_HEADER_NAME, "ROW"); final Map expectedHeader = ImmutableMap.of("EXPR$0", typeMap); - Assert.assertEquals(4, lines.size()); - Assert.assertEquals(expectedHeader, JSON_MAPPER.readValue(lines.get(0), Object.class)); - Assert.assertEquals( + Assertions.assertEquals(4, lines.size()); + Assertions.assertEquals(expectedHeader, JSON_MAPPER.readValue(lines.get(0), Object.class)); + Assertions.assertEquals( ImmutableMap .builder() .put("EXPR$0", Arrays.asList(1, 2)) @@ -1406,8 +1405,8 @@ public void testObjectLinesResultFormatWithFullHeader_nullColumnType() throws Ex JSON_MAPPER.readValue(lines.get(1), Object.class) ); - Assert.assertEquals("", lines.get(2)); - Assert.assertEquals("", lines.get(3)); + Assertions.assertEquals("", lines.get(2)); + Assertions.assertEquals("", lines.get(3)); } @Test @@ -1417,11 +1416,11 @@ public void testCsvResultFormat() throws Exception final Pair pair = doPostRaw( new SqlQuery(query, ResultFormat.CSV, false, false, false, null, null) ); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final List lines = Splitter.on('\n').splitToList(response); - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( "2000-01-01T00:00:00.000Z,,a,\"[\"\"a\"\",\"\"b\"\"]\",1,1.0,1.0,\"\"\"AQAAAEAAAA==\"\"\",", "2000-01-02T00:00:00.000Z,10.1,,\"[\"\"b\"\",\"\"c\"\"]\",1,2.0,2.0,\"\"\"AQAAAQAAAAHNBA==\"\"\",", @@ -1439,11 +1438,11 @@ public void testCsvResultFormatWithHeaders() throws Exception final Pair pair = doPostRaw( new SqlQuery(query, ResultFormat.CSV, true, true, true, null, null) ); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final List lines = Splitter.on('\n').splitToList(response); - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( String.join(",", EXPECTED_COLUMNS_FOR_RESULT_FORMAT_TESTS), String.join(",", EXPECTED_TYPES_FOR_RESULT_FORMAT_TESTS), @@ -1464,11 +1463,11 @@ public void testCsvResultFormatWithHeaders_nullColumnType() throws Exception final Pair pair = doPostRaw( new SqlQuery(query, ResultFormat.CSV, true, true, true, null, null) ); - Assert.assertNull(pair.lhs); + Assertions.assertNull(pair.lhs); final String response = pair.rhs; final List lines = Splitter.on('\n').splitToList(response); - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( "EXPR$0", "", @@ -1499,7 +1498,7 @@ public void testExplainCountStar() throws Exception ) ).rhs; - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of( ImmutableMap.of( "PLAN", @@ -1528,8 +1527,8 @@ public void testCannotParse() throws Exception errorResponse, "Incorrect syntax near the keyword 'FROM' at line 1, column 1" ); - Assert.assertEquals(0, testRequestLogger.getSqlQueryLogs().size()); // Invalid queries are not logged - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertEquals(0, testRequestLogger.getSqlQueryLogs().size()); // Invalid queries are not logged + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); } @Test @@ -1545,9 +1544,9 @@ public void testCannotValidate() throws Exception "Column 'dim4' not found in any table" ); checkSqlRequestLog(false); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } @Test @@ -1557,7 +1556,7 @@ public void testCannotConvert() throws Exception final SqlQuery unsupportedQuery = createSimpleQueryWithId("id", "SELECT dim1 FROM druid.foo ORDER BY dim1"); ErrorResponse exception = postSyncForException(unsupportedQuery, Status.BAD_REQUEST.getStatusCode()); - Assert.assertTrue((Boolean) req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)); + Assertions.assertTrue((Boolean) req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)); validateErrorResponse( exception, @@ -1568,9 +1567,9 @@ public void testCannotConvert() throws Exception + "[SQL query requires ordering a table by non-time column [[dim1]], which is not supported.]" ); checkSqlRequestLog(false); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } /** @@ -1592,9 +1591,9 @@ public void testCannotConvert_InvalidSQL() throws Exception "Aggregation [MAX] does not support type [STRING], column [v0]" ); checkSqlRequestLog(false); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } @Test @@ -1618,7 +1617,7 @@ public void testResourceLimitExceeded() throws Exception ResourceLimitExceededException.class.getName(), "" ); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); } private void failOnExecute(String errorMessage) @@ -1647,7 +1646,7 @@ public void testUnsupportedQueryThrowsException() throws Exception ); validateInvalidSqlError(exception, "Incorrect syntax near the keyword 'TO'"); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); } @Test @@ -1672,8 +1671,8 @@ public void testErrorResponseReturnSameQueryIdWhenSetInContext() // This is checked in the common method that returns the response, but checking it again just protects // from changes there breaking the checks, so doesn't hurt. assertStatusAndCommonHeaders(response, DruidException.Category.INVALID_INPUT.getExpectedStatus()); - Assert.assertEquals(queryId, getHeader(response, QueryResource.QUERY_ID_RESPONSE_HEADER)); - Assert.assertEquals(queryId, getHeader(response, SqlResource.SQL_QUERY_ID_RESPONSE_HEADER)); + Assertions.assertEquals(queryId, getHeader(response, QueryResource.QUERY_ID_RESPONSE_HEADER)); + Assertions.assertEquals(queryId, getHeader(response, SqlResource.SQL_QUERY_ID_RESPONSE_HEADER)); } @Test @@ -1694,8 +1693,8 @@ public void testErrorResponseReturnNoQueryIdWhenNotSetInContext() final Response response = resource.doPost(sqlQuery, req); // Query ID won't be set, but we can look for other aspects of the response that we expect. - Assert.assertEquals(DruidException.Category.INVALID_INPUT.getExpectedStatus(), response.getStatus()); - Assert.assertEquals("application/json", getContentType(response)); + Assertions.assertEquals(DruidException.Category.INVALID_INPUT.getExpectedStatus(), response.getStatus()); + Assertions.assertEquals("application/json", getContentType(response)); } @Test @@ -1749,7 +1748,7 @@ public ErrorResponseTransformStrategy getErrorResponseTransformStrategy() "org.apache.druid.query.QueryUnsupportedException", "This will be supported in Druid 9999" ); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); } /** @@ -1779,15 +1778,15 @@ public void testAssertionErrorThrowsErrorWithFilterResponse() throws Exception Status.BAD_REQUEST.getStatusCode() ); - assertThat( + BaseCalciteQueryTest.assertDruidException( exception.getUnderlyingException(), - DruidExceptionMatcher + DruidExceptionAssertions .invalidSqlInput() .expectMessageIs("Calcite assertion violated: [not a literal: assertion_error()]") ); - Assert.assertTrue(lifecycleManager.getAll("id").isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll("id").isEmpty()); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } @Test @@ -1864,8 +1863,8 @@ public void testTooManyRequestsAfterTotalLaning() throws Exception Response response = (Response) futures.get(i).get(); assertStatusAndCommonHeaders(response, 429); QueryException interruped = deserializeResponse(response, QueryException.class); - Assert.assertEquals(QueryException.QUERY_CAPACITY_EXCEEDED_ERROR_CODE, interruped.getErrorCode()); - Assert.assertEquals( + Assertions.assertEquals(QueryException.QUERY_CAPACITY_EXCEEDED_ERROR_CODE, interruped.getErrorCode()); + Assertions.assertEquals( QueryCapacityExceededException.makeLaneErrorMessage(HiLoQueryLaningStrategy.LOW, 2), interruped.getMessage() ); @@ -1873,17 +1872,17 @@ public void testTooManyRequestsAfterTotalLaning() throws Exception } else { MockHttpServletResponse response = (MockHttpServletResponse) futures.get(i).get(); assertStatusAndCommonHeaders(response, 200); - Assert.assertEquals( + Assertions.assertEquals( ImmutableList.of(ImmutableMap.of("cnt", 6, "TheFoo", "foo")), deserializeResponse(response, Object.class) ); success++; } } - Assert.assertEquals(2, success); - Assert.assertEquals(1, limited); - Assert.assertEquals(3, testRequestLogger.getSqlQueryLogs().size()); - Assert.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); + Assertions.assertEquals(2, success); + Assertions.assertEquals(1, limited); + Assertions.assertEquals(3, testRequestLogger.getSqlQueryLogs().size()); + Assertions.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); stubServiceEmitter.verifyEmitted("sqlQuery/time", 3); Map codeFrequencies = stubServiceEmitter.getMetricEvents("sqlQuery/time").stream() .map(event -> event.toMap()) @@ -1892,7 +1891,7 @@ public void testTooManyRequestsAfterTotalLaning() throws Exception code -> code, Collectors.counting() )); - Assert.assertEquals(Map.of(200, 2L, 429, 1L), codeFrequencies); + Assertions.assertEquals(Map.of(200, 2L, 429, 1L), codeFrequencies); } @Test @@ -1925,9 +1924,9 @@ public void testQueryTimeoutException() throws Exception QueryTimeoutException.class.getName(), "" ); - Assert.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(504, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(504, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } @Test @@ -1945,13 +1944,13 @@ public void testCancelBetweenValidateAndPlan() throws Exception makeRegularUserReq() ) ); - Assert.assertTrue(validateAndAuthorizeLatch.await(WAIT_TIMEOUT_SECS, TimeUnit.SECONDS)); - Assert.assertTrue(lifecycleAddLatch.await(WAIT_TIMEOUT_SECS, TimeUnit.SECONDS)); + Assertions.assertTrue(validateAndAuthorizeLatch.await(WAIT_TIMEOUT_SECS, TimeUnit.SECONDS)); + Assertions.assertTrue(lifecycleAddLatch.await(WAIT_TIMEOUT_SECS, TimeUnit.SECONDS)); Response cancelResponse = resource.cancelQuery(sqlQueryId, makeRequestForCancel()); planLatch.countDown(); - Assert.assertEquals(Status.ACCEPTED.getStatusCode(), cancelResponse.getStatus()); + Assertions.assertEquals(Status.ACCEPTED.getStatusCode(), cancelResponse.getStatus()); - Assert.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); Response queryResponse = future.get(); assertStatusAndCommonHeaders(queryResponse, Status.INTERNAL_SERVER_ERROR.getStatusCode()); @@ -1964,7 +1963,7 @@ public void testCancelBetweenValidateAndPlan() throws Exception "" ); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(500, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(500, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } @Test @@ -1981,12 +1980,12 @@ public void testCancelBetweenPlanAndExecute() throws Exception makeRegularUserReq() ) ); - Assert.assertTrue(planLatch.await(WAIT_TIMEOUT_SECS, TimeUnit.SECONDS)); + Assertions.assertTrue(planLatch.await(WAIT_TIMEOUT_SECS, TimeUnit.SECONDS)); Response cancelResponse = resource.cancelQuery(sqlQueryId, makeRequestForCancel()); execLatch.countDown(); - Assert.assertEquals(Status.ACCEPTED.getStatusCode(), cancelResponse.getStatus()); + Assertions.assertEquals(Status.ACCEPTED.getStatusCode(), cancelResponse.getStatus()); - Assert.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); Response queryResponse = future.get(); assertStatusAndCommonHeaders(queryResponse, Status.INTERNAL_SERVER_ERROR.getStatusCode()); @@ -1994,7 +1993,7 @@ public void testCancelBetweenPlanAndExecute() throws Exception ErrorResponse exception = deserializeResponse(queryResponse, ErrorResponse.class); validateLegacyQueryExceptionErrorResponse(exception, "Query cancelled", null, ""); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(500, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(500, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } @Test @@ -2011,15 +2010,15 @@ public void testCancelInvalidQuery() throws Exception makeRegularUserReq() ) ); - Assert.assertTrue(planLatch.await(WAIT_TIMEOUT_SECS, TimeUnit.SECONDS)); + Assertions.assertTrue(planLatch.await(WAIT_TIMEOUT_SECS, TimeUnit.SECONDS)); Response cancelResponse = resource.cancelQuery("invalidQuery", makeRequestForCancel()); - Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), cancelResponse.getStatus()); + Assertions.assertEquals(Status.NOT_FOUND.getStatusCode(), cancelResponse.getStatus()); - Assert.assertFalse(lifecycleManager.getAll(sqlQueryId).isEmpty()); + Assertions.assertFalse(lifecycleManager.getAll(sqlQueryId).isEmpty()); execLatch.countDown(); MockHttpServletResponse queryResponse = future.get(); - Assert.assertEquals(Status.OK.getStatusCode(), queryResponse.getStatus()); + Assertions.assertEquals(Status.OK.getStatusCode(), queryResponse.getStatus()); } @Test @@ -2036,15 +2035,15 @@ public void testCancelForbidden() throws Exception makeSuperUserReq() ) ); - Assert.assertTrue(planLatch.await(3, TimeUnit.SECONDS)); + Assertions.assertTrue(planLatch.await(3, TimeUnit.SECONDS)); Response cancelResponse = resource.cancelQuery(sqlQueryId, makeRequestForCancel()); - Assert.assertEquals(Status.FORBIDDEN.getStatusCode(), cancelResponse.getStatus()); + Assertions.assertEquals(Status.FORBIDDEN.getStatusCode(), cancelResponse.getStatus()); - Assert.assertFalse(lifecycleManager.getAll(sqlQueryId).isEmpty()); + Assertions.assertFalse(lifecycleManager.getAll(sqlQueryId).isEmpty()); execLatch.countDown(); MockHttpServletResponse queryResponse = future.get(); - Assert.assertEquals(Status.OK.getStatusCode(), queryResponse.getStatus()); + Assertions.assertEquals(Status.OK.getStatusCode(), queryResponse.getStatus()); } @Test @@ -2076,9 +2075,9 @@ public void testQueryContextException() throws Exception "2000'" ); checkSqlRequestLog(false); - Assert.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); + Assertions.assertTrue(lifecycleManager.getAll(sqlQueryId).isEmpty()); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } @Test @@ -2096,7 +2095,7 @@ public void testQueryContextKeyNotAllowed() throws Exception ); checkSqlRequestLog(false); stubServiceEmitter.verifyEmitted("sqlQuery/time", 1); - Assert.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); + Assertions.assertEquals(400, stubServiceEmitter.getMetricEvents("sqlQuery/time").get(0).toMap().get(DruidMetrics.STATUS_CODE)); } private void checkSqlRequestLog(boolean success) @@ -2107,21 +2106,21 @@ private void checkSqlRequestLog(boolean success) @SuppressWarnings("unchecked") private void checkSqlRequestLog(boolean success, String user) { - Assert.assertEquals(1, testRequestLogger.getSqlQueryLogs().size()); + Assertions.assertEquals(1, testRequestLogger.getSqlQueryLogs().size()); final Map stats = testRequestLogger.getSqlQueryLogs().get(0).getQueryStats().getStats(); final Map queryContext = (Map) testRequestLogger.getSqlQueryLogs() .get(0) .getSqlQueryContext(); - Assert.assertEquals(success, stats.get("success")); - Assert.assertEquals(user, stats.get("identity")); - Assert.assertTrue(stats.containsKey("sqlQuery/time")); - Assert.assertTrue(stats.containsKey("sqlQuery/planningTimeMs")); - Assert.assertTrue(queryContext.containsKey(QueryContexts.CTX_SQL_QUERY_ID)); + Assertions.assertEquals(success, stats.get("success")); + Assertions.assertEquals(user, stats.get("identity")); + Assertions.assertTrue(stats.containsKey("sqlQuery/time")); + Assertions.assertTrue(stats.containsKey("sqlQuery/planningTimeMs")); + Assertions.assertTrue(queryContext.containsKey(QueryContexts.CTX_SQL_QUERY_ID)); if (success) { - Assert.assertTrue(stats.containsKey("sqlQuery/bytes")); + Assertions.assertTrue(stats.containsKey("sqlQuery/bytes")); } else { - Assert.assertTrue(stats.containsKey("exception")); + Assertions.assertTrue(stats.containsKey("exception")); } } @@ -2188,7 +2187,7 @@ private MockHttpServletResponse postForAsyncResponse(SqlQuery query, MockHttpSer final Object explicitQueryId = query.getContext().get("queryId"); final Object explicitSqlQueryId = query.getContext().get("sqlQueryId"); - Assert.assertNull(resource.doPost(query, req)); + Assertions.assertNull(resource.doPost(query, req)); final Object actualQueryId = response.getHeader(QueryResource.QUERY_ID_RESPONSE_HEADER); final Object actualSqlQueryId = response.getHeader(SqlResource.SQL_QUERY_ID_RESPONSE_HEADER); @@ -2199,10 +2198,10 @@ private MockHttpServletResponse postForAsyncResponse(SqlQuery query, MockHttpSer private void assertStatusAndCommonHeaders(MockHttpServletResponse queryResponse, int statusCode) { - Assert.assertEquals(statusCode, queryResponse.getStatus()); - Assert.assertEquals("application/json", queryResponse.getContentType()); - Assert.assertNotNull(queryResponse.getHeader(QueryResource.QUERY_ID_RESPONSE_HEADER)); - Assert.assertNotNull(queryResponse.getHeader(SqlResource.SQL_QUERY_ID_RESPONSE_HEADER)); + Assertions.assertEquals(statusCode, queryResponse.getStatus()); + Assertions.assertEquals("application/json", queryResponse.getContentType()); + Assertions.assertNotNull(queryResponse.getHeader(QueryResource.QUERY_ID_RESPONSE_HEADER)); + Assertions.assertNotNull(queryResponse.getHeader(SqlResource.SQL_QUERY_ID_RESPONSE_HEADER)); } private T deserializeResponse(MockHttpServletResponse resp, Class clazz) throws IOException @@ -2270,10 +2269,10 @@ private Object getHeader(Response resp, String header) private void assertStatusAndCommonHeaders(Response queryResponse, int statusCode) { - Assert.assertEquals(statusCode, queryResponse.getStatus()); - Assert.assertEquals("application/json", getContentType(queryResponse)); - Assert.assertNotNull(getHeader(queryResponse, QueryResource.QUERY_ID_RESPONSE_HEADER)); - Assert.assertNotNull(getHeader(queryResponse, SqlResource.SQL_QUERY_ID_RESPONSE_HEADER)); + Assertions.assertEquals(statusCode, queryResponse.getStatus()); + Assertions.assertEquals("application/json", getContentType(queryResponse)); + Assertions.assertNotNull(getHeader(queryResponse, QueryResource.QUERY_ID_RESPONSE_HEADER)); + Assertions.assertNotNull(getHeader(queryResponse, SqlResource.SQL_QUERY_ID_RESPONSE_HEADER)); } private void validateQueryIds( @@ -2285,19 +2284,19 @@ private void validateQueryIds( { if (explicitQueryId == null) { if (null != explicitSqlQueryId) { - Assert.assertEquals(explicitSqlQueryId, actualQueryId); - Assert.assertEquals(explicitSqlQueryId, actualSqlQueryId); + Assertions.assertEquals(explicitSqlQueryId, actualQueryId); + Assertions.assertEquals(explicitSqlQueryId, actualSqlQueryId); } else { - Assert.assertNotNull(actualQueryId); - Assert.assertNotNull(actualSqlQueryId); + Assertions.assertNotNull(actualQueryId); + Assertions.assertNotNull(actualSqlQueryId); } } else { if (explicitSqlQueryId == null) { - Assert.assertEquals(explicitQueryId, actualQueryId); - Assert.assertEquals(explicitQueryId, actualSqlQueryId); + Assertions.assertEquals(explicitQueryId, actualQueryId); + Assertions.assertEquals(explicitQueryId, actualSqlQueryId); } else { - Assert.assertEquals(explicitQueryId, actualQueryId); - Assert.assertEquals(explicitSqlQueryId, actualSqlQueryId); + Assertions.assertEquals(explicitQueryId, actualQueryId); + Assertions.assertEquals(explicitSqlQueryId, actualSqlQueryId); } } } @@ -2496,17 +2495,17 @@ private DruidException validateErrorResponse( String messageContainsString ) { - Assert.assertNotNull(errorResponse); + Assertions.assertNotNull(errorResponse); DruidException exception = errorResponse.getUnderlyingException(); - Assert.assertEquals(errorCode, exception.getErrorCode()); - Assert.assertEquals(targetPersona, exception.getTargetPersona()); - Assert.assertEquals(category, exception.getCategory()); + Assertions.assertEquals(errorCode, exception.getErrorCode()); + Assertions.assertEquals(targetPersona, exception.getTargetPersona()); + Assertions.assertEquals(category, exception.getCategory()); if (messageContainsString == null) { - Assert.assertNull(exception.getMessage()); + Assertions.assertNull(exception.getMessage()); } else { - assertThat(exception.getMessage(), CoreMatchers.containsString(messageContainsString)); + Assertions.assertTrue(exception.getMessage().contains(messageContainsString)); } return exception; @@ -2518,7 +2517,7 @@ private DruidException validateInvalidSqlError( ) { final DruidException exception = validateInvalidInputError(response, containsString); - Assert.assertEquals("sql", exception.getContextValue("sourceType")); + Assertions.assertEquals("sql", exception.getContextValue("sourceType")); return exception; } @@ -2550,8 +2549,8 @@ private DruidException validateLegacyQueryExceptionErrorResponse( messageContainsString ); - Assert.assertEquals(legacyCode, exception.getContextValue("legacyErrorCode")); - Assert.assertEquals(errorClass, exception.getContextValue("errorClass")); + Assertions.assertEquals(legacyCode, exception.getContextValue("legacyErrorCode")); + Assertions.assertEquals(errorClass, exception.getContextValue("errorClass")); return exception; } From 3b056eda88a11f9904dda20f192e307562993170 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 7 Aug 2026 20:20:29 +0800 Subject: [PATCH 02/15] test: include momentsketch in shared extensions-contrib batch --- extensions-contrib/momentsketch/pom.xml | 20 ++- .../MomentSketchObjectStrategyTest.java | 6 +- .../momentsketch/MomentSketchWrapperTest.java | 10 +- .../MomentSketchAggregatorFactoryTest.java | 16 +-- .../MomentSketchMaxPostAggregatorTest.java | 12 +- .../MomentSketchMinPostAggregatorTest.java | 12 +- ...omentSketchQuantilePostAggregatorTest.java | 30 ++--- .../MomentsSketchAggregatorTest.java | 114 ++++++++++++------ 8 files changed, 137 insertions(+), 83 deletions(-) diff --git a/extensions-contrib/momentsketch/pom.xml b/extensions-contrib/momentsketch/pom.xml index d54752887819..6da1ecb52d43 100644 --- a/extensions-contrib/momentsketch/pom.xml +++ b/extensions-contrib/momentsketch/pom.xml @@ -33,6 +33,21 @@ Aggregators for the approximate quantile moment sketch + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + com.github.stanford-futuredata.momentsketch momentsketch-solver @@ -80,11 +95,6 @@ provided - - junit - junit - test - nl.jqno.equalsverifier equalsverifier diff --git a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/MomentSketchObjectStrategyTest.java b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/MomentSketchObjectStrategyTest.java index 5ef909dd8e71..ad80fa32f93d 100644 --- a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/MomentSketchObjectStrategyTest.java +++ b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/MomentSketchObjectStrategyTest.java @@ -19,8 +19,8 @@ package org.apache.druid.query.aggregation.momentsketch; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class MomentSketchObjectStrategyTest { @@ -28,6 +28,6 @@ public class MomentSketchObjectStrategyTest public void testReadRetainsBufferReference() { MomentSketchObjectStrategy strategy = new MomentSketchObjectStrategy(); - Assert.assertFalse(strategy.readRetainsBufferReference()); + Assertions.assertFalse(strategy.readRetainsBufferReference()); } } diff --git a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/MomentSketchWrapperTest.java b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/MomentSketchWrapperTest.java index 75b2abb7ad13..4b232bf6ed27 100644 --- a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/MomentSketchWrapperTest.java +++ b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/MomentSketchWrapperTest.java @@ -19,8 +19,8 @@ package org.apache.druid.query.aggregation.momentsketch; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class MomentSketchWrapperTest { @@ -33,7 +33,7 @@ public void testDeserialize() byte[] bs = mw.toByteArray(); MomentSketchWrapper mw2 = MomentSketchWrapper.fromByteArray(bs); - Assert.assertEquals(10, mw2.getPowerSums()[1], 1e-10); + Assertions.assertEquals(10, mw2.getPowerSums()[1], 1e-10); } @Test @@ -46,7 +46,7 @@ public void testSimpleSolve() } double[] ps = {0.0, 0.5, 1.0}; double[] qs = mw.getQuantiles(ps); - Assert.assertEquals(0, qs[0], 1.0); - Assert.assertEquals(50, qs[1], 1.0); + Assertions.assertEquals(0, qs[0], 1.0); + Assertions.assertEquals(50, qs[1], 1.0); } } diff --git a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchAggregatorFactoryTest.java b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchAggregatorFactoryTest.java index 096632214cbf..55818bde47a4 100644 --- a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchAggregatorFactoryTest.java +++ b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchAggregatorFactoryTest.java @@ -30,8 +30,8 @@ import org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest; 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.Assertions; +import org.junit.jupiter.api.Test; public class MomentSketchAggregatorFactoryTest { @@ -48,7 +48,7 @@ public void serializeDeserializeFactoryWithFieldName() throws Exception MomentSketchAggregatorFactory.class ); - Assert.assertEquals(factory, other); + Assertions.assertEquals(factory, other); } @Test @@ -72,7 +72,7 @@ public void testResultArraySignature() ) .build(); - Assert.assertEquals( + Assertions.assertEquals( RowSignature.builder() .addTimeColumn() .add("count", ColumnType.LONG) @@ -93,14 +93,14 @@ public void testWithName() MomentSketchAggregatorFactory sketchAggFactory = new MomentSketchAggregatorFactory( "name", "fieldName", 128, true ); - Assert.assertEquals(sketchAggFactory, sketchAggFactory.withName("name")); - Assert.assertEquals("newTest", sketchAggFactory.withName("newTest").getName()); + Assertions.assertEquals(sketchAggFactory, sketchAggFactory.withName("name")); + Assertions.assertEquals("newTest", sketchAggFactory.withName("newTest").getName()); MomentSketchMergeAggregatorFactory sketchMergeAggregatorFactory = new MomentSketchMergeAggregatorFactory( "name", 128, true ); - Assert.assertEquals(sketchMergeAggregatorFactory, sketchMergeAggregatorFactory.withName("name")); - Assert.assertEquals("newTest", sketchMergeAggregatorFactory.withName("newTest").getName()); + Assertions.assertEquals(sketchMergeAggregatorFactory, sketchMergeAggregatorFactory.withName("name")); + Assertions.assertEquals("newTest", sketchMergeAggregatorFactory.withName("newTest").getName()); } } diff --git a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchMaxPostAggregatorTest.java b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchMaxPostAggregatorTest.java index 83e1aab0d4fa..6c8259e8dade 100644 --- a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchMaxPostAggregatorTest.java +++ b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchMaxPostAggregatorTest.java @@ -23,8 +23,8 @@ import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.ConstantPostAggregator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class MomentSketchMaxPostAggregatorTest { @@ -40,9 +40,9 @@ public void testSerde() throws Exception MomentSketchMaxPostAggregator.class ); - Assert.assertEquals(there, andBackAgain); - Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); - Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); + Assertions.assertEquals(there, andBackAgain); + Assertions.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); + Assertions.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); } @Test @@ -51,7 +51,7 @@ public void testToString() PostAggregator postAgg = new MomentSketchMaxPostAggregator("post", new ConstantPostAggregator("", 100)); - Assert.assertEquals( + Assertions.assertEquals( "MomentSketchMaxPostAggregator{name='post', field=ConstantPostAggregator{name='', constantValue=100}}", postAgg.toString() ); diff --git a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchMinPostAggregatorTest.java b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchMinPostAggregatorTest.java index 6613d5f2aef2..33eef993ac7d 100644 --- a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchMinPostAggregatorTest.java +++ b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchMinPostAggregatorTest.java @@ -23,8 +23,8 @@ import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.ConstantPostAggregator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class MomentSketchMinPostAggregatorTest { @@ -40,9 +40,9 @@ public void testSerde() throws Exception MomentSketchMinPostAggregator.class ); - Assert.assertEquals(there, andBackAgain); - Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); - Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); + Assertions.assertEquals(there, andBackAgain); + Assertions.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); + Assertions.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); } @Test @@ -51,7 +51,7 @@ public void testToString() PostAggregator postAgg = new MomentSketchMinPostAggregator("post", new ConstantPostAggregator("", 100)); - Assert.assertEquals( + Assertions.assertEquals( "MomentSketchMinPostAggregator{name='post', field=ConstantPostAggregator{name='', constantValue=100}}", postAgg.toString() ); diff --git a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchQuantilePostAggregatorTest.java b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchQuantilePostAggregatorTest.java index bc2179d55d51..0ae46a751c0f 100644 --- a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchQuantilePostAggregatorTest.java +++ b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchQuantilePostAggregatorTest.java @@ -24,15 +24,14 @@ import org.apache.druid.java.util.common.IAE; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.ConstantPostAggregator; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class MomentSketchQuantilePostAggregatorTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); @Test public void testSerde() throws Exception @@ -46,9 +45,9 @@ public void testSerde() throws Exception MomentSketchQuantilePostAggregator.class ); - Assert.assertEquals(there, andBackAgain); - Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); - Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); + Assertions.assertEquals(there, andBackAgain); + Assertions.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); + Assertions.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); } @Test @@ -57,7 +56,7 @@ public void testToString() PostAggregator postAgg = new MomentSketchQuantilePostAggregator("post", new ConstantPostAggregator("", 100), new double[]{0.25, 0.75}); - Assert.assertEquals( + Assertions.assertEquals( "MomentSketchQuantilePostAggregator{name='post', field=ConstantPostAggregator{name='', constantValue=100}, fractions=[0.25, 0.75]}", postAgg.toString() ); @@ -66,11 +65,12 @@ public void testToString() @Test public void testComparator() { - expectedException.expect(IAE.class); - expectedException.expectMessage("Comparing arrays of quantiles is not supported"); - PostAggregator postAgg = - new MomentSketchQuantilePostAggregator("post", new ConstantPostAggregator("", 100), new double[]{0.25, 0.75}); - postAgg.getComparator(); + Throwable exception = assertThrows(IAE.class, () -> { + PostAggregator postAgg = + new MomentSketchQuantilePostAggregator("post", new ConstantPostAggregator("", 100), new double[]{0.25, 0.75}); + postAgg.getComparator(); + }); + assertTrue(exception.getMessage().contains("Comparing arrays of quantiles is not supported")); } @Test public void testEquals() diff --git a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java index 51d08bc5d331..520018512a82 100644 --- a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java +++ b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java @@ -28,6 +28,7 @@ import org.apache.druid.data.input.impl.StringDimensionSchema; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.initialization.DruidModule; +import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; @@ -38,15 +39,12 @@ import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.testing.InitializedNullHandlingTest; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.util.ArrayList; @@ -54,35 +52,79 @@ import java.util.Collections; import java.util.List; -@RunWith(Parameterized.class) public class MomentsSketchAggregatorTest extends InitializedNullHandlingTest { - private final AggregationTestHelper helper; + private AggregationTestHelper helper; - @Rule - public final TemporaryFolder tempFolder = new TemporaryFolder(); + @TempDir + public File tempFolder; - public MomentsSketchAggregatorTest(final GroupByQueryConfig config) + public void initMomentsSketchAggregatorTest(final GroupByQueryConfig config) { MomentSketchModule.registerSerde(); DruidModule module = new MomentSketchModule(); - helper = AggregationTestHelper.createGroupByQueryAggregationTestHelper( + helper = AggregationTestHelper.createGroupByQueryAggregationTestHelperWithTempDir( module.getJacksonModules(), config, tempFolder); } - @Parameterized.Parameters(name = "{0}") + private static List testConfigs() + { + return List.of( + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperInitialBuckets() + { + return 4; + } + }, + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperMaxSize() + { + return 2; + } + + @Override + public HumanReadableBytes getMaxOnDiskStorage() + { + return HumanReadableBytes.valueOf(10L * 1024 * 1024); + } + }, + new org.apache.druid.jackson.DefaultObjectMapper().convertValue( + java.util.Map.of( + "maxSelectorDictionarySize", 20, + "maxMergingDictionarySize", 400, + "maxOnDiskStorage", 10L * 1024 * 1024 + ), + GroupByQueryConfig.class + ), + new GroupByQueryConfig() + { + @Override + public int getNumParallelCombineThreads() + { + return 2; + } + } + ); + } + public static Collection constructorFeeder() { final List constructors = new ArrayList<>(); - for (GroupByQueryConfig config : GroupByQueryRunnerTest.testConfigs()) { + for (GroupByQueryConfig config : testConfigs()) { constructors.add(new Object[]{config}); } return constructors; } - @Test - public void buildingSketchesAtIngestionTime() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void buildingSketchesAtIngestionTime(final GroupByQueryConfig config) throws Exception { + initMomentsSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -145,51 +187,53 @@ public void buildingSketchesAtIngestionTime() throws Exception .build() ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); ResultRow row = results.get(0); MomentSketchWrapper sketchObject = (MomentSketchWrapper) row.get(0); // "sketch" // 400 total products since this is pre-rollup - Assert.assertEquals(400.0, sketchObject.getPowerSums()[0], 1e-10); + Assertions.assertEquals(400.0, sketchObject.getPowerSums()[0], 1e-10); MomentSketchWrapper sketchObjectWithNulls = (MomentSketchWrapper) row.get(1); // "sketchWithNulls" // 23 null values (377 when nulls are not replaced with default) - Assert.assertEquals( + Assertions.assertEquals( 377.0, sketchObjectWithNulls.getPowerSums()[0], 1e-10 ); double[] quantilesArray = (double[]) row.get(2); // "quantiles" - Assert.assertEquals(0, quantilesArray[0], 0.05); - Assert.assertEquals(.5, quantilesArray[1], 0.05); - Assert.assertEquals(1.0, quantilesArray[2], 0.05); + Assertions.assertEquals(0, quantilesArray[0], 0.05); + Assertions.assertEquals(.5, quantilesArray[1], 0.05); + Assertions.assertEquals(1.0, quantilesArray[2], 0.05); Double minValue = (Double) row.get(3); // "min" - Assert.assertEquals(0.0011, minValue, 0.0001); + Assertions.assertEquals(0.0011, minValue, 0.0001); Double maxValue = (Double) row.get(4); // "max" - Assert.assertEquals(0.9969, maxValue, 0.0001); + Assertions.assertEquals(0.9969, maxValue, 0.0001); double[] quantilesArrayWithNulls = (double[]) row.get(5); // "quantilesWithNulls" - Assert.assertEquals(5.0, quantilesArrayWithNulls[0], 0.05); - Assert.assertEquals( + Assertions.assertEquals(5.0, quantilesArrayWithNulls[0], 0.05); + Assertions.assertEquals( 7.57, quantilesArrayWithNulls[1], 0.05 ); - Assert.assertEquals(10.0, quantilesArrayWithNulls[2], 0.05); + Assertions.assertEquals(10.0, quantilesArrayWithNulls[2], 0.05); Double minValueWithNulls = (Double) row.get(6); // "minWithNulls" - Assert.assertEquals(5.0164, minValueWithNulls, 0.0001); + Assertions.assertEquals(5.0164, minValueWithNulls, 0.0001); Double maxValueWithNulls = (Double) row.get(7); // "maxWithNulls" - Assert.assertEquals(9.9788, maxValueWithNulls, 0.0001); + Assertions.assertEquals(9.9788, maxValueWithNulls, 0.0001); } - @Test - public void buildingSketchesAtQueryTime() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void buildingSketchesAtQueryTime(final GroupByQueryConfig config) throws Exception { + initMomentsSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -225,15 +269,15 @@ public void buildingSketchesAtQueryTime() throws Exception ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); ResultRow row = results.get(0); MomentSketchWrapper sketchObject = (MomentSketchWrapper) row.get(0); // "sketch" // 385 total products since roll-up limited by valueWithNulls column - Assert.assertEquals(385.0, sketchObject.getPowerSums()[0], 1e-10); + Assertions.assertEquals(385.0, sketchObject.getPowerSums()[0], 1e-10); MomentSketchWrapper sketchObjectWithNulls = (MomentSketchWrapper) row.get(1); // "sketchWithNulls" - Assert.assertEquals(377.0, sketchObjectWithNulls.getPowerSums()[0], 1e-10); + Assertions.assertEquals(377.0, sketchObjectWithNulls.getPowerSums()[0], 1e-10); } } From 1c54509dffd83a2c31c6303a990cd367362e214d Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 7 Aug 2026 20:27:36 +0800 Subject: [PATCH 03/15] test: include shared-fixture contrib dependents --- extensions-contrib/ddsketch/pom.xml | 20 +++- .../DDSketchAggregatorFactoryTest.java | 10 +- .../ddsketch/DDSketchAggregatorTest.java | 112 ++++++++++++------ .../ddsketch/DDSketchObjectStrategyTest.java | 6 +- .../DDSketchToQuantilePostAggregatorTest.java | 12 +- ...DDSketchToQuantilesPostAggregatorTest.java | 18 +-- extensions-contrib/time-min-max/pom.xml | 35 +++--- .../TimestampGroupByAggregationTest.java | 103 +++++++++++----- .../TimestampMinMaxAggregatorFactoryTest.java | 22 ++-- .../TimestampMinMaxAggregatorTest.java | 49 +++++--- 10 files changed, 249 insertions(+), 138 deletions(-) diff --git a/extensions-contrib/ddsketch/pom.xml b/extensions-contrib/ddsketch/pom.xml index 32e6a9be21b9..9c023fe76cfa 100644 --- a/extensions-contrib/ddsketch/pom.xml +++ b/extensions-contrib/ddsketch/pom.xml @@ -33,6 +33,21 @@ Druid extension for generating ddsketch backed sketches + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + com.datadoghq sketches-java @@ -142,11 +157,6 @@ - - junit - junit - test - org.easymock easymock diff --git a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorFactoryTest.java b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorFactoryTest.java index 0e07960a90d8..40184fb563fc 100644 --- a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorFactoryTest.java +++ b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorFactoryTest.java @@ -28,8 +28,8 @@ import org.apache.druid.query.timeseries.TimeseriesQueryQueryToolChest; 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.Assertions; +import org.junit.jupiter.api.Test; public class DDSketchAggregatorFactoryTest { @@ -51,7 +51,7 @@ public void testResultArraySignature() ) .build(); - Assert.assertEquals( + Assertions.assertEquals( RowSignature.builder() .addTimeColumn() .add("count", ColumnType.LONG) @@ -67,7 +67,7 @@ public void testResultArraySignature() public void testWithName() { DDSketchAggregatorFactory factory = new DDSketchAggregatorFactory("ddsketch", "col", 0.01, 1000); - Assert.assertEquals(factory, factory.withName("ddsketch")); - Assert.assertEquals("newTest", factory.withName("newTest").getName()); + Assertions.assertEquals(factory, factory.withName("ddsketch")); + Assertions.assertEquals("newTest", factory.withName("newTest").getName()); } } diff --git a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java index 651dc86d1929..009f9ffcbad8 100644 --- a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java +++ b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java @@ -26,6 +26,7 @@ import org.apache.druid.data.input.impl.DimensionsSpec; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.jackson.DefaultObjectMapper; +import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; @@ -35,15 +36,12 @@ import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.testing.InitializedNullHandlingTest; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.util.ArrayList; @@ -51,36 +49,80 @@ import java.util.Collections; import java.util.List; -@RunWith(Parameterized.class) public class DDSketchAggregatorTest extends InitializedNullHandlingTest { - private final AggregationTestHelper helper; + private AggregationTestHelper helper; - @Rule - public final TemporaryFolder tempFolder = new TemporaryFolder(); + @TempDir + public File tempFolder; - public DDSketchAggregatorTest(final GroupByQueryConfig config) + public void initDDSketchAggregatorTest(final GroupByQueryConfig config) { DDSketchModule module = new DDSketchModule(); DDSketchModule.registerSerde(); - helper = AggregationTestHelper.createGroupByQueryAggregationTestHelper( + helper = AggregationTestHelper.createGroupByQueryAggregationTestHelperWithTempDir( module.getJacksonModules(), config, tempFolder); } - @Parameterized.Parameters(name = "{0}") + private static List testConfigs() + { + return List.of( + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperInitialBuckets() + { + return 4; + } + }, + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperMaxSize() + { + return 2; + } + + @Override + public HumanReadableBytes getMaxOnDiskStorage() + { + return HumanReadableBytes.valueOf(10L * 1024 * 1024); + } + }, + new org.apache.druid.jackson.DefaultObjectMapper().convertValue( + java.util.Map.of( + "maxSelectorDictionarySize", 20, + "maxMergingDictionarySize", 400, + "maxOnDiskStorage", 10L * 1024 * 1024 + ), + GroupByQueryConfig.class + ), + new GroupByQueryConfig() + { + @Override + public int getNumParallelCombineThreads() + { + return 2; + } + } + ); + } + public static Collection constructorFeeder() { final List constructors = new ArrayList<>(); - for (GroupByQueryConfig config : GroupByQueryRunnerTest.testConfigs()) { + for (GroupByQueryConfig config : testConfigs()) { constructors.add(new Object[]{config}); } return constructors; } // this is to test Json properties and equals - @Test - public void serializeDeserializeFactoryWithFieldName() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void serializeDeserializeFactoryWithFieldName(final GroupByQueryConfig config) throws Exception { + initDDSketchAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); new DDSketchModule().getJacksonModules().forEach(objectMapper::registerModule); DDSketchAggregatorFactory factory = new DDSketchAggregatorFactory("name", "fieldName", 0.01, 1000); @@ -90,12 +132,14 @@ public void serializeDeserializeFactoryWithFieldName() throws Exception AggregatorFactory.class ); - Assert.assertEquals(factory, other); + Assertions.assertEquals(factory, other); } - @Test - public void buildingSketchesAtIngestionTime() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void buildingSketchesAtIngestionTime(final GroupByQueryConfig config) throws Exception { + initDDSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -129,22 +173,24 @@ public void buildingSketchesAtIngestionTime() throws Exception .build() ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); ResultRow row = results.get(0); // post agg Object quantilesObject = row.get(1); // "quantiles" - Assert.assertTrue(quantilesObject instanceof double[]); + Assertions.assertTrue(quantilesObject instanceof double[]); double[] quantiles = (double[]) quantilesObject; - Assert.assertEquals(0.001, quantiles[0], 0.0006); // min value - Assert.assertEquals(0.5, quantiles[1], 0.05); // median value - Assert.assertEquals(1, quantiles[2], 0.05); // max value + Assertions.assertEquals(0.001, quantiles[0], 0.0006); // min value + Assertions.assertEquals(0.5, quantiles[1], 0.05); // median value + Assertions.assertEquals(1, quantiles[2], 0.05); // max value } - @Test - public void buildingSketchesAtQueryTime() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + public void buildingSketchesAtQueryTime(final GroupByQueryConfig config) throws Exception { + initDDSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -175,18 +221,18 @@ public void buildingSketchesAtQueryTime() throws Exception .build() ); List results = seq.toList(); - Assert.assertEquals(1, results.size()); + Assertions.assertEquals(1, results.size()); ResultRow row = results.get(0); // post agg Object quantilesObject = row.get(1); // "quantiles" - Assert.assertTrue(quantilesObject instanceof double[]); + Assertions.assertTrue(quantilesObject instanceof double[]); double[] quantiles = (double[]) quantilesObject; // All these tests test that the quantiles are within 1% of the exact quantile value - Assert.assertEquals(0.9838, quantiles[0], 0.9838 * 0.01); // p99 - Assert.assertEquals(0.9860, quantiles[1], 0.9850 * 0.01); // p99.5 - Assert.assertEquals(0.9927, quantiles[2], 0.9927 * 0.01); // p999 - Assert.assertEquals(0.9952, quantiles[3], 0.9952 * 0.01); // max value + Assertions.assertEquals(0.9838, quantiles[0], 0.9838 * 0.01); // p99 + Assertions.assertEquals(0.9860, quantiles[1], 0.9850 * 0.01); // p99.5 + Assertions.assertEquals(0.9927, quantiles[2], 0.9927 * 0.01); // p999 + Assertions.assertEquals(0.9952, quantiles[3], 0.9952 * 0.01); // max value } } diff --git a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchObjectStrategyTest.java b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchObjectStrategyTest.java index 03b52b08720b..16b2c3734454 100644 --- a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchObjectStrategyTest.java +++ b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchObjectStrategyTest.java @@ -19,8 +19,8 @@ package org.apache.druid.query.aggregation.ddsketch; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DDSketchObjectStrategyTest { @@ -28,6 +28,6 @@ public class DDSketchObjectStrategyTest public void testReadRetainsBufferReference() { DDSketchObjectStrategy strategy = new DDSketchObjectStrategy(); - Assert.assertFalse(strategy.readRetainsBufferReference()); + Assertions.assertFalse(strategy.readRetainsBufferReference()); } } diff --git a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchToQuantilePostAggregatorTest.java b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchToQuantilePostAggregatorTest.java index 6f3cbd8a3c6a..c0953fd22595 100644 --- a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchToQuantilePostAggregatorTest.java +++ b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchToQuantilePostAggregatorTest.java @@ -23,8 +23,8 @@ import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.ConstantPostAggregator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DDSketchToQuantilePostAggregatorTest { @@ -40,9 +40,9 @@ public void testSerde() throws Exception DDSketchToQuantilePostAggregator.class ); - Assert.assertEquals(there, andBackAgain); - Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); - Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); + Assertions.assertEquals(there, andBackAgain); + Assertions.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); + Assertions.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); } @Test @@ -51,7 +51,7 @@ public void testToString() PostAggregator postAgg = new DDSketchToQuantilePostAggregator("post", new ConstantPostAggregator("", 100), 0.5); - Assert.assertEquals( + Assertions.assertEquals( "DDSketchToQuantilePostAggregator{name='post', field=ConstantPostAggregator{name='', constantValue=100}, fraction=0.5}", postAgg.toString() ); diff --git a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchToQuantilesPostAggregatorTest.java b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchToQuantilesPostAggregatorTest.java index 22861d46d2a1..8c955c292ccc 100644 --- a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchToQuantilesPostAggregatorTest.java +++ b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchToQuantilesPostAggregatorTest.java @@ -24,8 +24,8 @@ import org.apache.druid.java.util.common.IAE; import org.apache.druid.query.aggregation.PostAggregator; import org.apache.druid.query.aggregation.post.ConstantPostAggregator; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class DDSketchToQuantilesPostAggregatorTest { @@ -41,9 +41,9 @@ public void testSerde() throws Exception DDSketchToQuantilesPostAggregator.class ); - Assert.assertEquals(there, andBackAgain); - Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); - Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); + Assertions.assertEquals(there, andBackAgain); + Assertions.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey()); + Assertions.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields()); } @Test @@ -55,7 +55,7 @@ public void testToString() new double[]{0.25, 0.75} ); - Assert.assertEquals( + Assertions.assertEquals( "DDSketchToQuantilesPostAggregator{name='post', field=ConstantPostAggregator{name='', constantValue=100}, fractions=[0.25, 0.75]}", postAgg.toString() ); @@ -69,10 +69,10 @@ public void testComparator() new ConstantPostAggregator("", 100), new double[]{0.25, 0.75} ); - Assert.assertThrows( - "Comparing arrays of quantiles is not supported", + Assertions.assertThrows( IAE.class, - () -> postAgg.getComparator()); + () -> postAgg.getComparator(), + "Comparing arrays of quantiles is not supported"); } @Test diff --git a/extensions-contrib/time-min-max/pom.xml b/extensions-contrib/time-min-max/pom.xml index 08188d741208..7e8c5f0b1189 100644 --- a/extensions-contrib/time-min-max/pom.xml +++ b/extensions-contrib/time-min-max/pom.xml @@ -32,6 +32,21 @@ Min/Max of timestamp + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + org.apache.druid druid-processing @@ -78,26 +93,6 @@ fastutil provided - - junit - junit - test - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.vintage - junit-vintage-engine - test - org.easymock easymock diff --git a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java index 45c8a791719d..cc7fae3a9887 100644 --- a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java +++ b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java @@ -27,24 +27,21 @@ import org.apache.druid.data.input.impl.DimensionsSpec; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.segment.ColumnSelectorFactory; import org.easymock.EasyMock; import org.joda.time.DateTime; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.io.File; import java.io.IOException; @@ -54,20 +51,18 @@ import java.util.List; import java.util.zip.ZipFile; -@RunWith(Parameterized.class) public class TimestampGroupByAggregationTest { private AggregationTestHelper helper; - @Rule - public final TemporaryFolder temporaryFolder = new TemporaryFolder(); + @TempDir + public File temporaryFolder; private ColumnSelectorFactory selectorFactory; private TestObjectColumnSelector selector; private Timestamp[] values = new Timestamp[10]; - @Parameterized.Parameters(name = "{index}: Test for {0}, config = {1}") public static Iterable constructorFeeder() { final List constructors = new ArrayList<>(); @@ -78,7 +73,7 @@ public static Iterable constructorFeeder() ); for (final List partialConstructor : partialConstructors) { - for (GroupByQueryConfig config : GroupByQueryRunnerTest.testConfigs()) { + for (GroupByQueryConfig config : testConfigs()) { final List constructor = Lists.newArrayList(partialConstructor); constructor.add(config); constructors.add(constructor.toArray()); @@ -88,13 +83,57 @@ public static Iterable constructorFeeder() return constructors; } - private final String aggType; - private final String aggField; - private final String groupByField; - private final DateTime expected; - private final GroupByQueryConfig config; + private static List testConfigs() + { + return List.of( + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperInitialBuckets() + { + return 4; + } + }, + new GroupByQueryConfig() + { + @Override + public int getBufferGrouperMaxSize() + { + return 2; + } + + @Override + public HumanReadableBytes getMaxOnDiskStorage() + { + return HumanReadableBytes.valueOf(10L * 1024 * 1024); + } + }, + new org.apache.druid.jackson.DefaultObjectMapper().convertValue( + java.util.Map.of( + "maxSelectorDictionarySize", 20, + "maxMergingDictionarySize", 400, + "maxOnDiskStorage", 10L * 1024 * 1024 + ), + GroupByQueryConfig.class + ), + new GroupByQueryConfig() + { + @Override + public int getNumParallelCombineThreads() + { + return 2; + } + } + ); + } - public TimestampGroupByAggregationTest( + private String aggType; + private String aggField; + private String groupByField; + private DateTime expected; + private GroupByQueryConfig config; + + public void initTimestampGroupByAggregationTest( String aggType, String aggField, String groupByField, @@ -109,10 +148,9 @@ public TimestampGroupByAggregationTest( this.config = config; } - @Before - public void setup() + private void setup() { - helper = AggregationTestHelper.createGroupByQueryAggregationTestHelper( + helper = AggregationTestHelper.createGroupByQueryAggregationTestHelperWithTempDir( new TimestampMinMaxModule().getJacksonModules(), config, temporaryFolder @@ -124,7 +162,7 @@ public void setup() EasyMock.replay(selectorFactory); } - @After + @AfterEach public void teardown() throws IOException { helper.close(); @@ -137,9 +175,18 @@ private AggregatorFactory makeTimestampAggregator(String name, String fieldName) : new TimestampMaxAggregatorFactory(name, fieldName, null); } - @Test - public void testSimpleDataIngestionAndGroupByTest() throws Exception + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{index}: Test for {0}, config = {1}") + public void testSimpleDataIngestionAndGroupByTest( + String aggType, + String aggField, + String groupByField, + DateTime expected, + GroupByQueryConfig config + ) throws Exception { + initTimestampGroupByAggregationTest(aggType, aggField, groupByField, expected, config); + setup(); List aggregators = List.of(makeTimestampAggregator(aggField, "timestamp")); GroupByQuery groupByQuery = GroupByQuery.builder() @@ -176,7 +223,7 @@ public void testSimpleDataIngestionAndGroupByTest() throws Exception int groupByFieldNumber = groupByQuery.getResultRowSignature().indexOf(groupByField); List results = seq.toList(); - Assert.assertEquals(36, results.size()); - Assert.assertEquals(expected, results.get(0).get(groupByFieldNumber)); + Assertions.assertEquals(36, results.size()); + Assertions.assertEquals(expected, results.get(0).get(groupByFieldNumber)); } } diff --git a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorFactoryTest.java b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorFactoryTest.java index 7f3446d62df8..2ff26b952771 100644 --- a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorFactoryTest.java +++ b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorFactoryTest.java @@ -31,8 +31,8 @@ import org.apache.druid.segment.TestHelper; 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.Assertions; +import org.junit.jupiter.api.Test; public class TimestampMinMaxAggregatorFactoryTest { @@ -44,11 +44,11 @@ public void testSerde() throws JsonProcessingException TimestampMaxAggregatorFactory maxAgg = new TimestampMaxAggregatorFactory("timeMax", "__time", null); TimestampMinAggregatorFactory minAgg = new TimestampMinAggregatorFactory("timeMin", "__time", null); - Assert.assertEquals( + Assertions.assertEquals( maxAgg, JSON_MAPPER.readValue(JSON_MAPPER.writeValueAsString(maxAgg), TimestampMaxAggregatorFactory.class) ); - Assert.assertEquals( + Assertions.assertEquals( maxAgg.getCombiningFactory(), JSON_MAPPER.readValue( JSON_MAPPER.writeValueAsString(maxAgg.getCombiningFactory()), @@ -56,11 +56,11 @@ public void testSerde() throws JsonProcessingException ) ); - Assert.assertEquals( + Assertions.assertEquals( minAgg, JSON_MAPPER.readValue(JSON_MAPPER.writeValueAsString(minAgg), TimestampMinAggregatorFactory.class) ); - Assert.assertEquals( + Assertions.assertEquals( minAgg.getCombiningFactory(), JSON_MAPPER.readValue( JSON_MAPPER.writeValueAsString(minAgg.getCombiningFactory()), @@ -105,7 +105,7 @@ public void testResultArraySignature() ) .build(); - Assert.assertEquals( + Assertions.assertEquals( RowSignature.builder() .addTimeColumn() .add("count", ColumnType.LONG) @@ -124,11 +124,11 @@ public void testResultArraySignature() public void testWithName() { TimestampMaxAggregatorFactory maxAgg = new TimestampMaxAggregatorFactory("timeMax", "__time", null); - Assert.assertEquals(maxAgg, maxAgg.withName("timeMax")); - Assert.assertEquals("newTest", maxAgg.withName("newTest").getName()); + Assertions.assertEquals(maxAgg, maxAgg.withName("timeMax")); + Assertions.assertEquals("newTest", maxAgg.withName("newTest").getName()); TimestampMinAggregatorFactory minAgg = new TimestampMinAggregatorFactory("timeMin", "__time", null); - Assert.assertEquals(minAgg, minAgg.withName("timeMin")); - Assert.assertEquals("newTest", minAgg.withName("newTest").getName()); + Assertions.assertEquals(minAgg, minAgg.withName("timeMin")); + Assertions.assertEquals("newTest", minAgg.withName("newTest").getName()); } } diff --git a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorTest.java b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorTest.java index 4aa3476098a8..2b152fc8dc74 100644 --- a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorTest.java +++ b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorTest.java @@ -31,18 +31,15 @@ import org.apache.druid.initialization.Initialization; import org.apache.druid.segment.ColumnSelectorFactory; import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import javax.annotation.Nullable; import java.nio.ByteBuffer; import java.sql.Timestamp; import java.util.List; -@RunWith(Parameterized.class) public class TimestampMinMaxAggregatorTest { Injector injector; @@ -65,7 +62,6 @@ public class TimestampMinMaxAggregatorTest Timestamp.valueOf("2014-01-02 02:00:00") }; - @Parameterized.Parameters(name = "{index}: Test for {0}") public static Iterable constructorFeeder() { return Iterables.transform( @@ -90,7 +86,7 @@ public Object[] apply(List input) private Long initValue; private Timestamp expected; - public TimestampMinMaxAggregatorTest(String aggType, Class aggClass, Long initValue, Timestamp expected) + public void initTimestampMinMaxAggregatorTest(String aggType, Class aggClass, Long initValue, Timestamp expected) { this.aggType = aggType; this.aggClass = aggClass; @@ -98,8 +94,7 @@ public TimestampMinMaxAggregatorTest(String aggType, Class aggClass, + Long initValue, + Timestamp expected + ) + throws Exception { + initTimestampMinMaxAggregatorTest(aggType, aggClass, initValue, expected); + setup(); TimestampAggregator aggregator = (TimestampAggregator) aggregatorFactory.factorize(selectorFactory); - Assert.assertEquals(initValue, aggregator.get()); + Assertions.assertEquals(initValue, aggregator.get()); for (Timestamp value : values) { aggregate(selector, aggregator); } - Assert.assertEquals(expected, new Timestamp(aggregator.getLong())); + Assertions.assertEquals(expected, new Timestamp(aggregator.getLong())); } - @Test - public void testBufferAggregator() + @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{index}: Test for {0}") + public void testBufferAggregator( + String aggType, + Class aggClass, + Long initValue, + Timestamp expected + ) + throws Exception { + initTimestampMinMaxAggregatorTest(aggType, aggClass, initValue, expected); + setup(); TimestampBufferAggregator aggregator = (TimestampBufferAggregator) aggregatorFactory.factorizeBuffered(selectorFactory); ByteBuffer buffer = ByteBuffer.wrap(new byte[Long.BYTES]); @@ -154,11 +167,11 @@ public void testBufferAggregator() aggregate(selector, aggregator, buffer, 0); } - Assert.assertEquals(expected, new Timestamp(aggregator.getLong(buffer, 0))); + Assertions.assertEquals(expected, new Timestamp(aggregator.getLong(buffer, 0))); aggregator.init(buffer, 0); - Assert.assertEquals(initValue, aggregator.get(buffer, 0)); + Assertions.assertEquals(initValue, aggregator.get(buffer, 0)); } private void aggregate(TestObjectColumnSelector selector, TimestampAggregator agg) From 65dddc015ac611251bc849428c74185c75d7dc76 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 7 Aug 2026 20:43:09 +0800 Subject: [PATCH 04/15] test: include distinctcount in shared extensions-contrib batch --- extensions-contrib/distinctcount/pom.xml | 40 +++----- .../DistinctCountGroupByQueryTest.java | 95 ++++++++++++++++--- .../DistinctCountTimeseriesQueryTest.java | 2 +- .../DistinctCountTopNQueryTest.java | 10 +- 4 files changed, 104 insertions(+), 43 deletions(-) diff --git a/extensions-contrib/distinctcount/pom.xml b/extensions-contrib/distinctcount/pom.xml index 64a51563ce68..fff887197b68 100644 --- a/extensions-contrib/distinctcount/pom.xml +++ b/extensions-contrib/distinctcount/pom.xml @@ -34,6 +34,21 @@ + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + org.apache.druid druid-processing @@ -89,31 +104,6 @@ test test-jar - - junit - junit - test - - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.vintage - junit-vintage-engine - test - - - org.hamcrest - hamcrest - test - diff --git a/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountGroupByQueryTest.java b/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountGroupByQueryTest.java index 557b68e89375..02a1e3a8fe55 100644 --- a/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountGroupByQueryTest.java +++ b/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountGroupByQueryTest.java @@ -19,22 +19,31 @@ package org.apache.druid.query.aggregation.distinctcount; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.apache.druid.data.input.MapBasedInputRow; import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.io.Closer; +import org.apache.druid.query.DruidProcessingConfig; import org.apache.druid.query.FluentQueryRunner; import org.apache.druid.query.QueryPlus; import org.apache.druid.query.QueryRunnerTestHelper; import org.apache.druid.query.aggregation.CountAggregatorFactory; import org.apache.druid.query.dimension.DefaultDimensionSpec; +import org.apache.druid.query.groupby.DefaultGroupByQueryMetricsFactory; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryQueryToolChest; import org.apache.druid.query.groupby.GroupByQueryRunnerFactory; -import org.apache.druid.query.groupby.GroupByQueryRunnerTest; import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; +import org.apache.druid.query.groupby.GroupByResourcesReservationPool; +import org.apache.druid.query.groupby.GroupByStatsProvider; +import org.apache.druid.query.groupby.GroupingEngine; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.query.groupby.TestGroupByBuffers; import org.apache.druid.query.groupby.orderby.DefaultLimitSpec; @@ -46,10 +55,10 @@ import org.apache.druid.segment.incremental.IncrementalIndexSchema; import org.apache.druid.segment.incremental.OnheapIncrementalIndex; import org.apache.druid.testing.InitializedNullHandlingTest; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Arrays; @@ -58,21 +67,83 @@ public class DistinctCountGroupByQueryTest extends InitializedNullHandlingTest { + private static final DruidProcessingConfig PROCESSING_CONFIG = new DruidProcessingConfig() + { + @Override + public String getFormatString() + { + return null; + } + + @Override + public int intermediateComputeSizeBytes() + { + return 10 * 1024 * 1024; + } + + @Override + public int getNumMergeBuffers() + { + return 4; + } + + @Override + public int getNumThreads() + { + return 2; + } + }; + private GroupByQueryRunnerFactory factory; private Closer resourceCloser; - @Before + @BeforeEach public void setup() { final GroupByQueryConfig config = new GroupByQueryConfig(); this.resourceCloser = Closer.create(); - this.factory = GroupByQueryRunnerTest.makeQueryRunnerFactory( - config, - this.resourceCloser.register(TestGroupByBuffers.createDefault()) + final TestGroupByBuffers buffers = this.resourceCloser.register( + new TestGroupByBuffers(PROCESSING_CONFIG.intermediateComputeSizeBytes(), PROCESSING_CONFIG.getNumMergeBuffers()) + ); + this.factory = makeQueryRunnerFactory(TestHelper.makeJsonMapper(), config, buffers); + } + + private static GroupByQueryRunnerFactory makeQueryRunnerFactory( + final ObjectMapper mapper, + final GroupByQueryConfig config, + final TestGroupByBuffers bufferPools + ) + { + if (bufferPools.getBufferSize() != PROCESSING_CONFIG.intermediateComputeSizeBytes()) { + throw new ISE("Provided buffer size does not match configured size"); + } + if (bufferPools.getNumMergeBuffers() != PROCESSING_CONFIG.getNumMergeBuffers()) { + throw new ISE("Provided merge buffer count does not match configured count"); + } + final Supplier configSupplier = Suppliers.ofInstance(config); + final GroupByResourcesReservationPool reservationPool = + new GroupByResourcesReservationPool(bufferPools.getMergePool(), config); + final GroupByStatsProvider statsProvider = new GroupByStatsProvider(); + final GroupingEngine groupingEngine = new GroupingEngine( + PROCESSING_CONFIG, + configSupplier, + reservationPool, + mapper, + mapper, + QueryRunnerTestHelper.NOOP_QUERYWATCHER, + statsProvider + ); + final GroupByQueryQueryToolChest toolChest = new GroupByQueryQueryToolChest( + groupingEngine, + () -> config, + DefaultGroupByQueryMetricsFactory.instance(), + reservationPool, + statsProvider ); + return new GroupByQueryRunnerFactory(groupingEngine, toolChest, bufferPools.getProcessingPool()); } - @After + @AfterEach public void teardown() throws IOException { resourceCloser.close(); @@ -169,7 +240,7 @@ public void testWithName() "visitor_id", null ); - Assert.assertEquals(aggregatorFactory, aggregatorFactory.withName("distinct")); - Assert.assertEquals("newTest", aggregatorFactory.withName("newTest").getName()); + Assertions.assertEquals(aggregatorFactory, aggregatorFactory.withName("distinct")); + Assertions.assertEquals("newTest", aggregatorFactory.withName("newTest").getName()); } } diff --git a/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountTimeseriesQueryTest.java b/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountTimeseriesQueryTest.java index d3edf0827b32..90ebb9595db2 100644 --- a/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountTimeseriesQueryTest.java +++ b/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountTimeseriesQueryTest.java @@ -40,7 +40,7 @@ import org.apache.druid.segment.incremental.OnheapIncrementalIndex; import org.apache.druid.testing.InitializedNullHandlingTest; import org.joda.time.DateTime; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.List; diff --git a/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountTopNQueryTest.java b/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountTopNQueryTest.java index b54c9af1b2f7..fc9e112ed32b 100644 --- a/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountTopNQueryTest.java +++ b/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountTopNQueryTest.java @@ -41,9 +41,9 @@ import org.apache.druid.testing.InitializedNullHandlingTest; import org.apache.druid.timeline.SegmentId; import org.joda.time.DateTime; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.ByteBuffer; import java.util.Arrays; @@ -55,7 +55,7 @@ public class DistinctCountTopNQueryTest extends InitializedNullHandlingTest { private CloseableStupidPool pool; - @Before + @BeforeEach public void setup() { pool = new CloseableStupidPool<>( @@ -71,7 +71,7 @@ public ByteBuffer get() ); } - @After + @AfterEach public void teardown() { pool.close(); From 78d7950662773cb200265847e859a99bfe8ee322 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 7 Aug 2026 21:00:44 +0800 Subject: [PATCH 05/15] fix: keep shared exception assertions compatible with msq tests --- .../apache/druid/msq/test/MSQTestBase.java | 72 +++++++++++++++---- 1 file changed, 60 insertions(+), 12 deletions(-) diff --git a/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java b/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java index f0381b25c233..d2e475a2b50e 100644 --- a/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java +++ b/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java @@ -45,6 +45,7 @@ import org.apache.druid.data.input.impl.LongDimensionSchema; import org.apache.druid.data.input.impl.StringDimensionSchema; import org.apache.druid.discovery.NodeRole; +import org.apache.druid.error.DruidException; import org.apache.druid.frame.Frame; import org.apache.druid.frame.FrameType; import org.apache.druid.frame.channel.FrameChannelSequence; @@ -187,6 +188,7 @@ import org.apache.druid.sql.SqlStatementFactory; import org.apache.druid.sql.SqlToolbox; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; +import org.apache.druid.sql.calcite.DruidExceptionAssertions; import org.apache.druid.sql.calcite.SqlTestFrameworkConfig; import org.apache.druid.sql.calcite.TempDirProducer; import org.apache.druid.sql.calcite.external.ExternalDataSource; @@ -283,6 +285,18 @@ @SqlTestFrameworkConfig.ComponentSupplier(MSQBaseComponentSupplier.class) public class MSQTestBase extends BaseCalciteQueryTest { + private static void assertDruidException( + final DruidExceptionAssertions expectedAssertions, + final Throwable actual + ) + { + if (actual instanceof DruidException) { + expectedAssertions.assertMatches((DruidException) actual); + } else { + Assert.fail("Expected DruidException but got " + actual); + } + } + public static final Map DEFAULT_MSQ_CONTEXT = ImmutableMap.builder() .put(QueryContexts.CTX_SQL_QUERY_ID, "test-query") @@ -1004,8 +1018,10 @@ public abstract class MSQTester> protected List expectedResultRows = null; protected LookupLoadingSpec expectedLookupLoadingSpec = LookupLoadingSpec.NONE; protected Matcher expectedValidationErrorMatcher = null; + protected DruidExceptionAssertions expectedValidationErrorAssertions = null; protected List, String>> adhocReportAssertionAndReasons = new ArrayList<>(); protected Matcher expectedExecutionErrorMatcher = null; + protected DruidExceptionAssertions expectedExecutionErrorAssertions = null; protected MSQFault expectedMSQFault = null; protected Class expectedMSQFaultClass = null; protected MSQSegmentReport expectedSegmentReport = null; @@ -1107,12 +1123,24 @@ public Builder setExpectedValidationErrorMatcher(Matcher expectedVali return asBuilder(); } + public Builder setExpectedValidationErrorMatcher(DruidExceptionAssertions expectedValidationErrorAssertions) + { + this.expectedValidationErrorAssertions = expectedValidationErrorAssertions; + return asBuilder(); + } + public Builder setExpectedExecutionErrorMatcher(Matcher expectedExecutionErrorMatcher) { this.expectedExecutionErrorMatcher = expectedExecutionErrorMatcher; return asBuilder(); } + public Builder setExpectedExecutionErrorMatcher(DruidExceptionAssertions expectedExecutionErrorAssertions) + { + this.expectedExecutionErrorAssertions = expectedExecutionErrorAssertions; + return asBuilder(); + } + public Builder setExpectedMSQFault(MSQFault MSQFault) { this.expectedMSQFault = MSQFault; @@ -1176,7 +1204,10 @@ private Builder asBuilder() public void verifyPlanningErrors() { - Preconditions.checkArgument(expectedValidationErrorMatcher != null, "Validation error matcher cannot be null"); + Preconditions.checkArgument( + expectedValidationErrorMatcher != null || expectedValidationErrorAssertions != null, + "Validation error matcher cannot be null" + ); Preconditions.checkArgument(sql != null, "Sql cannot be null"); readyToRun(); @@ -1185,7 +1216,11 @@ public void verifyPlanningErrors() () -> runMultiStageQuery(sql, queryContext, authenticationResult, dynamicParameters) ); - assertThat(e, expectedValidationErrorMatcher); + if (expectedValidationErrorAssertions != null) { + assertDruidException(expectedValidationErrorAssertions, e); + } else { + assertThat(e, expectedValidationErrorMatcher); + } } protected void verifyMetrics() @@ -1598,7 +1633,10 @@ public void verifyExecutionError() "sql and taskSpec both cannot be provided in the same test" ); Preconditions.checkArgument(sql == null || queryContext != null, "queryContext cannot be null"); - Preconditions.checkArgument(expectedExecutionErrorMatcher != null, "Execution error matcher cannot be null"); + Preconditions.checkArgument( + expectedExecutionErrorMatcher != null || expectedExecutionErrorAssertions != null, + "Execution error matcher cannot be null" + ); readyToRun(); try { String controllerId; @@ -1613,11 +1651,15 @@ public void verifyExecutionError() Assert.fail(StringUtils.format("Query did not throw an exception (sql = [%s])", sql)); } catch (Exception e) { - assertThat( - StringUtils.format("Query error did not match expectations (sql = [%s])", sql), - e, - expectedExecutionErrorMatcher - ); + if (expectedExecutionErrorAssertions != null) { + assertDruidException(expectedExecutionErrorAssertions, e); + } else { + assertThat( + StringUtils.format("Query error did not match expectations (sql = [%s])", sql), + e, + expectedExecutionErrorMatcher + ); + } } verifyMetrics(); } @@ -1753,10 +1795,14 @@ public Pair, List resultSignatureFromRowSignat } } - From 597e19f4a039acc9ef1d6d365bf9f8646da82b4d Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 7 Aug 2026 21:53:23 +0800 Subject: [PATCH 06/15] fix: reuse the existing Druid exception matcher --- .../apache/druid/msq/test/MSQTestBase.java | 71 ++--------- .../apache/druid/sql/SqlQueryPlusTest.java | 6 +- .../apache/druid/sql/SqlStatementTest.java | 8 +- .../sql/calcite/BaseCalciteQueryTest.java | 26 ++-- .../sql/calcite/CalciteIngestionDmlTest.java | 3 +- .../sql/calcite/CalciteInsertDmlTest.java | 11 +- .../sql/calcite/CalciteJoinQueryTest.java | 3 +- .../calcite/CalciteNestedDataQueryTest.java | 3 +- .../calcite/CalciteParameterQueryTest.java | 7 +- .../druid/sql/calcite/CalciteQueryTest.java | 3 +- .../sql/calcite/CalciteReplaceDmlTest.java | 5 +- .../sql/calcite/CalciteSelectQueryTest.java | 5 +- .../sql/calcite/DruidExceptionAssertions.java | 114 ------------------ .../parser/DruidSqlParserUtilsTest.java | 20 +-- .../rule/DruidLogicalValuesRuleTest.java | 8 +- .../druid/sql/http/SqlResourceTest.java | 4 +- 16 files changed, 72 insertions(+), 225 deletions(-) delete mode 100644 sql/src/test/java/org/apache/druid/sql/calcite/DruidExceptionAssertions.java diff --git a/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java b/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java index d2e475a2b50e..b70d17a780e4 100644 --- a/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java +++ b/multi-stage-query/src/test/java/org/apache/druid/msq/test/MSQTestBase.java @@ -45,7 +45,6 @@ import org.apache.druid.data.input.impl.LongDimensionSchema; import org.apache.druid.data.input.impl.StringDimensionSchema; import org.apache.druid.discovery.NodeRole; -import org.apache.druid.error.DruidException; import org.apache.druid.frame.Frame; import org.apache.druid.frame.FrameType; import org.apache.druid.frame.channel.FrameChannelSequence; @@ -188,7 +187,6 @@ import org.apache.druid.sql.SqlStatementFactory; import org.apache.druid.sql.SqlToolbox; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; -import org.apache.druid.sql.calcite.DruidExceptionAssertions; import org.apache.druid.sql.calcite.SqlTestFrameworkConfig; import org.apache.druid.sql.calcite.TempDirProducer; import org.apache.druid.sql.calcite.external.ExternalDataSource; @@ -285,18 +283,6 @@ @SqlTestFrameworkConfig.ComponentSupplier(MSQBaseComponentSupplier.class) public class MSQTestBase extends BaseCalciteQueryTest { - private static void assertDruidException( - final DruidExceptionAssertions expectedAssertions, - final Throwable actual - ) - { - if (actual instanceof DruidException) { - expectedAssertions.assertMatches((DruidException) actual); - } else { - Assert.fail("Expected DruidException but got " + actual); - } - } - public static final Map DEFAULT_MSQ_CONTEXT = ImmutableMap.builder() .put(QueryContexts.CTX_SQL_QUERY_ID, "test-query") @@ -1018,10 +1004,8 @@ public abstract class MSQTester> protected List expectedResultRows = null; protected LookupLoadingSpec expectedLookupLoadingSpec = LookupLoadingSpec.NONE; protected Matcher expectedValidationErrorMatcher = null; - protected DruidExceptionAssertions expectedValidationErrorAssertions = null; protected List, String>> adhocReportAssertionAndReasons = new ArrayList<>(); protected Matcher expectedExecutionErrorMatcher = null; - protected DruidExceptionAssertions expectedExecutionErrorAssertions = null; protected MSQFault expectedMSQFault = null; protected Class expectedMSQFaultClass = null; protected MSQSegmentReport expectedSegmentReport = null; @@ -1123,24 +1107,12 @@ public Builder setExpectedValidationErrorMatcher(Matcher expectedVali return asBuilder(); } - public Builder setExpectedValidationErrorMatcher(DruidExceptionAssertions expectedValidationErrorAssertions) - { - this.expectedValidationErrorAssertions = expectedValidationErrorAssertions; - return asBuilder(); - } - public Builder setExpectedExecutionErrorMatcher(Matcher expectedExecutionErrorMatcher) { this.expectedExecutionErrorMatcher = expectedExecutionErrorMatcher; return asBuilder(); } - public Builder setExpectedExecutionErrorMatcher(DruidExceptionAssertions expectedExecutionErrorAssertions) - { - this.expectedExecutionErrorAssertions = expectedExecutionErrorAssertions; - return asBuilder(); - } - public Builder setExpectedMSQFault(MSQFault MSQFault) { this.expectedMSQFault = MSQFault; @@ -1204,10 +1176,7 @@ private Builder asBuilder() public void verifyPlanningErrors() { - Preconditions.checkArgument( - expectedValidationErrorMatcher != null || expectedValidationErrorAssertions != null, - "Validation error matcher cannot be null" - ); + Preconditions.checkArgument(expectedValidationErrorMatcher != null, "Validation error matcher cannot be null"); Preconditions.checkArgument(sql != null, "Sql cannot be null"); readyToRun(); @@ -1216,11 +1185,7 @@ public void verifyPlanningErrors() () -> runMultiStageQuery(sql, queryContext, authenticationResult, dynamicParameters) ); - if (expectedValidationErrorAssertions != null) { - assertDruidException(expectedValidationErrorAssertions, e); - } else { - assertThat(e, expectedValidationErrorMatcher); - } + assertThat(e, expectedValidationErrorMatcher); } protected void verifyMetrics() @@ -1633,10 +1598,7 @@ public void verifyExecutionError() "sql and taskSpec both cannot be provided in the same test" ); Preconditions.checkArgument(sql == null || queryContext != null, "queryContext cannot be null"); - Preconditions.checkArgument( - expectedExecutionErrorMatcher != null || expectedExecutionErrorAssertions != null, - "Execution error matcher cannot be null" - ); + Preconditions.checkArgument(expectedExecutionErrorMatcher != null, "Execution error matcher cannot be null"); readyToRun(); try { String controllerId; @@ -1651,15 +1613,11 @@ public void verifyExecutionError() Assert.fail(StringUtils.format("Query did not throw an exception (sql = [%s])", sql)); } catch (Exception e) { - if (expectedExecutionErrorAssertions != null) { - assertDruidException(expectedExecutionErrorAssertions, e); - } else { - assertThat( - StringUtils.format("Query error did not match expectations (sql = [%s])", sql), - e, - expectedExecutionErrorMatcher - ); - } + assertThat( + StringUtils.format("Query error did not match expectations (sql = [%s])", sql), + e, + expectedExecutionErrorMatcher + ); } verifyMetrics(); } @@ -1795,14 +1753,10 @@ public Pair, List expectedResult public void testQueryThrows( final String sql, - final DruidExceptionAssertions exceptionMatcher + final DruidExceptionMatcher exceptionMatcher ) { testQueryThrows(sql, null, DruidException.class, e -> assertDruidException(e, exceptionMatcher)); @@ -1078,7 +1080,7 @@ public void testQueryThrows( public void testQueryThrows( final String sql, final Class exceptionType, - final DruidExceptionAssertions exceptionMatcher + final DruidExceptionMatcher exceptionMatcher ) { testQueryThrows(sql, null, exceptionType, e -> assertDruidException(e, exceptionMatcher)); @@ -1088,7 +1090,7 @@ public void testQueryThrows( final String sql, final Map queryContext, final Class exceptionType, - final DruidExceptionAssertions exceptionMatcher + final DruidExceptionMatcher exceptionMatcher ) { testQueryThrows(sql, queryContext, exceptionType, e -> assertDruidException(e, exceptionMatcher)); @@ -1137,10 +1139,10 @@ public void testQueryThrows( public static void assertDruidException( final DruidException exception, - final DruidExceptionAssertions exceptionMatcher + final DruidExceptionMatcher exceptionMatcher ) { - exceptionMatcher.assertMatches(exception); + MatcherAssert.assertThat(exception, exceptionMatcher); } public void analyzeResources( 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 ab3684ef9d98..55241090f14e 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 @@ -38,6 +38,7 @@ import org.apache.druid.data.input.impl.InlineInputSource; import org.apache.druid.data.input.impl.SplittableInputSource; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.initialization.DruidModule; import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.StringUtils; @@ -328,7 +329,7 @@ public IngestionDmlTester expectValidationError(Consumer validationEr return this; } - public IngestionDmlTester expectValidationError(DruidExceptionAssertions exceptionMatcher) + public IngestionDmlTester expectValidationError(DruidExceptionMatcher exceptionMatcher) { return expectValidationError(e -> { Assertions.assertInstanceOf(DruidException.class, e); 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 8c2e34d5e4bd..d2bc4f8fe515 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 @@ -27,6 +27,7 @@ import org.apache.druid.data.input.impl.CsvInputFormat; import org.apache.druid.data.input.impl.InlineInputSource; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.granularity.Granularity; @@ -212,7 +213,7 @@ public void testInsertIntoInvalidDataSourceName() testIngestionQuery() .sql("INSERT INTO \"in/valid\" SELECT dim1, dim2 FROM foo PARTITIONED BY ALL TIME") .expectValidationError( - DruidExceptionAssertions.invalidInput().expectMessageIs( + DruidExceptionMatcher.invalidInput().expectMessageIs( "Invalid value for field [table]: Value [in/valid] cannot contain '/'." ) ) @@ -1596,7 +1597,7 @@ public void testErrorWithUnableToConstructColumnSignatureWithExtern() HashMap context = new HashMap<>(DEFAULT_CONTEXT); testIngestionQuery().context(context).sql(sqlString) .expectValidationError( - new DruidExceptionAssertions( + new DruidExceptionMatcher( DruidException.Persona.USER, DruidException.Category.INVALID_INPUT, "invalidInput" @@ -1624,7 +1625,7 @@ public void testErrorWhenBothRowSignatureAndExtendsProvidedToExtern() HashMap context = new HashMap<>(DEFAULT_CONTEXT); testIngestionQuery().context(context).sql(sqlString) .expectValidationError( - new DruidExceptionAssertions( + new DruidExceptionMatcher( DruidException.Persona.USER, DruidException.Category.INVALID_INPUT, "invalidInput" @@ -1651,7 +1652,7 @@ public void testErrorWhenNoneOfRowSignatureAndExtendsProvidedToExtern() HashMap context = new HashMap<>(DEFAULT_CONTEXT); testIngestionQuery().context(context).sql(sqlString) .expectValidationError( - new DruidExceptionAssertions( + new DruidExceptionMatcher( DruidException.Persona.USER, DruidException.Category.INVALID_INPUT, "invalidInput" @@ -1679,7 +1680,7 @@ public void testErrorWhenInputSourceInvalid() HashMap context = new HashMap<>(DEFAULT_CONTEXT); testIngestionQuery().context(context).sql(sqlString) .expectValidationError( - new DruidExceptionAssertions( + new DruidExceptionMatcher( DruidException.Persona.USER, DruidException.Category.INVALID_INPUT, "invalidInput" 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 87f10d8d860e..4e12609cbcc6 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 @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.JodaUtils; @@ -1576,7 +1577,7 @@ public void testTimeColumnAggregationsOnLookups(Map queryContext catch (DruidException e) { assertDruidException( e, - new DruidExceptionAssertions(DruidException.Persona.ADMIN, DruidException.Category.INVALID_INPUT, "general") + new DruidExceptionMatcher(DruidException.Persona.ADMIN, DruidException.Category.INVALID_INPUT, "general") .expectMessageIs( "Query could not be planned. A possible reason is " + "[LATEST and EARLIEST aggregators implicitly depend on the __time column, " 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 408616e861a8..0758656c81fa 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 @@ -32,6 +32,7 @@ import org.apache.druid.data.input.impl.StringDimensionSchema; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.guice.BuiltInTypesModule; import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.granularity.Granularities; @@ -4887,7 +4888,7 @@ public void testGroupByInvalidPath() + "JSON_VALUE(nester, '.array.[1]'), " + "SUM(cnt) " + "FROM druid.nested GROUP BY 1", - DruidExceptionAssertions + DruidExceptionMatcher .invalidInput() .expectMessageIs("JSONPath [.array.[1]] is invalid, it must start with '$'") ); 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 ad227af517a5..48c8322a94fe 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 @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList; import org.apache.calcite.avatica.SqlType; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; @@ -585,7 +586,7 @@ public void testMissingParameter() ); assertDruidException( exception, - DruidExceptionAssertions.invalidSqlInput().expectMessageIs("No value bound for parameter (position [1])") + DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value bound for parameter (position [1])") ); } @@ -605,7 +606,7 @@ public void testPartiallyMissingParameter() ); assertDruidException( exception, - DruidExceptionAssertions.invalidSqlInput().expectMessageIs("No value bound for parameter (position [2])") + DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value bound for parameter (position [2])") ); } @@ -627,7 +628,7 @@ public void testPartiallyMissingParameterInTheMiddle() assertDruidException( exception, - DruidExceptionAssertions.invalidSqlInput().expectMessageIs("No value bound for parameter (position [1])") + DruidExceptionMatcher.invalidSqlInput().expectMessageIs("No value bound for parameter (position [1])") ); } 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 ab9d1ef7f2e0..3c2cff27729d 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 @@ -26,6 +26,7 @@ import org.apache.calcite.rel.RelNode; import org.apache.calcite.runtime.CalciteContextException; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.Intervals; @@ -8539,7 +8540,7 @@ public void testRegexpExtractWithBadRegexPattern() "SELECT DISTINCT\n" + " REGEXP_EXTRACT(dim1, '^(.))', 1)\n" + "FROM foo", - DruidExceptionAssertions.invalidInput().expectMessageContains( + DruidExceptionMatcher.invalidInput().expectMessageContains( "An invalid pattern [^(.))] was provided for the [regexp_extract] function, " + "error: [Unmatched closing ')' near index 3\n^(.))\n ^]" ) 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 75f1e93100ba..fb4e3581dc16 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 @@ -24,6 +24,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.granularity.Granularity; @@ -402,7 +403,7 @@ public void testReplaceIntoInvalidDataSourceName() testIngestionQuery() .sql("REPLACE INTO \"in/valid\" OVERWRITE ALL SELECT dim1, dim2 FROM foo PARTITIONED BY ALL TIME") .expectValidationError( - DruidExceptionAssertions + DruidExceptionMatcher .invalidInput() .expectMessageIs("Invalid value for field [table]: Value [in/valid] cannot contain '/'.") ) @@ -1105,7 +1106,7 @@ public void testReplaceWithSqlOuterLimit() testIngestionQuery() .context(context) .sql("REPLACE INTO dst OVERWRITE ALL SELECT * FROM foo PARTITIONED BY ALL TIME") - .expectValidationError(DruidExceptionAssertions.invalidInput().expectMessageIs( + .expectValidationError(DruidExceptionMatcher.invalidInput().expectMessageIs( "Context parameter [sqlOuterLimit] cannot be provided on operator [REPLACE]" )) .verify(); 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 5c54ccc04c47..59fef5a20a7a 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 @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; @@ -169,7 +170,7 @@ public void testTimeCeilExpressionContainingInvalidPeriod() { testQueryThrows( "SELECT TIME_CEIL(__time, 'PT1Y') FROM foo", - DruidExceptionAssertions.invalidInput().expectMessageContains( + DruidExceptionMatcher.invalidInput().expectMessageContains( "Invalid period['PT1Y'] specified for expression[timestamp_ceil(\"__time\", 'PT1Y', null, 'UTC')]" ) ); @@ -180,7 +181,7 @@ public void testTimeFloorExpressionContainingInvalidPeriod() { testQueryThrows( "SELECT TIME_FLOOR(TIMESTAMPADD(DAY, -1, __time), 'PT1D') FROM foo", - DruidExceptionAssertions.invalidInput().expectMessageContains( + DruidExceptionMatcher.invalidInput().expectMessageContains( "Invalid period['PT1D'] specified for expression[timestamp_floor((\"__time\" + -86400000), 'PT1D', null, 'UTC')]" ) ); diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/DruidExceptionAssertions.java b/sql/src/test/java/org/apache/druid/sql/calcite/DruidExceptionAssertions.java deleted file mode 100644 index c743aded687d..000000000000 --- a/sql/src/test/java/org/apache/druid/sql/calcite/DruidExceptionAssertions.java +++ /dev/null @@ -1,114 +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.sql.calcite; - -import org.apache.druid.error.DruidException; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.function.Executable; - -import javax.annotation.Nullable; - -public class DruidExceptionAssertions -{ - private final DruidException.Persona persona; - private final DruidException.Category category; - private final String errorCode; - @Nullable - private String expectedMessage; - @Nullable - private String expectedMessagePart; - @Nullable - private String contextKey; - @Nullable - private String contextValue; - - public DruidExceptionAssertions( - final DruidException.Persona persona, - final DruidException.Category category, - final String errorCode - ) - { - this.persona = persona; - this.category = category; - this.errorCode = errorCode; - } - - public static DruidExceptionAssertions invalidInput() - { - return new DruidExceptionAssertions( - DruidException.Persona.USER, - DruidException.Category.INVALID_INPUT, - "invalidInput" - ); - } - - public static DruidExceptionAssertions invalidSqlInput() - { - return invalidInput().expectContext("sourceType", "sql"); - } - - public DruidExceptionAssertions expectMessageIs(final String message) - { - expectedMessage = message; - return this; - } - - public DruidExceptionAssertions expectMessageContains(final String messagePart) - { - expectedMessagePart = messagePart; - return this; - } - - public DruidExceptionAssertions expectContext(final String key, final String value) - { - contextKey = key; - contextValue = value; - return this; - } - - public void assertThrowsAndMatches(final Executable executable) - { - assertMatches(Assertions.assertThrows(DruidException.class, executable)); - } - - public void assertMatches(final DruidException exception) - { - Assertions.assertAll( - () -> Assertions.assertEquals(persona, exception.getTargetPersona()), - () -> Assertions.assertEquals(category, exception.getCategory()), - () -> Assertions.assertEquals(errorCode, exception.getErrorCode()), - () -> { - if (expectedMessage != null) { - Assertions.assertEquals(expectedMessage, exception.getMessage()); - } - }, - () -> { - if (expectedMessagePart != null) { - Assertions.assertTrue(exception.getMessage().contains(expectedMessagePart), exception.getMessage()); - } - }, - () -> { - if (contextKey != null) { - Assertions.assertEquals(contextValue, exception.getContext().get(contextKey)); - } - } - ); - } -} 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 2d44e471a3ad..c3f3f839168b 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 @@ -36,11 +36,11 @@ import org.apache.calcite.sql.parser.SqlParserPos; import org.apache.calcite.sql.type.SqlTypeName; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.granularity.Granularity; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; -import org.apache.druid.sql.calcite.DruidExceptionAssertions; import org.apache.druid.sql.calcite.expression.TimeUnits; import org.apache.druid.sql.calcite.expression.builtin.TimeFloorOperatorConversion; import org.apache.druid.sql.calcite.planner.Calcites; @@ -313,7 +313,7 @@ public void testClusteredByColumnsWithDescThrowsException() ); clusteredByArgs.add(sqlBasicCall); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs("Invalid CLUSTERED BY clause [`DIM4` DESC]: cannot sort in descending order.") .assertThrowsAndMatches(() -> DruidSqlParserUtils.validateClusteredByColumns(clusteredByArgs)); @@ -331,7 +331,7 @@ public void testClusteredByColumnsWithNegativeOrdinalThrowsException() clusteredByArgs.add(new SqlIdentifier("3", SqlParserPos.ZERO)); clusteredByArgs.add(SqlLiteral.createExactNumeric("-10", SqlParserPos.ZERO)); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs("Ordinal [-10] specified in the CLUSTERED BY clause is invalid. It must be a positive integer.") .assertThrowsAndMatches(() -> DruidSqlParserUtils.validateClusteredByColumns(clusteredByArgs)); @@ -351,7 +351,7 @@ public void testConvertSqlNodeToGranularityWithIncorrectFunctionCall() args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); args.add(new SqlIntervalQualifier(TimeUnit.DAY, null, SqlParserPos.ZERO)); final SqlNode sqlNode = SqlStdOperatorTable.CEIL.createCall(args); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs( "Invalid operator[CEIL] specified. PARTITIONED BY clause only supports FLOOR(__time TO )" @@ -369,7 +369,7 @@ public void testConvertSqlNodeToGranularityWithIncorrectNumberOfArguments() final SqlNodeList args = new SqlNodeList(SqlParserPos.ZERO); args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); final SqlNode sqlNode = SqlStdOperatorTable.FLOOR.createCall(args); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs( "FLOOR in PARTITIONED BY clause must have 2 arguments, but only [1] provided." @@ -387,7 +387,7 @@ public void testConvertSqlNodeToGranularityWithWrongIdentifierInFloorFunction() args.add(new SqlIdentifier("timestamps", SqlParserPos.ZERO)); args.add(new SqlIntervalQualifier(TimeUnit.DAY, null, SqlParserPos.ZERO)); final SqlNode sqlNode = SqlStdOperatorTable.FLOOR.createCall(args); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs( "Invalid argument[timestamps] provided. The first argument to FLOOR in PARTITIONED BY" @@ -406,7 +406,7 @@ public void testConvertSqlNodeToGranularityWithWrongIdentifierInTimeFloorFunctio args.add(new SqlIdentifier("timestamps", SqlParserPos.ZERO)); args.add(SqlLiteral.createCharString("PT1H", SqlParserPos.ZERO)); final SqlNode sqlNode = TimeFloorOperatorConversion.SQL_FUNCTION.createCall(args); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs( "Invalid argument[timestamps] provided. The first argument to TIME_FLOOR in" @@ -425,7 +425,7 @@ public void testConvertSqlNodeToGranularityWithIncorrectIngestionGranularityInFl args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); args.add(new SqlIntervalQualifier(TimeUnit.ISOYEAR, null, SqlParserPos.ZERO)); final SqlNode sqlNode = SqlStdOperatorTable.FLOOR.createCall(args); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs( "ISOYEAR is not a valid period granularity for ingestion." @@ -443,7 +443,7 @@ public void testConvertSqlNodeToGranularityWithIncorrectIngestionGranularityInTi args.add(new SqlIdentifier("__time", SqlParserPos.ZERO)); args.add(SqlLiteral.createCharString("abc", SqlParserPos.ZERO)); final SqlNode sqlNode = TimeFloorOperatorConversion.SQL_FUNCTION.createCall(args); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs( "granularity['abc'] is an invalid period literal." @@ -614,7 +614,7 @@ public void test_parseTimeStampWithTimeZone_unknownTimestamp_invalid() BaseCalciteQueryTest.assertDruidException( e, - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageContains("Cannot get a timestamp from sql expression") ); 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 6c53cf5ce330..13d9682adfaa 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 @@ -29,8 +29,8 @@ import org.apache.calcite.util.DateString; import org.apache.calcite.util.TimeString; import org.apache.calcite.util.TimestampString; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.java.util.common.DateTimes; -import org.apache.druid.sql.calcite.DruidExceptionAssertions; import org.apache.druid.sql.calcite.planner.DruidTypeSystem; import org.apache.druid.sql.calcite.planner.PlannerContext; import org.apache.druid.testing.InitializedNullHandlingTest; @@ -165,7 +165,7 @@ public void testGetValueFromTimestampWithLocalTimeZoneLiteral() new TimestampString("2021-04-01 16:54:31"), 0 ); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs( "Cannot handle literal [2021-04-01 16:54:31:TIMESTAMP_WITH_LOCAL_TIME_ZONE(0)] " @@ -178,7 +178,7 @@ public void testGetValueFromTimestampWithLocalTimeZoneLiteral() public void testGetValueFromTimeLiteral() { RexLiteral literal = REX_BUILDER.makeTimeLiteral(new TimeString("16:54:31"), 0); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs("Cannot handle literal [16:54:31] of unsupported type [TIME].") .assertThrowsAndMatches(() -> DruidLogicalValuesRule.getValueFromLiteral(literal, DEFAULT_CONTEXT)); @@ -188,7 +188,7 @@ public void testGetValueFromTimeLiteral() public void testGetValueFromTimeWithLocalTimeZoneLiteral() { RexLiteral literal = REX_BUILDER.makeTimeWithLocalTimeZoneLiteral(new TimeString("16:54:31"), 0); - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs( "Cannot handle literal [16:54:31:TIME_WITH_LOCAL_TIME_ZONE(0)] " 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 e54ddc89a9c8..aa148dd486db 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 @@ -35,6 +35,7 @@ import org.apache.druid.common.exception.ErrorResponseTransformStrategy; import org.apache.druid.common.guava.SettableSupplier; import org.apache.druid.error.DruidException; +import org.apache.druid.error.DruidExceptionMatcher; import org.apache.druid.error.ErrorResponse; import org.apache.druid.error.QueryExceptionCompat; import org.apache.druid.jackson.DefaultObjectMapper; @@ -90,7 +91,6 @@ import org.apache.druid.sql.SqlStatementFactory; import org.apache.druid.sql.SqlToolbox; import org.apache.druid.sql.calcite.BaseCalciteQueryTest; -import org.apache.druid.sql.calcite.DruidExceptionAssertions; import org.apache.druid.sql.calcite.parser.DruidSqlInsert; import org.apache.druid.sql.calcite.planner.CalciteRulesManager; import org.apache.druid.sql.calcite.planner.CatalogResolver; @@ -1780,7 +1780,7 @@ public void testAssertionErrorThrowsErrorWithFilterResponse() throws Exception BaseCalciteQueryTest.assertDruidException( exception.getUnderlyingException(), - DruidExceptionAssertions + DruidExceptionMatcher .invalidSqlInput() .expectMessageIs("Calcite assertion violated: [not a literal: assertion_error()]") ); From 6faafbaadecc96fed87205ccd648ce06f8d8cfbd Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 7 Aug 2026 22:03:27 +0800 Subject: [PATCH 07/15] fix: use Druid file utility in spectator test --- .../histogram/SpectatorHistogramAggregatorTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java index 92c8a8a47991..5ddaae6f4ecb 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java @@ -32,6 +32,7 @@ import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.java.util.common.FileUtils; import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; @@ -913,9 +914,7 @@ private static File newFolder(File root, String... subDirs) throws IOException { final String subFolder = String.join("/", subDirs); final File result = new File(root, subFolder); - if (!result.mkdirs()) { - throw new IOException("Couldn't create folders " + root); - } + FileUtils.mkdirp(result); return result; } From 8dceae231d0065160ba114b6c9ca02207c58acb2 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 7 Aug 2026 22:43:50 +0800 Subject: [PATCH 08/15] fix: restore contrib test runtime dependencies --- extensions-contrib/compressed-bigdecimal/pom.xml | 5 +++++ extensions-contrib/druid-exact-count-bitmap/pom.xml | 5 +++++ extensions-contrib/grpc-query/pom.xml | 5 +++++ extensions-contrib/spectator-histogram/pom.xml | 5 +++++ extensions-contrib/tdigestsketch/pom.xml | 5 +++++ .../src/test/java/org/apache/druid/segment/TestHelper.java | 2 +- .../org/apache/druid/sql/calcite/BaseCalciteQueryTest.java | 4 ++-- 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/extensions-contrib/compressed-bigdecimal/pom.xml b/extensions-contrib/compressed-bigdecimal/pom.xml index 417bd0ccde3e..19d11bec822b 100644 --- a/extensions-contrib/compressed-bigdecimal/pom.xml +++ b/extensions-contrib/compressed-bigdecimal/pom.xml @@ -53,6 +53,11 @@ junit-jupiter-engine test + + org.hamcrest + hamcrest + test + org.apache.druid druid-processing diff --git a/extensions-contrib/druid-exact-count-bitmap/pom.xml b/extensions-contrib/druid-exact-count-bitmap/pom.xml index e137a0341962..36c4c7e172cf 100644 --- a/extensions-contrib/druid-exact-count-bitmap/pom.xml +++ b/extensions-contrib/druid-exact-count-bitmap/pom.xml @@ -110,6 +110,11 @@ junit-jupiter-engine test + + org.hamcrest + hamcrest + test + org.easymock easymock diff --git a/extensions-contrib/grpc-query/pom.xml b/extensions-contrib/grpc-query/pom.xml index 6a2f70039e29..2ea3e43e0a15 100644 --- a/extensions-contrib/grpc-query/pom.xml +++ b/extensions-contrib/grpc-query/pom.xml @@ -73,6 +73,11 @@ junit-jupiter-engine test + + org.hamcrest + hamcrest + test + org.apache.druid druid-server diff --git a/extensions-contrib/spectator-histogram/pom.xml b/extensions-contrib/spectator-histogram/pom.xml index 374885156bde..c42b26b723a2 100644 --- a/extensions-contrib/spectator-histogram/pom.xml +++ b/extensions-contrib/spectator-histogram/pom.xml @@ -50,6 +50,11 @@ junit-jupiter-engine test + + org.hamcrest + hamcrest + test + com.netflix.spectator spectator-api diff --git a/extensions-contrib/tdigestsketch/pom.xml b/extensions-contrib/tdigestsketch/pom.xml index 56fafc4e8ada..770c7a1dfa85 100644 --- a/extensions-contrib/tdigestsketch/pom.xml +++ b/extensions-contrib/tdigestsketch/pom.xml @@ -48,6 +48,11 @@ junit-jupiter-engine test + + org.hamcrest + hamcrest + test + com.tdunning t-digest diff --git a/processing/src/test/java/org/apache/druid/segment/TestHelper.java b/processing/src/test/java/org/apache/druid/segment/TestHelper.java index f846db3c98d3..6b3ef27f8548 100644 --- a/processing/src/test/java/org/apache/druid/segment/TestHelper.java +++ b/processing/src/test/java/org/apache/druid/segment/TestHelper.java @@ -442,7 +442,7 @@ public static void assertRow(String msg, ResultRow expected, ResultRow actual) if (expectedValue != null && expectedValue.getClass().isArray()) { // spilled results will materialize into lists, coerce them back to arrays if we expected arrays if (actualValue instanceof List) { - Assertions.assertEquals( + Assertions.assertArrayEquals( (Object[]) expectedValue, (Object[]) ExprEval.coerceListToArray((List) actualValue, true).rhs, message 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 78220e39e928..a1d3f58e8b0e 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 @@ -96,7 +96,6 @@ import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.PlannerFixture; import org.apache.druid.sql.http.SqlParameter; -import org.hamcrest.MatcherAssert; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Interval; @@ -122,6 +121,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assumptions.assumeFalse; @@ -1142,7 +1142,7 @@ public static void assertDruidException( final DruidExceptionMatcher exceptionMatcher ) { - MatcherAssert.assertThat(exception, exceptionMatcher); + assertThat(exception, exceptionMatcher); } public void analyzeResources( From 77413749cb444a8a06961833ae8bae869c8c3a89 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Fri, 7 Aug 2026 23:01:26 +0800 Subject: [PATCH 09/15] fix: address advanced security test findings --- ...sedBigDecimalMaxAggregatorGroupByTest.java | 1 + ...sedBigDecimalMinAggregatorGroupByTest.java | 1 + ...sedBigDecimalSumAggregatorGroupByTest.java | 1 + .../parser/DruidSqlParserUtilsTest.java | 24 ++++++++++++++----- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java index 47bac7d0bd3e..2f7cdf6ea597 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java @@ -34,6 +34,7 @@ public class CompressedBigDecimalMaxAggregatorGroupByTest extends CompressedBigDecimalAggregatorGroupByTestBase { + @Override @ParameterizedTest @MethodSource("constructorFeeder") public void testIngestAndGroupByAllQuery( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java index daad3f7f82c9..1b6e1b3f565c 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java @@ -34,6 +34,7 @@ public class CompressedBigDecimalMinAggregatorGroupByTest extends CompressedBigDecimalAggregatorGroupByTestBase { + @Override @ParameterizedTest @MethodSource("constructorFeeder") public void testIngestAndGroupByAllQuery( diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java index 2a3efbaa803b..83dee90a2492 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java @@ -34,6 +34,7 @@ public class CompressedBigDecimalSumAggregatorGroupByTest extends CompressedBigDecimalAggregatorGroupByTestBase { + @Override @ParameterizedTest @MethodSource("constructorFeeder") public void testIngestAndGroupByAllQuery( 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 c3f3f839168b..a8686e6d981d 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 @@ -105,6 +105,20 @@ public static Iterable constructorFeeder() ); } + public static Iterable periodConstructorFeeder() + { + return ImmutableList.of( + new Object[]{TimeUnits.toPeriod(TimeUnitRange.SECOND), Granularities.SECOND}, + new Object[]{TimeUnits.toPeriod(TimeUnitRange.MINUTE), Granularities.MINUTE}, + new Object[]{TimeUnits.toPeriod(TimeUnitRange.HOUR), Granularities.HOUR}, + new Object[]{TimeUnits.toPeriod(TimeUnitRange.DAY), Granularities.DAY}, + new Object[]{TimeUnits.toPeriod(TimeUnitRange.WEEK), Granularities.WEEK}, + new Object[]{TimeUnits.toPeriod(TimeUnitRange.MONTH), Granularities.MONTH}, + new Object[]{TimeUnits.toPeriod(TimeUnitRange.QUARTER), Granularities.QUARTER}, + new Object[]{TimeUnits.toPeriod(TimeUnitRange.YEAR), Granularities.YEAR} + ); + } + @ParameterizedTest(name = "{1}") @MethodSource("constructorFeeder") public void testGetGranularityFromFloor(TimeUnit timeUnit, Period period, Granularity expectedGranularity) @@ -137,10 +151,9 @@ public void testConvertSqlNodeToGranularityAsLiteral( /** * Tests clause like "PARTITIONED BY PT1D" */ - @ParameterizedTest(name = "{1}") - @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + @MethodSource("periodConstructorFeeder") public void testConvertSqlNodeToPeriodFormGranularityAsIdentifier( - TimeUnit timeUnit, Period period, Granularity expectedGranularity ) @@ -153,10 +166,9 @@ public void testConvertSqlNodeToPeriodFormGranularityAsIdentifier( /** * Tests clause like "PARTITIONED BY 'PT1D'" */ - @ParameterizedTest(name = "{1}") - @MethodSource("constructorFeeder") + @ParameterizedTest(name = "{0}") + @MethodSource("periodConstructorFeeder") public void testConvertSqlNodeToPeriodFormGranularityAsLiteral( - TimeUnit timeUnit, Period period, Granularity expectedGranularity ) From 37c772bd3628ddc3900e54d974b55af478ed7fa8 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Sat, 8 Aug 2026 00:43:51 +0800 Subject: [PATCH 10/15] fix: preserve restricted join failure details --- .../org/apache/druid/sql/calcite/CalciteJoinQueryTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 4e12609cbcc6..0c21e6a90a6a 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 @@ -5176,7 +5176,8 @@ public void testJoinOnRestrictedBroadcast(Map queryContext) Assertions.assertTrue( e.getMessage().contains( "Restricted data source [GlobalTableDataSource{name='restrictedBroadcastDatasource_m1_is_6'}] with policy [RowFilterPolicy{rowFilter=m1 = 6 (LONG)}] is not supported" - ) + ), + e.getMessage() ); } From cb0f0df66e1e7912707ee3d35e62983df17eb7b2 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Sat, 8 Aug 2026 15:54:01 +0800 Subject: [PATCH 11/15] test: use parameterized classes for shared contrib tests --- ...edBigDecimalAggregatorGroupByTestBase.java | 38 ++++-- ...sedBigDecimalMaxAggregatorGroupByTest.java | 13 +- ...sedBigDecimalMinAggregatorGroupByTest.java | 13 +- ...sedBigDecimalSumAggregatorGroupByTest.java | 13 +- .../ddsketch/DDSketchAggregatorTest.java | 33 +++-- .../MomentsSketchAggregatorTest.java | 27 ++-- .../SpectatorHistogramAggregatorTest.java | 123 +++++++----------- .../TDigestSketchAggregatorTest.java | 51 ++++---- .../TimestampMinMaxAggregatorTest.java | 50 +++---- 9 files changed, 178 insertions(+), 183 deletions(-) diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java index 2e97675010e0..a37195375992 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java @@ -33,6 +33,8 @@ import org.joda.time.DateTimeZone; import org.junit.jupiter.api.Assertions; 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; @@ -44,9 +46,34 @@ public abstract class CompressedBigDecimalAggregatorGroupByTestBase { + private final GroupByQueryConfig config; + private final CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig; + private AggregationTestHelper helper; + @TempDir public File tempFolder; + protected CompressedBigDecimalAggregatorGroupByTestBase( + GroupByQueryConfig config, + CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig + ) + { + this.config = config; + this.cbdGroupByQueryConfig = cbdGroupByQueryConfig; + } + + @BeforeEach + public void setup() + { + final CompressedBigDecimalModule module = new CompressedBigDecimalModule(); + CompressedBigDecimalModule.registerSerde(); + helper = AggregationTestHelper.createGroupByQueryAggregationTestHelperWithTempDir( + module.getJacksonModules(), + config, + tempFolder + ); + } + /** * Default setup of UTC timezone. @@ -125,16 +152,9 @@ public String toString() * @throws IOException IOException * @throws Exception Exception */ - protected void testIngestAndGroupByAllQuery( - GroupByQueryConfig config, - CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig - ) throws Exception + @Test + public void testIngestAndGroupByAllQuery() throws Exception { - final CompressedBigDecimalModule module = new CompressedBigDecimalModule(); - CompressedBigDecimalModule.registerSerde(); - final AggregationTestHelper helper = AggregationTestHelper.createGroupByQueryAggregationTestHelperWithTempDir( - module.getJacksonModules(), config, tempFolder - ); Sequence seq = helper.createIndexAndRunQueryOnSegment( this.getClass().getResourceAsStream("/" + "bd_test_data.csv"), CompressedBigDecimalAggregatorTimeseriesTestBase.SCHEMA, diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java index 2f7cdf6ea597..32f05583c233 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java @@ -24,7 +24,7 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; import java.util.ArrayList; @@ -32,17 +32,16 @@ import java.util.List; +@ParameterizedClass(name = "{0}") +@MethodSource("constructorFeeder") public class CompressedBigDecimalMaxAggregatorGroupByTest extends CompressedBigDecimalAggregatorGroupByTestBase { - @Override - @ParameterizedTest - @MethodSource("constructorFeeder") - public void testIngestAndGroupByAllQuery( + public CompressedBigDecimalMaxAggregatorGroupByTest( GroupByQueryConfig config, CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig - ) throws Exception + ) { - super.testIngestAndGroupByAllQuery(config, cbdGroupByQueryConfig); + super(config, cbdGroupByQueryConfig); } /** diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java index 1b6e1b3f565c..039bf4cfc4cc 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java @@ -24,7 +24,7 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; import java.util.ArrayList; @@ -32,17 +32,16 @@ import java.util.List; +@ParameterizedClass(name = "{0}") +@MethodSource("constructorFeeder") public class CompressedBigDecimalMinAggregatorGroupByTest extends CompressedBigDecimalAggregatorGroupByTestBase { - @Override - @ParameterizedTest - @MethodSource("constructorFeeder") - public void testIngestAndGroupByAllQuery( + public CompressedBigDecimalMinAggregatorGroupByTest( GroupByQueryConfig config, CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig - ) throws Exception + ) { - super.testIngestAndGroupByAllQuery(config, cbdGroupByQueryConfig); + super(config, cbdGroupByQueryConfig); } /** diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java index 83dee90a2492..ebde7007a8e1 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java @@ -24,7 +24,7 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; import java.util.ArrayList; @@ -32,17 +32,16 @@ import java.util.List; +@ParameterizedClass(name = "{0}") +@MethodSource("constructorFeeder") public class CompressedBigDecimalSumAggregatorGroupByTest extends CompressedBigDecimalAggregatorGroupByTestBase { - @Override - @ParameterizedTest - @MethodSource("constructorFeeder") - public void testIngestAndGroupByAllQuery( + public CompressedBigDecimalSumAggregatorGroupByTest( GroupByQueryConfig config, CompressedBigDecimalGroupByQueryConfig cbdGroupByQueryConfig - ) throws Exception + ) { - super.testIngestAndGroupByAllQuery(config, cbdGroupByQueryConfig); + super(config, cbdGroupByQueryConfig); } /** diff --git a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java index 009f9ffcbad8..26f7a7998353 100644 --- a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java +++ b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java @@ -39,8 +39,10 @@ import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.testing.InitializedNullHandlingTest; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; import java.io.File; @@ -49,14 +51,23 @@ import java.util.Collections; import java.util.List; +@ParameterizedClass(name = "{0}") +@MethodSource("constructorFeeder") public class DDSketchAggregatorTest extends InitializedNullHandlingTest { + private final GroupByQueryConfig config; private AggregationTestHelper helper; @TempDir public File tempFolder; - public void initDDSketchAggregatorTest(final GroupByQueryConfig config) + public DDSketchAggregatorTest(final GroupByQueryConfig config) + { + this.config = config; + } + + @BeforeEach + public void initDDSketchAggregatorTest() { DDSketchModule module = new DDSketchModule(); DDSketchModule.registerSerde(); @@ -118,11 +129,9 @@ public static Collection constructorFeeder() } // this is to test Json properties and equals - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void serializeDeserializeFactoryWithFieldName(final GroupByQueryConfig config) throws Exception + @Test + public void serializeDeserializeFactoryWithFieldName() throws Exception { - initDDSketchAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); new DDSketchModule().getJacksonModules().forEach(objectMapper::registerModule); DDSketchAggregatorFactory factory = new DDSketchAggregatorFactory("name", "fieldName", 0.01, 1000); @@ -135,11 +144,9 @@ public void serializeDeserializeFactoryWithFieldName(final GroupByQueryConfig co Assertions.assertEquals(factory, other); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void buildingSketchesAtIngestionTime(final GroupByQueryConfig config) throws Exception + @Test + public void buildingSketchesAtIngestionTime() throws Exception { - initDDSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -186,11 +193,9 @@ public void buildingSketchesAtIngestionTime(final GroupByQueryConfig config) thr Assertions.assertEquals(1, quantiles[2], 0.05); // max value } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void buildingSketchesAtQueryTime(final GroupByQueryConfig config) throws Exception + @Test + public void buildingSketchesAtQueryTime() throws Exception { - initDDSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( diff --git a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java index 520018512a82..978bfedc85b4 100644 --- a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java +++ b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java @@ -42,8 +42,10 @@ import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.testing.InitializedNullHandlingTest; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; import java.io.File; @@ -52,14 +54,23 @@ import java.util.Collections; import java.util.List; +@ParameterizedClass(name = "{0}") +@MethodSource("constructorFeeder") public class MomentsSketchAggregatorTest extends InitializedNullHandlingTest { + private final GroupByQueryConfig config; private AggregationTestHelper helper; @TempDir public File tempFolder; - public void initMomentsSketchAggregatorTest(final GroupByQueryConfig config) + public MomentsSketchAggregatorTest(final GroupByQueryConfig config) + { + this.config = config; + } + + @BeforeEach + public void initMomentsSketchAggregatorTest() { MomentSketchModule.registerSerde(); DruidModule module = new MomentSketchModule(); @@ -120,11 +131,9 @@ public static Collection constructorFeeder() return constructors; } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void buildingSketchesAtIngestionTime(final GroupByQueryConfig config) throws Exception + @Test + public void buildingSketchesAtIngestionTime() throws Exception { - initMomentsSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -229,11 +238,9 @@ public void buildingSketchesAtIngestionTime(final GroupByQueryConfig config) thr } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void buildingSketchesAtQueryTime(final GroupByQueryConfig config) throws Exception + @Test + public void buildingSketchesAtQueryTime() throws Exception { - initMomentsSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java index 5ddaae6f4ecb..ccc97c0268ae 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java @@ -77,8 +77,10 @@ import org.apache.druid.timeline.SegmentId; import org.joda.time.DateTime; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; import java.io.File; @@ -90,6 +92,8 @@ import java.util.List; import java.util.Map; +@ParameterizedClass(name = "{0}") +@MethodSource("constructorFeeder") public class SpectatorHistogramAggregatorTest extends InitializedNullHandlingTest { private static final InputRowSchema INPUT_ROW_SCHEMA = new InputRowSchema( @@ -124,10 +128,17 @@ public class SpectatorHistogramAggregatorTest extends InitializedNullHandlingTes EXPECTED_HISTOGRAMS.put("C", histogram); } + private final GroupByQueryConfig config; private AggregationTestHelper helper; private AggregationTestHelper timeSeriesHelper; - public void initSpectatorHistogramAggregatorTest(final GroupByQueryConfig config) + public SpectatorHistogramAggregatorTest(final GroupByQueryConfig config) + { + this.config = config; + } + + @BeforeEach + public void initSpectatorHistogramAggregatorTest() { SpectatorHistogramModule.registerSerde(); SpectatorHistogramModule module = new SpectatorHistogramModule(); @@ -193,11 +204,9 @@ public static Collection constructorFeeder() } // this is to test Json properties and equals - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void serializeDeserializeFactoryWithFieldName(final GroupByQueryConfig config) throws Exception + @Test + public void serializeDeserializeFactoryWithFieldName() throws Exception { - initSpectatorHistogramAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); new SpectatorHistogramModule().getJacksonModules().forEach(objectMapper::registerModule); SpectatorHistogramAggregatorFactory factory = new SpectatorHistogramAggregatorFactory( @@ -213,11 +222,9 @@ public void serializeDeserializeFactoryWithFieldName(final GroupByQueryConfig co Assertions.assertEquals(factory, other); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testBuildingHistogramQueryTime(final GroupByQueryConfig config) throws Exception + @Test + public void testBuildingHistogramQueryTime() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -240,11 +247,9 @@ public void testBuildingHistogramQueryTime(final GroupByQueryConfig config) thro assertResultsMatch(results, 2, "C"); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testBuildingAndMergingHistograms(final GroupByQueryConfig config) throws Exception + @Test + public void testBuildingAndMergingHistograms() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -272,11 +277,9 @@ public void testBuildingAndMergingHistograms(final GroupByQueryConfig config) th Assertions.assertEquals(expected, results.get(0).get(0)); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testBuildingAndMergingHistogramsTimeseriesQuery(final GroupByQueryConfig config) throws Exception + @Test + public void testBuildingAndMergingHistogramsTimeseriesQuery() throws Exception { - initSpectatorHistogramAggregatorTest(config); TimeseriesQuery tsQuery = Druids.newTimeseriesQueryBuilder() .dataSource("test_datasource") .granularity(Granularities.ALL) @@ -306,11 +309,9 @@ public void testBuildingAndMergingHistogramsTimeseriesQuery(final GroupByQueryCo Assertions.assertEquals(expected, value); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testBuildingAndMergingGroupbyHistograms(final GroupByQueryConfig config) throws Exception + @Test + public void testBuildingAndMergingGroupbyHistograms() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -351,11 +352,9 @@ public void testBuildingAndMergingGroupbyHistograms(final GroupByQueryConfig con Assertions.assertNull(results.get(5).get(1)); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testBuildingAndCountingHistograms(final GroupByQueryConfig config) throws Exception + @Test + public void testBuildingAndCountingHistograms() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -383,11 +382,9 @@ public void testBuildingAndCountingHistograms(final GroupByQueryConfig config) t Assertions.assertEquals(9.0, (Double) results.get(0).get(1), 0.001); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testBuildingAndCountingHistogramsWithNullFilter(final GroupByQueryConfig config) throws Exception + @Test + public void testBuildingAndCountingHistogramsWithNullFilter() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -419,11 +416,9 @@ public void testBuildingAndCountingHistogramsWithNullFilter(final GroupByQueryCo Assertions.assertEquals(9.0, (Double) results.get(0).get(1), 0.001); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testIngestAsHistogramDistribution(final GroupByQueryConfig config) throws Exception + @Test + public void testIngestAsHistogramDistribution() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -451,11 +446,9 @@ public void testIngestAsHistogramDistribution(final GroupByQueryConfig config) t Assertions.assertEquals(expected, results.get(0).get(0)); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testIngestHistogramsTimer(final GroupByQueryConfig config) throws Exception + @Test + public void testIngestHistogramsTimer() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -483,11 +476,9 @@ public void testIngestHistogramsTimer(final GroupByQueryConfig config) throws Ex Assertions.assertEquals(expected, results.get(0).get(0)); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testIngestingPreaggregatedHistograms(final GroupByQueryConfig config) throws Exception + @Test + public void testIngestingPreaggregatedHistograms() throws Exception { - initSpectatorHistogramAggregatorTest(config); TimeseriesQuery preAggTsQuery = Druids.newTimeseriesQueryBuilder() .dataSource("test_datasource") .granularity(Granularities.ALL) @@ -517,11 +508,9 @@ public void testIngestingPreaggregatedHistograms(final GroupByQueryConfig config Assertions.assertEquals(expected, value); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testMetadataQueryTimer(final GroupByQueryConfig config) throws Exception + @Test + public void testMetadataQueryTimer() throws Exception { - initSpectatorHistogramAggregatorTest(config); File segmentDir = newFolder(tempFolder, "junit"); helper.createIndex( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), @@ -565,11 +554,9 @@ public void testMetadataQueryTimer(final GroupByQueryConfig config) throws Excep Assertions.assertEquals("spectatorHistogramTimer", columns.get("histogram").getType()); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testMetadataQueryDistribution(final GroupByQueryConfig config) throws Exception + @Test + public void testMetadataQueryDistribution() throws Exception { - initSpectatorHistogramAggregatorTest(config); File segmentDir = newFolder(tempFolder, "junit"); helper.createIndex( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), @@ -613,11 +600,9 @@ public void testMetadataQueryDistribution(final GroupByQueryConfig config) throw Assertions.assertEquals("spectatorHistogramDistribution", columns.get("histogram").getType()); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testPercentilePostAggregator(final GroupByQueryConfig config) throws Exception + @Test + public void testPercentilePostAggregator() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -669,11 +654,9 @@ public void testPercentilePostAggregator(final GroupByQueryConfig config) throws } } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testBuildingAndCountingHistogramsIncrementalIndex(final GroupByQueryConfig config) throws Exception + @Test + public void testBuildingAndCountingHistogramsIncrementalIndex() throws Exception { - initSpectatorHistogramAggregatorTest(config); List dimensions = Collections.singletonList("d"); int n = 10; DateTime startOfDay = DateTimes.of("2000-01-01"); @@ -729,11 +712,9 @@ public void testBuildingAndCountingHistogramsIncrementalIndex(final GroupByQuery Assertions.assertEquals(n * segments.size(), (Double) results.get(0).get(1), 0.001); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testPercentilePostAggregatorWithNullSketch(final GroupByQueryConfig config) throws Exception + @Test + public void testPercentilePostAggregatorWithNullSketch() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -772,11 +753,9 @@ public void testPercentilePostAggregatorWithNullSketch(final GroupByQueryConfig Assertions.assertNull(results.get(5).get(2), "Row [5] should have null percentile when histogram is null"); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testPercentilesPostAggregatorWithNullSketch(final GroupByQueryConfig config) throws Exception + @Test + public void testPercentilesPostAggregatorWithNullSketch() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -818,11 +797,9 @@ public void testPercentilesPostAggregatorWithNullSketch(final GroupByQueryConfig Assertions.assertNull(results.get(5).get(2), "Row [5] should have null percentiles when histogram is null"); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testCountPostAggregator(final GroupByQueryConfig config) throws Exception + @Test + public void testCountPostAggregator() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, @@ -851,11 +828,9 @@ public void testCountPostAggregator(final GroupByQueryConfig config) throws Exce Assertions.assertEquals(9L, results.get(0).get(1)); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testCountPostAggregatorWithNullSketch(final GroupByQueryConfig config) throws Exception + @Test + public void testCountPostAggregatorWithNullSketch() throws Exception { - initSpectatorHistogramAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("input_data.tsv").getFile()), INPUT_ROW_SCHEMA, diff --git a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java index ac3f454d2b6b..23f250d4a1c8 100644 --- a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java +++ b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java @@ -40,8 +40,10 @@ import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.testing.InitializedNullHandlingTest; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; import java.io.File; @@ -50,14 +52,23 @@ import java.util.Collections; import java.util.List; +@ParameterizedClass(name = "{0}") +@MethodSource("constructorFeeder") public class TDigestSketchAggregatorTest extends InitializedNullHandlingTest { + private final GroupByQueryConfig config; private AggregationTestHelper helper; @TempDir public File tempFolder; - public void initTDigestSketchAggregatorTest(final GroupByQueryConfig config) + public TDigestSketchAggregatorTest(final GroupByQueryConfig config) + { + this.config = config; + } + + @BeforeEach + public void initTDigestSketchAggregatorTest() { TDigestSketchModule.registerSerde(); TDigestSketchModule module = new TDigestSketchModule(); @@ -123,11 +134,9 @@ public static Collection constructorFeeder() } // this is to test Json properties and equals - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void serializeDeserializeFactoryWithFieldName(final GroupByQueryConfig config) throws Exception + @Test + public void serializeDeserializeFactoryWithFieldName() throws Exception { - initTDigestSketchAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); objectMapper.setInjectableValues( new InjectableValues.Std() @@ -144,11 +153,9 @@ public void serializeDeserializeFactoryWithFieldName(final GroupByQueryConfig co Assertions.assertEquals(factory, other); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void deserializedFactoryCompressionCappedAtMaxCompression(final GroupByQueryConfig config) throws Exception + @Test + public void deserializedFactoryCompressionCappedAtMaxCompression() throws Exception { - initTDigestSketchAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); objectMapper.setInjectableValues( new InjectableValues.Std() @@ -165,11 +172,9 @@ public void deserializedFactoryCompressionCappedAtMaxCompression(final GroupByQu Assertions.assertEquals(150, deserialized.getCompression()); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void deserializedFactoryCompressionBelowMaxCompressionUnchanged(final GroupByQueryConfig config) throws Exception + @Test + public void deserializedFactoryCompressionBelowMaxCompressionUnchanged() throws Exception { - initTDigestSketchAggregatorTest(config); ObjectMapper objectMapper = new DefaultObjectMapper(); objectMapper.setInjectableValues( new InjectableValues.Std() @@ -186,11 +191,9 @@ public void deserializedFactoryCompressionBelowMaxCompressionUnchanged(final Gro Assertions.assertEquals(100, deserialized.getCompression()); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void buildingSketchesAtIngestionTime(final GroupByQueryConfig config) throws Exception + @Test + public void buildingSketchesAtIngestionTime() throws Exception { - initTDigestSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -236,11 +239,9 @@ public void buildingSketchesAtIngestionTime(final GroupByQueryConfig config) thr Assertions.assertEquals(1, quantiles[2], 0.05); // max value } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void buildingSketchesAtQueryTime(final GroupByQueryConfig config) throws Exception + @Test + public void buildingSketchesAtQueryTime() throws Exception { - initTDigestSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_build_data.tsv").getFile()), new InputRowSchema( @@ -284,11 +285,9 @@ public void buildingSketchesAtQueryTime(final GroupByQueryConfig config) throws Assertions.assertEquals(1, quantiles[2], 0.05); // max value } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{0}") - public void testIngestingSketches(final GroupByQueryConfig config) throws Exception + @Test + public void testIngestingSketches() throws Exception { - initTDigestSketchAggregatorTest(config); Sequence seq = helper.createIndexAndRunQueryOnSegment( new File(this.getClass().getClassLoader().getResource("doubles_sketch_data.tsv").getFile()), new InputRowSchema( diff --git a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorTest.java b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorTest.java index 2b152fc8dc74..3940c2c9437e 100644 --- a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorTest.java +++ b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampMinMaxAggregatorTest.java @@ -32,7 +32,9 @@ import org.apache.druid.segment.ColumnSelectorFactory; import org.easymock.EasyMock; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; import javax.annotation.Nullable; @@ -40,6 +42,8 @@ import java.sql.Timestamp; import java.util.List; +@ParameterizedClass(name = "{index}: Test for {0}") +@MethodSource("constructorFeeder") public class TimestampMinMaxAggregatorTest { Injector injector; @@ -81,12 +85,17 @@ public Object[] apply(List input) ); } - private String aggType; - private Class aggClass; - private Long initValue; - private Timestamp expected; + private final String aggType; + private final Class aggClass; + private final Long initValue; + private final Timestamp expected; - public void initTimestampMinMaxAggregatorTest(String aggType, Class aggClass, Long initValue, Timestamp expected) + public TimestampMinMaxAggregatorTest( + String aggType, + Class aggClass, + Long initValue, + Timestamp expected + ) { this.aggType = aggType; this.aggClass = aggClass; @@ -94,7 +103,8 @@ public void initTimestampMinMaxAggregatorTest(String aggType, Class aggClass, - Long initValue, - Timestamp expected - ) - throws Exception + @Test + public void testAggregator() throws Exception { - initTimestampMinMaxAggregatorTest(aggType, aggClass, initValue, expected); - setup(); TimestampAggregator aggregator = (TimestampAggregator) aggregatorFactory.factorize(selectorFactory); Assertions.assertEquals(initValue, aggregator.get()); @@ -146,18 +147,9 @@ public void testAggregator( Assertions.assertEquals(expected, new Timestamp(aggregator.getLong())); } - @MethodSource("constructorFeeder") - @ParameterizedTest(name = "{index}: Test for {0}") - public void testBufferAggregator( - String aggType, - Class aggClass, - Long initValue, - Timestamp expected - ) - throws Exception + @Test + public void testBufferAggregator() throws Exception { - initTimestampMinMaxAggregatorTest(aggType, aggClass, initValue, expected); - setup(); TimestampBufferAggregator aggregator = (TimestampBufferAggregator) aggregatorFactory.factorizeBuffered(selectorFactory); ByteBuffer buffer = ByteBuffer.wrap(new byte[Long.BYTES]); From 57ea469cf7f261470b60563220d55c80a62da85b Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Sat, 8 Aug 2026 16:04:27 +0800 Subject: [PATCH 12/15] test: document legacy exception matcher bridge --- .../java/org/apache/druid/sql/calcite/BaseCalciteQueryTest.java | 2 ++ 1 file changed, 2 insertions(+) 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 a1d3f58e8b0e..4fc42ff2a303 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 @@ -1142,6 +1142,8 @@ public static void assertDruidException( final DruidExceptionMatcher exceptionMatcher ) { + // DruidExceptionMatcher is a Hamcrest matcher, so this delegates to Hamcrest's MatcherAssert.assertThat. + // Remove this bridge in the final cleanup after all DruidExceptionMatcher callers are migrated. assertThat(exception, exceptionMatcher); } From 09ca097ea3c00ac945bb86e61d112702fbc15290 Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Sat, 8 Aug 2026 16:23:45 +0800 Subject: [PATCH 13/15] test: reuse shared group by test configs --- ...edBigDecimalAggregatorGroupByTestBase.java | 63 ------------------- ...sedBigDecimalMaxAggregatorGroupByTest.java | 3 +- ...sedBigDecimalMinAggregatorGroupByTest.java | 3 +- ...sedBigDecimalSumAggregatorGroupByTest.java | 3 +- 4 files changed, 6 insertions(+), 66 deletions(-) diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java index a37195375992..740240b655a6 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/CompressedBigDecimalAggregatorGroupByTestBase.java @@ -23,7 +23,6 @@ import org.apache.druid.compressedbigdecimal.CompressedBigDecimalGroupByQueryConfig; import org.apache.druid.compressedbigdecimal.CompressedBigDecimalModule; import org.apache.druid.data.input.MapBasedRow; -import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.aggregation.AggregationTestHelper; @@ -84,68 +83,6 @@ public static void setupClass() System.setProperty("user.timezone", "UTC"); } - public static List testConfigs() - { - return List.of( - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperInitialBuckets() - { - return 4; - } - - @Override - public String toString() - { - return "v2"; - } - }, - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperMaxSize() - { - return 2; - } - - @Override - public HumanReadableBytes getMaxOnDiskStorage() - { - return HumanReadableBytes.valueOf(10L * 1024 * 1024); - } - - @Override - public String toString() - { - return "v2SmallBuffer"; - } - }, - new org.apache.druid.jackson.DefaultObjectMapper().convertValue( - java.util.Map.of( - "maxSelectorDictionarySize", 20, - "maxMergingDictionarySize", 400, - "maxOnDiskStorage", 10L * 1024 * 1024 - ), - GroupByQueryConfig.class - ), - new GroupByQueryConfig() - { - @Override - public int getNumParallelCombineThreads() - { - return 2; - } - - @Override - public String toString() - { - return "v2ParallelCombine"; - } - } - ); - } - /** * ingetion method for all groupBy query. * diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java index 32f05583c233..34a0d04b128d 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/max/CompressedBigDecimalMaxAggregatorGroupByTest.java @@ -24,6 +24,7 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; @@ -68,7 +69,7 @@ public static Collection constructorFeeder() "9999999999.000000000", "9999999999.000000000" ); - for (GroupByQueryConfig config : testConfigs()) { + for (GroupByQueryConfig config : GroupByQueryRunnerTestHelper.testConfigs()) { constructors.add(new Object[]{config, cbdGroupByQueryConfig}); } return constructors; diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java index 039bf4cfc4cc..299699863d1f 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/min/CompressedBigDecimalMinAggregatorGroupByTest.java @@ -24,6 +24,7 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; @@ -68,7 +69,7 @@ public static Collection constructorFeeder() "-1.000000000", "-1.000000000" ); - for (GroupByQueryConfig config : testConfigs()) { + for (GroupByQueryConfig config : GroupByQueryRunnerTestHelper.testConfigs()) { constructors.add(new Object[]{config, cbdGroupByQueryConfig}); } return constructors; diff --git a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java index ebde7007a8e1..d6a7295f84d1 100644 --- a/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java +++ b/extensions-contrib/compressed-bigdecimal/src/test/java/org/apache/druid/compressedbigdecimal/aggregator/sum/CompressedBigDecimalSumAggregatorGroupByTest.java @@ -24,6 +24,7 @@ import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; import org.junit.jupiter.params.ParameterizedClass; import org.junit.jupiter.params.provider.MethodSource; @@ -68,7 +69,7 @@ public static Collection constructorFeeder() "10000000010.000000000", "15000000010.500000000" ); - for (GroupByQueryConfig config : testConfigs()) { + for (GroupByQueryConfig config : GroupByQueryRunnerTestHelper.testConfigs()) { constructors.add(new Object[]{config, cbdGroupByQueryConfig}); } return constructors; From ec4f7217166e9f2df4b4d2d14cfb9aff221e291f Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Sat, 8 Aug 2026 16:34:49 +0800 Subject: [PATCH 14/15] test: reuse shared group by test helpers --- .../ddsketch/DDSketchAggregatorTest.java | 48 +---------- .../DistinctCountGroupByQueryTest.java | 80 ++----------------- .../MomentsSketchAggregatorTest.java | 48 +---------- .../SpectatorHistogramAggregatorTest.java | 48 +---------- .../TDigestSketchAggregatorTest.java | 48 +---------- .../TimestampGroupByAggregationTest.java | 48 +---------- 6 files changed, 15 insertions(+), 305 deletions(-) diff --git a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java index 26f7a7998353..4c1a72a54493 100644 --- a/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java +++ b/extensions-contrib/ddsketch/src/test/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregatorTest.java @@ -26,7 +26,6 @@ import org.apache.druid.data.input.impl.DimensionsSpec; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.jackson.DefaultObjectMapper; -import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; @@ -36,6 +35,7 @@ import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.testing.InitializedNullHandlingTest; import org.junit.jupiter.api.Assertions; @@ -75,54 +75,10 @@ public void initDDSketchAggregatorTest() module.getJacksonModules(), config, tempFolder); } - private static List testConfigs() - { - return List.of( - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperInitialBuckets() - { - return 4; - } - }, - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperMaxSize() - { - return 2; - } - - @Override - public HumanReadableBytes getMaxOnDiskStorage() - { - return HumanReadableBytes.valueOf(10L * 1024 * 1024); - } - }, - new org.apache.druid.jackson.DefaultObjectMapper().convertValue( - java.util.Map.of( - "maxSelectorDictionarySize", 20, - "maxMergingDictionarySize", 400, - "maxOnDiskStorage", 10L * 1024 * 1024 - ), - GroupByQueryConfig.class - ), - new GroupByQueryConfig() - { - @Override - public int getNumParallelCombineThreads() - { - return 2; - } - } - ); - } - public static Collection constructorFeeder() { final List constructors = new ArrayList<>(); - for (GroupByQueryConfig config : testConfigs()) { + for (GroupByQueryConfig config : GroupByQueryRunnerTestHelper.testConfigs()) { constructors.add(new Object[]{config}); } return constructors; diff --git a/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountGroupByQueryTest.java b/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountGroupByQueryTest.java index 02a1e3a8fe55..6165e27c95c0 100644 --- a/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountGroupByQueryTest.java +++ b/extensions-contrib/distinctcount/src/test/java/org/apache/druid/query/aggregation/distinctcount/DistinctCountGroupByQueryTest.java @@ -19,31 +19,21 @@ package org.apache.druid.query.aggregation.distinctcount; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import org.apache.druid.data.input.MapBasedInputRow; import org.apache.druid.java.util.common.DateTimes; -import org.apache.druid.java.util.common.ISE; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.io.Closer; -import org.apache.druid.query.DruidProcessingConfig; import org.apache.druid.query.FluentQueryRunner; import org.apache.druid.query.QueryPlus; import org.apache.druid.query.QueryRunnerTestHelper; import org.apache.druid.query.aggregation.CountAggregatorFactory; import org.apache.druid.query.dimension.DefaultDimensionSpec; -import org.apache.druid.query.groupby.DefaultGroupByQueryMetricsFactory; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; -import org.apache.druid.query.groupby.GroupByQueryQueryToolChest; import org.apache.druid.query.groupby.GroupByQueryRunnerFactory; import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; -import org.apache.druid.query.groupby.GroupByResourcesReservationPool; -import org.apache.druid.query.groupby.GroupByStatsProvider; -import org.apache.druid.query.groupby.GroupingEngine; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.query.groupby.TestGroupByBuffers; import org.apache.druid.query.groupby.orderby.DefaultLimitSpec; @@ -67,33 +57,6 @@ public class DistinctCountGroupByQueryTest extends InitializedNullHandlingTest { - private static final DruidProcessingConfig PROCESSING_CONFIG = new DruidProcessingConfig() - { - @Override - public String getFormatString() - { - return null; - } - - @Override - public int intermediateComputeSizeBytes() - { - return 10 * 1024 * 1024; - } - - @Override - public int getNumMergeBuffers() - { - return 4; - } - - @Override - public int getNumThreads() - { - return 2; - } - }; - private GroupByQueryRunnerFactory factory; private Closer resourceCloser; @@ -102,45 +65,12 @@ public void setup() { final GroupByQueryConfig config = new GroupByQueryConfig(); this.resourceCloser = Closer.create(); - final TestGroupByBuffers buffers = this.resourceCloser.register( - new TestGroupByBuffers(PROCESSING_CONFIG.intermediateComputeSizeBytes(), PROCESSING_CONFIG.getNumMergeBuffers()) - ); - this.factory = makeQueryRunnerFactory(TestHelper.makeJsonMapper(), config, buffers); - } - - private static GroupByQueryRunnerFactory makeQueryRunnerFactory( - final ObjectMapper mapper, - final GroupByQueryConfig config, - final TestGroupByBuffers bufferPools - ) - { - if (bufferPools.getBufferSize() != PROCESSING_CONFIG.intermediateComputeSizeBytes()) { - throw new ISE("Provided buffer size does not match configured size"); - } - if (bufferPools.getNumMergeBuffers() != PROCESSING_CONFIG.getNumMergeBuffers()) { - throw new ISE("Provided merge buffer count does not match configured count"); - } - final Supplier configSupplier = Suppliers.ofInstance(config); - final GroupByResourcesReservationPool reservationPool = - new GroupByResourcesReservationPool(bufferPools.getMergePool(), config); - final GroupByStatsProvider statsProvider = new GroupByStatsProvider(); - final GroupingEngine groupingEngine = new GroupingEngine( - PROCESSING_CONFIG, - configSupplier, - reservationPool, - mapper, - mapper, - QueryRunnerTestHelper.NOOP_QUERYWATCHER, - statsProvider - ); - final GroupByQueryQueryToolChest toolChest = new GroupByQueryQueryToolChest( - groupingEngine, - () -> config, - DefaultGroupByQueryMetricsFactory.instance(), - reservationPool, - statsProvider + final TestGroupByBuffers buffers = this.resourceCloser.register(TestGroupByBuffers.createDefault()); + this.factory = GroupByQueryRunnerTestHelper.makeQueryRunnerFactory( + TestHelper.makeJsonMapper(), + config, + buffers ); - return new GroupByQueryRunnerFactory(groupingEngine, toolChest, bufferPools.getProcessingPool()); } @AfterEach diff --git a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java index 978bfedc85b4..a7a8aa7d7d69 100644 --- a/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java +++ b/extensions-contrib/momentsketch/src/test/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentsSketchAggregatorTest.java @@ -28,7 +28,6 @@ import org.apache.druid.data.input.impl.StringDimensionSchema; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.initialization.DruidModule; -import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; @@ -39,6 +38,7 @@ import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.testing.InitializedNullHandlingTest; import org.junit.jupiter.api.Assertions; @@ -78,54 +78,10 @@ public void initMomentsSketchAggregatorTest() module.getJacksonModules(), config, tempFolder); } - private static List testConfigs() - { - return List.of( - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperInitialBuckets() - { - return 4; - } - }, - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperMaxSize() - { - return 2; - } - - @Override - public HumanReadableBytes getMaxOnDiskStorage() - { - return HumanReadableBytes.valueOf(10L * 1024 * 1024); - } - }, - new org.apache.druid.jackson.DefaultObjectMapper().convertValue( - java.util.Map.of( - "maxSelectorDictionarySize", 20, - "maxMergingDictionarySize", 400, - "maxOnDiskStorage", 10L * 1024 * 1024 - ), - GroupByQueryConfig.class - ), - new GroupByQueryConfig() - { - @Override - public int getNumParallelCombineThreads() - { - return 2; - } - } - ); - } - public static Collection constructorFeeder() { final List constructors = new ArrayList<>(); - for (GroupByQueryConfig config : testConfigs()) { + for (GroupByQueryConfig config : GroupByQueryRunnerTestHelper.testConfigs()) { constructors.add(new Object[]{config}); } return constructors; diff --git a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java index ccc97c0268ae..bbf76451e518 100644 --- a/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java +++ b/extensions-contrib/spectator-histogram/src/test/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregatorTest.java @@ -33,7 +33,6 @@ import org.apache.druid.jackson.DefaultObjectMapper; import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.FileUtils; -import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.Druids; @@ -54,6 +53,7 @@ import org.apache.druid.query.filter.SelectorDimFilter; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.query.metadata.SegmentMetadataQueryConfig; import org.apache.druid.query.metadata.SegmentMetadataQueryQueryToolChest; @@ -150,54 +150,10 @@ public void initSpectatorHistogramAggregatorTest() ); } - private static List testConfigs() - { - return List.of( - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperInitialBuckets() - { - return 4; - } - }, - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperMaxSize() - { - return 2; - } - - @Override - public HumanReadableBytes getMaxOnDiskStorage() - { - return HumanReadableBytes.valueOf(10L * 1024 * 1024); - } - }, - new org.apache.druid.jackson.DefaultObjectMapper().convertValue( - java.util.Map.of( - "maxSelectorDictionarySize", 20, - "maxMergingDictionarySize", 400, - "maxOnDiskStorage", 10L * 1024 * 1024 - ), - GroupByQueryConfig.class - ), - new GroupByQueryConfig() - { - @Override - public int getNumParallelCombineThreads() - { - return 2; - } - } - ); - } - public static Collection constructorFeeder() { final List constructors = new ArrayList<>(); - for (GroupByQueryConfig config : testConfigs()) { + for (GroupByQueryConfig config : GroupByQueryRunnerTestHelper.testConfigs()) { constructors.add(new Object[]{config}); } return constructors; diff --git a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java index 23f250d4a1c8..c00334c61891 100644 --- a/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java +++ b/extensions-contrib/tdigestsketch/src/test/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregatorTest.java @@ -27,7 +27,6 @@ import org.apache.druid.data.input.impl.DimensionsSpec; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.jackson.DefaultObjectMapper; -import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; @@ -37,6 +36,7 @@ import org.apache.druid.query.aggregation.post.FieldAccessPostAggregator; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.testing.InitializedNullHandlingTest; import org.junit.jupiter.api.Assertions; @@ -80,54 +80,10 @@ public void initTDigestSketchAggregatorTest() helper.getObjectMapper().setInjectableValues(currentInjectableValuesStd); } - private static List testConfigs() - { - return List.of( - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperInitialBuckets() - { - return 4; - } - }, - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperMaxSize() - { - return 2; - } - - @Override - public HumanReadableBytes getMaxOnDiskStorage() - { - return HumanReadableBytes.valueOf(10L * 1024 * 1024); - } - }, - new org.apache.druid.jackson.DefaultObjectMapper().convertValue( - java.util.Map.of( - "maxSelectorDictionarySize", 20, - "maxMergingDictionarySize", 400, - "maxOnDiskStorage", 10L * 1024 * 1024 - ), - GroupByQueryConfig.class - ), - new GroupByQueryConfig() - { - @Override - public int getNumParallelCombineThreads() - { - return 2; - } - } - ); - } - public static Collection constructorFeeder() { final List constructors = new ArrayList<>(); - for (GroupByQueryConfig config : testConfigs()) { + for (GroupByQueryConfig config : GroupByQueryRunnerTestHelper.testConfigs()) { constructors.add(new Object[]{config}); } return constructors; diff --git a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java index cc7fae3a9887..45b80c4a9f9f 100644 --- a/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java +++ b/extensions-contrib/time-min-max/src/test/java/org/apache/druid/query/aggregation/TimestampGroupByAggregationTest.java @@ -27,12 +27,12 @@ import org.apache.druid.data.input.impl.DimensionsSpec; import org.apache.druid.data.input.impl.TimestampSpec; import org.apache.druid.java.util.common.DateTimes; -import org.apache.druid.java.util.common.HumanReadableBytes; import org.apache.druid.java.util.common.granularity.Granularities; import org.apache.druid.java.util.common.guava.Sequence; import org.apache.druid.query.dimension.DefaultDimensionSpec; import org.apache.druid.query.groupby.GroupByQuery; import org.apache.druid.query.groupby.GroupByQueryConfig; +import org.apache.druid.query.groupby.GroupByQueryRunnerTestHelper; import org.apache.druid.query.groupby.ResultRow; import org.apache.druid.segment.ColumnSelectorFactory; import org.easymock.EasyMock; @@ -73,7 +73,7 @@ public static Iterable constructorFeeder() ); for (final List partialConstructor : partialConstructors) { - for (GroupByQueryConfig config : testConfigs()) { + for (GroupByQueryConfig config : GroupByQueryRunnerTestHelper.testConfigs()) { final List constructor = Lists.newArrayList(partialConstructor); constructor.add(config); constructors.add(constructor.toArray()); @@ -83,50 +83,6 @@ public static Iterable constructorFeeder() return constructors; } - private static List testConfigs() - { - return List.of( - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperInitialBuckets() - { - return 4; - } - }, - new GroupByQueryConfig() - { - @Override - public int getBufferGrouperMaxSize() - { - return 2; - } - - @Override - public HumanReadableBytes getMaxOnDiskStorage() - { - return HumanReadableBytes.valueOf(10L * 1024 * 1024); - } - }, - new org.apache.druid.jackson.DefaultObjectMapper().convertValue( - java.util.Map.of( - "maxSelectorDictionarySize", 20, - "maxMergingDictionarySize", 400, - "maxOnDiskStorage", 10L * 1024 * 1024 - ), - GroupByQueryConfig.class - ), - new GroupByQueryConfig() - { - @Override - public int getNumParallelCombineThreads() - { - return 2; - } - } - ); - } - private String aggType; private String aggField; private String groupByField; From 27ee96d1af51ec16633a39bdb0a9340911aaa05f Mon Sep 17 00:00:00 2001 From: Frank Chen Date: Sat, 8 Aug 2026 16:48:49 +0800 Subject: [PATCH 15/15] test: rename SQL query stack helper --- .../java/org/apache/druid/sql/SqlStatementTest.java | 4 ++-- .../druid/sql/calcite/SqlTestFrameworkConfig.java | 4 ++-- .../apache/druid/sql/calcite/util/CalciteTests.java | 2 +- .../druid/sql/calcite/util/QueryFrameworkUtils.java | 4 ++-- ...estQueryStack.java => QueryStackTestHelper.java} | 13 +++++++++++-- .../druid/sql/calcite/util/SqlTestFramework.java | 8 ++++---- .../druid/sql/calcite/util/TestDataBuilder.java | 4 ++-- .../org/apache/druid/sql/http/SqlResourceTest.java | 4 ++-- 8 files changed, 26 insertions(+), 17 deletions(-) rename sql/src/test/java/org/apache/druid/sql/calcite/util/{SqlTestQueryStack.java => QueryStackTestHelper.java} (96%) 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 f386def1e5a8..3d0c30a0fe04 100644 --- a/sql/src/test/java/org/apache/druid/sql/SqlStatementTest.java +++ b/sql/src/test/java/org/apache/druid/sql/SqlStatementTest.java @@ -63,7 +63,7 @@ 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.SqlTestQueryStack; +import org.apache.druid.sql.calcite.util.QueryStackTestHelper; import org.apache.druid.sql.hook.DruidHookDispatcher; import org.easymock.EasyMock; import org.junit.jupiter.api.AfterAll; @@ -108,7 +108,7 @@ public class SqlStatementTest public static void setUpClass() { resourceCloser = Closer.create(); - conglomerate = SqlTestQueryStack.createQueryRunnerFactoryConglomerate(resourceCloser); + conglomerate = QueryStackTestHelper.createQueryRunnerFactoryConglomerate(resourceCloser); final QueryScheduler scheduler = new QueryScheduler( 5, 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 5fac056c2faa..ee94501f7397 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 @@ -32,10 +32,10 @@ import org.apache.druid.java.util.common.StringUtils; import org.apache.druid.sql.calcite.util.CacheTestHelperModule.ResultCacheMode; import org.apache.druid.sql.calcite.util.FakeIndexTaskUtil; +import org.apache.druid.sql.calcite.util.QueryStackTestHelper; import org.apache.druid.sql.calcite.util.SqlTestFramework; import org.apache.druid.sql.calcite.util.SqlTestFramework.QueryComponentSupplier; import org.apache.druid.sql.calcite.util.SqlTestFramework.StandardComponentSupplier; -import org.apache.druid.sql.calcite.util.SqlTestQueryStack; import org.apache.http.NameValuePair; import org.apache.http.client.utils.URIBuilder; import org.apache.http.client.utils.URLEncodedUtils; @@ -95,7 +95,7 @@ public class SqlTestFrameworkConfig { @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) - @NumMergeBuffers(SqlTestQueryStack.DEFAULT_NUM_MERGE_BUFFERS) + @NumMergeBuffers(QueryStackTestHelper.DEFAULT_NUM_MERGE_BUFFERS) public @interface NumMergeBuffers { ConfigOptionProcessor PROCESSOR = new ConfigOptionProcessor<>(NumMergeBuffers.class) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTests.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTests.java index 463faf15a2bd..e625cf782564 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTests.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTests.java @@ -198,7 +198,7 @@ public AuthenticationResult createEscalatedAuthenticationResult() null ); - public static final Injector INJECTOR = SqlTestQueryStack.defaultInjectorBuilder() + public static final Injector INJECTOR = QueryStackTestHelper.defaultInjectorBuilder() .addModule(new LookylooModule()) .addModule(new SqlAggregationModule()) .addModule(new CalciteTestOperatorModule()) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java index 12fc6a8a3f3c..1ca2ea35a559 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java @@ -138,7 +138,7 @@ private static SqlToolbox createTestToolbox(SqlEngine engine, PlannerFactory pla plannerFactory, NoopServiceEmitter.instance(), NoopRequestLogger.instance(), - SqlTestQueryStack.DEFAULT_NOOP_SCHEDULER, + QueryStackTestHelper.DEFAULT_NOOP_SCHEDULER, new SqlLifecycleManager() ); } @@ -313,7 +313,7 @@ public Set getDataSourceNames() public static JoinableFactory createDefaultJoinableFactory(Injector injector) { - return SqlTestQueryStack.makeJoinableFactoryFromDefault( + return QueryStackTestHelper.makeJoinableFactoryFromDefault( injector.getInstance(LookupExtractorFactoryContainerProvider.class), ImmutableSet.of(TestDataBuilder.CUSTOM_ROW_TABLE_JOINABLE), ImmutableMap.of(TestDataBuilder.CUSTOM_ROW_TABLE_JOINABLE.getClass(), GlobalTableDataSource.class) diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestQueryStack.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryStackTestHelper.java similarity index 96% rename from sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestQueryStack.java rename to sql/src/test/java/org/apache/druid/sql/calcite/util/QueryStackTestHelper.java index 7166784743d6..43a28be32ac3 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestQueryStack.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/QueryStackTestHelper.java @@ -99,7 +99,16 @@ import java.util.Map; import java.util.Set; -public class SqlTestQueryStack +/** + * JUnit 4-free query-stack utilities for SQL tests. + * + *

This class is derived from the reusable query-stack setup in + * {@link org.apache.druid.server.QueryStackTests}. It is kept separately because + * {@code QueryStackTests} still exposes JUnit 4-only fixtures for legacy tests. + * Migrated JUnit 5 SQL tests use this helper until the common query-stack setup + * can be extracted into a shared JUnit 4-free test fixture.

+ */ +public class QueryStackTestHelper { private static final int COMPUTE_BUFFER_SIZE = 10 * 1024 * 1024; @@ -112,7 +121,7 @@ public class SqlTestQueryStack new ServerConfig() ); - private SqlTestQueryStack() + private QueryStackTestHelper() { } 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 8085aa5c7835..45cf4e63b189 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 @@ -620,7 +620,7 @@ public Class getSqlEngineClass() public JoinableFactoryWrapper createJoinableFactoryWrapper(LookupExtractorFactoryContainerProvider lookupProvider) { return new JoinableFactoryWrapper( - SqlTestQueryStack.makeJoinableFactoryFromDefault( + QueryStackTestHelper.makeJoinableFactoryFromDefault( lookupProvider, ImmutableSet.of(TestDataBuilder.CUSTOM_ROW_TABLE_JOINABLE), ImmutableMap.of(TestDataBuilder.CUSTOM_ROW_TABLE_JOINABLE.getClass(), GlobalTableDataSource.class) @@ -985,21 +985,21 @@ GroupByResourcesReservationPool makeMergingGroupByResourcesReservationPool( @LazySingleton public DruidProcessingConfig makeProcessingConfig(Builder builder) { - return SqlTestQueryStack.getProcessingConfig(builder.mergeBufferCount); + return QueryStackTestHelper.getProcessingConfig(builder.mergeBufferCount); } @Provides @LazySingleton public TestBufferPool makeTestBufferPool(Builder builder) { - return SqlTestQueryStack.makeTestBufferPool(builder.resourceCloser); + return QueryStackTestHelper.makeTestBufferPool(builder.resourceCloser); } @Provides @LazySingleton public TestGroupByBuffers makeTestGroupByBuffers(DruidProcessingConfig processingConfig, Builder builder) { - return SqlTestQueryStack.makeGroupByBuffers(builder.resourceCloser, processingConfig); + return QueryStackTestHelper.makeGroupByBuffers(builder.resourceCloser, processingConfig); } @Provides diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/TestDataBuilder.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/TestDataBuilder.java index ed41c165740b..4e4c7c196e4b 100644 --- a/sql/src/test/java/org/apache/druid/sql/calcite/util/TestDataBuilder.java +++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/TestDataBuilder.java @@ -661,7 +661,7 @@ public static SpecificSegmentsQuerySegmentWalker createMockWalker( injector, conglomerate, tmpDir, - SqlTestQueryStack.DEFAULT_NOOP_SCHEDULER, + QueryStackTestHelper.DEFAULT_NOOP_SCHEDULER, QueryFrameworkUtils.createDefaultJoinableFactory(injector) ); } @@ -692,7 +692,7 @@ public static SpecificSegmentsQuerySegmentWalker createMockWalker( { final JoinableFactory joinableFactoryToUse; if (joinableFactory == null) { - joinableFactoryToUse = SqlTestQueryStack.makeJoinableFactoryForLookup( + joinableFactoryToUse = QueryStackTestHelper.makeJoinableFactoryForLookup( injector.getInstance(LookupExtractorFactoryContainerProvider.class) ); } else { 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 aa148dd486db..b019ae43bf31 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 @@ -104,7 +104,7 @@ 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.SqlTestQueryStack; +import org.apache.druid.sql.calcite.util.QueryStackTestHelper; import org.apache.druid.sql.hook.DruidHookDispatcher; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; @@ -196,7 +196,7 @@ public class SqlResourceTest extends CalciteTestBase @BeforeAll public static void setupClass(@TempDir File tempDir) { - conglomerate = SqlTestQueryStack.createQueryRunnerFactoryConglomerate(staticCloser); + conglomerate = QueryStackTestHelper.createQueryRunnerFactoryConglomerate(staticCloser); scheduler = new QueryScheduler( 5, ManualQueryPrioritizationStrategy.INSTANCE,