public void TestPostSendInterceptorWithSentMessage()
        {
            QueueChannel channel = new QueueChannel();
            AtomicBoolean invoked = new AtomicBoolean(false);

            channel.AddInterceptor(new TestPostSendInterceptorWithSentMessageInterceptor(invoked, channel));

            channel.Send(new StringMessage("test"));
            Assert.IsTrue(invoked.Value);
        }
 public void ForEachStopsAsSoonAsStopCalledAt(
     [Values(Parallelism / 2, Parallelism, Parallelism * 2)] int stopAt)
 {
     string[] sources = TestData<string>.MakeTestArray(_sampleSize);
     List<string> completed = new List<string>(_sampleSize);
     Exception e = null;
     long badIndex = 0;
     var stopCalled = new AtomicBoolean();
     Action<string, ParallelLoopState, long> body =
         (t, s, i) =>
             {
                 if (i == stopAt)
                 {
                     s.Stop();
                     stopCalled.Value = true;
                 }
                 else
                 {
                     try
                     {
                         do { Thread.Sleep(10); }
                         while (i == 0 && !stopCalled);
                     }
                     catch(ThreadInterruptedException){}
                     if (!s.ShouldExitCurrentIteration)
                         lock (completed) completed.Add(t);
                     else
                     {
                         try
                         {
                             Assert.That(s.LowestBreakIteration, Is.Null);
                             Assert.That(s.IsExceptional, Is.False);
                             Assert.That(s.IsStopped, Is.True);
                         }
                         catch (Exception ex)
                         {
                             lock (completed)
                             {
                                 e = ex;
                                 badIndex = i;
                             }
                         }
                     }
                 }
             };
     var result = Parallel.ForEach(sources, body);
     Assert.That(result.IsCompleted, Is.False);
     Assert.That(result.LowestBreakIteration, Is.Null);
     lock (completed)
     {
         if (e != null) throw new AssertionException("Error processing " + badIndex, e);
         Assert.That(completed, Has.No.Member(sources[0]));
     }
 }
 public TestPostSendInterceptorWithSentMessageInterceptor(AtomicBoolean invoked, IMessageChannel channel)
 {
     _invoked = invoked;
     _channel = channel;
 }