Ejemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void queryLogRotation()
        public virtual void QueryLogRotation()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File logsDirectory = new java.io.File(testDirectory.storeDir(), "logs");
            File logsDirectory = new File(TestDirectory.storeDir(), "logs");

            _databaseBuilder.setConfig(log_queries, Settings.TRUE).setConfig(logs_directory, logsDirectory.Path).setConfig(log_queries_max_archives, "100").setConfig(log_queries_rotation_threshold, "1");
            _database = _databaseBuilder.newGraphDatabase();

            // Logging is done asynchronously, and it turns out it's really hard to make it all work the same on Linux
            // and on Windows, so just write many times to make sure we rotate several times.

            for (int i = 0; i < 100; i++)
            {
                _database.execute(QUERY);
            }

            _database.shutdown();

            File[] queryLogs = FileSystem.get().listFiles(logsDirectory, (dir, name) => name.StartsWith("query.log"));
            assertThat("Expect to have more then one query log file.", queryLogs.Length, greaterThanOrEqualTo(2));

            IList <string> loggedQueries = java.util.queryLogs.Select(this.readAllLinesSilent).flatMap(System.Collections.ICollection.stream).ToList();

            assertThat("Expected log file to have at least one log entry", loggedQueries, hasSize(100));

            _database = _databaseBuilder.newGraphDatabase();
            // Now modify max_archives and rotation_threshold at runtime, and observe that we end up with fewer larger files
            _database.execute("CALL dbms.setConfigValue('" + log_queries_max_archives.name() + "','1')");
            _database.execute("CALL dbms.setConfigValue('" + log_queries_rotation_threshold.name() + "','20m')");
            for (int i = 0; i < 100; i++)
            {
                _database.execute(QUERY);
            }

            _database.shutdown();

            queryLogs = FileSystem.get().listFiles(logsDirectory, (dir, name) => name.StartsWith("query.log"));
            assertThat("Expect to have more then one query log file.", queryLogs.Length, lessThan(100));

            loggedQueries = java.util.queryLogs.Select(this.readAllLinesSilent).flatMap(System.Collections.ICollection.stream).ToList();
            assertThat("Expected log file to have at least one log entry", loggedQueries.Count, lessThanOrEqualTo(202));
        }
Ejemplo n.º 2
0
 public virtual void EnsureStarted()
 {
     lock (this)
     {
         if (_database == null)
         {
             _database          = ( GraphDatabaseAPI )_databaseBuilder.newGraphDatabase();
             _databaseLayout    = _database.databaseLayout();
             _statementSupplier = ResolveDependency(typeof(ThreadToStatementContextBridge));
         }
     }
 }
Ejemplo n.º 3
0
 private GraphDatabaseService CreateDatabase()
 {
     return(_cleanup.add(_builder.newGraphDatabase()));
 }