[HUDI-798] Migrate to Mockito Jupiter for JUnit 5 (#1521)
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user