Search in sources :

Example 16 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.

the class SingleFilePageSwapperTest method creatingSwapperForExternallyLockedFileMustThrow.

@Test
@DisabledOnOs(OS.WINDOWS)
void creatingSwapperForExternallyLockedFileMustThrow() throws Exception {
    PageSwapperFactory factory = createSwapperFactory(fileSystem);
    Path file = testDir.file("file");
    ((StoreChannel) fileSystem.write(file)).close();
    var process = start(pb -> pb.directory(Path.of("target/test-classes").toAbsolutePath().toFile()), LockThisFileProgram.class.getCanonicalName(), file.toAbsolutePath().toString());
    BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()));
    InputStream stderr = process.getErrorStream();
    try {
        assumeTrue(LockThisFileProgram.LOCKED_OUTPUT.equals(stdout.readLine()));
    } catch (Throwable e) {
        int b = stderr.read();
        while (b != -1) {
            System.err.write(b);
            b = stderr.read();
        }
        System.err.flush();
        int exitCode = process.waitFor();
        System.out.println("exitCode = " + exitCode);
        throw e;
    }
    try {
        assertThrows(FileLockException.class, () -> createSwapper(factory, file, 4, NO_CALLBACK, true));
    } finally {
        process.getOutputStream().write(0);
        process.getOutputStream().flush();
        process.waitFor();
    }
}
Also used : Path(java.nio.file.Path) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.io.fs.DelegatingStoreChannel) BufferedReader(java.io.BufferedReader) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Example 17 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.

the class SingleFilePageSwapperTest method creatingSwapperForInternallyLockedFileMustThrow.

@Test
@DisabledOnOs(OS.WINDOWS)
void creatingSwapperForInternallyLockedFileMustThrow() throws Exception {
    PageSwapperFactory factory = createSwapperFactory(fileSystem);
    Path file = testDir.file("file");
    StoreFileChannel channel = fileSystem.write(file);
    try (FileLock fileLock = channel.tryLock()) {
        assertThat(fileLock).isNotNull();
        assertThrows(FileLockException.class, () -> createSwapper(factory, file, 4, NO_CALLBACK, true));
    }
}
Also used : Path(java.nio.file.Path) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) StoreFileChannel(org.neo4j.io.fs.StoreFileChannel) 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 18 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.

the class SingleFilePageSwapperTest method creatingSwapperForFileMustTakeLockOnFile.

/**
 * The OverlappingFileLockException is thrown when tryLock is called on the same file *in the same JVM*.
 */
@Test
@DisabledOnOs(OS.WINDOWS)
void creatingSwapperForFileMustTakeLockOnFile() throws Exception {
    PageSwapperFactory factory = createSwapperFactory(fileSystem);
    Path file = testDir.file("file");
    ((StoreChannel) fileSystem.write(file)).close();
    PageSwapper pageSwapper = createSwapper(factory, file, 4, NO_CALLBACK, false);
    try {
        StoreChannel channel = fileSystem.write(file);
        assertThrows(OverlappingFileLockException.class, channel::tryLock);
    } finally {
        pageSwapper.close();
    }
}
Also used : Path(java.nio.file.Path) PageSwapperFactory(org.neo4j.io.pagecache.PageSwapperFactory) StoreChannel(org.neo4j.io.fs.StoreChannel) DelegatingStoreChannel(org.neo4j.io.fs.DelegatingStoreChannel) PageSwapper(org.neo4j.io.pagecache.PageSwapper) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) PageSwapperTest(org.neo4j.io.pagecache.PageSwapperTest) Test(org.junit.jupiter.api.Test)

Example 19 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.

the class DumpCommandIT method shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock.

@Test
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldReportAHelpfulErrorIfWeDontHaveWritePermissionsForLock() throws Exception {
    DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(databaseDirectory);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction()) {
        Path file = databaseLayout.databaseLockFile();
        try (Closeable ignored = withPermissions(file, emptySet())) {
            CommandFailedException commandFailed = assertThrows(CommandFailedException.class, () -> execute("foo"));
            assertEquals("You do not have permission to dump the database.", commandFailed.getMessage());
        }
    }
}
Also used : Path(java.nio.file.Path) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) CommandFailedException(org.neo4j.cli.CommandFailedException) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Example 20 with DisabledOnOs

use of org.junit.jupiter.api.condition.DisabledOnOs in project neo4j by neo4j.

the class LoaderTest method shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryIsNotWritable.

@Test
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldGiveAClearErrorMessageIfTheTxLogsParentDirectoryIsNotWritable() throws IOException {
    Path archive = testDirectory.file("the-archive.dump");
    Path txLogsDirectory = testDirectory.directory("subdir", "txLogs");
    Config config = Config.newBuilder().set(neo4j_home, testDirectory.homePath()).set(transaction_logs_root_path, txLogsDirectory.toAbsolutePath()).set(default_database, "destination").build();
    DatabaseLayout databaseLayout = DatabaseLayout.of(config);
    Path txLogsRoot = databaseLayout.getTransactionLogsDirectory().getParent();
    try (Closeable ignored = withPermissions(txLogsRoot, emptySet())) {
        AccessDeniedException exception = assertThrows(AccessDeniedException.class, () -> new Loader().load(archive, databaseLayout));
        assertEquals(txLogsRoot.toString(), exception.getMessage());
    }
}
Also used : Path(java.nio.file.Path) AccessDeniedException(java.nio.file.AccessDeniedException) Config(org.neo4j.configuration.Config) Closeable(java.io.Closeable) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Aggregations

DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)85 Test (org.junit.jupiter.api.Test)78 Path (java.nio.file.Path)38 File (java.io.File)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 PathsBaseTest (org.assertj.core.internal.PathsBaseTest)12 AssertionsUtil.expectAssertionError (org.assertj.core.util.AssertionsUtil.expectAssertionError)11 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)6 PageSwapperFactory (org.neo4j.io.pagecache.PageSwapperFactory)6 PageSwapperTest (org.neo4j.io.pagecache.PageSwapperTest)6 CommandBuilder (com.thoughtworks.go.domain.builder.CommandBuilder)5 DelegatingStoreChannel (org.neo4j.io.fs.DelegatingStoreChannel)5 StoreChannel (org.neo4j.io.fs.StoreChannel)5 DisabledForRoot (org.neo4j.test.extension.DisabledForRoot)5 Closeable (java.io.Closeable)4 URI (java.net.URI)4 FileUtils.writeByteArrayToFile (org.apache.commons.io.FileUtils.writeByteArrayToFile)4 ShouldBeFile.shouldBeFile (org.assertj.core.error.ShouldBeFile.shouldBeFile)4 FilesBaseTest (org.assertj.core.internal.FilesBaseTest)4 Files.newFile (org.assertj.core.util.Files.newFile)4