Пример #1
0
        /// <summary>
        /// This test makes sure that the database is able to start after having been stopped during initialization.
        ///
        /// In order to make sure that the server is stopped during startup we create a separate thread that calls stop.
        /// In order to make sure that this thread does not call stop before the startup procedure has started we use a
        /// custom implementation of a PageSwapperFactory, which communicates with the thread that calls stop. We do this
        /// via a static semaphore. </summary>
        /// <exception cref="IOException"> </exception>
        /// <exception cref="InterruptedException"> </exception>

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToRestartWhenStoppedDuringStartup() throws java.io.IOException, InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToRestartWhenStoppedDuringStartup()
        {
            // Make sure that the semaphore is in a clean state.
            _semaphore.drainPermits();
            // Get a server that uses our custom swapper.
            NeoServer server = GetNeoServer(CUSTOM_SWAPPER);

            try
            {
                AtomicBoolean failure = new AtomicBoolean();
                Thread        serverStoppingThread = ThreadTestUtils.fork(StopServerAfterStartingHasStarted(server, failure));
                server.Start();
                // Wait for the server to stop.
                serverStoppingThread.Join();
                // Check if the server stopped successfully.
                if (failure.get())
                {
                    fail("Server failed to stop.");
                }
                // Verify that we can start the server again.
                server = GetNeoServer(CUSTOM_SWAPPER);
                server.Start();
            }
            finally
            {
                server.Stop();
            }
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void writerCloseWaitForMergesInMergeQueue()
        internal virtual void WriterCloseWaitForMergesInMergeQueue()
        {
            assertTimeout(Duration.ofSeconds(10), () =>
            {
                _indexWriter = mock(typeof(IndexWriter));
                SegmentCommitInfo segmentCommitInfo = SegmentCommitInfo;

                Mockito.when(_indexWriter.NextMerge).thenReturn(new TestOneMerge(segmentCommitInfo)).thenReturn(null);

                _mergeScheduler.merge(_indexWriter, MergeTrigger.EXPLICIT, false);

                assertEquals(1, _mergeScheduler.WriterTaskCount);

                Thread closeSchedulerThread = ThreadTestUtils.fork(() => _mergeScheduler.close());
                ThreadTestUtils.awaitThreadState(closeSchedulerThread, TimeUnit.SECONDS.toMillis(5), Thread.State.TIMED_WAITING);
                _mergeScheduler.ExecutionLatch.Signal();
                closeSchedulerThread.Join();

                assertEquals(0, _mergeScheduler.WriterTaskCount);
            });
        }