Skip to content

Commit e900152

Browse files
committed
Add test for empty iterator in UnsafeSorter
1 parent 57a4ea0 commit e900152

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

core/src/test/java/org/apache/spark/unsafe/sort/UnsafeSorterSuite.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import org.junit.Assert;
2424
import org.junit.Test;
25+
import static org.mockito.Mockito.*;
2526

2627
import org.apache.spark.HashPartitioner;
2728
import org.apache.spark.unsafe.PlatformDependent;
@@ -43,6 +44,18 @@ private static String getStringFromDataPage(Object baseObject, long baseOffset)
4344
return new String(strBytes);
4445
}
4546

47+
@Test
48+
public void testSortingEmptyInput() {
49+
final UnsafeSorter sorter = new UnsafeSorter(
50+
new TaskMemoryManager(new ExecutorMemoryManager(MemoryAllocator.HEAP)),
51+
mock(UnsafeSorter.RecordComparator.class),
52+
mock(UnsafeSorter.PrefixComputer.class),
53+
mock(UnsafeSorter.PrefixComparator.class),
54+
100);
55+
final Iterator<UnsafeSorter.KeyPointerAndPrefix> iter = sorter.getSortedIterator();
56+
assert(!iter.hasNext());
57+
}
58+
4659
/**
4760
* Tests the type of sorting that's used in the non-combiner path of sort-based shuffle.
4861
*/

0 commit comments

Comments
 (0)