Skip to content

Commit 41b8881

Browse files
committed
Get UnsafeInMemorySorterSuite to pass (WIP)
1 parent 90c2b6a commit 41b8881

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

core/pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -343,28 +343,28 @@
343343
<scope>test</scope>
344344
</dependency>
345345
<dependency>
346-
<groupId>org.mockito</groupId>
347-
<artifactId>mockito-core</artifactId>
346+
<groupId>org.hamcrest</groupId>
347+
<artifactId>hamcrest-core</artifactId>
348348
<scope>test</scope>
349349
</dependency>
350350
<dependency>
351-
<groupId>org.scalacheck</groupId>
352-
<artifactId>scalacheck_${scala.binary.version}</artifactId>
351+
<groupId>org.hamcrest</groupId>
352+
<artifactId>hamcrest-library</artifactId>
353353
<scope>test</scope>
354354
</dependency>
355355
<dependency>
356-
<groupId>junit</groupId>
357-
<artifactId>junit</artifactId>
356+
<groupId>org.mockito</groupId>
357+
<artifactId>mockito-core</artifactId>
358358
<scope>test</scope>
359359
</dependency>
360360
<dependency>
361-
<groupId>org.hamcrest</groupId>
362-
<artifactId>hamcrest-core</artifactId>
361+
<groupId>org.scalacheck</groupId>
362+
<artifactId>scalacheck_${scala.binary.version}</artifactId>
363363
<scope>test</scope>
364364
</dependency>
365365
<dependency>
366-
<groupId>org.hamcrest</groupId>
367-
<artifactId>hamcrest-library</artifactId>
366+
<groupId>junit</groupId>
367+
<artifactId>junit</artifactId>
368368
<scope>test</scope>
369369
</dependency>
370370
<dependency>

core/src/test/java/org/apache/spark/util/collection/unsafe/sort/UnsafeInMemorySorterSuite.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
public class UnsafeInMemorySorterSuite {
3636

3737
private static String getStringFromDataPage(Object baseObject, long baseOffset) {
38-
final int strLength = (int) PlatformDependent.UNSAFE.getLong(baseObject, baseOffset);
38+
final int strLength = PlatformDependent.UNSAFE.getInt(baseObject, baseOffset);
3939
final byte[] strBytes = new byte[strLength];
4040
PlatformDependent.copyMemory(
4141
baseObject,
42-
baseOffset + 8,
42+
baseOffset + 4,
4343
strBytes,
4444
PlatformDependent.BYTE_ARRAY_OFFSET, strLength);
4545
return new String(strBytes);
@@ -77,8 +77,8 @@ public void testSortingOnlyByIntegerPrefix() throws Exception {
7777
long position = dataPage.getBaseOffset();
7878
for (String str : dataToSort) {
7979
final byte[] strBytes = str.getBytes("utf-8");
80-
PlatformDependent.UNSAFE.putLong(baseObject, position, strBytes.length);
81-
position += 8;
80+
PlatformDependent.UNSAFE.putInt(baseObject, position, strBytes.length);
81+
position += 4;
8282
PlatformDependent.copyMemory(
8383
strBytes,
8484
PlatformDependent.BYTE_ARRAY_OFFSET,
@@ -114,22 +114,24 @@ public int compare(long prefix1, long prefix2) {
114114
position = dataPage.getBaseOffset();
115115
for (int i = 0; i < dataToSort.length; i++) {
116116
// position now points to the start of a record (which holds its length).
117-
final long recordLength = PlatformDependent.UNSAFE.getLong(baseObject, position);
117+
final int recordLength = PlatformDependent.UNSAFE.getInt(baseObject, position);
118118
final long address = memoryManager.encodePageNumberAndOffset(dataPage, position);
119119
final String str = getStringFromDataPage(baseObject, position);
120120
final int partitionId = hashPartitioner.getPartition(str);
121121
sorter.insertRecord(address, partitionId);
122-
position += 8 + recordLength;
122+
position += 4 + recordLength;
123123
}
124124
final UnsafeSorterIterator iter = sorter.getSortedIterator();
125125
int iterLength = 0;
126126
long prevPrefix = -1;
127127
Arrays.sort(dataToSort);
128128
while (iter.hasNext()) {
129129
iter.loadNext();
130-
final String str = getStringFromDataPage(iter.getBaseObject(), iter.getBaseOffset());
130+
// TODO: the logic for how we manipulate record length offsets here is confusing; clean
131+
// this up and clarify it in comments.
132+
final String str = getStringFromDataPage(iter.getBaseObject(), iter.getBaseOffset() - 4);
131133
final long keyPrefix = iter.getKeyPrefix();
132-
assertTrue(Arrays.asList(dataToSort).contains(str));
134+
assertThat(str, isIn(Arrays.asList(dataToSort)));
133135
assertThat(keyPrefix, greaterThanOrEqualTo(prevPrefix));
134136
prevPrefix = keyPrefix;
135137
iterLength++;

0 commit comments

Comments
 (0)