Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void execute(String[] incomingArguments) throws org.neo4j.commandline.admin.IncorrectUsage, org.neo4j.commandline.admin.CommandFailed
        public override void Execute(string[] incomingArguments)
        {
            string databaseName;
            string fromPath;
            bool   forceOverwrite;

            try
            {
                databaseName   = _arguments.parse(incomingArguments).get(ARG_DATABASE);
                fromPath       = _arguments.get("from");
                forceOverwrite = _arguments.getBoolean("force");
            }
            catch (System.ArgumentException e)
            {
                throw new IncorrectUsage(e.Message);
            }

            Config config = LoadNeo4jConfig(_homeDir, _configDir, databaseName);

            try
            {
                using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction())
                {
                    RestoreDatabaseCommand restoreDatabaseCommand = new RestoreDatabaseCommand(fileSystem, new File(fromPath), config, databaseName, forceOverwrite);
                    restoreDatabaseCommand.Execute();
                }
            }
            catch (IOException e)
            {
                throw new CommandFailed("Failed to restore database", e);
            }
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void rebuildReplicatedIdGeneratorsOnRecovery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void RebuildReplicatedIdGeneratorsOnRecovery()
        {
            DefaultFileSystemAbstraction fileSystem = FileSystemRule.get();
            File stickyGenerator      = new File(TestDirectory.databaseDir(), "stickyGenerator");
            File nodeStoreIdGenerator = TestDirectory.databaseLayout().idNodeStore();

            StoreFactory storeFactory = new StoreFactory(TestDirectory.databaseLayout(), Config.defaults(), GetIdGenerationFactory(fileSystem), PageCacheRule.getPageCache(fileSystem), fileSystem, NullLogProvider.Instance, EmptyVersionContextSupplier.EMPTY);

            using (NeoStores neoStores = storeFactory.OpenAllNeoStores(true))
            {
                NodeStore nodeStore = neoStores.NodeStore;
                for (int i = 0; i < 50; i++)
                {
                    NodeRecord nodeRecord = nodeStore.NewRecord();
                    nodeRecord.InUse = true;
                    nodeRecord.Id    = nodeStore.NextId();
                    if (i == 47)
                    {
                        FileUtils.copyFile(nodeStoreIdGenerator, stickyGenerator);
                    }
                    nodeStore.UpdateRecord(nodeRecord);
                }
            }

            FileUtils.copyFile(stickyGenerator, nodeStoreIdGenerator);
            using (NeoStores reopenedStores = storeFactory.OpenAllNeoStores())
            {
                reopenedStores.MakeStoreOk();
                assertEquals(51L, reopenedStores.NodeStore.nextId());
            }
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static org.neo4j.kernel.impl.transaction.log.files.LogFiles readLogFiles(org.neo4j.io.layout.DatabaseLayout databaseLayout) throws java.io.IOException
        internal static LogFiles ReadLogFiles(DatabaseLayout databaseLayout)
        {
            FileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction();
            PageCache             pageCache             = ConfigurableStandalonePageCacheFactory.createPageCache(fileSystemAbstraction, new ThreadPoolJobScheduler());

            return(LogFilesBuilder.activeFilesBuilder(databaseLayout, fileSystemAbstraction, pageCache).build());
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            _backupLayout          = TestDirectory.databaseLayout("backups");
            _backupDir             = _backupLayout.databaseDirectory().toPath();
            _fs                    = new DefaultFileSystemAbstraction();
            _jobScheduler          = new ThreadPoolJobScheduler();
            _pageCache             = StandalonePageCacheFactory.createPageCache(_fs, _jobScheduler);
            _backupProtocolService = _backupProtocolService();
            _backupTool            = new BackupTool(_backupProtocolService, mock(typeof(PrintStream)));
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void run() throws Exception
        public virtual void Run()
        {
            using (FileSystemAbstraction fs = new DefaultFileSystemAbstraction(), JobScheduler jobScheduler = new ThreadPoolJobScheduler())
            {
                PageSwapperFactory swapperFactory = new SingleFilePageSwapperFactory();
                swapperFactory.Open(fs, Configuration.EMPTY);
                using (PageCache pageCacheUnderTest = new MuninnPageCache(swapperFactory, _numberOfCachePages, _tracer, _pageCursorTracerSupplier, EmptyVersionContextSupplier.EMPTY, jobScheduler))
                {
                    PageCacheStresser pageCacheStresser = new PageCacheStresser(_numberOfPages, _numberOfThreads, _workingDirectory);
                    pageCacheStresser.Stress(pageCacheUnderTest, _condition);
                }
            }
        }
Ejemplo n.º 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldRespectTheStoreLock() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldRespectTheStoreLock()
        {
            Path databaseDirectory = _homeDir.resolve("data/databases/foo.db");

            Files.createDirectories(databaseDirectory);
            StoreLayout storeLayout = DatabaseLayout.of(databaseDirectory.toFile()).StoreLayout;

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), StoreLocker locker = new StoreLocker(fileSystem, storeLayout))
            {
                locker.CheckLock();
                CommandFailed commandFailed = assertThrows(typeof(CommandFailed), () => execute("foo.db", "--force"));
                assertEquals("the database is in use -- stop Neo4j and try again", commandFailed.Message);
            }
        }
