Skip to content

Commit

Permalink
Add unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
otbutz committed Nov 20, 2023
1 parent b5f4a94 commit f5a5f5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public final class MMapDataAccess extends AbstractDataAccess {
this.allowWrites = allowWrites;
}

private static MethodHandle getByteBufferCleaner() {
static MethodHandle getByteBufferCleaner() {
try {
Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
Lookup lookup = MethodHandles.privateLookupIn(unsafeClass, MethodHandles.lookup());
Expand Down
16 changes: 16 additions & 0 deletions core/src/test/java/com/graphhopper/storage/MMapDataAccessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

import org.junit.jupiter.api.Test;

import java.lang.invoke.MethodHandle;
import java.nio.ByteBuffer;

import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -59,4 +62,17 @@ public void textMixMMAP2RAM() {
assertEquals(123, da.getInt(7 * 4));
da.close();
}

@Test
public void testByteBufferCleaner() {
MethodHandle bufferCleaner = MMapDataAccess.getByteBufferCleaner();
assertNotNull(bufferCleaner);
try {
bufferCleaner.invokeExact(ByteBuffer.allocate(10));
fail("Cleaner invocation should fail for a non-direct buffer");
} catch (Throwable t) {
assertInstanceOf(IllegalArgumentException.class, t);
assertEquals("buffer is non-direct", t.getMessage());
}
}
}

0 comments on commit f5a5f5f

Please sign in to comment.