Exemplo n.º 1
0
        /// <summary>
        /// Gets the update puller going, if it's not already going, and waits for the supplied condition to be
        /// fulfilled as part of the update pulling happening.
        /// </summary>
        /// <param name="condition"> <seealso cref="UpdatePuller.Condition"/> to wait for. </param>
        /// <param name="strictlyAssertActive"> if {@code true} then observing an inactive update puller, whether
        /// <seealso cref="stop() halted"/>, will throw an <seealso cref="System.InvalidOperationException"/>,
        /// otherwise if {@code false} just stop waiting and return {@code false}. </param>
        /// <returns> whether or not the condition was met. If {@code strictlyAssertActive} either
        /// {@code true} will be returned or exception thrown, if puller became inactive.
        /// If {@code !strictlyAssertActive} and puller became inactive then {@code false} is returned. </returns>
        /// <exception cref="InterruptedException"> if we were interrupted while awaiting the condition. </exception>
        /// <exception cref="IllegalStateException"> if {@code strictlyAssertActive} and the update puller
        /// became inactive while awaiting the condition. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private boolean await(UpdatePuller_Condition condition, boolean strictlyAssertActive) throws InterruptedException
        private bool Await(UpdatePuller_Condition condition, bool strictlyAssertActive)
        {
            if (!CheckActive(strictlyAssertActive))
            {
                return(false);
            }

            int ticket = Poke();

            while (!condition.Evaluate(_currentTicket.get(), ticket))
            {
                if (!CheckActive(strictlyAssertActive))
                {
                    return(false);
                }

                Thread.Sleep(1);
            }
            return(true);
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldThrowIfPullerBecomesInactiveWhileWaitingStrict() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldThrowIfPullerBecomesInactiveWhileWaitingStrict()
        {
            // GIVEN
            UpdatePuller_Condition condition = mock(typeof(UpdatePuller_Condition));

            when(condition.Evaluate(anyInt(), anyInt())).thenAnswer(invocation =>
            {
                _updatePuller.stop();
                return(false);
            });

            // WHEN
            try
            {
                _updatePuller.pullUpdates(condition, true);
                fail("Should have thrown");
            }
            catch (System.InvalidOperationException)
            {               // THEN Good
                verify(condition).evaluate(anyInt(), anyInt());
            }
        }