示例#1
0
        private bool Recover(File storeDir, LogFiles logFiles)
        {
            LifeSupport     life    = new LifeSupport();
            RecoveryMonitor monitor = mock(typeof(RecoveryMonitor));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean recoveryRequired = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean recoveryRequired = new AtomicBoolean();

            try
            {
                StorageEngine storageEngine = mock(typeof(StorageEngine));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel> reader = new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>();
                LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
                LogTailScanner tailScanner = GetTailScanner(logFiles, reader);

                TransactionMetadataCache metadataCache = new TransactionMetadataCache();
                LogicalTransactionStore  txStore       = new PhysicalLogicalTransactionStore(logFiles, metadataCache, reader, _monitors, false);
                CorruptedLogsTruncator   logPruner     = new CorruptedLogsTruncator(storeDir, logFiles, FileSystemRule.get());
                life.add(new Recovery(new DefaultRecoveryServiceAnonymousInnerClass3(this, storageEngine, tailScanner, _transactionIdStore, txStore, _versionRepository, NO_MONITOR, recoveryRequired)
                                      , logPruner, _schemaLife, monitor, SilentProgressReporter.INSTANCE, false));

                life.Start();
            }
            finally
            {
                life.Shutdown();
            }
            return(recoveryRequired.get());
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldOpenAndRecoverExistingData() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldOpenAndRecoverExistingData()
        {
            // GIVEN
            TransactionIdStore       transactionIdStore = new SimpleTransactionIdStore();
            TransactionMetadataCache positionCache      = new TransactionMetadataCache();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final byte[] additionalHeader = new byte[]{1, 2, 5};
            sbyte[]     additionalHeader             = new sbyte[] { 1, 2, 5 };
            const int   masterId                     = 2;
            int         authorId                     = 1;
            const long  timeStarted                  = 12345;
            long        latestCommittedTxWhenStarted = 4545;
            long        timeCommitted                = timeStarted + 10;
            LifeSupport life = new LifeSupport();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.files.LogFiles logFiles = org.neo4j.kernel.impl.transaction.log.files.LogFilesBuilder.builder(dir.databaseLayout(), fileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(LogVersionRepository.class)).build();
            LogFiles logFiles = LogFilesBuilder.builder(Dir.databaseLayout(), FileSystemRule.get()).withTransactionIdStore(transactionIdStore).withLogVersionRepository(mock(typeof(LogVersionRepository))).build();

            life.Start();
            life.Add(logFiles);
            try
            {
                AddATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
            }
            finally
            {
                life.Shutdown();
            }

            life = new LifeSupport();
            life.Add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean recoveryRequired = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean       recoveryRequired = new AtomicBoolean();
            FakeRecoveryVisitor visitor          = new FakeRecoveryVisitor(additionalHeader, masterId, authorId, timeStarted, timeCommitted, latestCommittedTxWhenStarted);

            LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, positionCache, new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>(), _monitors, true);

            life.Add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, BYPASS, _databaseHealth));
            CorruptedLogsTruncator logPruner = new CorruptedLogsTruncator(_databaseDirectory, logFiles, FileSystemRule.get());

            life.add(new Recovery(new RecoveryServiceAnonymousInnerClass(this, recoveryRequired, visitor, txStore)
                                  , logPruner, new LifecycleAdapter(), mock(typeof(RecoveryMonitor)), SilentProgressReporter.INSTANCE, false));

            // WHEN
            try
            {
                life.Start();
            }
            finally
            {
                life.Shutdown();
            }

            // THEN
            assertEquals(1, visitor.VisitedTransactions);
            assertTrue(recoveryRequired.get());
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSeeThatACleanDatabaseShouldNotRequireRecovery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSeeThatACleanDatabaseShouldNotRequireRecovery()
        {
            File file = _logFiles.getLogFileForVersion(_logVersion);

            WriteSomeData(file, pair =>
            {
                LogEntryWriter writer = pair.first();
                Consumer <LogPositionMarker> consumer = pair.other();
                LogPositionMarker marker = new LogPositionMarker();

                // last committed tx
                consumer.accept(marker);
                writer.writeStartEntry(0, 1, 2L, 3L, new sbyte[0]);
                writer.writeCommitEntry(4L, 5L);

                // check point
                consumer.accept(marker);
                writer.writeCheckPointEntry(marker.newPosition());

                return(true);
            });

            LifeSupport     life    = new LifeSupport();
            RecoveryMonitor monitor = mock(typeof(RecoveryMonitor));

            try
            {
                StorageEngine storageEngine = mock(typeof(StorageEngine));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel> reader = new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>();
                LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
                LogTailScanner tailScanner = GetTailScanner(_logFiles, reader);

                TransactionMetadataCache metadataCache = new TransactionMetadataCache();
                LogicalTransactionStore  txStore       = new PhysicalLogicalTransactionStore(_logFiles, metadataCache, reader, _monitors, false);
                CorruptedLogsTruncator   logPruner     = new CorruptedLogsTruncator(_storeDir, _logFiles, FileSystemRule.get());
                life.add(new Recovery(new DefaultRecoveryServiceAnonymousInnerClass2(this, storageEngine, tailScanner, _transactionIdStore, txStore, _versionRepository, NO_MONITOR)
                                      , logPruner, _schemaLife, monitor, SilentProgressReporter.INSTANCE, false));

                life.Start();

                verifyZeroInteractions(monitor);
            }
            finally
            {
                life.Shutdown();
            }
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRecoverExistingData() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRecoverExistingData()
        {
            File file = _logFiles.getLogFileForVersion(_logVersion);

            WriteSomeData(file, pair =>
            {
                LogEntryWriter writer = pair.first();
                Consumer <LogPositionMarker> consumer = pair.other();
                LogPositionMarker marker = new LogPositionMarker();

                // last committed tx
                consumer.accept(marker);
                LogPosition lastCommittedTxPosition = marker.newPosition();
                writer.writeStartEntry(0, 1, 2L, 3L, new sbyte[0]);
                _lastCommittedTxStartEntry = new LogEntryStart(0, 1, 2L, 3L, new sbyte[0], lastCommittedTxPosition);
                writer.writeCommitEntry(4L, 5L);
                _lastCommittedTxCommitEntry = new LogEntryCommit(4L, 5L);

                // check point pointing to the previously committed transaction
                writer.writeCheckPointEntry(lastCommittedTxPosition);
                _expectedCheckPointEntry = new CheckPoint(lastCommittedTxPosition);

                // tx committed after checkpoint
                consumer.accept(marker);
                writer.writeStartEntry(0, 1, 6L, 4L, new sbyte[0]);
                _expectedStartEntry = new LogEntryStart(0, 1, 6L, 4L, new sbyte[0], marker.newPosition());

                writer.writeCommitEntry(5L, 7L);
                _expectedCommitEntry = new LogEntryCommit(5L, 7L);

                return(true);
            });

            LifeSupport     life    = new LifeSupport();
            RecoveryMonitor monitor = mock(typeof(RecoveryMonitor));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.atomic.AtomicBoolean recoveryRequired = new java.util.concurrent.atomic.AtomicBoolean();
            AtomicBoolean recoveryRequired = new AtomicBoolean();

            try
            {
                StorageEngine storageEngine = mock(typeof(StorageEngine));
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel> reader = new org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader<>();
                LogEntryReader <ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();
                LogTailScanner tailScanner = GetTailScanner(_logFiles, reader);

                TransactionMetadataCache metadataCache = new TransactionMetadataCache();
                LogicalTransactionStore  txStore       = new PhysicalLogicalTransactionStore(_logFiles, metadataCache, reader, _monitors, false);
                CorruptedLogsTruncator   logPruner     = new CorruptedLogsTruncator(_storeDir, _logFiles, FileSystemRule.get());
                life.add(new Recovery(new DefaultRecoveryServiceAnonymousInnerClass(this, storageEngine, tailScanner, _transactionIdStore, txStore, _versionRepository, NO_MONITOR, recoveryRequired)
                                      , logPruner, _schemaLife, monitor, SilentProgressReporter.INSTANCE, false));

                life.Start();

                InOrder order = inOrder(monitor);
                order.verify(monitor, times(1)).recoveryRequired(any(typeof(LogPosition)));
                order.verify(monitor, times(1)).recoveryCompleted(2);
                assertTrue(recoveryRequired.get());
            }
            finally
            {
                life.Shutdown();
            }
        }