public void Process_WithFollowingStage()
        {
            var stage1 = ProcessingPipelineStage.Create <ProcessingPipelineTestStage>("Stage1", null);
            var stage2 = stage1.AddNextStage <ProcessingPipelineTestStage>("Stage2");

            // initialize the stages
            Assert.False(stage1.IsInitialized);
            Assert.False(stage2.IsInitialized);
            stage1.Initialize();
            Assert.True(stage1.IsInitialized);
            Assert.True(stage2.IsInitialized);

            // process a log message
            var message = MessagePool.GetUninitializedMessage();

            Assert.False(stage1.ProcessSyncWasCalled);
            Assert.False(stage2.ProcessSyncWasCalled);
            stage1.ProcessMessage(message);
            Assert.True(stage1.ProcessSyncWasCalled);
            Assert.True(stage2.ProcessSyncWasCalled);
            Assert.Same(message, stage1.MessagePassedToProcessSync);
            Assert.Same(message, stage2.MessagePassedToProcessSync);

            // shut the stages down
            stage1.Shutdown();
            Assert.False(stage1.IsInitialized);
            Assert.False(stage2.IsInitialized);
        }
        public void Process_Standalone(bool processSyncReturnValue)
        {
            var callback = new Callback {
                ProcessSyncCallbackReturnValue = processSyncReturnValue
            };
            var stage = ProcessingPipelineStage.Create <CallbackPipelineStage>("Callback", null);

            stage.ProcessingCallback = callback.ProcessSyncCallback;

            // initialize the stage
            Assert.False(stage.IsInitialized);
            stage.Initialize();
            Assert.True(stage.IsInitialized);

            // process a log message
            var message = MessagePool.GetUninitializedMessage();

            Assert.False(callback.ProcessSyncCallbackWasCalled);
            stage.ProcessMessage(message);
            Assert.True(callback.ProcessSyncCallbackWasCalled);
            Assert.Same(message, callback.MessagePassedToProcessSyncCallback);

            // shut the stage down
            stage.Shutdown();
            Assert.False(stage.IsInitialized);
        }
Esempio n. 3
0
        public void Process_WithFollowingStage()
        {
            var stage1 = ProcessingPipelineStage.Create <AsyncProcessingPipelineTestStage>("Stage1", null);
            var stage2 = stage1.AddNextStage <AsyncProcessingPipelineTestStage>("Stage2");

            // initialize the stages
            Assert.False(stage1.IsInitialized);
            Assert.False(stage2.IsInitialized);
            stage1.Initialize();
            Assert.True(stage1.IsInitialized);
            Assert.True(stage2.IsInitialized);

            // process a log message
            var message = MessagePool.GetUninitializedMessage();

            Assert.False(stage1.ProcessSyncWasCalled);
            Assert.False(stage2.ProcessSyncWasCalled);
            Assert.False(stage1.ProcessAsyncWasCalled);
            Assert.False(stage2.ProcessAsyncWasCalled);
            stage1.ProcessMessage(message);
            Assert.True(stage1.ProcessSyncWasCalled);
            Assert.True(stage2.ProcessSyncWasCalled);
            Assert.Same(message, stage1.MessagePassedToProcessSync);
            Assert.Same(message, stage2.MessagePassedToProcessSync);

            // give the processing threads time to call ProcessAsync()
            Thread.Sleep(500);

            Assert.True(stage1.ProcessAsyncWasCalled);
            Assert.True(stage2.ProcessAsyncWasCalled);
            Assert.Single(stage1.MessagesPassedToProcessAsync);
            Assert.Single(stage2.MessagesPassedToProcessAsync);
            Assert.Same(message, stage1.MessagesPassedToProcessAsync.First());
            Assert.Same(message, stage2.MessagesPassedToProcessAsync.First());
        }
        public void Process_WithFollowingStage(bool processSyncReturnValue)
        {
            var callback1 = new Callback {
                ProcessSyncCallbackReturnValue = processSyncReturnValue
            };
            var callback2 = new Callback {
                ProcessSyncCallbackReturnValue = processSyncReturnValue
            };
            var stage1 = ProcessingPipelineStage.Create <CallbackPipelineStage>("Callback1", null);
            var stage2 = stage1.AddNextStage <CallbackPipelineStage>("Callback2");

            stage1.ProcessingCallback = callback1.ProcessSyncCallback;
            stage2.ProcessingCallback = callback2.ProcessSyncCallback;

            // initialize the stages
            Assert.False(stage1.IsInitialized);
            Assert.False(stage2.IsInitialized);
            stage1.Initialize();
            Assert.True(stage1.IsInitialized);
            Assert.True(stage2.IsInitialized);

            // process a log message
            var message = MessagePool.GetUninitializedMessage();

            Assert.False(callback1.ProcessSyncCallbackWasCalled);
            Assert.False(callback2.ProcessSyncCallbackWasCalled);
            stage1.ProcessMessage(message);
            if (processSyncReturnValue)
            {
                // the message should have traveled through stage 1 and 2
                Assert.True(callback1.ProcessSyncCallbackWasCalled);
                Assert.True(callback2.ProcessSyncCallbackWasCalled);
                Assert.Same(message, callback1.MessagePassedToProcessSyncCallback);
                Assert.Same(message, callback2.MessagePassedToProcessSyncCallback);
            }
            else
            {
                // the message should have traveled through stage 1 only
                Assert.True(callback1.ProcessSyncCallbackWasCalled);
                Assert.False(callback2.ProcessSyncCallbackWasCalled);
                Assert.Same(message, callback1.MessagePassedToProcessSyncCallback);
                Assert.Null(callback2.MessagePassedToProcessSyncCallback);
            }

            // shut the stages down
            stage1.Shutdown();
            Assert.False(stage1.IsInitialized);
            Assert.False(stage2.IsInitialized);
        }
