1
0

[HUDI-798] Migrate to Mockito Jupiter for JUnit 5 (#1521)

This commit is contained in:
Raymond Xu
2020-04-16 01:07:32 -07:00
committed by GitHub
parent 19d29ac7d0
commit acdc4a8d00
15 changed files with 135 additions and 135 deletions

View File

@@ -276,7 +276,7 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -265,7 +265,7 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -20,11 +20,11 @@ package org.apache.hudi.client;
import org.apache.hudi.common.model.HoodieRecord; import org.apache.hudi.common.model.HoodieRecord;
import org.junit.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
public class TestWriteStatus { public class TestWriteStatus {
@Test @Test
@@ -32,7 +32,7 @@ public class TestWriteStatus {
WriteStatus status = new WriteStatus(true, 0.1); WriteStatus status = new WriteStatus(true, 0.1);
Throwable t = new Exception("some error in writing"); Throwable t = new Exception("some error in writing");
for (int i = 0; i < 1000; i++) { 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() > 0);
assertTrue(status.getFailedRecords().size() < 150); // 150 instead of 100, to prevent flaky test 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); WriteStatus status = new WriteStatus(false, 1.0);
Throwable t = new Exception("some error in writing"); Throwable t = new Exception("some error in writing");
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
status.markSuccess(Mockito.mock(HoodieRecord.class), null); status.markSuccess(mock(HoodieRecord.class), null);
status.markFailure(Mockito.mock(HoodieRecord.class), t, null); status.markFailure(mock(HoodieRecord.class), t, null);
} }
assertEquals(1000, status.getFailedRecords().size()); assertEquals(1000, status.getFailedRecords().size());
assertTrue(status.hasErrors()); assertTrue(status.hasErrors());

View File

@@ -21,11 +21,14 @@ package org.apache.hudi.client.utils;
import org.apache.hudi.exception.HoodieIOException; import org.apache.hudi.exception.HoodieIOException;
import org.apache.parquet.hadoop.ParquetReader; import org.apache.parquet.hadoop.ParquetReader;
import org.junit.Assert; import org.junit.jupiter.api.Test;
import org.junit.Test;
import java.io.IOException; 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.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -40,7 +43,7 @@ public class TestParquetReaderIterator {
int idempotencyCheckCounter = 0; int idempotencyCheckCounter = 0;
// call hasNext() 3 times // call hasNext() 3 times
while (idempotencyCheckCounter < 3) { while (idempotencyCheckCounter < 3) {
Assert.assertTrue(iterator.hasNext()); assertTrue(iterator.hasNext());
idempotencyCheckCounter++; idempotencyCheckCounter++;
} }
} }
@@ -53,13 +56,9 @@ public class TestParquetReaderIterator {
when(reader.read()).thenReturn(1).thenReturn(null); when(reader.read()).thenReturn(1).thenReturn(null);
ParquetReaderIterator<Integer> iterator = new ParquetReaderIterator<>(reader); ParquetReaderIterator<Integer> iterator = new ParquetReaderIterator<>(reader);
// should return value even though hasNext() hasn't been called // 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 // no more entries to iterate on
Assert.assertFalse(iterator.hasNext()); assertFalse(iterator.hasNext());
try { assertThrows(HoodieIOException.class, iterator::next, "should throw an exception since there is only 1 record");
iterator.next();
} catch (HoodieIOException e) {
// should throw an exception since there is only 1 record
}
} }
} }

View File

