Search in sources :

Example 1 with IOController

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

the class NodeStoreTest method shouldCloseStoreFileOnFailureToOpen.

@Test
void shouldCloseStoreFileOnFailureToOpen() {
    // GIVEN
    final MutableBoolean fired = new MutableBoolean();
    // WHEN
    Exception exception = assertThrows(Exception.class, () -> {
        try (PageCache pageCache = pageCacheExtension.getPageCache(fs)) {
            PageCache customPageCache = new DelegatingPageCache(pageCache) {

                @Override
                public PagedFile map(Path path, int pageSize, String databaseName, ImmutableSet<OpenOption> openOptions, IOController ioController) throws IOException {
                    if (path.getFileName().toString().toLowerCase().endsWith(".id")) {
                        fired.setTrue();
                        throw new IOException("Proving a point here");
                    }
                    return super.map(path, pageSize, databaseName, openOptions, ioController);
                }
            };
            newNodeStore(fs, customPageCache);
        }
    });
    assertTrue(indexOfThrowable(exception, IOException.class) != -1);
    assertTrue(fired.booleanValue());
}
Also used : Path(java.nio.file.Path) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) ImmutableSet(org.eclipse.collections.api.set.ImmutableSet) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) IOController(org.neo4j.io.pagecache.IOController) StringContains.containsString(org.hamcrest.core.StringContains.containsString) IOException(java.io.IOException) IOException(java.io.IOException) PageCache(org.neo4j.io.pagecache.PageCache) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) Test(org.junit.jupiter.api.Test)

Example 2 with IOController

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

the class MetaDataStoreTest method setUp.

@BeforeEach
void setUp() {
    pageCache = pageCacheExtension.getPageCache(fs);
    fakePageCursorOverflow = false;
    pageCacheWithFakeOverflow = new DelegatingPageCache(pageCache) {

        @Override
        public PagedFile map(Path path, int pageSize, String databaseName, ImmutableSet<OpenOption> openOptions, IOController ioController) throws IOException {
            return new DelegatingPagedFile(super.map(path, pageSize, databaseName, openOptions, ioController)) {

                @Override
                public PageCursor io(long pageId, int pf_flags, CursorContext context) throws IOException {
                    return new DelegatingPageCursor(super.io(pageId, pf_flags, context)) {

                        @Override
                        public boolean checkAndClearBoundsFlag() {
                            return fakePageCursorOverflow | super.checkAndClearBoundsFlag();
                        }
                    };
                }
            };
        }
    };
}
Also used : Path(java.nio.file.Path) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) PagedFile(org.neo4j.io.pagecache.PagedFile) DelegatingPagedFile(org.neo4j.io.pagecache.DelegatingPagedFile) IOController(org.neo4j.io.pagecache.IOController) IOException(java.io.IOException) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PageCursor(org.neo4j.io.pagecache.PageCursor) DelegatingPageCursor(org.neo4j.io.pagecache.impl.DelegatingPageCursor) OpenOption(java.nio.file.OpenOption) DelegatingPagedFile(org.neo4j.io.pagecache.DelegatingPagedFile) DelegatingPageCursor(org.neo4j.io.pagecache.impl.DelegatingPageCursor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

IOException (java.io.IOException)2 Path (java.nio.file.Path)2 DelegatingPageCache (org.neo4j.io.pagecache.DelegatingPageCache)2 IOController (org.neo4j.io.pagecache.IOController)2 OpenOption (java.nio.file.OpenOption)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 ImmutableSet (org.eclipse.collections.api.set.ImmutableSet)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 DelegatingPagedFile (org.neo4j.io.pagecache.DelegatingPagedFile)1 PageCache (org.neo4j.io.pagecache.PageCache)1 PageCursor (org.neo4j.io.pagecache.PageCursor)1 PagedFile (org.neo4j.io.pagecache.PagedFile)1 CursorContext (org.neo4j.io.pagecache.context.CursorContext)1 DelegatingPageCursor (org.neo4j.io.pagecache.impl.DelegatingPageCursor)1