diff --git a/examples/storm-loadgen/pom.xml b/examples/storm-loadgen/pom.xml index 68478b512dd..ebca6b1aa6e 100644 --- a/examples/storm-loadgen/pom.xml +++ b/examples/storm-loadgen/pom.xml @@ -35,11 +35,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs org.hdrhistogram HdrHistogram - - junit - junit - test - org.apache.storm storm-client diff --git a/examples/storm-starter/pom.xml b/examples/storm-starter/pom.xml index 569daf556da..6842feefa2c 100644 --- a/examples/storm-starter/pom.xml +++ b/examples/storm-starter/pom.xml @@ -39,11 +39,6 @@ org.hdrhistogram HdrHistogram - - junit - junit - test - org.testng testng diff --git a/external/storm-elasticsearch/pom.xml b/external/storm-elasticsearch/pom.xml index c6371a4e428..3386fbd8f4b 100644 --- a/external/storm-elasticsearch/pom.xml +++ b/external/storm-elasticsearch/pom.xml @@ -80,11 +80,6 @@ com.fasterxml.jackson.core jackson-databind - - junit - junit - test - com.google.guava guava-testlib diff --git a/external/storm-hbase/pom.xml b/external/storm-hbase/pom.xml index 04e8ba077e3..e5295a67968 100644 --- a/external/storm-hbase/pom.xml +++ b/external/storm-hbase/pom.xml @@ -83,11 +83,6 @@ com.fasterxml.jackson.core jackson-databind - - junit - junit - test - org.mockito mockito-core diff --git a/external/storm-jms/pom.xml b/external/storm-jms/pom.xml index d5121ab9d7d..387c0526183 100644 --- a/external/storm-jms/pom.xml +++ b/external/storm-jms/pom.xml @@ -48,12 +48,6 @@ geronimo-jms_1.1_spec 1.1.1 - - junit - junit - 4.10 - test - diff --git a/external/storm-kafka-client/pom.xml b/external/storm-kafka-client/pom.xml index 54043a7a4c9..d3d1aab8ced 100644 --- a/external/storm-kafka-client/pom.xml +++ b/external/storm-kafka-client/pom.xml @@ -88,6 +88,10 @@ org.mockito mockito-core + + org.mockito + mockito-junit-jupiter + org.hamcrest java-hamcrest diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnit.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnit.java index a9f8208ab1b..3f212cc9029 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnit.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnit.java @@ -40,12 +40,14 @@ import org.apache.kafka.clients.producer.KafkaProducer; import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.common.serialization.Serializer; +import org.apache.storm.testing.TmpPath; public class KafkaUnit { private KafkaServer kafkaServer; private EmbeddedZookeeper zkServer; private ZkUtils zkUtils; private KafkaProducer producer; + private TmpPath kafkaDir; private static final String ZK_HOST = "127.0.0.1"; private static final String KAFKA_HOST = "127.0.0.1"; private static final int KAFKA_PORT = 9092; @@ -61,10 +63,11 @@ public void setUp() throws IOException { zkUtils = ZkUtils.apply(zkClient, false); // setup Broker + kafkaDir = new TmpPath(Files.createTempDirectory("kafka-").toAbsolutePath().toString()); Properties brokerProps = new Properties(); brokerProps.setProperty("zookeeper.connect", zkConnect); brokerProps.setProperty("broker.id", "0"); - brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString()); + brokerProps.setProperty("log.dirs", kafkaDir.getPath()); brokerProps.setProperty("listeners", String.format("PLAINTEXT://%s:%d", KAFKA_HOST, KAFKA_PORT)); KafkaConfig config = new KafkaConfig(brokerProps); MockTime mock = new MockTime(); @@ -77,6 +80,7 @@ public void setUp() throws IOException { public void tearDown() { closeProducer(); kafkaServer.shutdown(); + kafkaDir.close(); zkUtils.close(); zkServer.shutdown(); } diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnitRule.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnitExtension.java similarity index 72% rename from external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnitRule.java rename to external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnitExtension.java index 013d20f2224..e7e004124a5 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnitRule.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/KafkaUnitExtension.java @@ -17,25 +17,25 @@ */ package org.apache.storm.kafka; -import java.io.IOException; -import org.junit.rules.ExternalResource; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; - -public class KafkaUnitRule extends ExternalResource { +public class KafkaUnitExtension implements BeforeEachCallback, AfterEachCallback { private final KafkaUnit kafkaUnit; - public KafkaUnitRule() { + public KafkaUnitExtension() { this.kafkaUnit = new KafkaUnit(); } @Override - public void before() throws IOException { + public void beforeEach(ExtensionContext ctx) throws Exception { kafkaUnit.setUp(); } @Override - public void after() { + public void afterEach(ExtensionContext ctx) throws Exception { kafkaUnit.tearDown(); } diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/NullRecordTranslator.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/NullRecordTranslator.java index 065244e1c54..8f800a091c8 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/NullRecordTranslator.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/NullRecordTranslator.java @@ -16,7 +16,6 @@ package org.apache.storm.kafka; -import java.util.Collections; import java.util.List; import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.storm.kafka.spout.RecordTranslator; diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutAbstractTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutAbstractTest.java index a7b3e09a20a..98aed93e9e1 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutAbstractTest.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutAbstractTest.java @@ -18,45 +18,41 @@ package org.apache.storm.kafka.spout; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +import java.util.HashMap; +import java.util.Map; import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.clients.consumer.OffsetAndMetadata; import org.apache.kafka.common.TopicPartition; -import org.apache.storm.kafka.KafkaUnitRule; +import org.apache.storm.kafka.KafkaUnitExtension; import org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration; import org.apache.storm.kafka.spout.internal.KafkaConsumerFactory; import org.apache.storm.kafka.spout.internal.KafkaConsumerFactoryDefault; +import org.apache.storm.kafka.spout.subscription.TopicAssigner; import org.apache.storm.spout.SpoutOutputCollector; import org.apache.storm.task.TopologyContext; import org.apache.storm.tuple.Values; import org.apache.storm.utils.Time; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.ArgumentCaptor; import org.mockito.Captor; +import org.mockito.junit.jupiter.MockitoExtension; -import java.util.HashMap; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; - -import org.apache.storm.kafka.spout.subscription.TopicAssigner; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; - +@ExtendWith(MockitoExtension.class) public abstract class KafkaSpoutAbstractTest { - @Rule - public MockitoRule mockito = MockitoJUnit.rule(); - - @Rule - public KafkaUnitRule kafkaUnitRule = new KafkaUnitRule(); + @RegisterExtension + public KafkaUnitExtension kafkaUnitExtension = new KafkaUnitExtension(); final TopologyContext topologyContext = mock(TopologyContext.class); final Map conf = new HashMap<>(); @@ -79,7 +75,7 @@ protected KafkaSpoutAbstractTest(long commitOffsetPeriodMs) { this.commitOffsetPeriodMs = commitOffsetPeriodMs; } - @Before + @BeforeEach public void setUp() { spoutConfig = createSpoutConfig(); @@ -105,7 +101,7 @@ KafkaConsumer createConsumerSpy() { return spy(new KafkaConsumerFactoryDefault().createConsumer(spoutConfig)); } - @After + @AfterEach public void tearDown() throws Exception { simulatedTime.close(); } @@ -113,7 +109,7 @@ public void tearDown() throws Exception { abstract KafkaSpoutConfig createSpoutConfig(); void prepareSpout(int messageCount) throws Exception { - SingleTopicKafkaUnitSetupHelper.populateTopicData(kafkaUnitRule.getKafkaUnit(), SingleTopicKafkaSpoutConfiguration.TOPIC, messageCount); + SingleTopicKafkaUnitSetupHelper.populateTopicData(kafkaUnitExtension.getKafkaUnit(), SingleTopicKafkaSpoutConfiguration.TOPIC, messageCount); SingleTopicKafkaUnitSetupHelper.initializeSpout(spout, conf, topologyContext, collectorMock); } diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutConfigTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutConfigTest.java index 17e070006e6..e168f07b7bd 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutConfigTest.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutConfigTest.java @@ -19,28 +19,24 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashMap; import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.common.serialization.StringDeserializer; import org.apache.storm.kafka.spout.KafkaSpoutConfig.FirstPollOffsetStrategy; -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 KafkaSpoutConfigTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); @Test public void testBasic() { KafkaSpoutConfig conf = KafkaSpoutConfig.builder("localhost:1234", "topic").build(); - assertEquals(FirstPollOffsetStrategy.UNCOMMITTED_EARLIEST, conf.getFirstPollOffsetStrategy()); + assertEquals(conf.getFirstPollOffsetStrategy(), FirstPollOffsetStrategy.UNCOMMITTED_EARLIEST); assertNull(conf.getConsumerGroupId()); assertTrue(conf.getTranslator() instanceof DefaultRecordTranslator); HashMap expected = new HashMap<>(); @@ -49,8 +45,8 @@ public void testBasic() { expected.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); expected.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); expected.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); - assertEquals(expected, conf.getKafkaProps()); - assertEquals(KafkaSpoutConfig.DEFAULT_METRICS_TIME_BUCKET_SIZE_SECONDS, conf.getMetricsTimeBucketSizeInSecs()); + assertEquals(conf.getKafkaProps(), expected); + assertEquals(conf.getMetricsTimeBucketSizeInSecs(), KafkaSpoutConfig.DEFAULT_METRICS_TIME_BUCKET_SIZE_SECONDS); } @Test @@ -59,7 +55,7 @@ public void testSetEmitNullTuplesToTrue() { .setEmitNullTuples(true) .build(); - assertTrue("Failed to set emit null tuples to true", conf.isEmitNullTuples()); + assertTrue(conf.isEmitNullTuples(), "Failed to set emit null tuples to true"); } @Test @@ -88,14 +84,13 @@ public void testMetricsTimeBucketSizeInSecs() { .setMetricsTimeBucketSizeInSecs(100) .build(); - assertEquals(100, conf.getMetricsTimeBucketSizeInSecs()); + assertEquals(conf.getMetricsTimeBucketSizeInSecs(), 100); } @Test public void testThrowsIfEnableAutoCommitIsSet() { - expectedException.expect(IllegalStateException.class); - KafkaSpoutConfig.builder("localhost:1234", "topic") + Assertions.assertThrows(IllegalStateException.class, () -> KafkaSpoutConfig.builder("localhost:1234", "topic") .setProp(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, true) - .build(); + .build()); } } diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutEmitTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutEmitTest.java index 01e2e9f7a55..c8f490cc868 100755 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutEmitTest.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutEmitTest.java @@ -16,7 +16,6 @@ package org.apache.storm.kafka.spout; import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; @@ -40,8 +39,6 @@ import org.apache.storm.task.TopologyContext; import org.apache.storm.utils.Time; import org.apache.storm.utils.Time.SimulatedTime; -import org.junit.Before; -import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.InOrder; @@ -54,9 +51,10 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; -import org.apache.kafka.clients.consumer.internals.PartitionAssignor.Subscription; import org.apache.storm.kafka.spout.subscription.ManualPartitioner; import org.apache.storm.kafka.spout.subscription.TopicFilter; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class KafkaSpoutEmitTest { @@ -68,7 +66,7 @@ public class KafkaSpoutEmitTest { private KafkaConsumer consumerMock; private KafkaSpoutConfig spoutConfig; - @Before + @BeforeEach public void setUp() { spoutConfig = createKafkaSpoutConfigBuilder(mock(TopicFilter.class), mock(ManualPartitioner.class), -1) .setOffsetCommitPeriodMs(offsetCommitPeriodMs) diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutNullTupleTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutNullTupleTest.java index ce93ea2ef58..6d520304cbd 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutNullTupleTest.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutNullTupleTest.java @@ -18,17 +18,15 @@ package org.apache.storm.kafka.spout; -import org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration; -import org.apache.storm.utils.Time; -import org.junit.Test; - -import java.util.regex.Pattern; - import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import java.util.regex.Pattern; import org.apache.storm.kafka.NullRecordTranslator; +import org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration; +import org.apache.storm.utils.Time; +import org.junit.jupiter.api.Test; public class KafkaSpoutNullTupleTest extends KafkaSpoutAbstractTest { @@ -39,7 +37,7 @@ public KafkaSpoutNullTupleTest() { @Override KafkaSpoutConfig createSpoutConfig() { - return KafkaSpoutConfig.builder("127.0.0.1:" + kafkaUnitRule.getKafkaUnit().getKafkaPort(), + return KafkaSpoutConfig.builder("127.0.0.1:" + kafkaUnitExtension.getKafkaUnit().getKafkaPort(), Pattern.compile(SingleTopicKafkaSpoutConfiguration.TOPIC)) .setOffsetCommitPeriodMs(commitOffsetPeriodMs) .setRecordTranslator(new NullRecordTranslator<>()) diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutReactivationTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutReactivationTest.java index 5b37a8dbec4..1b3a490cd40 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutReactivationTest.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutReactivationTest.java @@ -34,7 +34,7 @@ import org.apache.kafka.clients.consumer.KafkaConsumer; import org.apache.kafka.clients.consumer.OffsetAndMetadata; import org.apache.kafka.common.TopicPartition; -import org.apache.storm.kafka.KafkaUnitRule; +import org.apache.storm.kafka.KafkaUnitExtension; import org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration; import org.apache.storm.kafka.spout.internal.KafkaConsumerFactory; import org.apache.storm.kafka.spout.internal.KafkaConsumerFactoryDefault; @@ -42,19 +42,19 @@ import org.apache.storm.spout.SpoutOutputCollector; import org.apache.storm.task.TopologyContext; import org.apache.storm.utils.Time; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.ArgumentCaptor; import org.mockito.Captor; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class KafkaSpoutReactivationTest { - @Rule - public KafkaUnitRule kafkaUnitRule = new KafkaUnitRule(); + @RegisterExtension + public KafkaUnitExtension kafkaUnitExtension = new KafkaUnitExtension(); @Captor private ArgumentCaptor> commitCapture; @@ -68,11 +68,10 @@ public class KafkaSpoutReactivationTest { private KafkaSpout spout; private final int maxPollRecords = 10; - @Before + @BeforeEach public void setUp() { KafkaSpoutConfig spoutConfig = - SingleTopicKafkaSpoutConfiguration.setCommonSpoutConfig( - KafkaSpoutConfig.builder("127.0.0.1:" + kafkaUnitRule.getKafkaUnit().getKafkaPort(), + SingleTopicKafkaSpoutConfiguration.setCommonSpoutConfig(KafkaSpoutConfig.builder("127.0.0.1:" + kafkaUnitExtension.getKafkaUnit().getKafkaPort(), SingleTopicKafkaSpoutConfiguration.TOPIC)) .setFirstPollOffsetStrategy(UNCOMMITTED_EARLIEST) .setOffsetCommitPeriodMs(commitOffsetPeriodMs) @@ -89,7 +88,7 @@ public void setUp() { } private void prepareSpout(int messageCount) throws Exception { - SingleTopicKafkaUnitSetupHelper.populateTopicData(kafkaUnitRule.getKafkaUnit(), SingleTopicKafkaSpoutConfiguration.TOPIC, messageCount); + SingleTopicKafkaUnitSetupHelper.populateTopicData(kafkaUnitExtension.getKafkaUnit(), SingleTopicKafkaSpoutConfiguration.TOPIC, messageCount); SingleTopicKafkaUnitSetupHelper.initializeSpout(spout, conf, topologyContext, collector); } diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutSingleTopicTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutSingleTopicTest.java index 7842349c510..1d877f5b4b8 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutSingleTopicTest.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutSingleTopicTest.java @@ -18,40 +18,35 @@ package org.apache.storm.kafka.spout; -import org.apache.kafka.clients.consumer.OffsetAndMetadata; -import org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration; -import org.apache.storm.tuple.Values; -import org.junit.Test; -import org.mockito.ArgumentCaptor; - -import java.util.Map; - import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyListOf; import static org.mockito.ArgumentMatchers.anyObject; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.clearInvocations; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; - -import org.apache.kafka.common.TopicPartition; -import org.apache.storm.utils.Time; - -import static org.mockito.Mockito.clearInvocations; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.junit.Assert.assertEquals; - import java.util.regex.Pattern; import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.consumer.OffsetAndMetadata; +import org.apache.kafka.common.TopicPartition; +import org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration; +import org.apache.storm.tuple.Values; +import org.apache.storm.utils.Time; import org.hamcrest.Matchers; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; public class KafkaSpoutSingleTopicTest extends KafkaSpoutAbstractTest { private final int maxPollRecords = 10; @@ -64,7 +59,7 @@ public KafkaSpoutSingleTopicTest() { @Override KafkaSpoutConfig createSpoutConfig() { return SingleTopicKafkaSpoutConfiguration.setCommonSpoutConfig( - KafkaSpoutConfig.builder("127.0.0.1:" + kafkaUnitRule.getKafkaUnit().getKafkaPort(), + KafkaSpoutConfig.builder("127.0.0.1:" + kafkaUnitExtension.getKafkaUnit().getKafkaPort(), Pattern.compile(SingleTopicKafkaSpoutConfiguration.TOPIC))) .setOffsetCommitPeriodMs(commitOffsetPeriodMs) .setRetry(new KafkaSpoutRetryExponentialBackoff(KafkaSpoutRetryExponentialBackoff.TimeInterval.seconds(0), KafkaSpoutRetryExponentialBackoff.TimeInterval.seconds(0), @@ -338,7 +333,7 @@ public void testSpoutMustRefreshPartitionsEvenIfNotPolling() throws Exception { spout.nextTuple(); verify(collectorMock, never()).emit(anyString(), anyList(), any(KafkaSpoutMessageId.class)); - SingleTopicKafkaUnitSetupHelper.populateTopicData(kafkaUnitRule.getKafkaUnit(), SingleTopicKafkaSpoutConfiguration.TOPIC, 1); + SingleTopicKafkaUnitSetupHelper.populateTopicData(kafkaUnitExtension.getKafkaUnit(), SingleTopicKafkaSpoutConfiguration.TOPIC, 1); Time.advanceTime(KafkaSpoutConfig.DEFAULT_PARTITION_REFRESH_PERIOD_MS + KafkaSpout.TIMER_DELAY_MS); //The new partition should be discovered and the message should be emitted @@ -352,14 +347,14 @@ public void testOffsetMetrics() throws Exception { prepareSpout(messageCount); Map offsetMetric = (Map) spout.getKafkaOffsetMetric().getValueAndReset(); - assertEquals(0, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalEarliestTimeOffset").longValue()); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalEarliestTimeOffset").longValue(), 0); // the offset of the last available message + 1. - assertEquals(10, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestTimeOffset").longValue()); - assertEquals(10, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalRecordsInPartitions").longValue()); - assertEquals(0, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestEmittedOffset").longValue()); - assertEquals(0, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestCompletedOffset").longValue()); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestTimeOffset").longValue(), 10); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalRecordsInPartitions").longValue(), 10); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestEmittedOffset").longValue(), 0); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestCompletedOffset").longValue(), 0); //totalSpoutLag = totalLatestTimeOffset-totalLatestCompletedOffset - assertEquals(10, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalSpoutLag").longValue()); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalSpoutLag").longValue(), 10); //Emit all messages and check that they are emitted. Ack the messages too for (int i = 0; i < messageCount; i++) { @@ -369,12 +364,12 @@ public void testOffsetMetrics() throws Exception { commitAndVerifyAllMessagesCommitted(messageCount); offsetMetric = (Map) spout.getKafkaOffsetMetric().getValueAndReset(); - assertEquals(0, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalEarliestTimeOffset").longValue()); - assertEquals(10, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestTimeOffset").longValue()); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalEarliestTimeOffset").longValue(), 0); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestTimeOffset").longValue(), 10); //latest offset - assertEquals(9, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestEmittedOffset").longValue()); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestEmittedOffset").longValue(), 9); // offset where processing will resume upon spout restart - assertEquals(10, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestCompletedOffset").longValue()); - assertEquals(0, offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalSpoutLag").longValue()); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalLatestCompletedOffset").longValue(), 10); + assertEquals(offsetMetric.get(SingleTopicKafkaSpoutConfiguration.TOPIC+"/totalSpoutLag").longValue(), 0); } } diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutTopologyDeployActivateDeactivateTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutTopologyDeployActivateDeactivateTest.java index a9d7c75f5bf..3276210a264 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutTopologyDeployActivateDeactivateTest.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/KafkaSpoutTopologyDeployActivateDeactivateTest.java @@ -18,12 +18,11 @@ package org.apache.storm.kafka.spout; -import org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration; -import org.junit.Test; +import static org.mockito.Mockito.when; import java.util.regex.Pattern; - -import static org.mockito.Mockito.when; +import org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration; +import org.junit.jupiter.api.Test; public class KafkaSpoutTopologyDeployActivateDeactivateTest extends KafkaSpoutAbstractTest { @@ -34,7 +33,7 @@ public KafkaSpoutTopologyDeployActivateDeactivateTest() { @Override KafkaSpoutConfig createSpoutConfig() { return SingleTopicKafkaSpoutConfiguration.setCommonSpoutConfig( - KafkaSpoutConfig.builder("127.0.0.1:" + kafkaUnitRule.getKafkaUnit().getKafkaPort(), + KafkaSpoutConfig.builder("127.0.0.1:" + kafkaUnitExtension.getKafkaUnit().getKafkaPort(), Pattern.compile(SingleTopicKafkaSpoutConfiguration.TOPIC))) .setOffsetCommitPeriodMs(commitOffsetPeriodMs) .setFirstPollOffsetStrategy(KafkaSpoutConfig.FirstPollOffsetStrategy.EARLIEST) diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/MaxUncommittedOffsetTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/MaxUncommittedOffsetTest.java index 6b8b94bb4cb..646134ad26f 100755 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/MaxUncommittedOffsetTest.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/MaxUncommittedOffsetTest.java @@ -15,14 +15,19 @@ */ package org.apache.storm.kafka.spout; +import static org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration.createKafkaSpoutConfigBuilder; import static org.hamcrest.CoreMatchers.either; import static org.hamcrest.CoreMatchers.everyItem; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.isIn; import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -31,31 +36,22 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; - import org.apache.kafka.clients.consumer.ConsumerConfig; -import org.apache.kafka.clients.consumer.KafkaConsumer; -import org.apache.storm.kafka.KafkaUnitRule; +import org.apache.storm.kafka.KafkaUnitExtension; import org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration; import org.apache.storm.kafka.spout.internal.KafkaConsumerFactoryDefault; import org.apache.storm.spout.SpoutOutputCollector; import org.apache.storm.task.TopologyContext; import org.apache.storm.utils.Time; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.ArgumentCaptor; -import org.mockito.MockitoAnnotations; - -import static org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration.createKafkaSpoutConfigBuilder; -import static org.mockito.ArgumentMatchers.anyList; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.never; public class MaxUncommittedOffsetTest { - @Rule - public KafkaUnitRule kafkaUnitRule = new KafkaUnitRule(); + @RegisterExtension + public KafkaUnitExtension kafkaUnitExtension = new KafkaUnitExtension(); private final TopologyContext topologyContext = mock(TopologyContext.class); private final Map conf = new HashMap<>(); @@ -65,7 +61,7 @@ public class MaxUncommittedOffsetTest { private final int maxUncommittedOffsets = 10; private final int maxPollRecords = 5; private final int initialRetryDelaySecs = 60; - private final KafkaSpoutConfig spoutConfig = createKafkaSpoutConfigBuilder(kafkaUnitRule.getKafkaUnit().getKafkaPort()) + private final KafkaSpoutConfig spoutConfig = createKafkaSpoutConfigBuilder(kafkaUnitExtension.getKafkaUnit().getKafkaPort()) .setOffsetCommitPeriodMs(commitOffsetPeriodMs) .setProp(ConsumerConfig.MAX_POLL_RECORDS_CONFIG, maxPollRecords) .setMaxUncommittedOffsets(maxUncommittedOffsets) @@ -74,7 +70,7 @@ public class MaxUncommittedOffsetTest { .build(); private KafkaSpout spout; - @Before + @BeforeEach public void setUp() { //This is because the tests are checking that a hard cap of maxUncommittedOffsets + maxPollRecords - 1 uncommitted offsets exists //so Kafka must be able to return more messages than that in order for the tests to be meaningful @@ -87,7 +83,7 @@ public void setUp() { } private void prepareSpout(int msgCount) throws Exception { - SingleTopicKafkaUnitSetupHelper.populateTopicData(kafkaUnitRule.getKafkaUnit(), SingleTopicKafkaSpoutConfiguration.TOPIC, msgCount); + SingleTopicKafkaUnitSetupHelper.populateTopicData(kafkaUnitExtension.getKafkaUnit(), SingleTopicKafkaSpoutConfiguration.TOPIC, msgCount); SingleTopicKafkaUnitSetupHelper.initializeSpout(spout, conf, topologyContext, collector); } diff --git a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/internal/OffsetManagerTest.java b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/internal/OffsetManagerTest.java index 9972d4cb6da..6aa37d16312 100644 --- a/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/internal/OffsetManagerTest.java +++ b/external/storm-kafka-client/src/test/java/org/apache/storm/kafka/spout/internal/OffsetManagerTest.java @@ -18,24 +18,20 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import java.util.NoSuchElementException; import org.apache.kafka.clients.consumer.OffsetAndMetadata; import org.apache.kafka.common.TopicPartition; import org.apache.storm.kafka.spout.KafkaSpoutMessageId; -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 OffsetManagerTest { private static final String COMMIT_METADATA = "{\"topologyId\":\"tp1\",\"taskId\":3,\"threadName\":\"Thread-20\"}"; - - @Rule - public ExpectedException expect = ExpectedException.none(); private final long initialFetchOffset = 0; private final TopicPartition testTp = new TopicPartition("testTopic", 0); @@ -183,8 +179,7 @@ public void testGetNthUncommittedOffsetAfterCommittedOffset() { assertThat("The third uncommitted offset should be 5", manager.getNthUncommittedOffsetAfterCommittedOffset(3), is(initialFetchOffset + 5L)); assertThat("The fourth uncommitted offset should be 30", manager.getNthUncommittedOffsetAfterCommittedOffset(4), is(initialFetchOffset + 30L)); - expect.expect(NoSuchElementException.class); - manager.getNthUncommittedOffsetAfterCommittedOffset(5); + Assertions.assertThrows(NoSuchElementException.class, () -> manager.getNthUncommittedOffsetAfterCommittedOffset(5)); } @Test diff --git a/external/storm-mongodb/pom.xml b/external/storm-mongodb/pom.xml index b374957e3a1..f4b65ddc440 100644 --- a/external/storm-mongodb/pom.xml +++ b/external/storm-mongodb/pom.xml @@ -56,11 +56,6 @@ commons-lang - - junit - junit - test - org.mockito mockito-core diff --git a/external/storm-opentsdb/pom.xml b/external/storm-opentsdb/pom.xml index 53ce5ba9f4b..84c8e689e75 100644 --- a/external/storm-opentsdb/pom.xml +++ b/external/storm-opentsdb/pom.xml @@ -90,11 +90,6 @@ - - junit - junit - test - org.mockito mockito-core diff --git a/external/storm-redis/pom.xml b/external/storm-redis/pom.xml index 5943496267d..52915d9dc0e 100644 --- a/external/storm-redis/pom.xml +++ b/external/storm-redis/pom.xml @@ -70,11 +70,6 @@ jackson-databind - - junit - junit - test - org.mockito mockito-core diff --git a/external/storm-rocketmq/pom.xml b/external/storm-rocketmq/pom.xml index bc0272d8bab..7c2ae455c49 100644 --- a/external/storm-rocketmq/pom.xml +++ b/external/storm-rocketmq/pom.xml @@ -61,11 +61,6 @@ commons-lang - - junit - junit - test - org.mockito mockito-core diff --git a/pom.xml b/pom.xml index a89e339d093..5c107c86bb0 100644 --- a/pom.xml +++ b/pom.xml @@ -297,7 +297,8 @@ 3.1.0 2.3 0.11.0 - 4.11 + 5.2.0 + 2.22.0 3.1.0 2.5.1 2.1.10 @@ -413,8 +414,14 @@ - junit - junit + org.junit.jupiter + junit-jupiter-engine + test + + + + org.junit.vintage + junit-vintage-engine test @@ -1035,6 +1042,12 @@ ${mockito.version} test + + org.mockito + mockito-junit-jupiter + ${mockito.version} + test + org.awaitility awaitility @@ -1061,10 +1074,11 @@ - junit - junit - ${junit.version} - test + org.junit + junit-bom + ${junit.jupiter.version} + pom + import org.apache.calcite diff --git a/sql/storm-sql-core/pom.xml b/sql/storm-sql-core/pom.xml index e92a80d0722..712f734ba60 100644 --- a/sql/storm-sql-core/pom.xml +++ b/sql/storm-sql-core/pom.xml @@ -85,11 +85,6 @@ commons-lang runtime - - junit - junit - test - org.mockito mockito-core diff --git a/sql/storm-sql-external/storm-sql-hdfs/pom.xml b/sql/storm-sql-external/storm-sql-hdfs/pom.xml index 4259951eb7d..2695d5668e5 100644 --- a/sql/storm-sql-external/storm-sql-hdfs/pom.xml +++ b/sql/storm-sql-external/storm-sql-hdfs/pom.xml @@ -81,11 +81,6 @@ test - - junit - junit - test - org.mockito mockito-core diff --git a/sql/storm-sql-external/storm-sql-kafka/pom.xml b/sql/storm-sql-external/storm-sql-kafka/pom.xml index 97bd87c47c1..b1173a0e83f 100644 --- a/sql/storm-sql-external/storm-sql-kafka/pom.xml +++ b/sql/storm-sql-external/storm-sql-kafka/pom.xml @@ -70,11 +70,6 @@ kafka-clients ${storm.kafka.version} - - junit - junit - test - org.mockito mockito-core diff --git a/sql/storm-sql-external/storm-sql-mongodb/pom.xml b/sql/storm-sql-external/storm-sql-mongodb/pom.xml index 8bd56519db4..ef754052c72 100644 --- a/sql/storm-sql-external/storm-sql-mongodb/pom.xml +++ b/sql/storm-sql-external/storm-sql-mongodb/pom.xml @@ -61,11 +61,6 @@ ${project.version} ${provided.scope} - - junit - junit - test - org.mockito mockito-core diff --git a/sql/storm-sql-external/storm-sql-redis/pom.xml b/sql/storm-sql-external/storm-sql-redis/pom.xml index 4627450bb03..0e2646e1c8e 100644 --- a/sql/storm-sql-external/storm-sql-redis/pom.xml +++ b/sql/storm-sql-external/storm-sql-redis/pom.xml @@ -53,11 +53,6 @@ ${project.version} ${provided.scope} - - junit - junit - test - org.mockito mockito-core diff --git a/sql/storm-sql-runtime/pom.xml b/sql/storm-sql-runtime/pom.xml index 77e22a49243..b6601a98aa9 100644 --- a/sql/storm-sql-runtime/pom.xml +++ b/sql/storm-sql-runtime/pom.xml @@ -91,11 +91,6 @@ org.hamcrest java-hamcrest - - junit - junit - test - src/jvm diff --git a/storm-buildtools/storm-maven-plugins/pom.xml b/storm-buildtools/storm-maven-plugins/pom.xml index b850f21ded5..7ecffb3b3a2 100644 --- a/storm-buildtools/storm-maven-plugins/pom.xml +++ b/storm-buildtools/storm-maven-plugins/pom.xml @@ -52,11 +52,6 @@ ${maven.dependency.version} provided - - junit - junit - test - diff --git a/storm-client/pom.xml b/storm-client/pom.xml index 2bf0ed1b99c..7c28cce8823 100644 --- a/storm-client/pom.xml +++ b/storm-client/pom.xml @@ -98,10 +98,6 @@ - - junit - junit - org.mockito mockito-core diff --git a/storm-client/src/jvm/org/apache/storm/testing/TmpPath.java b/storm-client/src/jvm/org/apache/storm/testing/TmpPath.java index 92bb5919b03..115a3f0706c 100644 --- a/storm-client/src/jvm/org/apache/storm/testing/TmpPath.java +++ b/storm-client/src/jvm/org/apache/storm/testing/TmpPath.java @@ -48,7 +48,7 @@ public File getFile() { } @Override - public void close() throws Exception { + public void close() { if (path.exists()) { try { FileUtils.forceDelete(path); diff --git a/storm-core/pom.xml b/storm-core/pom.xml index 9690a067e45..7829f4947a7 100644 --- a/storm-core/pom.xml +++ b/storm-core/pom.xml @@ -174,11 +174,6 @@ org.slf4j log4j-over-slf4j - - junit - junit - test - org.mockito mockito-core diff --git a/storm-webapp/pom.xml b/storm-webapp/pom.xml index ba11870732d..407cd9288dc 100644 --- a/storm-webapp/pom.xml +++ b/storm-webapp/pom.xml @@ -61,10 +61,6 @@ io.dropwizard.metrics metrics-core - - junit - junit - org.mockito mockito-core