@@ -52,7 +52,6 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.spark.api.java.JavaRDD; import org.apache.spark.api.java.JavaRDD;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.FixMethodOrder; 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.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; 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.atMost;
import static org.mockito.Mockito.times; 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, * 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 // Mock hbaseConnection and related entities
Connection hbaseConnection = Mockito.mock(Connection.class); Connection hbaseConnection = Mockito.mock(Connection.class);
HTable table = Mockito.mock(HTable.class); HTable table = Mockito.mock(HTable.class);
Mockito.when(hbaseConnection.getTable(TableName.valueOf(tableName))).thenReturn(table); when(hbaseConnection.getTable(TableName.valueOf(tableName))).thenReturn(table);
Mockito.when(table.get((List<Get>) anyObject())).thenReturn(new Result[0]); when(table.get((List<Get>) any())).thenReturn(new Result[0]);
// only for test, set the hbaseConnection to mocked object // only for test, set the hbaseConnection to mocked object
index.setHbaseConnection(hbaseConnection); index.setHbaseConnection(hbaseConnection);
@@ -281,7 +282,7 @@ public class TestHbaseIndex extends HoodieClientTestHarness {
index.tagLocation(writeRecords, jsc, hoodieTable); index.tagLocation(writeRecords, jsc, hoodieTable);
// 3 batches should be executed given batchSize = 100 and parallelism = 1 // 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 // Mock hbaseConnection and related entities
Connection hbaseConnection = Mockito.mock(Connection.class); Connection hbaseConnection = Mockito.mock(Connection.class);
HTable table = Mockito.mock(HTable.class); HTable table = Mockito.mock(HTable.class);
Mockito.when(hbaseConnection.getTable(TableName.valueOf(tableName))).thenReturn(table); when(hbaseConnection.getTable(TableName.valueOf(tableName))).thenReturn(table);
Mockito.when(table.get((List<Get>) anyObject())).thenReturn(new Result[0]); when(table.get((List<Get>) any())).thenReturn(new Result[0]);
// only for test, set the hbaseConnection to mocked object // only for test, set the hbaseConnection to mocked object
index.setHbaseConnection(hbaseConnection); index.setHbaseConnection(hbaseConnection);
@@ -319,7 +320,7 @@ public class TestHbaseIndex extends HoodieClientTestHarness {
index.updateLocation(writeStatues, jsc, hoodieTable); index.updateLocation(writeStatues, jsc, hoodieTable);
// 3 batches should be executed given batchSize = 100 and <=numberOfDataFileIds getting updated, // 3 batches should be executed given batchSize = 100 and <=numberOfDataFileIds getting updated,
// so each fileId ideally gets updates // so each fileId ideally gets updates
Mockito.verify(table, atMost(numberOfDataFileIds)).put((List<Put>) anyObject()); verify(table, atMost(numberOfDataFileIds)).put((List<Put>) any());
} }
@Test @Test
@@ -334,28 +335,28 @@ public class TestHbaseIndex extends HoodieClientTestHarness {
// 8 (batchSize) * 200 (parallelism) * 10 (maxReqsInOneSecond) * 10 (numRegionServers) * 0.1 (qpsFraction)) => 16000 // 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 // 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. // 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 // 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); 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 // If the parallelism is halved, batchSize has to double
int putBatchSize3 = batchSizeCalculator.getBatchSize(10, 16667, 1200, 100, 100, 0.1f); 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. // If the parallelism is halved, batchSize has to double.
// This time parallelism is driven by numTasks rather than numExecutors // This time parallelism is driven by numTasks rather than numExecutors
int putBatchSize4 = batchSizeCalculator.getBatchSize(10, 16667, 100, 200, 100, 0.1f); 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 // If sleepTimeMs is halved, batchSize has to halve
int putBatchSize5 = batchSizeCalculator.getBatchSize(10, 16667, 1200, 200, 100, 0.05f); 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 // If maxQPSPerRegionServer is doubled, batchSize also doubles
int putBatchSize6 = batchSizeCalculator.getBatchSize(10, 33334, 1200, 200, 100, 0.1f); int putBatchSize6 = batchSizeCalculator.getBatchSize(10, 33334, 1200, 200, 100, 0.1f);
Assert.assertEquals(putBatchSize6, 16); assertEquals(putBatchSize6, 16);
} }
@Test @Test
@@ -367,9 +368,9 @@ public class TestHbaseIndex extends HoodieClientTestHarness {
final Tuple2<Long, Integer> tuple = index.getHBasePutAccessParallelism(writeStatusRDD); final Tuple2<Long, Integer> tuple = index.getHBasePutAccessParallelism(writeStatusRDD);
final int hbasePutAccessParallelism = Integer.parseInt(tuple._2.toString()); final int hbasePutAccessParallelism = Integer.parseInt(tuple._2.toString());
final int hbaseNumPuts = Integer.parseInt(tuple._1.toString()); final int hbaseNumPuts = Integer.parseInt(tuple._1.toString());
Assert.assertEquals(10, writeStatusRDD.getNumPartitions()); assertEquals(10, writeStatusRDD.getNumPartitions());
Assert.assertEquals(2, hbasePutAccessParallelism); assertEquals(2, hbasePutAccessParallelism);
Assert.assertEquals(11, hbaseNumPuts); assertEquals(11, hbaseNumPuts);
} }
@Test @Test
@@ -381,9 +382,9 @@ public class TestHbaseIndex extends HoodieClientTestHarness {
final Tuple2<Long, Integer> tuple = index.getHBasePutAccessParallelism(writeStatusRDD); final Tuple2<Long, Integer> tuple = index.getHBasePutAccessParallelism(writeStatusRDD);
final int hbasePutAccessParallelism = Integer.parseInt(tuple._2.toString()); final int hbasePutAccessParallelism = Integer.parseInt(tuple._2.toString());
final int hbaseNumPuts = Integer.parseInt(tuple._1.toString()); final int hbaseNumPuts = Integer.parseInt(tuple._1.toString());
Assert.assertEquals(10, writeStatusRDD.getNumPartitions()); assertEquals(10, writeStatusRDD.getNumPartitions());
Assert.assertEquals(0, hbasePutAccessParallelism); assertEquals(0, hbasePutAccessParallelism);
Assert.assertEquals(0, hbaseNumPuts); assertEquals(0, hbaseNumPuts);
} }
@Test @Test
@@ -391,9 +392,9 @@ public class TestHbaseIndex extends HoodieClientTestHarness {
HoodieWriteConfig config = getConfig(); HoodieWriteConfig config = getConfig();
HBaseIndex index = new HBaseIndex(config); HBaseIndex index = new HBaseIndex(config);
HBaseIndexQPSResourceAllocator hBaseIndexQPSResourceAllocator = index.createQPSResourceAllocator(config); HBaseIndexQPSResourceAllocator hBaseIndexQPSResourceAllocator = index.createQPSResourceAllocator(config);
Assert.assertEquals(hBaseIndexQPSResourceAllocator.getClass().getName(), assertEquals(hBaseIndexQPSResourceAllocator.getClass().getName(),
DefaultHBaseQPSResourceAllocator.class.getName()); DefaultHBaseQPSResourceAllocator.class.getName());
Assert.assertEquals(config.getHbaseIndexQPSFraction(), assertEquals(config.getHbaseIndexQPSFraction(),
hBaseIndexQPSResourceAllocator.acquireQPSResources(config.getHbaseIndexQPSFraction(), 100), 0.0f); hBaseIndexQPSResourceAllocator.acquireQPSResources(config.getHbaseIndexQPSFraction(), 100), 0.0f);
} }

