Exemplo n.º 1
0
        public void When_interrupt_throws_then_doesnt_interrupt()
        {
            const BehaviourReturnCode actual = BehaviourReturnCode.Success;
            var action = new BehaviourAction(() => actual);

            var condition  = new Conditional(() => { throw new Exception(); });
            var returnCode = new Interruptible(action, condition, BehaviourReturnCode.Success).Behave();

            Assert.AreEqual(actual, returnCode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Marks the beginning of an I/O operation that might block indefinitely.
        ///
        /// <para> This method should be invoked in tandem with the <seealso cref="#end end"/>
        /// method, using a <tt>try</tt>&nbsp;...&nbsp;<tt>finally</tt> block as
        /// shown <a href="#be">above</a>, in order to implement interruption for
        /// this selector.
        ///
        /// </para>
        /// <para> Invoking this method arranges for the selector's {@link
        /// Selector#wakeup wakeup} method to be invoked if a thread's {@link
        /// Thread#interrupt interrupt} method is invoked while the thread is
        /// blocked in an I/O operation upon the selector.  </para>
        /// </summary>
        protected internal void Begin()
        {
            if (Interruptor == null)
            {
                Interruptor = new InterruptibleAnonymousInnerClassHelper(this);
            }
            AbstractInterruptibleChannel.BlockedOn(Interruptor);
            Thread me = Thread.CurrentThread;

            if (me.Interrupted)
            {
                Interruptor.interrupt(me);
            }
        }
Exemplo n.º 3
0
        public void When_interrupt_is_true_returns_assigned_interrupt_return_value()
        {
            var action = new BehaviourAction(() => BehaviourReturnCode.Success);

            var condition = new Conditional(() => true);

            var successInterruptable = new Interruptible(action, condition, BehaviourReturnCode.Success);
            var failureInterruptable = new Interruptible(action, condition, BehaviourReturnCode.Failure);
            var runningInterruptable = new Interruptible(action, condition, BehaviourReturnCode.Running);

            Assert.AreEqual(successInterruptable.Behave(), BehaviourReturnCode.Success);
            Assert.AreEqual(failureInterruptable.Behave(), BehaviourReturnCode.Failure);
            Assert.AreEqual(runningInterruptable.Behave(), BehaviourReturnCode.Running);
        }
Exemplo n.º 4
0
        public void When_interrupt_is_false_child_behaves_as_normal()
        {
            var successAction = new BehaviourAction(() => BehaviourReturnCode.Success);
            var failureAction = new BehaviourAction(() => BehaviourReturnCode.Failure);
            var runningAction = new BehaviourAction(() => BehaviourReturnCode.Running);

            var condition = new Conditional(() => false);

            var successInterruptable = new Interruptible(successAction, condition, BehaviourReturnCode.Failure);
            var failureInterruptable = new Interruptible(failureAction, condition, BehaviourReturnCode.Failure);
            var runningInterruptable = new Interruptible(runningAction, condition, BehaviourReturnCode.Failure);

            Assert.AreEqual(successInterruptable.Behave(), BehaviourReturnCode.Success);
            Assert.AreEqual(failureInterruptable.Behave(), BehaviourReturnCode.Failure);
            Assert.AreEqual(runningInterruptable.Behave(), BehaviourReturnCode.Running);
        }
 // -- sun.misc.SharedSecrets --
 internal static void BlockedOn(Interruptible intr)         // package-private
 {
     sun.misc.SharedSecrets.JavaLangAccess.blockedOn(Thread.CurrentThread, intr);
 }