Search in sources :

Example 21 with ExecutionContext

use of org.neo4j.cli.ExecutionContext in project neo4j by neo4j.

the class MemoryRecommendationsCommandTest method doNotPrintRecommendationsForOffHeapWhenOnHeapIsConfigured.

@Test
void doNotPrintRecommendationsForOffHeapWhenOnHeapIsConfigured() throws Exception {
    PrintStream output = mock(PrintStream.class);
    Path homeDir = testDirectory.homePath();
    Path configDir = homeDir.resolve("conf");
    Path configFile = configDir.resolve(DEFAULT_CONFIG_FILE_NAME);
    Files.createDirectories(configDir);
    store(stringMap(data_directory.name(), homeDir.toString(), tx_state_memory_allocation.name(), TransactionStateMemoryAllocation.ON_HEAP.name()), configFile);
    MemoryRecommendationsCommand command = new MemoryRecommendationsCommand(new ExecutionContext(homeDir, configDir, output, mock(PrintStream.class), testDirectory.getFileSystem()));
    CommandLine.populateCommand(command, "--memory=8g");
    String heap = bytesToString(recommendHeapMemory(gibiBytes(8)));
    String pagecache = bytesToString(recommendPageCacheMemory(gibiBytes(8), 0));
    String offHeap = bytesToString(gibiBytes(2));
    command.execute();
    verify(output).println(initial_heap_size.name() + "=" + heap);
    verify(output).println(max_heap_size.name() + "=" + heap);
    verify(output).println(pagecache_memory.name() + "=" + pagecache);
    verify(output, never()).println(tx_state_max_off_heap_memory.name() + "=" + offHeap);
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) MemoryRecommendationsCommand.bytesToString(org.neo4j.commandline.dbms.MemoryRecommendationsCommand.bytesToString) Test(org.junit.jupiter.api.Test)

Example 22 with ExecutionContext

use of org.neo4j.cli.ExecutionContext in project neo4j by neo4j.

the class MemoryRecommendationsCommandTest method mustPrintMinimalPageCacheMemorySettingForConfiguredDb.

@Test
void mustPrintMinimalPageCacheMemorySettingForConfiguredDb() throws Exception {
    // given
    Path homeDir = neo4jLayout.homeDirectory();
    Path configDir = homeDir.resolve("conf");
    Files.createDirectories(configDir);
    Path configFile = configDir.resolve(DEFAULT_CONFIG_FILE_NAME);
    Files.createFile(configFile);
    createDatabaseWithNativeIndexes(homeDir, DEFAULT_DATABASE_NAME);
    PrintStream output = mock(PrintStream.class);
    MemoryRecommendationsCommand command = new MemoryRecommendationsCommand(new ExecutionContext(homeDir, configDir, output, mock(PrintStream.class), testDirectory.getFileSystem()));
    String heap = bytesToString(recommendHeapMemory(gibiBytes(8)));
    String pagecache = bytesToString(recommendPageCacheMemory(gibiBytes(8), gibiBytes(2)));
    // when
    CommandLine.populateCommand(command, "--memory=8g");
    command.execute();
    // then
    verify(output).println(contains(initial_heap_size.name() + "=" + heap));
    verify(output).println(contains(max_heap_size.name() + "=" + heap));
    verify(output).println(contains(pagecache_memory.name() + "=" + pagecache));
    DatabaseLayout databaseLayout = neo4jLayout.databaseLayout(DEFAULT_DATABASE_NAME);
    DatabaseLayout systemLayout = neo4jLayout.databaseLayout(SYSTEM_DATABASE_NAME);
    long[] expectedSizes = calculatePageCacheFileSize(databaseLayout);
    long[] systemSizes = calculatePageCacheFileSize(systemLayout);
    long expectedPageCacheSize = expectedSizes[0] + systemSizes[0];
    long expectedLuceneSize = expectedSizes[1] + systemSizes[1];
    verify(output).println(contains("Total size of lucene indexes in all databases: " + bytesToString(expectedLuceneSize)));
    verify(output).println(contains("Total size of data and native indexes in all databases: " + bytesToString(expectedPageCacheSize)));
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) MemoryRecommendationsCommand.bytesToString(org.neo4j.commandline.dbms.MemoryRecommendationsCommand.bytesToString) Test(org.junit.jupiter.api.Test)

Example 23 with ExecutionContext

use of org.neo4j.cli.ExecutionContext in project neo4j by neo4j.

the class MemoryRecommendationsCommandTest method mustPrintRecommendationsAsConfigReadableOutput.

