Search in sources :

Example 11 with DelegatingFileSystemAbstraction

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

the class FileLockerTest method shouldNotObtainLockWhenDirCannotBeCreated.

@ParameterizedTest
@MethodSource("lockerFactories")
void shouldNotObtainLockWhenDirCannotBeCreated(LockerFactory lockerFactory) {
    FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystem) {

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

        @Override
        public boolean fileExists(Path file) {
            return false;
        }
    };
    FileLockException fileLockException = assertThrows(FileLockException.class, () -> {
        try (Locker storeLocker = lockerFactory.createLocker(fileSystemAbstraction, testDirectory)) {
            storeLocker.checkLock();
        }
    });
    assertThat(fileLockException.getMessage()).startsWith("Unable to create path for dir: ");
}
Also used : Path(java.nio.file.Path) DelegatingFileSystemAbstraction(org.neo4j.io.fs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) IOException(java.io.IOException) DelegatingFileSystemAbstraction(org.neo4j.io.fs.DelegatingFileSystemAbstraction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 12 with DelegatingFileSystemAbstraction

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

the class FileLockerTest method shouldObtainLockWhenFileNotLocked.

@ParameterizedTest
@MethodSource("lockerFactories")
void shouldObtainLockWhenFileNotLocked(LockerFactory lockerFactory) {
    FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystem) {

        @Override
        public boolean fileExists(Path file) {
            return fileSystem.fileExists(file);
        }
    };
    assertDoesNotThrow(() -> {
        try (Locker locker = lockerFactory.createLocker(fileSystemAbstraction, testDirectory)) {
            locker.checkLock();
        }
    });
}
Also used : Path(java.nio.file.Path) DelegatingFileSystemAbstraction(org.neo4j.io.fs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DelegatingFileSystemAbstraction(org.neo4j.io.fs.DelegatingFileSystemAbstraction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with DelegatingFileSystemAbstraction

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

the class FileLockerTest method shouldNotObtainLockWhenUnableToOpenLockFile.

@ParameterizedTest
@MethodSource("lockerFactories")
void shouldNotObtainLockWhenUnableToOpenLockFile(LockerFactory lockerFactory) {
    FileSystemAbstraction fileSystemAbstraction = new DelegatingFileSystemAbstraction(fileSystem) {

        @Override
        public StoreChannel write(Path fileName) throws IOException {
            throw new IOException("cannot open lock file");
        }

        @Override
        public boolean fileExists(Path file) {
            return false;
        }
    };
    FileLockException fileLockException = assertThrows(FileLockException.class, () -> {
        try (Locker storeLocker = lockerFactory.createLocker(fileSystemAbstraction, testDirectory)) {
            storeLocker.checkLock();
        }
    });
    assertThat(fileLockException.getMessage()).startsWith("Unable to obtain lock on file:");
}
Also used : Path(java.nio.file.Path) DelegatingFileSystemAbstraction(org.neo4j.io.fs.DelegatingFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) IOException(java.io.IOException) DelegatingFileSystemAbstraction(org.neo4j.io.fs.DelegatingFileSystemAbstraction) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 14 with DelegatingFileSystemAbstraction

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

the class SingleFilePageSwapperTest method mustCloseFilesIfTakingFileLockThrows.

@Test
@DisabledOnOs(OS.WINDOWS)
void mustCloseFilesIfTakingFileLockThrows() throws Exception {
    final AtomicInteger openFilesCounter = new AtomicInteger();
    PageSwapperFactory factory = createSwapperFactory(new DelegatingFileSystemAbstraction(fileSystem) {

        @Override
        public StoreChannel open(Path fileName, Set<OpenOption> options) throws IOException {
            openFilesCounter.getAndIncrement();
            return new DelegatingStoreChannel(super.open(fileName, options)) {

                @Override
                public void close() throws IOException {
                    openFilesCounter.getAndDecrement();
                    super.close();
                }
            };
        }
    });
    Path file = testDir.file("file");
    try (StoreChannel ch = fileSystem.write(file);
        FileLock ignore = ch.tryLock()) {
        createSwapper(factory, file, 4, NO_CALLBACK, false).close();
        fail("Creating a page swapper for a locked channel should have thrown");
    } catch (FileLockException e) {
    // As expected.
    }
    assertThat(openFilesCounter.get()).isEqualTo(0);
}
Also used : Path(java.nio.file.Path) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) OpenOption(java.nio.file.OpenOption) OverlappingFileLockException(java.nio.channels.OverlappingFileLockException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.io.fs.DelegatingStoreChannel) FileLock(java.nio.channels.FileLock) DelegatingStoreChannel(org.neo4j.io.fs.DelegatingStoreChannel) IOException(java.io.IOException) DelegatingFileSystemAbstraction(org.neo4j.io.fs.DelegatingFileSystemAbstraction) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Aggregations

Path (java.nio.file.Path)14 DelegatingFileSystemAbstraction (org.neo4j.io.fs.DelegatingFileSystemAbstraction)14 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)13 IOException (java.io.IOException)12 DelegatingStoreChannel (org.neo4j.io.fs.DelegatingStoreChannel)10 Test (org.junit.jupiter.api.Test)9 ByteBuffer (java.nio.ByteBuffer)8 Set (java.util.Set)8 UncheckedIOException (java.io.UncheckedIOException)6 ImmutableSet (org.eclipse.collections.api.set.ImmutableSet)6 RepeatedTest (org.junit.jupiter.api.RepeatedTest)6 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)6 EphemeralFileSystemAbstraction (org.neo4j.io.fs.EphemeralFileSystemAbstraction)6 SwapperSet (org.neo4j.io.pagecache.impl.muninn.SwapperSet)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)4 StoreChannel (org.neo4j.io.fs.StoreChannel)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 LinkedList (java.util.LinkedList)2