Search in sources :

Example 1 with DelegatingPageCache

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

the class RecordStorageEngineTest method mustFlushStoresWithGivenIOLimiter.

@Test
public void mustFlushStoresWithGivenIOLimiter() throws Exception {
    IOLimiter limiter = (stamp, completedIOs, swapper) -> 0;
    FileSystemAbstraction fs = fsRule.get();
    AtomicReference<IOLimiter> observedLimiter = new AtomicReference<>();
    PageCache pageCache = new DelegatingPageCache(pageCacheRule.getPageCache(fs)) {

        @Override
        public void flushAndForce(IOLimiter limiter) throws IOException {
            super.flushAndForce(limiter);
            observedLimiter.set(limiter);
        }
    };
    RecordStorageEngine engine = storageEngineRule.getWith(fs, pageCache).build();
    engine.flushAndForce(limiter);
    assertThat(observedLimiter.get(), sameInstance(limiter));
}
Also used : RecordFormat(org.neo4j.kernel.impl.store.format.RecordFormat) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Exceptions(org.neo4j.helpers.Exceptions) BatchTransactionApplierFacade(org.neo4j.kernel.impl.api.BatchTransactionApplierFacade) IOLimiter(org.neo4j.io.pagecache.IOLimiter) AtomicReference(java.util.concurrent.atomic.AtomicReference) TransactionToApply(org.neo4j.kernel.impl.api.TransactionToApply) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) RecordStorageEngineRule(org.neo4j.test.rule.RecordStorageEngineRule) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) Mockito.doThrow(org.mockito.Mockito.doThrow) PageCacheRule(org.neo4j.test.rule.PageCacheRule) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) TransactionApplicationMode(org.neo4j.storageengine.api.TransactionApplicationMode) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Assert.fail(org.junit.Assert.fail) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) PageCache(org.neo4j.io.pagecache.PageCache) UnderlyingStorageException(org.neo4j.kernel.impl.store.UnderlyingStorageException) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) TransactionRepresentation(org.neo4j.kernel.impl.transaction.TransactionRepresentation) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) RuleChain(org.junit.rules.RuleChain) Matchers.any(org.mockito.Matchers.any) Rule(org.junit.Rule) CountsAccessor(org.neo4j.kernel.impl.api.CountsAccessor) StoreFileType(org.neo4j.kernel.impl.storemigration.StoreFileType) DatabaseHealth(org.neo4j.kernel.internal.DatabaseHealth) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) StoreType(org.neo4j.kernel.impl.store.StoreType) Matchers.equalTo(org.hamcrest.Matchers.equalTo) CommandsToApply(org.neo4j.storageengine.api.CommandsToApply) Optional(java.util.Optional) FakeCommitment(org.neo4j.kernel.impl.transaction.log.FakeCommitment) Matchers.anyOf(org.hamcrest.Matchers.anyOf) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Mockito.mock(org.mockito.Mockito.mock) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) IOLimiter(org.neo4j.io.pagecache.IOLimiter) AtomicReference(java.util.concurrent.atomic.AtomicReference) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 2 with DelegatingPageCache

use of org.neo4j.io.pagecache.DelegatingPageCache 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 3 with DelegatingPageCache

use of org.neo4j.io.pagecache.DelegatingPageCache 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)3 DelegatingPageCache (org.neo4j.io.pagecache.DelegatingPageCache)3 Path (java.nio.file.Path)2 IOController (org.neo4j.io.pagecache.IOController)2 PageCache (org.neo4j.io.pagecache.PageCache)2 File (java.io.File)1 OpenOption (java.nio.file.OpenOption)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)1 ImmutableSet (org.eclipse.collections.api.set.ImmutableSet)1 Matchers.anyOf (org.hamcrest.Matchers.anyOf)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Matchers.sameInstance (org.hamcrest.Matchers.sameInstance)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertSame (org.junit.Assert.assertSame)1 Assert.assertThat (org.junit.Assert.assertThat)1