@Test
void mustPrintRecommendationsAsConfigReadableOutput() throws Exception {
    PrintStream output = mock(PrintStream.class);
    Path homeDir = testDirectory.homePath();
    Path configDir = homeDir.resolve("conf");
    Path configFile = configDir.resolve(DEFAULT_CONFIG_FILE_NAME);
    Files.createDirectories(configDir);
    store(stringMap(data_directory.name(), homeDir.toString()), configFile);
    MemoryRecommendationsCommand command = new MemoryRecommendationsCommand(new ExecutionContext(homeDir, configDir, output, mock(PrintStream.class), testDirectory.getFileSystem()));
    CommandLine.populateCommand(command, "--memory=8g");
    String heap = bytesToString(recommendHeapMemory(gibiBytes(8)));
    String pagecache = bytesToString(recommendPageCacheMemory(gibiBytes(8), gibiBytes(2)));
    String offHeap = bytesToString(gibiBytes(2));
    command.execute();
    verify(output).println(initial_heap_size.name() + "=" + heap);
    verify(output).println(max_heap_size.name() + "=" + heap);
    verify(output).println(pagecache_memory.name() + "=" + pagecache);
    verify(output).println(tx_state_max_off_heap_memory.name() + "=" + offHeap);
    verify(output).println(additional_jvm.name() + "=" + "-XX:+ExitOnOutOfMemoryError");
}
Also used : Path(java.nio.file.Path) PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) MemoryRecommendationsCommand.bytesToString(org.neo4j.commandline.dbms.MemoryRecommendationsCommand.bytesToString) Test(org.junit.jupiter.api.Test)

Example 24 with ExecutionContext

use of org.neo4j.cli.ExecutionContext in project neo4j by neo4j.

the class DumpCommandIT method execute.

private void execute(String database, Path to) {
    final ExecutionContext ctx = new ExecutionContext(homeDir, configDir, mock(PrintStream.class), mock(PrintStream.class), testDirectory.getFileSystem());
    final var command = new DumpCommand(ctx, dumper);
    CommandLine.populateCommand(command, "--database=" + database, "--to=" + to.toAbsolutePath());
    command.execute();
}
Also used : PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext)

Example 25 with ExecutionContext

use of org.neo4j.cli.ExecutionContext in project neo4j by neo4j.

the class SetDefaultAdminCommandTest method setup.

@BeforeEach
void setup() throws IOException, InvalidArgumentsException {
    command = new SetDefaultAdminCommand(new ExecutionContext(testDir.directory("home"), testDir.directory("conf"), mock(PrintStream.class), mock(PrintStream.class), fileSystem));
    final Config config = command.loadNeo4jConfig();
    UserRepository users = CommunitySecurityModule.getUserRepository(config, NullLogProvider.getInstance(), fileSystem);
    users.create(new User.Builder("jake", LegacyCredential.forPassword("123")).withRequiredPasswordChange(false).build());
    adminIniFile = CommunitySecurityModule.getUserRepositoryFile(config).resolveSibling("admin.ini");
}
Also used : PrintStream(java.io.PrintStream) ExecutionContext(org.neo4j.cli.ExecutionContext) UserRepository(org.neo4j.server.security.auth.UserRepository) FileUserRepository(org.neo4j.server.security.auth.FileUserRepository) User(org.neo4j.kernel.impl.security.User) Config(org.neo4j.configuration.Config) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ExecutionContext (org.neo4j.cli.ExecutionContext)38 Test (org.junit.jupiter.api.Test)30 PrintStream (java.io.PrintStream)21 CheckConsistencyCommand (org.neo4j.consistency.CheckConsistencyCommand)13 Path (java.nio.file.Path)12 ConsistencyCheckService (org.neo4j.consistency.ConsistencyCheckService)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 ConsistencyFlags (org.neo4j.consistency.checking.full.ConsistencyFlags)10 Config (org.neo4j.configuration.Config)8 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)8 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)6 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)6 ProgressMonitorFactory (org.neo4j.internal.helpers.progress.ProgressMonitorFactory)5 LogProvider (org.neo4j.logging.LogProvider)5 BeforeEach (org.junit.jupiter.api.BeforeEach)4 CommandFailedException (org.neo4j.cli.CommandFailedException)4 MemoryRecommendationsCommand.bytesToString (org.neo4j.commandline.dbms.MemoryRecommendationsCommand.bytesToString)4 FileSystem (java.nio.file.FileSystem)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock.matchingJsonPath (com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath)1