コード例 #1
0
//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();
        }
コード例 #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);
            });
        }
コード例 #3
0
//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();
        }
コード例 #4
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()));
        }