Search in sources :

Example 36 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class StoreLockerTest method shouldNotObtainLockWhenUnableToOpenLockFile.

@Test
public void shouldNotObtainLockWhenUnableToOpenLockFile() throws Exception {
    FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {

        @Override
        public StoreChannel open(File fileName, String mode) throws IOException {
            throw new IOException("cannot open lock file");
        }

        @Override
        public boolean fileExists(File fileName) {
            return false;
        }
    };
    File storeDir = target.directory("unused");
    try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
        storeLocker.checkLock(storeDir);
        fail();
    } catch (StoreLockException e) {
        String msg = format("Unable to obtain lock on store lock file: %s. " + "Please ensure no other process is using this database, and that the " + "directory is writable (required even for read-only access)", new File(storeDir, STORE_LOCK_FILENAME));
        assertThat(e.getMessage(), is(msg));
    }
}
Also used : DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreLockException(org.neo4j.kernel.StoreLockException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) File(java.io.File) Test(org.junit.Test)

Example 37 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class StoreLockerTest method shouldNotObtainLockWhenStoreDirCannotBeCreated.

@Test
public void shouldNotObtainLockWhenStoreDirCannotBeCreated() throws Exception {
    FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystemRule.get()) {

        @Override
        public void mkdirs(File fileName) throws IOException {
            throw new IOException("store dir could not be created");
        }

        @Override
        public boolean fileExists(File fileName) {
            return false;
        }
    };
    File storeDir = target.directory("unused");
    try (StoreLocker storeLocker = new StoreLocker(fileSystemAbstraction)) {
        storeLocker.checkLock(storeDir);
        fail();
    } catch (StoreLockException e) {
        String msg = format("Unable to create path for store dir: %s. " + "Please ensure no other process is using this database, and that " + "the directory is writable (required even for read-only access)", storeDir);
        assertThat(e.getMessage(), is(msg));
    }
}
Also used : DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreLockException(org.neo4j.kernel.StoreLockException) IOException(java.io.IOException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) File(java.io.File) Test(org.junit.Test)

Example 38 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class EditionModule method setupSecurityModule.

protected static void setupSecurityModule(PlatformModule platformModule, Log log, Procedures procedures, String key) {
    for (SecurityModule candidate : Service.load(SecurityModule.class)) {
        if (candidate.matches(key)) {
            try {
                candidate.setup(new SecurityModule.Dependencies() {

                    @Override
                    public LogService logService() {
                        return platformModule.logging;
                    }

                    @Override
                    public Config config() {
                        return platformModule.config;
                    }

                    @Override
                    public Procedures procedures() {
                        return procedures;
                    }

                    @Override
                    public JobScheduler scheduler() {
                        return platformModule.jobScheduler;
                    }

                    @Override
                    public FileSystemAbstraction fileSystem() {
                        return platformModule.fileSystem;
                    }

                    @Override
                    public LifeSupport lifeSupport() {
                        return platformModule.life;
                    }

                    @Override
                    public DependencySatisfier dependencySatisfier() {
                        return platformModule.dependencies;
                    }
                });
                return;
            } catch (Exception e) {
                String errorMessage = "Failed to load security module.";
                log.error(errorMessage);
                throw new RuntimeException(errorMessage, e);
            }
        }
    }
    String errorMessage = "Failed to load security module with key '" + key + "'.";
    log.error(errorMessage);
    throw new IllegalArgumentException(errorMessage);
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) Procedures(org.neo4j.kernel.impl.proc.Procedures) KernelException(org.neo4j.kernel.api.exceptions.KernelException) SecurityModule(org.neo4j.kernel.api.security.SecurityModule) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) DependencySatisfier(org.neo4j.kernel.impl.util.DependencySatisfier) LogService(org.neo4j.kernel.impl.logging.LogService)

Example 39 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class RecoveryRequiredCheckerTest method shouldWantToRecoverBrokenStore.

@Test
public void shouldWantToRecoverBrokenStore() throws Exception {
    try (FileSystemAbstraction fileSystemAbstraction = createSomeDataAndCrash(storeDir, fileSystem)) {
        PageCache pageCache = pageCacheRule.getPageCache(fileSystemAbstraction);
        RecoveryRequiredChecker recoverer = new RecoveryRequiredChecker(fileSystemAbstraction, pageCache);
        assertThat(recoverer.isRecoveryRequiredAt(storeDir), is(true));
    }
}
Also used : EphemeralFileSystemAbstraction(org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 40 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction 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)

Aggregations

FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)125 File (java.io.File)88 Test (org.junit.Test)82 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)34 IOException (java.io.IOException)28 Config (org.neo4j.kernel.configuration.Config)23 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)22 PageCache (org.neo4j.io.pagecache.PageCache)22 DelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction)20 ByteBuffer (java.nio.ByteBuffer)13 StoreChannel (org.neo4j.io.fs.StoreChannel)11 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)10 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)9 DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)9 OutputStream (java.io.OutputStream)8 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)8 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)8 Map (java.util.Map)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)7