mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-10-05 21:22:39 +02:00
(test) Fix tests that works on my machine (TM)
This commit is contained in:
@@ -4,18 +4,31 @@ import nu.marginalia.array.DirectFileReader;
|
||||
import nu.marginalia.array.LongArray;
|
||||
import nu.marginalia.array.LongArrayFactory;
|
||||
import nu.marginalia.ffi.LinuxSystemCalls;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.foreign.Arena;
|
||||
import java.lang.foreign.MemorySegment;
|
||||
import java.lang.foreign.ValueLayout;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class NativeAlgosTest {
|
||||
Path testFile;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws IOException {
|
||||
testFile = Files.createTempFile("NativeAlgosTest", ".dat");
|
||||
}
|
||||
@AfterEach
|
||||
public void tearDown() throws IOException {
|
||||
Files.deleteIfExists(testFile);
|
||||
}
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
LongArray array = LongArrayFactory.mmapForWritingShared(Path.of("/tmp/test"), 1024);
|
||||
LongArray array = LongArrayFactory.mmapForWritingShared(testFile, 1024);
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
array.set(i, i);
|
||||
}
|
||||
@@ -23,7 +36,7 @@ public class NativeAlgosTest {
|
||||
|
||||
var ms = Arena.global().allocate(512, 8);
|
||||
|
||||
int fd = LinuxSystemCalls.openDirect(Path.of("/tmp/test"));
|
||||
int fd = LinuxSystemCalls.openDirect(testFile);
|
||||
int ret = LinuxSystemCalls.readAt(fd, ms, 512);
|
||||
System.out.println(ret);
|
||||
System.out.println(ms.byteSize());
|
||||
@@ -38,14 +51,14 @@ public class NativeAlgosTest {
|
||||
|
||||
@Test
|
||||
void testDirectFileReader() throws IOException {
|
||||
LongArray array = LongArrayFactory.mmapForWritingShared(Path.of("/tmp/test"), 1024);
|
||||
LongArray array = LongArrayFactory.mmapForWritingShared(testFile, 1024);
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
array.set(i, i);
|
||||
}
|
||||
array.close();
|
||||
|
||||
|
||||
try (var dfr = new DirectFileReader(Path.of("/tmp/test"))) {
|
||||
try (var dfr = new DirectFileReader(testFile)) {
|
||||
LongArray array2 = LongArrayFactory.onHeapConfined(64);
|
||||
dfr.readAligned(array2, 0);
|
||||
for (int i = 0; i < array2.size(); i++) {
|
||||
@@ -54,7 +67,7 @@ public class NativeAlgosTest {
|
||||
}
|
||||
|
||||
var alignedBuffer = Arena.ofAuto().allocate(4096, 4096);
|
||||
try (var dfr = new DirectFileReader(Path.of("/tmp/test"))) {
|
||||
try (var dfr = new DirectFileReader(testFile)) {
|
||||
MemorySegment dest = Arena.ofAuto().allocate(504, 1);
|
||||
dfr.readUnaligned(dest, alignedBuffer, 8);
|
||||
|
||||
|
Reference in New Issue
Block a user