Search in sources :

Example 6 with DisabledForRoot

use of org.neo4j.test.extension.DisabledForRoot in project neo4j by neo4j.

the class LoaderTest method shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsNotWritable.

@Test
@DisabledOnOs(OS.WINDOWS)
@DisabledForRoot
void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsNotWritable() throws IOException {
    Path archive = testDirectory.file("the-archive.dump");
    Path destination = testDirectory.directory("subdir/the-destination");
    DatabaseLayout databaseLayout = DatabaseLayout.ofFlat(destination);
    Path parentPath = databaseLayout.databaseDirectory().getParent();
    try (Closeable ignored = withPermissions(parentPath, emptySet())) {
        AccessDeniedException exception = assertThrows(AccessDeniedException.class, () -> new Loader().load(archive, databaseLayout));
        assertEquals(parentPath.toString(), exception.getMessage());
    }
}
Also used : Path(java.nio.file.Path) AccessDeniedException(java.nio.file.AccessDeniedException) 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)

Example 7 with DisabledForRoot

use of org.neo4j.test.extension.DisabledForRoot in project neo4j by neo4j.

the class NeoStoreOpenFailureTest method mustCloseAllStoresIfNeoStoresFailToOpen.

@Test
@DisabledForRoot
void mustCloseAllStoresIfNeoStoresFailToOpen() {
    Config config = Config.defaults();
    IdGeneratorFactory idGenFactory = new DefaultIdGeneratorFactory(fileSystem, immediate(), databaseLayout.getDatabaseName());
    LogProvider logProvider = NullLogProvider.getInstance();
    RecordFormats formats = Standard.LATEST_RECORD_FORMATS;
    RecordFormatPropertyConfigurator.configureRecordFormat(formats, config);
    boolean create = true;
    StoreType[] storeTypes = StoreType.values();
    ImmutableSet<OpenOption> openOptions = immutable.empty();
    NeoStores neoStores = new NeoStores(fileSystem, databaseLayout, config, idGenFactory, pageCache, logProvider, formats, create, NULL, writable(), storeTypes, openOptions);
    Path schemaStore = neoStores.getSchemaStore().getStorageFile();
    neoStores.close();
    // Make the schema store inaccessible, to sabotage the next initialisation we'll do.
    assumeTrue(schemaStore.toFile().setReadable(false));
    assumeTrue(schemaStore.toFile().setWritable(false));
    assertThrows(RuntimeException.class, () -> new NeoStores(fileSystem, databaseLayout, config, idGenFactory, pageCache, logProvider, formats, create, NULL, writable(), storeTypes, openOptions));
    // We verify that the successfully opened stores were closed again by the failed NeoStores open,
    // by closing the page cache, which will throw if not all files have been unmapped.
    pageCache.close();
}
Also used : Path(java.nio.file.Path) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) OpenOption(java.nio.file.OpenOption) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) Config(org.neo4j.configuration.Config) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) DefaultIdGeneratorFactory(org.neo4j.internal.id.DefaultIdGeneratorFactory) Test(org.junit.jupiter.api.Test) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Example 8 with DisabledForRoot

use of org.neo4j.test.extension.DisabledForRoot in project neo4j by neo4j.

the class ConfigTest method mustThrowIfConfigFileCouldNotBeRead.

@Test
@DisabledForRoot
void mustThrowIfConfigFileCouldNotBeRead() throws IOException {
    Path confFile = testDirectory.file("test.conf");
    assertTrue(confFile.toFile().createNewFile());
    assumeTrue(confFile.toFile().setReadable(false));
    assertThrows(IllegalArgumentException.class, () -> Config.emptyBuilder().fromFile(confFile).build());
}
Also used : Path(java.nio.file.Path) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisabledForRoot(org.neo4j.test.extension.DisabledForRoot)

Aggregations

Test (org.junit.jupiter.api.Test)8 DisabledForRoot (org.neo4j.test.extension.DisabledForRoot)8 Path (java.nio.file.Path)7 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)5 Closeable (java.io.Closeable)4 AccessDeniedException (java.nio.file.AccessDeniedException)3 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Config (org.neo4j.configuration.Config)2 IOException (java.io.IOException)1 OpenOption (java.nio.file.OpenOption)1 CommandFailedException (org.neo4j.cli.CommandFailedException)1 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)1 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 RecordFormats (org.neo4j.kernel.impl.store.format.RecordFormats)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 Log (org.neo4j.logging.Log)1 LogProvider (org.neo4j.logging.LogProvider)1