Esempio n. 5
0
        public void Process_Standalone(bool processSyncReturnValue, bool queueForAsyncProcessing)
        {
            var callback = new Callback
            {
                ProcessSyncCallbackReturnValue             = processSyncReturnValue,
                ProcessSyncCallbackQueueForAsyncProcessing = queueForAsyncProcessing
            };

            var stage = ProcessingPipelineStage.Create <AsyncCallbackPipelineStage>("Callback", null);

            stage.SynchronousProcessingCallback  = callback.ProcessSyncCallback;
            stage.AsynchronousProcessingCallback = callback.ProcessAsyncCallback;

            // initialize the stage
            Assert.False(stage.IsInitialized);
            stage.Initialize();
            Assert.True(stage.IsInitialized);

            // process a log message
            var message = MessagePool.GetUninitializedMessage();

            Assert.False(callback.ProcessSyncCallbackWasCalled);
            stage.ProcessMessage(message);

            // wait for the message to travel through asynchronous processing
            Thread.Sleep(500);

            // check synchronous processing
            Assert.True(callback.ProcessSyncCallbackWasCalled);
            Assert.Same(message, callback.MessagePassedToProcessSyncCallback);

            // check asynchronous processing
            if (queueForAsyncProcessing)
            {
                Assert.True(callback.ProcessAsyncCallbackWasCalled);
                Assert.Single(callback.MessagesPassedToProcessAsyncCallback);
                Assert.Same(message, callback.MessagesPassedToProcessAsyncCallback.First());
            }
            else
            {
                Assert.False(callback.ProcessAsyncCallbackWasCalled);
                Assert.Empty(callback.MessagesPassedToProcessAsyncCallback);
            }

            // shut the stage down
            stage.Shutdown();
            Assert.False(stage.IsInitialized);
        }
Esempio n. 6
0
        public void Process_Standalone()
        {
            var stage = ProcessingPipelineStage.Create <AsyncProcessingPipelineTestStage>("Stage", null);

            // initialize the stage
            Assert.False(stage.IsInitialized);
            Assert.False(stage.OnInitializeWasCalled);
            stage.Initialize();
            Assert.True(stage.OnInitializeWasCalled);
            Assert.True(stage.IsInitialized);

            // process a log message
            var message = MessagePool.GetUninitializedMessage();

            Assert.False(stage.ProcessSyncWasCalled);
            stage.ProcessMessage(message);
            Assert.True(stage.ProcessSyncWasCalled);
        }
