コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public PhysicalTransactionCursor(T channel, org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader<T> entryReader) throws java.io.IOException
        public PhysicalTransactionCursor(T channel, LogEntryReader <T> entryReader)
        {
            this._channel = channel;
            channel.GetCurrentPosition(_lastGoodPositionMarker);
            this._logEntryCursor = new LogEntryCursor((LogEntryReader <ReadableClosablePositionAwareChannel>)entryReader, channel);
        }
コード例 #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void databasePanicShouldHandleOutOfMemoryErrors() throws java.io.IOException, InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DatabasePanicShouldHandleOutOfMemoryErrors()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch panicLatch = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent panicLatch = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch adversaryLatch = new java.util.concurrent.CountDownLatch(1);
            System.Threading.CountdownEvent adversaryLatch = new System.Threading.CountdownEvent(1);
            OutOfMemoryAwareFileSystem      fs             = new OutOfMemoryAwareFileSystem();

            _life.add(new FileSystemLifecycleAdapter(fs));
            DatabaseHealth slowPanicDatabaseHealth = new SlowPanickingDatabaseHealth(panicLatch, adversaryLatch);
            LogFiles       logFiles = LogFilesBuilder.builder(_testDirectory.databaseLayout(), fs).withLogVersionRepository(_logVersionRepository).withTransactionIdStore(_transactionIdStore).build();

            _life.add(logFiles);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final BatchingTransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, logRotation, transactionMetadataCache, transactionIdStore, explicitIndexTransactionOrdering, slowPanicDatabaseHealth));
            BatchingTransactionAppender appender = _life.add(new BatchingTransactionAppender(logFiles, _logRotation, _transactionMetadataCache, _transactionIdStore, _explicitIndexTransactionOrdering, slowPanicDatabaseHealth));

            _life.start();

            // Commit initial transaction
            appender.Append(Tx(), Org.Neo4j.Kernel.impl.transaction.tracing.LogAppendEvent_Fields.Null);

            // Try to commit one transaction, will fail during flush with OOM, but not actually panic
            fs.ShouldOOM = true;
            Future <long> failingTransaction = _executor.submit(() => appender.Append(Tx(), Org.Neo4j.Kernel.impl.transaction.tracing.LogAppendEvent_Fields.Null));

            panicLatch.await();

            // Try to commit one additional transaction, should fail since database has already panicked
            fs.ShouldOOM = false;
            try
            {
                appender.Append(Tx(), new LogAppendEvent_EmptyAnonymousInnerClass2(this, adversaryLatch));
                fail("Should have failed since database should have panicked");
            }
            catch (IOException e)
            {
                assertTrue(e.Message.contains("The database has encountered a critical error"));
            }

            // Check that we actually got an OutOfMemoryError
            try
            {
                failingTransaction.get();
                fail("Should have failed with OutOfMemoryError error");
            }
            catch (ExecutionException e)
            {
                assertTrue(e.InnerException is System.OutOfMemoryException);
            }

            // Check number of transactions, should only have one
            LogEntryReader <ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader <ReadableClosablePositionAwareChannel>();

            assertEquals(logFiles.LowestLogVersion, logFiles.HighestLogVersion);
            long version = logFiles.HighestLogVersion;

            using (LogVersionedStoreChannel channel = logFiles.OpenForVersion(version), ReadAheadLogChannel readAheadLogChannel = new ReadAheadLogChannel(channel), LogEntryCursor cursor = new LogEntryCursor(logEntryReader, readAheadLogChannel))
            {
                LogEntry entry;
                long     numberOfTransactions = 0;
                while (cursor.Next())
                {
                    entry = cursor.Get();
                    if (entry is LogEntryCommit)
                    {
                        numberOfTransactions++;
                    }
                }
                assertEquals(1, numberOfTransactions);
            }
        }