Search in sources :

Example 11 with CommandFailed

use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.

the class UnbindFromClusterCommandTest method shouldFailToUnbindLiveDatabase.

@Test
public void shouldFailToUnbindLiveDatabase() throws Exception {
    // given
    createClusterStateDir(fs);
    UnbindFromClusterCommand command = new UnbindFromClusterCommand(homeDir, confDir, outsideWorld);
    FileLock fileLock = createLockedFakeDbDir(homeDir);
    try {
        // when
        command.execute(databaseNameParameter("graph.db"));
        fail();
    } catch (CommandFailed e) {
        // then
        assertThat(e.getMessage(), containsString("Database is currently locked. Please shutdown Neo4j."));
    } finally {
        fileLock.release();
    }
}
Also used : FileLock(java.nio.channels.FileLock) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 12 with CommandFailed

use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.

the class VersionCommand method execute.

@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
    final Path storeDir = arguments.parseMandatoryPath("store", args);
    Validators.CONTAINS_EXISTING_DATABASE.validate(storeDir.toFile());
    try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
        final String storeVersion = new StoreVersionCheck(pageCache).getVersion(storeDir.resolve(MetaDataStore.DEFAULT_NAME).toFile()).orElseThrow(() -> new CommandFailed(String.format("Could not find version metadata in store '%s'", storeDir)));
        final String fmt = "%-25s%s";
        out.accept(String.format(fmt, "Store format version:", storeVersion));
        RecordFormats format = RecordFormatSelector.selectForVersion(storeVersion);
        out.accept(String.format(fmt, "Introduced in version:", format.introductionVersion()));
        findSuccessor(format).map(next -> String.format(fmt, "Superseded in version:", next.introductionVersion())).ifPresent(out);
        out.accept(String.format(fmt, "Current version:", Version.getNeo4jVersion()));
    } catch (IOException e) {
        throw new CommandFailed(e.getMessage(), e);
    }
}
Also used : MandatoryCanonicalPath(org.neo4j.commandline.arguments.common.MandatoryCanonicalPath) Path(java.nio.file.Path) PageCache(org.neo4j.io.pagecache.PageCache) Validators(org.neo4j.kernel.impl.util.Validators) StandalonePageCacheFactory(org.neo4j.io.pagecache.impl.muninn.StandalonePageCacheFactory) Version(org.neo4j.kernel.internal.Version) IOException(java.io.IOException) RecordFormatSelector(org.neo4j.kernel.impl.store.format.RecordFormatSelector) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) AdminCommand(org.neo4j.commandline.admin.AdminCommand) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) Consumer(java.util.function.Consumer) MandatoryCanonicalPath(org.neo4j.commandline.arguments.common.MandatoryCanonicalPath) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) Arguments(org.neo4j.commandline.arguments.Arguments) OutsideWorld(org.neo4j.commandline.admin.OutsideWorld) RecordFormatSelector.findSuccessor(org.neo4j.kernel.impl.store.format.RecordFormatSelector.findSuccessor) MetaDataStore(org.neo4j.kernel.impl.store.MetaDataStore) CommandFailed(org.neo4j.commandline.admin.CommandFailed) IncorrectUsage(org.neo4j.commandline.admin.IncorrectUsage) Path(java.nio.file.Path) StoreVersionCheck(org.neo4j.kernel.impl.storemigration.StoreVersionCheck) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) CommandFailed(org.neo4j.commandline.admin.CommandFailed) IOException(java.io.IOException) PageCache(org.neo4j.io.pagecache.PageCache)

Example 13 with CommandFailed

use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.

the class DumpCommandTest method shouldGiveAClearMessageIfTheArchivesParentDoesntExist.

@Test
public void shouldGiveAClearMessageIfTheArchivesParentDoesntExist() throws Exception {
    doThrow(new NoSuchFileException(archive.getParent().toString())).when(dumper).dump(any(), any(), any());
    try {
        execute("foo.db");
        fail("expected exception");
    } catch (CommandFailed e) {
        assertThat(e.getMessage(), equalTo("unable to dump database: NoSuchFileException: " + archive.getParent()));
    }
}
Also used : NoSuchFileException(java.nio.file.NoSuchFileException) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 14 with CommandFailed

use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.

the class DumpCommandTest method shouldRespectTheStoreLock.

@Test
public void shouldRespectTheStoreLock() throws Exception {
    Path databaseDirectory = homeDir.resolve("data/databases/foo.db");
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        StoreLocker storeLocker = new StoreLocker(fileSystem)) {
        storeLocker.checkLock(databaseDirectory.toFile());
        execute("foo.db");
        fail("expected exception");
    } catch (CommandFailed e) {
        assertThat(e.getMessage(), equalTo("the database is in use -- stop Neo4j and try again"));
    }
}
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) StoreLocker(org.neo4j.kernel.internal.StoreLocker) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Example 15 with CommandFailed

use of org.neo4j.commandline.admin.CommandFailed in project neo4j by neo4j.

the class LoadCommandTest method shouldRespectTheStoreLock.

@Test
public void shouldRespectTheStoreLock() throws IOException, IncorrectUsage {
    Path databaseDirectory = homeDir.resolve("data/databases/foo.db");
    Files.createDirectories(databaseDirectory);
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        StoreLocker locker = new StoreLocker(fileSystem)) {
        locker.checkLock(databaseDirectory.toFile());
        execute("foo.db", "--force");
        fail("expected exception");
    } catch (CommandFailed e) {
        assertThat(e.getMessage(), equalTo("the database is in use -- stop Neo4j and try again"));
    }
}
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) StoreLocker(org.neo4j.kernel.internal.StoreLocker) CommandFailed(org.neo4j.commandline.admin.CommandFailed) Test(org.junit.Test)

Aggregations

CommandFailed (org.neo4j.commandline.admin.CommandFailed)18 Test (org.junit.Test)9 Path (java.nio.file.Path)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)8 File (java.io.File)7 IOException (java.io.IOException)7 Config (org.neo4j.kernel.configuration.Config)7 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)6 IncorrectUsage (org.neo4j.commandline.admin.IncorrectUsage)5 CheckConsistencyConfig (org.neo4j.consistency.checking.full.CheckConsistencyConfig)3 StoreLocker (org.neo4j.kernel.internal.StoreLocker)3 Closeable (java.io.Closeable)2 OutsideWorld (org.neo4j.commandline.admin.OutsideWorld)2 MandatoryCanonicalPath (org.neo4j.commandline.arguments.common.MandatoryCanonicalPath)2 OptionalCanonicalPath (org.neo4j.commandline.arguments.common.OptionalCanonicalPath)2 StoreLockException (org.neo4j.kernel.StoreLockException)2 FileUserRepository (org.neo4j.server.security.auth.FileUserRepository)2 FileLock (java.nio.channels.FileLock)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 FileSystemException (java.nio.file.FileSystemException)1