View File

@@ -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.table.timeline.HoodieTimeline;
import org.apache.hudi.common.util.Option; import org.apache.hudi.common.util.Option;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; 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.common.model.HoodieTestUtils.generateFakeHoodieWriteStat;
import static org.apache.hudi.table.HoodieCopyOnWriteTable.averageBytesPerRecord; import static org.apache.hudi.table.HoodieCopyOnWriteTable.averageBytesPerRecord;
import static org.junit.Assert.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;

View File

@@ -179,7 +179,7 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@@ -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.ImmutablePair;
import org.apache.hudi.common.util.collection.Pair; import org.apache.hudi.common.util.collection.Pair;
import junit.framework.TestCase; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Rule; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit; import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.MockitoRule;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Stream; 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.reset;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class) @ExtendWith(MockitoExtension.class)
public class TestPriorityBasedFileSystemView extends TestCase { public class TestPriorityBasedFileSystemView {
@Mock @Mock
private SyncableFileSystemView primary; private SyncableFileSystemView primary;
@@ -62,27 +59,20 @@ public class TestPriorityBasedFileSystemView extends TestCase {
@InjectMocks @InjectMocks
private PriorityBasedFileSystemView fsView; private PriorityBasedFileSystemView fsView;
@Rule
public MockitoRule rule = MockitoJUnit.rule();
private Stream<HoodieBaseFile> testBaseFileStream; private Stream<HoodieBaseFile> testBaseFileStream;
private Stream<FileSlice> testFileSliceStream; private Stream<FileSlice> testFileSliceStream;
@Before @BeforeEach
public void setUp() { public void setUp() {
fsView = new PriorityBasedFileSystemView(primary, secondary); fsView = new PriorityBasedFileSystemView(primary, secondary);
testBaseFileStream = Collections.singleton(new HoodieBaseFile("test")).stream(); testBaseFileStream = Stream.of(new HoodieBaseFile("test"));
testFileSliceStream = Collections testFileSliceStream = Stream.of(new FileSlice("2020-01-01", "20:20", "file0001.parquet"));
.singleton(new FileSlice("2020-01-01", "20:20", "file0001.parquet")).stream();
} }
private void resetMocks() { private void resetMocks() {
reset(primary, secondary); reset(primary, secondary);
} }
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testGetLatestBaseFiles() { public void testGetLatestBaseFiles() {
Stream<HoodieBaseFile> actual; Stream<HoodieBaseFile> actual;
@@ -105,8 +95,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestBaseFiles()).thenThrow(new RuntimeException()); when(secondary.getLatestBaseFiles()).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestBaseFiles(); fsView.getLatestBaseFiles();
});
} }
@Test @Test
@@ -132,8 +123,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestBaseFiles(partitionPath)).thenThrow(new RuntimeException()); when(secondary.getLatestBaseFiles(partitionPath)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestBaseFiles(partitionPath); fsView.getLatestBaseFiles(partitionPath);
});
} }
@Test @Test
@@ -165,8 +157,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestBaseFilesBeforeOrOn(partitionPath, maxCommitTime)) when(secondary.getLatestBaseFilesBeforeOrOn(partitionPath, maxCommitTime))
.thenThrow(new RuntimeException()); .thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestBaseFilesBeforeOrOn(partitionPath, maxCommitTime); fsView.getLatestBaseFilesBeforeOrOn(partitionPath, maxCommitTime);
});
} }
@Test @Test
@@ -193,8 +186,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestBaseFile(partitionPath, fileID)).thenThrow(new RuntimeException()); when(secondary.getLatestBaseFile(partitionPath, fileID)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestBaseFile(partitionPath, fileID); fsView.getLatestBaseFile(partitionPath, fileID);
});
} }
@Test @Test
@@ -224,8 +218,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getBaseFileOn(partitionPath, instantTime, fileID)) when(secondary.getBaseFileOn(partitionPath, instantTime, fileID))
.thenThrow(new RuntimeException()); .thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getBaseFileOn(partitionPath, instantTime, fileID); fsView.getBaseFileOn(partitionPath, instantTime, fileID);
});
} }
@Test @Test
@@ -251,8 +246,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestBaseFilesInRange(commitsToReturn)).thenThrow(new RuntimeException()); when(secondary.getLatestBaseFilesInRange(commitsToReturn)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestBaseFilesInRange(commitsToReturn); fsView.getLatestBaseFilesInRange(commitsToReturn);
});
} }
@Test @Test
@@ -278,8 +274,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getAllBaseFiles(partitionPath)).thenThrow(new RuntimeException()); when(secondary.getAllBaseFiles(partitionPath)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getAllBaseFiles(partitionPath); fsView.getAllBaseFiles(partitionPath);
});
} }
@Test @Test
@@ -305,8 +302,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestFileSlices(partitionPath)).thenThrow(new RuntimeException()); when(secondary.getLatestFileSlices(partitionPath)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestFileSlices(partitionPath); fsView.getLatestFileSlices(partitionPath);
});
} }
@Test @Test
@@ -332,8 +330,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestUnCompactedFileSlices(partitionPath)).thenThrow(new RuntimeException()); when(secondary.getLatestUnCompactedFileSlices(partitionPath)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestUnCompactedFileSlices(partitionPath); fsView.getLatestUnCompactedFileSlices(partitionPath);
});
} }
@Test @Test
@@ -365,8 +364,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestFileSlicesBeforeOrOn(partitionPath, maxCommitTime, false)) when(secondary.getLatestFileSlicesBeforeOrOn(partitionPath, maxCommitTime, false))
.thenThrow(new RuntimeException()); .thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestFileSlicesBeforeOrOn(partitionPath, maxCommitTime, false); fsView.getLatestFileSlicesBeforeOrOn(partitionPath, maxCommitTime, false);
});
} }
@Test @Test
@@ -398,8 +398,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestMergedFileSlicesBeforeOrOn(partitionPath, maxInstantTime)) when(secondary.getLatestMergedFileSlicesBeforeOrOn(partitionPath, maxInstantTime))
.thenThrow(new RuntimeException()); .thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestMergedFileSlicesBeforeOrOn(partitionPath, maxInstantTime); fsView.getLatestMergedFileSlicesBeforeOrOn(partitionPath, maxInstantTime);
});
} }
@Test @Test
@@ -425,8 +426,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestFileSliceInRange(commitsToReturn)).thenThrow(new RuntimeException()); when(secondary.getLatestFileSliceInRange(commitsToReturn)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestFileSliceInRange(commitsToReturn); fsView.getLatestFileSliceInRange(commitsToReturn);
});
} }
@Test @Test
@@ -452,8 +454,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getAllFileSlices(partitionPath)).thenThrow(new RuntimeException()); when(secondary.getAllFileSlices(partitionPath)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getAllFileSlices(partitionPath); fsView.getAllFileSlices(partitionPath);
});
} }
@Test @Test
@@ -481,8 +484,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getAllFileGroups(partitionPath)).thenThrow(new RuntimeException()); when(secondary.getAllFileGroups(partitionPath)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getAllFileGroups(partitionPath); fsView.getAllFileGroups(partitionPath);
});
} }
@Test @Test
@@ -509,8 +513,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getPendingCompactionOperations()).thenThrow(new RuntimeException()); when(secondary.getPendingCompactionOperations()).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getPendingCompactionOperations(); fsView.getPendingCompactionOperations();
});
} }
@Test @Test
@@ -549,8 +554,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLastInstant()).thenThrow(new RuntimeException()); when(secondary.getLastInstant()).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLastInstant(); fsView.getLastInstant();
});
} }
@Test @Test
@@ -575,8 +581,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getTimeline()).thenThrow(new RuntimeException()); when(secondary.getTimeline()).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getTimeline(); fsView.getTimeline();
});
} }
@Test @Test
@@ -610,8 +617,9 @@ public class TestPriorityBasedFileSystemView extends TestCase {
resetMocks(); resetMocks();
when(secondary.getLatestFileSlice(partitionPath, fileID)).thenThrow(new RuntimeException()); when(secondary.getLatestFileSlice(partitionPath, fileID)).thenThrow(new RuntimeException());
thrown.expect(RuntimeException.class); assertThrows(RuntimeException.class, () -> {
fsView.getLatestFileSlice(partitionPath, fileID); fsView.getLatestFileSlice(partitionPath, fileID);
});
} }
@Test @Test
@@ -623,4 +631,4 @@ public class TestPriorityBasedFileSystemView extends TestCase {
public void testGetSecondaryView() { public void testGetSecondaryView() {
assertEquals(secondary, fsView.getSecondaryView()); assertEquals(secondary, fsView.getSecondaryView());
} }
} }

