Пример #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();
            }
        }
        public void DeleteFileLocksFile()
        {
            Debug.WriteLine("TEST START: DeleteFileLocksFile");

            using (new FileMutex(FileName))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(
                    () => { Assert.ThrowsException <InvalidOperationException>(() => _io.DeleteFile(FileName)); });
            }
        }
        public void DeleteFileLocksParentDirectory()
        {
            Debug.WriteLine("TEST START: DeleteFileLocksParentDirectory");

            // Mutex name for the root directory, which is the parent directory for the file we're about to try to delete
            using (new FileMutex(string.Empty))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(
                    () => Assert.ThrowsException <InvalidOperationException>(() => { _io.DeleteFile(FileName); }));
            }
        }
        public void ReadFileConcurrently()
        {
            _io.Write(FileName, _data);

            ThreadTestUtils.ParallelExecute(
                () =>
            {
                Thread.Sleep(new Random().Next() % 10);
                byte[] actual = _io.Read(FileName);
                CollectionAssert.AreEqual(_data, actual);
            });
        }
        public void ReadFileDoesNotLockParentDirectory()
        {
            Debug.WriteLine("TEST START: ReadFileDoesNotLockParentDirectory");

            _io.Write(FileName, _data);

            // Mutex name for the root directory, which is the parent directory for the file we're about to read
            using (new FileMutex(string.Empty))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(() => { Assert.AreEqual(_data, _io.Read(FileName)); });
            }
        }
        public void DeleteContentLocksParentDirectory()
        {
            Debug.WriteLine("TEST START: DeleteContentLocksParentDirectory");

            _io.Write("x/a.txt", _data);

            // Mutex name for the root directory, which is the parent directory for the directory we're about to try to delete
            using (new FileMutex(string.Empty))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(
                    () => Assert.ThrowsException <InvalidOperationException>(() => _io.DeleteContent("x")));
            }
        }
        public void WriteFileConcurrently()
        {
            ThreadTestUtils.ParallelExecute(
                () =>
            {
                Thread.Sleep(new Random().Next() % 10);
                _io.Write(FileName, _data);
            });

            CollectionAssert.AreEqual(_data, _io.Read(FileName));

            // The file is in the right location
            Assert.IsTrue(_io.RootDirectory.FileExists(FileName));
        }
        public void WriteDoesNotLockParentDirectory()
        {
            Debug.WriteLine("TEST START: WriteDoesNotLockParentDirectory");

            // Mutex name for the root directory, which is the parent directory for the file we're about to write to
            // Create the file
            _io.Write(FileName, _data);

            using (new FileMutex(string.Empty))
            {
                // Writing into the file should work, because the file already exists and FileIO::Write doesn't need to lock the
                // parent directory
                ThreadTestUtils.RunActionOnThreadAndJoin(() => _io.Write(FileName, _data));
            }
        }
        [Ignore]  // TODO: re-enable this, getting mutex timeouts...
        public void WriteFileConcurrently()
        {
            Debug.WriteLine("TEST START: WriteFileConcurrently");

            ThreadTestUtils.ParallelExecute(
                () =>
            {
                Thread.Sleep(new Random().Next() % 10);
                _io.Write(FileName, _data);
            });

            CollectionAssert.AreEqual(_data, _io.Read(FileName));

            // The file is in the right location
            Assert.IsTrue(File.Exists(_io.GetFullPath(FileName)));
        }
        [Ignore]  // TODO: re-enable this, getting mutex timeouts...
        public void CreateDirectoriesConcurrently()
        {
            Debug.WriteLine("TEST START: CreateDirectoriesConcurrently");

            ThreadTestUtils.ParallelExecute(
                () =>
            {
                Thread.Sleep(new Random().Next() % 10);
                using (_io.CreateDirectoriesLockParent("Level1/Level2/Level3"))
                {
                }
            });

            string actual = _io.GetFullPath("Level1/Level2/Level3");

            Assert.IsTrue(Directory.Exists(actual));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void closeWaitForUpdateToFinish() throws java.io.IOException, InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CloseWaitForUpdateToFinish()
        {
            // GIVEN
            System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexProxy inner = new IndexProxyAdapter()
            IndexProxy inner = new IndexProxyAdapterAnonymousInnerClass3(this);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexProxy outer = newContractCheckingIndexProxy(inner);
            IndexProxy outer        = NewContractCheckingIndexProxy(inner);
            Thread     actionThread = CreateActionThread(outer.close);

            outer.Start();

            // WHEN
            Thread updaterThread = RunInSeparateThread(() =>
            {
                try
                {
                    using (IndexUpdater updater = outer.NewUpdater(IndexUpdateMode.Online))
                    {
                        updater.process(null);
                        try
                        {
                            actionThread.Start();
                            latch.await();
                        }
                        catch (InterruptedException e)
                        {
                            throw new Exception(e);
                        }
                    }
                }
                catch (IndexEntryConflictException e)
                {
                    throw new Exception(e);
                }
            });

            ThreadTestUtils.awaitThreadState(actionThread, TEST_TIMEOUT, Thread.State.TIMED_WAITING);
            latch.Signal();
            updaterThread.Join();
            actionThread.Join();
        }
Пример #12
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);
            });
        }
        public void LockFile()
        {
            Debug.WriteLine("TEST START: LockFile");

            using (_io.LockFile(FileName))
            {
                ThreadTestUtils.RunActionOnThreadAndJoin(
                    () =>
                {
                    // Another thread should not be able to acquire mutex with this name because it's being used by fileMutex
                    Assert.ThrowsException <InvalidOperationException>(() => new FileMutex(FileName));
                });
            }

            ThreadTestUtils.RunActionOnThreadAndJoin(
                () =>
            {
                // Now this thread should be able to acquire mutex with this name because fileMutex went out of scope
                Assert.ThrowsException <InvalidOperationException>(() => new FileMutex(FileName));
            });
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = TEST_TIMEOUT) public void closeWaitForForceToComplete() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CloseWaitForForceToComplete()
        {
            // GIVEN
            System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(1);
            AtomicReference <Thread>        actionThreadReference = new AtomicReference <Thread>();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final IndexProxy inner = new IndexProxyAdapter()
            IndexProxy inner        = new IndexProxyAdapterAnonymousInnerClass4(this, latch, actionThreadReference);
            IndexProxy outer        = NewContractCheckingIndexProxy(inner);
            Thread     actionThread = CreateActionThread(outer.close);

            actionThreadReference.set(actionThread);

            outer.Start();
            Thread thread = RunInSeparateThread(() => outer.force(Org.Neo4j.Io.pagecache.IOLimiter_Fields.Unlimited));

            ThreadTestUtils.awaitThreadState(actionThread, TEST_TIMEOUT, Thread.State.TIMED_WAITING);
            latch.Signal();

            thread.Join();
            actionThread.Join();
        }
Пример #15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void takeOrAwaitLatchMustAwaitExistingLatchAndReturnNull() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void TakeOrAwaitLatchMustAwaitExistingLatchAndReturnNull()
        {
            AtomicReference <Thread> threadRef = new AtomicReference <Thread>();
            BinaryLatch latch = _latches.takeOrAwaitLatch(42);

            assertThat(latch, @is(notNullValue()));
            ExecutorService      executor = Executors.newSingleThreadExecutor();
            Future <BinaryLatch> future   = executor.submit(() =>
            {
                threadRef.set(Thread.CurrentThread);
                return(_latches.takeOrAwaitLatch(42));
            });
            Thread th;

            do
            {
                th = threadRef.get();
            } while (th == null);
            ThreadTestUtils.awaitThreadState(th, 10_000, Thread.State.WAITING);
            latch.Release();
            assertThat(future.get(1, TimeUnit.SECONDS), @is(nullValue()));
        }