[MINOR] Some unit test code optimize (#2782)
* Optimized code * Optimized code
This commit is contained in:
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -36,8 +37,8 @@ public class TestConcatenatingIterator {
|
|||||||
@Test
|
@Test
|
||||||
public void testConcatBasic() {
|
public void testConcatBasic() {
|
||||||
Iterator<Integer> i1 = Arrays.asList(5, 3, 2, 1).iterator();
|
Iterator<Integer> i1 = Arrays.asList(5, 3, 2, 1).iterator();
|
||||||
Iterator<Integer> i2 = new ArrayList<Integer>().iterator(); // empty iterator
|
Iterator<Integer> i2 = Collections.emptyIterator(); // empty iterator
|
||||||
Iterator<Integer> i3 = Arrays.asList(3).iterator();
|
Iterator<Integer> i3 = Collections.singletonList(3).iterator();
|
||||||
|
|
||||||
ConcatenatingIterator<Integer> ci = new ConcatenatingIterator<>(Arrays.asList(i1, i2, i3));
|
ConcatenatingIterator<Integer> ci = new ConcatenatingIterator<>(Arrays.asList(i1, i2, i3));
|
||||||
List<Integer> allElements = new ArrayList<>();
|
List<Integer> allElements = new ArrayList<>();
|
||||||
@@ -51,9 +52,9 @@ public class TestConcatenatingIterator {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConcatError() {
|
public void testConcatError() {
|
||||||
Iterator<Integer> i1 = new ArrayList<Integer>().iterator(); // empty iterator
|
Iterator<Integer> i1 = Collections.emptyIterator(); // empty iterator
|
||||||
|
|
||||||
ConcatenatingIterator<Integer> ci = new ConcatenatingIterator<>(Arrays.asList(i1));
|
ConcatenatingIterator<Integer> ci = new ConcatenatingIterator<>(Collections.singletonList(i1));
|
||||||
assertFalse(ci.hasNext());
|
assertFalse(ci.hasNext());
|
||||||
try {
|
try {
|
||||||
ci.next();
|
ci.next();
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package org.apache.hudi.integ.testsuite.converter;
|
|||||||
import static junit.framework.TestCase.assertTrue;
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ public class TestUpdateConverter {
|
|||||||
|
|
||||||
// 2. DFS converter reads existing records and generates random updates for the same row keys
|
// 2. DFS converter reads existing records and generates random updates for the same row keys
|
||||||
UpdateConverter updateConverter = new UpdateConverter(schemaStr, minPayloadSize,
|
UpdateConverter updateConverter = new UpdateConverter(schemaStr, minPayloadSize,
|
||||||
Arrays.asList("timestamp"), Arrays.asList("_row_key"));
|
Collections.singletonList("timestamp"), Collections.singletonList("_row_key"));
|
||||||
List<String> insertRowKeys = inputRDD.map(r -> r.get("_row_key").toString()).collect();
|
List<String> insertRowKeys = inputRDD.map(r -> r.get("_row_key").toString()).collect();
|
||||||
assertTrue(inputRDD.count() == 10);
|
assertTrue(inputRDD.count() == 10);
|
||||||
JavaRDD<GenericRecord> outputRDD = updateConverter.convert(inputRDD);
|
JavaRDD<GenericRecord> outputRDD = updateConverter.convert(inputRDD);
|
||||||
@@ -75,7 +76,7 @@ public class TestUpdateConverter {
|
|||||||
Map<String, GenericRecord> inputRecords = inputRDD.mapToPair(r -> new Tuple2<>(r.get("_row_key").toString(), r))
|
Map<String, GenericRecord> inputRecords = inputRDD.mapToPair(r -> new Tuple2<>(r.get("_row_key").toString(), r))
|
||||||
.collectAsMap();
|
.collectAsMap();
|
||||||
List<GenericRecord> updateRecords = outputRDD.collect();
|
List<GenericRecord> updateRecords = outputRDD.collect();
|
||||||
updateRecords.stream().forEach(updateRecord -> {
|
updateRecords.forEach(updateRecord -> {
|
||||||
GenericRecord inputRecord = inputRecords.get(updateRecord.get("_row_key").toString());
|
GenericRecord inputRecord = inputRecords.get(updateRecord.get("_row_key").toString());
|
||||||
assertTrue(areRecordsDifferent(inputRecord, updateRecord));
|
assertTrue(areRecordsDifferent(inputRecord, updateRecord));
|
||||||
});
|
});
|
||||||
@@ -87,11 +88,11 @@ public class TestUpdateConverter {
|
|||||||
*/
|
*/
|
||||||
private boolean areRecordsDifferent(GenericRecord in, GenericRecord up) {
|
private boolean areRecordsDifferent(GenericRecord in, GenericRecord up) {
|
||||||
for (Field field : in.getSchema().getFields()) {
|
for (Field field : in.getSchema().getFields()) {
|
||||||
if (field.name() == "_row_key") {
|
if (field.name().equals("_row_key")) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
// Just convert all types to string for now since all are primitive
|
// Just convert all types to string for now since all are primitive
|
||||||
if (in.get(field.name()).toString() != up.get(field.name()).toString()) {
|
if (!in.get(field.name()).toString().equals(up.get(field.name()).toString())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user