View File

@@ -128,7 +128,7 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -21,12 +21,13 @@ package org.apache.hudi.hadoop.realtime;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileSplit; import org.apache.hadoop.mapred.FileSplit;
import org.junit.After; import org.junit.jupiter.api.BeforeEach;
import org.junit.Before; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.rules.TemporaryFolder; import org.junit.jupiter.api.io.TempDir;
import org.mockito.InOrder; import org.mockito.InOrder;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import java.io.DataInput; import java.io.DataInput;
@@ -36,11 +37,10 @@ import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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.AdditionalMatchers.aryEq;
import static org.mockito.Matchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyByte; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.eq; 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.times;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class TestHoodieRealtimeFileSplit { public class TestHoodieRealtimeFileSplit {
private HoodieRealtimeFileSplit split; private HoodieRealtimeFileSplit split;
@@ -57,27 +58,18 @@ public class TestHoodieRealtimeFileSplit {
private String fileSplitName; private String fileSplitName;
private FileSplit baseFileSplit; private FileSplit baseFileSplit;
private String maxCommitTime; private String maxCommitTime;
private TemporaryFolder tmp;
@Before @BeforeEach
public void setUp() throws Exception { public void setUp(@TempDir java.nio.file.Path tempDir) throws Exception {
tmp = new TemporaryFolder(); basePath = tempDir.toAbsolutePath().toString();
tmp.create();
basePath = tmp.getRoot().toString();
deltaLogPaths = Collections.singletonList(basePath + "/1.log"); deltaLogPaths = Collections.singletonList(basePath + "/1.log");
fileSplitName = basePath + "/test.file"; 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"; maxCommitTime = "10001";
split = new HoodieRealtimeFileSplit(baseFileSplit, basePath, deltaLogPaths, maxCommitTime); split = new HoodieRealtimeFileSplit(baseFileSplit, basePath, deltaLogPaths, maxCommitTime);
} }
@After
public void tearDown() throws Exception {
tmp.delete();
}
@Test @Test
public void testWrite() throws IOException { public void testWrite() throws IOException {
// create a mock for DataOutput that will be used in the write method // 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 // register expected method calls for void functions
// so that we can verify what was called after the method call finishes // 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).writeInt(anyInt());
doNothing().when(out).write(any(byte[].class), anyInt(), anyInt()); doNothing().when(out).write(any(byte[].class), anyInt(), anyInt());
doNothing().when(out).write(any(byte[].class)); doNothing().when(out).write(any(byte[].class));
@@ -140,7 +132,7 @@ public class TestHoodieRealtimeFileSplit {
@Override @Override
public Void answer(InvocationOnMock invocation) throws Throwable { public Void answer(InvocationOnMock invocation) throws Throwable {
byte[] bytes = invocation.getArgumentAt(0, byte[].class); byte[] bytes = invocation.getArgument(0);
byte[] answer = answers[count++]; byte[] answer = answers[count++];
System.arraycopy(answer, 0, bytes, 0, answer.length); System.arraycopy(answer, 0, bytes, 0, answer.length);
return null; return null;
@@ -159,4 +151,4 @@ public class TestHoodieRealtimeFileSplit {
assertEquals(deltaLogPaths, read.getDeltaLogPaths()); assertEquals(deltaLogPaths, read.getDeltaLogPaths());
assertEquals(split.toString(), read.toString()); assertEquals(split.toString(), read.toString());
} }
} }

View File

@@ -167,7 +167,7 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@@ -340,7 +340,7 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@@ -209,7 +209,7 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>

View File

@@ -389,7 +389,7 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@@ -85,7 +85,7 @@
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
<junit.jupiter.version>5.6.1</junit.jupiter.version> <junit.jupiter.version>5.6.1</junit.jupiter.version>
<junit.vintage.version>5.6.1</junit.vintage.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> <log4j.version>1.2.17</log4j.version>
<slf4j.version>1.7.5</slf4j.version> <slf4j.version>1.7.5</slf4j.version>
<joda.version>2.9.9</joda.version> <joda.version>2.9.9</joda.version>
@@ -852,9 +852,9 @@
<dependency> <dependency>
<groupId>org.mockito</groupId> <groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId> <artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope> <scope>test</scope>
<version>${mockito.version}</version> <version>${mockito.jupiter.version}</version>
</dependency> </dependency>
<dependency> <dependency>