Ejemplo n.º 7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testFailsOnExistingStoreLockFile() throws java.io.IOException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void TestFailsOnExistingStoreLockFile()
        {
            // Given
            StoreLayout storeLayout = _testDirectory.storeLayout();

            using (FileSystemAbstraction fileSystemAbstraction = new DefaultFileSystemAbstraction(), StoreLocker @lock = new StoreLocker(fileSystemAbstraction, storeLayout))
            {
                @lock.CheckLock();

                // Then
                _expected.expect(typeof(StoreLockException));
                _expected.expectMessage("Unable to obtain lock on store lock file");
                // When
                BatchInserters.inserter(storeLayout.DatabaseLayout("any").databaseDirectory(), fileSystemAbstraction);
            }
        }
Ejemplo n.º 8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public System.Nullable<long> call() throws Exception
        public override long?Call()
        {
            long lastCommittedTransactionId;

            using (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction(), Lifespan life = new Lifespan())
            {
                TransactionIdStore       transactionIdStore       = new SimpleTransactionIdStore();
                TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache();
                LogFiles logFiles = life.Add(CreateLogFiles(transactionIdStore, fileSystem));

                TransactionAppender transactionAppender = life.Add(CreateBatchingTransactionAppender(transactionIdStore, transactionMetadataCache, logFiles));

                ExecutorService executorService = Executors.newFixedThreadPool(_threads);
                try
                {
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.concurrent.Future<?>[] handlers = new java.util.concurrent.Future[threads];
                    Future <object>[] handlers = new Future[_threads];
                    for (int i = 0; i < _threads; i++)
                    {
                        TransactionRepresentationFactory factory = new TransactionRepresentationFactory();
                        Worker task = new Worker(transactionAppender, factory, _condition);
                        handlers[i] = executorService.submit(task);
                    }

                    // wait for all the workers to complete
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (java.util.concurrent.Future<?> handle : handlers)
                    foreach (Future <object> handle in handlers)
                    {
                        handle.get();
                    }
                }
                finally
                {
                    executorService.shutdown();
                }

                lastCommittedTransactionId = transactionIdStore.LastCommittedTransactionId;
            }

            return(lastCommittedTransactionId);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustAutomaticallyStartEvictionThread() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustAutomaticallyStartEvictionThread()
        {
            using (FileSystemAbstraction fs = new DefaultFileSystemAbstraction(), JobScheduler jobScheduler = new ThreadPoolJobScheduler())
            {
                File file = (new File(TestDirectory.directory(), "a")).CanonicalFile;
                fs.Create(file).close();

                using (PageCache cache = ConfigurableStandalonePageCacheFactory.CreatePageCache(fs, jobScheduler), PagedFile pf = cache.Map(file, 4096), PageCursor cursor = pf.Io(0, Org.Neo4j.Io.pagecache.PagedFile_Fields.PfSharedWriteLock))
                {
                    // The default size is currently 8MBs.
                    // It should be possible to write more than that.
                    // If the eviction thread has not been started, then this test will block forever.
                    for (int i = 0; i < 10_000; i++)
                    {
                        assertTrue(cursor.Next());
                        cursor.PutInt(42);
                    }
                }
            }
        }
Ejemplo n.º 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public long parseAllTxLogs() throws java.io.IOException
            public virtual long ParseAllTxLogs()
            {
                // Initialize this txId to the BASE_TX_ID because if we don't find any tx log that means that
                // no transactions have been appended in this test and that getLastCommittedTransactionId()
                // will also return this constant. Why this is, is another question - but thread scheduling and
                // I/O spikes on some build machines can be all over the place and also the test duration is
                // configurable.
                long txId = Org.Neo4j.Kernel.impl.transaction.log.TransactionIdStore_Fields.BASE_TX_ID;

                using (FileSystemAbstraction fs = new DefaultFileSystemAbstraction(), ReadableLogChannel channel = OpenLogFile(fs, 0))
                {
                    LogEntryReader <ReadableLogChannel> reader = new VersionAwareLogEntryReader <ReadableLogChannel>();
                    LogEntry logEntry = reader.ReadLogEntry(channel);
                    for ( ; logEntry != null; logEntry = reader.ReadLogEntry(channel))
                    {
                        if (logEntry.Type == LogEntryByteCodes.TX_COMMIT)
                        {
                            txId = logEntry.As <LogEntryCommit>().TxId;
                        }
                    }
                }
                return(txId);
            }
Ejemplo n.º 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            _storeDirectory = TestDirectory.directory();
            _fileSystem     = FileSystemRule.get();
        }