Esempio n. 7
0
        public void Process_WithFollowingStage(bool processSyncReturnValue, bool queueForAsyncProcessing)
        {
            var callback1 = new Callback
            {
                ProcessSyncCallbackReturnValue             = processSyncReturnValue,
                ProcessSyncCallbackQueueForAsyncProcessing = queueForAsyncProcessing
            };
            var callback2 = new Callback
            {
                ProcessSyncCallbackReturnValue             = processSyncReturnValue,
                ProcessSyncCallbackQueueForAsyncProcessing = queueForAsyncProcessing
            };

            var stage1 = ProcessingPipelineStage.Create <AsyncCallbackPipelineStage>("Callback1", null);

            stage1.SynchronousProcessingCallback  = callback1.ProcessSyncCallback;
            stage1.AsynchronousProcessingCallback = callback1.ProcessAsyncCallback;
            var stage2 = stage1.AddNextStage <AsyncCallbackPipelineStage>("Callback2");

            stage2.SynchronousProcessingCallback  = callback2.ProcessSyncCallback;
            stage2.AsynchronousProcessingCallback = callback2.ProcessAsyncCallback;

            // initialize the stages
            Assert.False(stage1.IsInitialized);
            Assert.False(stage2.IsInitialized);
            stage1.Initialize();
            Assert.True(stage1.IsInitialized);
            Assert.True(stage2.IsInitialized);

            // process a log message
            var message = MessagePool.GetUninitializedMessage();

            Assert.False(callback1.ProcessSyncCallbackWasCalled);
            Assert.False(callback2.ProcessSyncCallbackWasCalled);
            stage1.ProcessMessage(message);

            // wait for the message to travel through asynchronous processing
            Thread.Sleep(500);

            // check where the message went to
            if (processSyncReturnValue)
            {
                // check synchronous processing
                // (the message should have traveled through stage 1 and 2)
                Assert.True(callback1.ProcessSyncCallbackWasCalled);
                Assert.True(callback2.ProcessSyncCallbackWasCalled);
                Assert.Same(message, callback1.MessagePassedToProcessSyncCallback);
                Assert.Same(message, callback2.MessagePassedToProcessSyncCallback);

                // check asynchronous processing
                if (queueForAsyncProcessing)
                {
                    Assert.True(callback1.ProcessAsyncCallbackWasCalled);
                    Assert.True(callback2.ProcessAsyncCallbackWasCalled);
                    Assert.Single(callback1.MessagesPassedToProcessAsyncCallback);
                    Assert.Single(callback2.MessagesPassedToProcessAsyncCallback);
                    Assert.Same(message, callback1.MessagesPassedToProcessAsyncCallback.First());
                    Assert.Same(message, callback2.MessagesPassedToProcessAsyncCallback.First());
                }
                else
                {
                    Assert.False(callback1.ProcessAsyncCallbackWasCalled);
                    Assert.False(callback2.ProcessAsyncCallbackWasCalled);
                    Assert.Empty(callback1.MessagesPassedToProcessAsyncCallback);
                    Assert.Empty(callback2.MessagesPassedToProcessAsyncCallback);
                }
            }
            else
            {
                // check synchronous processing
                // (the message should have traveled through stage 1 only)
                Assert.True(callback1.ProcessSyncCallbackWasCalled);
                Assert.False(callback2.ProcessSyncCallbackWasCalled);
                Assert.Same(message, callback1.MessagePassedToProcessSyncCallback);
                Assert.Null(callback2.MessagePassedToProcessSyncCallback);

                // check asynchronous processing
                if (queueForAsyncProcessing)
                {
                    Assert.True(callback1.ProcessAsyncCallbackWasCalled);
                    Assert.False(callback2.ProcessAsyncCallbackWasCalled);
                    Assert.Single(callback1.MessagesPassedToProcessAsyncCallback);
                    Assert.Empty(callback2.MessagesPassedToProcessAsyncCallback);
                    Assert.Same(message, callback1.MessagesPassedToProcessAsyncCallback.First());
                }
                else
                {
                    Assert.False(callback1.ProcessAsyncCallbackWasCalled);
                    Assert.False(callback2.ProcessAsyncCallbackWasCalled);
                    Assert.Empty(callback1.MessagesPassedToProcessAsyncCallback);
                    Assert.Empty(callback2.MessagesPassedToProcessAsyncCallback);
                }
            }

            // shut the pipeline stages down
            stage1.Shutdown();
            Assert.False(stage1.IsInitialized);
            Assert.False(stage2.IsInitialized);
        }