This is an automated email from the ASF dual-hosted git repository. vinoyang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-hudi.git
The following commit(s) were added to refs/heads/master by this push: new acdc4a8 [HUDI-798] Migrate to Mockito Jupiter for JUnit 5 (#1521) acdc4a8 is described below commit acdc4a8d004394590f9e5ffcc703ea23624e66d9 Author: Raymond Xu <2701446+xushi...@users.noreply.github.com> AuthorDate: Thu Apr 16 01:07:32 2020 -0700 [HUDI-798] Migrate to Mockito Jupiter for JUnit 5 (#1521) --- hudi-cli/pom.xml | 2 +- hudi-client/pom.xml | 2 +- .../org/apache/hudi/client/TestWriteStatus.java | 14 +-- .../client/utils/TestParquetReaderIterator.java | 19 ++-- .../java/org/apache/hudi/index/TestHbaseIndex.java | 45 ++++---- .../apache/hudi/table/TestHoodieRecordSizing.java | 6 +- hudi-common/pom.xml | 2 +- .../view/TestPriorityBasedFileSystemView.java | 124 +++++++++++---------- hudi-hadoop-mr/pom.xml | 2 +- .../realtime/TestHoodieRealtimeFileSplit.java | 40 +++---- hudi-hive-sync/pom.xml | 2 +- hudi-spark/pom.xml | 2 +- hudi-timeline-service/pom.xml | 2 +- hudi-utilities/pom.xml | 2 +- pom.xml | 6 +- 15 files changed, 135 insertions(+), 135 deletions(-) diff --git a/hudi-cli/pom.xml b/hudi-cli/pom.xml index 2f0f4b4..fed2bf9 100644 --- a/hudi-cli/pom.xml +++ b/hudi-cli/pom.xml @@ -276,7 +276,7 @@ <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/hudi-client/pom.xml b/hudi-client/pom.xml index 9c716f2..326cf83 100644 --- a/hudi-client/pom.xml +++ b/hudi-client/pom.xml @@ -265,7 +265,7 @@ <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/hudi-client/src/test/java/org/apache/hudi/client/TestWriteStatus.java b/hudi-client/src/test/java/org/apache/hudi/client/TestWriteStatus.java index 945759f..91878e1 100644 --- a/hudi-client/src/test/java/org/apache/hudi/client/TestWriteStatus.java +++ b/hudi-client/src/test/java/org/apache/hudi/client/TestWriteStatus.java @@ -20,11 +20,11 @@ package org.apache.hudi.client; import org.apache.hudi.common.model.HoodieRecord; -import org.junit.Test; -import org.mockito.Mockito; +import org.junit.jupiter.api.Test; -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; +import static org.mockito.Mockito.mock; public class TestWriteStatus { @Test @@ -32,7 +32,7 @@ public class TestWriteStatus { WriteStatus status = new WriteStatus(true, 0.1); Throwable t = new Exception("some error in writing"); for (int i = 0; i < 1000; i++) { - status.markFailure(Mockito.mock(HoodieRecord.class), t, null); + status.markFailure(mock(HoodieRecord.class), t, null); } assertTrue(status.getFailedRecords().size() > 0); assertTrue(status.getFailedRecords().size() < 150); // 150 instead of 100, to prevent flaky test @@ -44,8 +44,8 @@ public class TestWriteStatus { WriteStatus status = new WriteStatus(false, 1.0); Throwable t = new Exception("some error in writing"); for (int i = 0; i < 1000; i++) { - status.markSuccess(Mockito.mock(HoodieRecord.class), null); - status.markFailure(Mockito.mock(HoodieRecord.class), t, null); + status.markSuccess(mock(HoodieRecord.class), null); + status.markFailure(mock(HoodieRecord.class), t, null); } assertEquals(1000, status.getFailedRecords().size()); assertTrue(status.hasErrors()); diff --git a/hudi-client/src/test/java/org/apache/hudi/client/utils/TestParquetReaderIterator.java b/hudi-client/src/test/java/org/apache/hudi/client/utils/TestParquetReaderIterator.java index 4e291aa..f20c5f9 100644 --- a/hudi-client/src/test/java/org/apache/hudi/client/utils/TestParquetReaderIterator.java +++ b/hudi-client/src/test/java/org/apache/hudi/client/utils/TestParquetReaderIterator.java @@ -21,11 +21,14 @@ package org.apache.hudi.client.utils; import org.apache.hudi.exception.HoodieIOException; import org.apache.parquet.hadoop.ParquetReader; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -40,7 +43,7 @@ public class TestParquetReaderIterator { int idempotencyCheckCounter = 0; // call hasNext() 3 times while (idempotencyCheckCounter < 3) { - Assert.assertTrue(iterator.hasNext()); + assertTrue(iterator.hasNext()); idempotencyCheckCounter++; } } @@ -53,13 +56,9 @@ public class TestParquetReaderIterator { when(reader.read()).thenReturn(1).thenReturn(null); ParquetReaderIterator<Integer> iterator = new ParquetReaderIterator<>(reader); // should return value even though hasNext() hasn't been called - Assert.assertTrue(iterator.next() == 1); + assertEquals(1, iterator.next()); // no more entries to iterate on - Assert.assertFalse(iterator.hasNext()); - try { - iterator.next(); - } catch (HoodieIOException e) { - // should throw an exception since there is only 1 record - } + assertFalse(iterator.hasNext()); + assertThrows(HoodieIOException.class, iterator::next, "should throw an exception since there is only 1 record"); } } diff --git a/hudi-client/src/test/java/org/apache/hudi/index/TestHbaseIndex.java b/hudi-client/src/test/java/org/apache/hudi/index/TestHbaseIndex.java index 803f1be..991c81c 100644 --- a/hudi-client/src/test/java/org/apache/hudi/index/TestHbaseIndex.java +++ b/hudi-client/src/test/java/org/apache/hudi/index/TestHbaseIndex.java @@ -52,7 +52,6 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.spark.api.java.JavaRDD; import org.junit.After; import org.junit.AfterClass; -import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.FixMethodOrder; @@ -70,9 +69,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Matchers.anyObject; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atMost; import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * Note :: HBaseTestingUtility is really flaky with issues where the HbaseMiniCluster fails to shutdown across tests, @@ -258,8 +259,8 @@ public class TestHbaseIndex extends HoodieClientTestHarness { // Mock hbaseConnection and related entities Connection hbaseConnection = Mockito.mock(Connection.class); HTable table = Mockito.mock(HTable.class); - Mockito.when(hbaseConnection.getTable(TableName.valueOf(tableName))).thenReturn(table); - Mockito.when(table.get((List<Get>) anyObject())).thenReturn(new Result[0]); + when(hbaseConnection.getTable(TableName.valueOf(tableName))).thenReturn(table); + when(table.get((List<Get>) any())).thenReturn(new Result[0]); // only for test, set the hbaseConnection to mocked object index.setHbaseConnection(hbaseConnection); @@ -281,7 +282,7 @@ public class TestHbaseIndex extends HoodieClientTestHarness { index.tagLocation(writeRecords, jsc, hoodieTable); // 3 batches should be executed given batchSize = 100 and parallelism = 1 - Mockito.verify(table, times(3)).get((List<Get>) anyObject()); + verify(table, times(3)).get((List<Get>) any()); } @@ -307,8 +308,8 @@ public class TestHbaseIndex extends HoodieClientTestHarness { // Mock hbaseConnection and related entities Connection hbaseConnection = Mockito.mock(Connection.class); HTable table = Mockito.mock(HTable.class); - Mockito.when(hbaseConnection.getTable(TableName.valueOf(tableName))).thenReturn(table); - Mockito.when(table.get((List<Get>) anyObject())).thenReturn(new Result[0]); + when(hbaseConnection.getTable(TableName.valueOf(tableName))).thenReturn(table); + when(table.get((List<Get>) any())).thenReturn(new Result[0]); // only for test, set the hbaseConnection to mocked object index.setHbaseConnection(hbaseConnection); @@ -319,7 +320,7 @@ public class TestHbaseIndex extends HoodieClientTestHarness { index.updateLocation(writeStatues, jsc, hoodieTable); // 3 batches should be executed given batchSize = 100 and <=numberOfDataFileIds getting updated, // so each fileId ideally gets updates - Mockito.verify(table, atMost(numberOfDataFileIds)).put((List<Put>) anyObject()); + verify(table, atMost(numberOfDataFileIds)).put((List<Put>) any()); } @Test @@ -334,28 +335,28 @@ public class TestHbaseIndex extends HoodieClientTestHarness { // 8 (batchSize) * 200 (parallelism) * 10 (maxReqsInOneSecond) * 10 (numRegionServers) * 0.1 (qpsFraction)) => 16000 // We assume requests get distributed to Region Servers uniformly, so each RS gets 1600 request // 1600 happens to be 10% of 16667 (maxQPSPerRegionServer) as expected. - Assert.assertEquals(putBatchSize, 8); + assertEquals(putBatchSize, 8); // Number of Region Servers are halved, total requests sent in a second are also halved, so batchSize is also halved int putBatchSize2 = batchSizeCalculator.getBatchSize(5, 16667, 1200, 200, 100, 0.1f); - Assert.assertEquals(putBatchSize2, 4); + assertEquals(putBatchSize2, 4); // If the parallelism is halved, batchSize has to double int putBatchSize3 = batchSizeCalculator.getBatchSize(10, 16667, 1200, 100, 100, 0.1f); - Assert.assertEquals(putBatchSize3, 16); + assertEquals(putBatchSize3, 16); // If the parallelism is halved, batchSize has to double. // This time parallelism is driven by numTasks rather than numExecutors int putBatchSize4 = batchSizeCalculator.getBatchSize(10, 16667, 100, 200, 100, 0.1f); - Assert.assertEquals(putBatchSize4, 16); + assertEquals(putBatchSize4, 16); // If sleepTimeMs is halved, batchSize has to halve int putBatchSize5 = batchSizeCalculator.getBatchSize(10, 16667, 1200, 200, 100, 0.05f); - Assert.assertEquals(putBatchSize5, 4); + assertEquals(putBatchSize5, 4); // If maxQPSPerRegionServer is doubled, batchSize also doubles int putBatchSize6 = batchSizeCalculator.getBatchSize(10, 33334, 1200, 200, 100, 0.1f); - Assert.assertEquals(putBatchSize6, 16); + assertEquals(putBatchSize6, 16); } @Test @@ -367,9 +368,9 @@ public class TestHbaseIndex extends HoodieClientTestHarness { final Tuple2<Long, Integer> tuple = index.getHBasePutAccessParallelism(writeStatusRDD); final int hbasePutAccessParallelism = Integer.parseInt(tuple._2.toString()); final int hbaseNumPuts = Integer.parseInt(tuple._1.toString()); - Assert.assertEquals(10, writeStatusRDD.getNumPartitions()); - Assert.assertEquals(2, hbasePutAccessParallelism); - Assert.assertEquals(11, hbaseNumPuts); + assertEquals(10, writeStatusRDD.getNumPartitions()); + assertEquals(2, hbasePutAccessParallelism); + assertEquals(11, hbaseNumPuts); } @Test @@ -381,9 +382,9 @@ public class TestHbaseIndex extends HoodieClientTestHarness { final Tuple2<Long, Integer> tuple = index.getHBasePutAccessParallelism(writeStatusRDD); final int hbasePutAccessParallelism = Integer.parseInt(tuple._2.toString()); final int hbaseNumPuts = Integer.parseInt(tuple._1.toString()); - Assert.assertEquals(10, writeStatusRDD.getNumPartitions()); - Assert.assertEquals(0, hbasePutAccessParallelism); - Assert.assertEquals(0, hbaseNumPuts); + assertEquals(10, writeStatusRDD.getNumPartitions()); + assertEquals(0, hbasePutAccessParallelism); + assertEquals(0, hbaseNumPuts); } @Test @@ -391,9 +392,9 @@ public class TestHbaseIndex extends HoodieClientTestHarness { HoodieWriteConfig config = getConfig(); HBaseIndex index = new HBaseIndex(config); HBaseIndexQPSResourceAllocator hBaseIndexQPSResourceAllocator = index.createQPSResourceAllocator(config); - Assert.assertEquals(hBaseIndexQPSResourceAllocator.getClass().getName(), + assertEquals(hBaseIndexQPSResourceAllocator.getClass().getName(), DefaultHBaseQPSResourceAllocator.class.getName()); - Assert.assertEquals(config.getHbaseIndexQPSFraction(), + assertEquals(config.getHbaseIndexQPSFraction(), hBaseIndexQPSResourceAllocator.acquireQPSResources(config.getHbaseIndexQPSFraction(), 100), 0.0f); } diff --git a/hudi-client/src/test/java/org/apache/hudi/table/TestHoodieRecordSizing.java b/hudi-client/src/test/java/org/apache/hudi/table/TestHoodieRecordSizing.java index 03a32db..1ce87f0 100644 --- a/hudi-client/src/test/java/org/apache/hudi/table/TestHoodieRecordSizing.java +++ b/hudi-client/src/test/java/org/apache/hudi/table/TestHoodieRecordSizing.java @@ -24,7 +24,7 @@ import org.apache.hudi.common.table.timeline.HoodieInstant; import org.apache.hudi.common.table.timeline.HoodieTimeline; import org.apache.hudi.common.util.Option; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -35,8 +35,8 @@ import java.util.List; import static org.apache.hudi.common.model.HoodieTestUtils.generateFakeHoodieWriteStat; import static org.apache.hudi.table.HoodieCopyOnWriteTable.averageBytesPerRecord; -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/hudi-common/pom.xml b/hudi-common/pom.xml index 424f6c1..b65cc34 100644 --- a/hudi-common/pom.xml +++ b/hudi-common/pom.xml @@ -179,7 +179,7 @@ <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> diff --git a/hudi-common/src/test/java/org/apache/hudi/common/table/view/TestPriorityBasedFileSystemView.java b/hudi-common/src/test/java/org/apache/hudi/common/table/view/TestPriorityBasedFileSystemView.java index 14304a7..e59860e 100644 --- a/hudi-common/src/test/java/org/apache/hudi/common/table/view/TestPriorityBasedFileSystemView.java +++ b/hudi-common/src/test/java/org/apache/hudi/common/table/view/TestPriorityBasedFileSystemView.java @@ -29,29 +29,26 @@ import org.apache.hudi.common.util.Option; import org.apache.hudi.common.util.collection.ImmutablePair; import org.apache.hudi.common.util.collection.Pair; -import junit.framework.TestCase; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -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.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collections; import java.util.List; import java.util.stream.Stream; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) -public class TestPriorityBasedFileSystemView extends TestCase { +@ExtendWith(MockitoExtension.class) +public class TestPriorityBasedFileSystemView { @Mock private SyncableFileSystemView primary; @@ -62,27 +59,20 @@ public class TestPriorityBasedFileSystemView extends TestCase { @InjectMocks private PriorityBasedFileSystemView fsView; - @Rule - public MockitoRule rule = MockitoJUnit.rule(); - private Stream<HoodieBaseFile> testBaseFileStream; private Stream<FileSlice> testFileSliceStream; - @Before + @BeforeEach public void setUp() { fsView = new PriorityBasedFileSystemView(primary, secondary); - testBaseFileStream = Collections.singleton(new HoodieBaseFile("test")).stream(); - testFileSliceStream = Collections - .singleton(new FileSlice("2020-01-01", "20:20", "file0001.parquet")).stream(); + testBaseFileStream = Stream.of(new HoodieBaseFile("test")); + testFileSliceStream = Stream.of(new FileSlice("2020-01-01", "20:20", "file0001.parquet")); } private void resetMocks() { reset(primary, secondary); } - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test public void testGetLatestBaseFiles() { Stream<HoodieBaseFile> actual; @@ -105,8 +95,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestBaseFiles()).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestBaseFiles(); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestBaseFiles(); + }); } @Test @@ -132,8 +123,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestBaseFiles(partitionPath)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestBaseFiles(partitionPath); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestBaseFiles(partitionPath); + }); } @Test @@ -165,8 +157,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestBaseFilesBeforeOrOn(partitionPath, maxCommitTime)) .thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestBaseFilesBeforeOrOn(partitionPath, maxCommitTime); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestBaseFilesBeforeOrOn(partitionPath, maxCommitTime); + }); } @Test @@ -193,8 +186,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestBaseFile(partitionPath, fileID)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestBaseFile(partitionPath, fileID); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestBaseFile(partitionPath, fileID); + }); } @Test @@ -224,8 +218,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getBaseFileOn(partitionPath, instantTime, fileID)) .thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getBaseFileOn(partitionPath, instantTime, fileID); + assertThrows(RuntimeException.class, () -> { + fsView.getBaseFileOn(partitionPath, instantTime, fileID); + }); } @Test @@ -251,8 +246,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestBaseFilesInRange(commitsToReturn)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestBaseFilesInRange(commitsToReturn); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestBaseFilesInRange(commitsToReturn); + }); } @Test @@ -278,8 +274,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getAllBaseFiles(partitionPath)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getAllBaseFiles(partitionPath); + assertThrows(RuntimeException.class, () -> { + fsView.getAllBaseFiles(partitionPath); + }); } @Test @@ -305,8 +302,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestFileSlices(partitionPath)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestFileSlices(partitionPath); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestFileSlices(partitionPath); + }); } @Test @@ -332,8 +330,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestUnCompactedFileSlices(partitionPath)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestUnCompactedFileSlices(partitionPath); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestUnCompactedFileSlices(partitionPath); + }); } @Test @@ -365,8 +364,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestFileSlicesBeforeOrOn(partitionPath, maxCommitTime, false)) .thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestFileSlicesBeforeOrOn(partitionPath, maxCommitTime, false); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestFileSlicesBeforeOrOn(partitionPath, maxCommitTime, false); + }); } @Test @@ -398,8 +398,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestMergedFileSlicesBeforeOrOn(partitionPath, maxInstantTime)) .thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestMergedFileSlicesBeforeOrOn(partitionPath, maxInstantTime); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestMergedFileSlicesBeforeOrOn(partitionPath, maxInstantTime); + }); } @Test @@ -425,8 +426,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestFileSliceInRange(commitsToReturn)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestFileSliceInRange(commitsToReturn); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestFileSliceInRange(commitsToReturn); + }); } @Test @@ -452,8 +454,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getAllFileSlices(partitionPath)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getAllFileSlices(partitionPath); + assertThrows(RuntimeException.class, () -> { + fsView.getAllFileSlices(partitionPath); + }); } @Test @@ -481,8 +484,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getAllFileGroups(partitionPath)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getAllFileGroups(partitionPath); + assertThrows(RuntimeException.class, () -> { + fsView.getAllFileGroups(partitionPath); + }); } @Test @@ -509,8 +513,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getPendingCompactionOperations()).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getPendingCompactionOperations(); + assertThrows(RuntimeException.class, () -> { + fsView.getPendingCompactionOperations(); + }); } @Test @@ -549,8 +554,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLastInstant()).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLastInstant(); + assertThrows(RuntimeException.class, () -> { + fsView.getLastInstant(); + }); } @Test @@ -575,8 +581,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getTimeline()).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getTimeline(); + assertThrows(RuntimeException.class, () -> { + fsView.getTimeline(); + }); } @Test @@ -610,8 +617,9 @@ public class TestPriorityBasedFileSystemView extends TestCase { resetMocks(); when(secondary.getLatestFileSlice(partitionPath, fileID)).thenThrow(new RuntimeException()); - thrown.expect(RuntimeException.class); - fsView.getLatestFileSlice(partitionPath, fileID); + assertThrows(RuntimeException.class, () -> { + fsView.getLatestFileSlice(partitionPath, fileID); + }); } @Test @@ -623,4 +631,4 @@ public class TestPriorityBasedFileSystemView extends TestCase { public void testGetSecondaryView() { assertEquals(secondary, fsView.getSecondaryView()); } -} \ No newline at end of file +} diff --git a/hudi-hadoop-mr/pom.xml b/hudi-hadoop-mr/pom.xml index 8983ca5..a77932c 100644 --- a/hudi-hadoop-mr/pom.xml +++ b/hudi-hadoop-mr/pom.xml @@ -128,7 +128,7 @@ <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/hudi-hadoop-mr/src/test/java/org/apache/hudi/hadoop/realtime/TestHoodieRealtimeFileSplit.java b/hudi-hadoop-mr/src/test/java/org/apache/hudi/hadoop/realtime/TestHoodieRealtimeFileSplit.java index cab1e66..4e0adb0 100644 --- a/hudi-hadoop-mr/src/test/java/org/apache/hudi/hadoop/realtime/TestHoodieRealtimeFileSplit.java +++ b/hudi-hadoop-mr/src/test/java/org/apache/hudi/hadoop/realtime/TestHoodieRealtimeFileSplit.java @@ -21,12 +21,13 @@ package org.apache.hudi.hadoop.realtime; import org.apache.hadoop.fs.Path; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapred.FileSplit; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; import org.mockito.InOrder; import org.mockito.invocation.InvocationOnMock; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; import java.io.DataInput; @@ -36,11 +37,10 @@ import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.AdditionalMatchers.aryEq; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyByte; -import static org.mockito.Matchers.anyInt; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.eq; @@ -49,6 +49,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) public class TestHoodieRealtimeFileSplit { private HoodieRealtimeFileSplit split; @@ -57,27 +58,18 @@ public class TestHoodieRealtimeFileSplit { private String fileSplitName; private FileSplit baseFileSplit; private String maxCommitTime; - private TemporaryFolder tmp; - @Before - public void setUp() throws Exception { - tmp = new TemporaryFolder(); - tmp.create(); - - basePath = tmp.getRoot().toString(); + @BeforeEach + public void setUp(@TempDir java.nio.file.Path tempDir) throws Exception { + basePath = tempDir.toAbsolutePath().toString(); deltaLogPaths = Collections.singletonList(basePath + "/1.log"); fileSplitName = basePath + "/test.file"; - baseFileSplit = new FileSplit(new Path(fileSplitName), 0, 100, new String[]{}); + baseFileSplit = new FileSplit(new Path(fileSplitName), 0, 100, new String[] {}); maxCommitTime = "10001"; split = new HoodieRealtimeFileSplit(baseFileSplit, basePath, deltaLogPaths, maxCommitTime); } - @After - public void tearDown() throws Exception { - tmp.delete(); - } - @Test public void testWrite() throws IOException { // create a mock for DataOutput that will be used in the write method @@ -86,7 +78,7 @@ public class TestHoodieRealtimeFileSplit { // register expected method calls for void functions // so that we can verify what was called after the method call finishes - doNothing().when(out).writeByte(anyByte()); + doNothing().when(out).writeByte(anyInt()); doNothing().when(out).writeInt(anyInt()); doNothing().when(out).write(any(byte[].class), anyInt(), anyInt()); doNothing().when(out).write(any(byte[].class)); @@ -140,7 +132,7 @@ public class TestHoodieRealtimeFileSplit { @Override public Void answer(InvocationOnMock invocation) throws Throwable { - byte[] bytes = invocation.getArgumentAt(0, byte[].class); + byte[] bytes = invocation.getArgument(0); byte[] answer = answers[count++]; System.arraycopy(answer, 0, bytes, 0, answer.length); return null; @@ -159,4 +151,4 @@ public class TestHoodieRealtimeFileSplit { assertEquals(deltaLogPaths, read.getDeltaLogPaths()); assertEquals(split.toString(), read.toString()); } -} \ No newline at end of file +} diff --git a/hudi-hive-sync/pom.xml b/hudi-hive-sync/pom.xml index 3b13915..973cb3e 100644 --- a/hudi-hive-sync/pom.xml +++ b/hudi-hive-sync/pom.xml @@ -167,7 +167,7 @@ <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> diff --git a/hudi-spark/pom.xml b/hudi-spark/pom.xml index 49e883c..9bd07c0 100644 --- a/hudi-spark/pom.xml +++ b/hudi-spark/pom.xml @@ -340,7 +340,7 @@ <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> diff --git a/hudi-timeline-service/pom.xml b/hudi-timeline-service/pom.xml index 81323dd..7ab3bcd 100644 --- a/hudi-timeline-service/pom.xml +++ b/hudi-timeline-service/pom.xml @@ -209,7 +209,7 @@ <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> diff --git a/hudi-utilities/pom.xml b/hudi-utilities/pom.xml index 827a056..9c63cad 100644 --- a/hudi-utilities/pom.xml +++ b/hudi-utilities/pom.xml @@ -389,7 +389,7 @@ <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/pom.xml b/pom.xml index e725b74..ecfd356 100644 --- a/pom.xml +++ b/pom.xml @@ -85,7 +85,7 @@ <junit.version>4.12</junit.version> <junit.jupiter.version>5.6.1</junit.jupiter.version> <junit.vintage.version>5.6.1</junit.vintage.version> - <mockito.version>1.10.19</mockito.version> + <mockito.jupiter.version>3.3.3</mockito.jupiter.version> <log4j.version>1.2.17</log4j.version> <slf4j.version>1.7.5</slf4j.version> <joda.version>2.9.9</joda.version> @@ -852,9 +852,9 @@ <dependency> <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> + <artifactId>mockito-junit-jupiter</artifactId> <scope>test</scope> - <version>${mockito.version}</version> + <version>${mockito.jupiter.version}</version> </dependency> <dependency>