[HUDI-798] Migrate to Mockito Jupiter for JUnit 5 (#1521)
This commit is contained in:
@@ -276,7 +276,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -265,7 +265,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -340,7 +340,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -389,7 +389,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
6
pom.xml
6
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>
|
||||
|
||||
Reference in New Issue
Block a user