Search in sources :

Example 26 with PageSwapperFactory

use of org.neo4j.io.pagecache.PageSwapperFactory in project neo4j by neo4j.

the class SingleFilePageSwapperTest method mustUnlockFileWhenThePageSwapperIsClosed.

@Test
@DisabledOnOs(OS.WINDOWS)
void mustUnlockFileWhenThePageSwapperIsClosed() throws Exception {
    PageSwapperFactory factory = createSwapperFactory(fileSystem);
    Path file = testDir.file("file");
    ((StoreChannel) fileSystem.write(file)).close();
    createSwapper(factory, file, 4, NO_CALLBACK, false).close();
    try (StoreFileChannel channel = fileSystem.write(file);
        FileLock fileLock = channel.tryLock()) {
        assertThat(fileLock).isNotNull();
    }
}
Also used : Path(java.nio.file.Path) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.io.fs.DelegatingStoreChannel) FileLock(java.nio.channels.FileLock) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Example 27 with PageSwapperFactory

use of org.neo4j.io.pagecache.PageSwapperFactory in project neo4j by neo4j.

the class SingleFilePageSwapperTest method reportExternalIoOnSwapIn.

@Test
void reportExternalIoOnSwapIn() throws IOException {
    byte[] bytes = new byte[] { 1, 2, 3, 4 };
    try (StoreChannel channel = getFs().write(getPath())) {
        channel.writeAll(wrap(bytes));
    }
    PageSwapperFactory factory = createSwapperFactory(getFs());
    CountingIOController controller = new CountingIOController();
    try (var swapper = createSwapper(factory, getPath(), 4, null, false, false, true, controller)) {
        long target = createPage(4);
        int numberOfReads = 12;
        for (int i = 0; i < numberOfReads; i++) {
            assertEquals(4, swapper.read(0, target));
        }
        assertEquals(numberOfReads, controller.getExternalIOCounter());
    }
}
Also used : PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.io.fs.DelegatingStoreChannel) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Aggregations

PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)27 Test (org.junit.jupiter.api.Test)23 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)22 DelegatingStoreChannel (org.neo4j.io.fs.DelegatingStoreChannel)13 StoreChannel (org.neo4j.io.fs.StoreChannel)13 PageSwapper (org.neo4j.io.pagecache.PageSwapper)12 Path (java.nio.file.Path)11 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)6 RandomAdversary (org.neo4j.adversaries.RandomAdversary)5 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)5 SingleFilePageSwapperFactory (org.neo4j.io.pagecache.impl.SingleFilePageSwapperFactory)4 InputStream (java.io.InputStream)3 FileLock (java.nio.channels.FileLock)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)2 StoreFileChannel (org.neo4j.io.fs.StoreFileChannel)2 PageCache (org.neo4j.io.pagecache.PageCache)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2