Exemple #1
0
        private async Task TestMultipleDrainMode <T>(bool sendToQueue)
        {
            _drainValidationPreDelay  = new ManualResetEvent(initialState: false);
            _drainValidationPostDelay = new ManualResetEvent(initialState: false);

            if (sendToQueue)
            {
                await ServiceBusEndToEndTests.WriteQueueMessage(_connectionString, _queueName, DrainingQueueMessageBody, _drainModeSessionId);
            }
            else
            {
                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, DrainingTopicMessageBody, _drainModeSessionId);
            }

            using (IHost host = ServiceBusSessionsTestHelper.CreateHost <T>(_nameResolver, false, false))
            {
                await host.StartAsync();

                // Wait to ensure function invocatoin has started before draining messages
                Assert.True(_drainValidationPreDelay.WaitOne(SBTimeoutMills));

                // Start draining in-flight messages
                var drainModeManager = host.Services.GetService <IDrainModeManager>();
                await drainModeManager.EnableDrainModeAsync(CancellationToken.None);

                // Validate that function execution was allowed to complete
                Assert.True(_drainValidationPostDelay.WaitOne(DrainWaitTimeoutMills + SBTimeoutMills));

                // Wait for the host to terminate
                await host.StopAsync();
            }
        }
        public async Task ServiceBusSessionTopicSubscription_OrderGuaranteed()
        {
            using (var host = ServiceBusSessionsTestHelper.CreateHost <ServiceBusSessionsTestJobs1>(_nameResolver))
            {
                await host.StartAsync();

                _waitHandle1 = new ManualResetEvent(initialState: false);

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message1", "test-session1");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message2", "test-session1");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message3", "test-session1");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message4", "test-session1");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message5", "test-session1");

                Assert.True(_waitHandle1.WaitOne(SBTimeout));

                IEnumerable <LogMessage> logMessages = host.GetTestLoggerProvider().GetAllLogMessages();

                // filter out anything from the custom processor for easier validation.
                List <LogMessage> consoleOutput = logMessages.Where(m => m.Category == "Function.SBSub1Trigger.User").ToList();

                Assert.True(consoleOutput.Count() == 5, ServiceBusSessionsTestHelper.GetLogsAsString(consoleOutput));

                int i = 1;
                foreach (LogMessage logMessage in consoleOutput)
                {
                    Assert.True(logMessage.FormattedMessage.StartsWith("message" + i++));
                }
            }
        }
        public async Task ServiceBusSessionSub_DifferentHosts_DifferentSessions()
        {
            using (var host1 = ServiceBusSessionsTestHelper.CreateHost <ServiceBusSessionsTestJobs1>(_nameResolver, true))
                using (var host2 = ServiceBusSessionsTestHelper.CreateHost <ServiceBusSessionsTestJobs2>(_nameResolver, true))
                {
                    await host1.StartAsync();

                    await host2.StartAsync();

                    _waitHandle1 = new ManualResetEvent(initialState: false);
                    _waitHandle2 = new ManualResetEvent(initialState: false);

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message1", "test-session1");

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message1", "test-session2");

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message2", "test-session1");

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message2", "test-session2");

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message3", "test-session1");

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message3", "test-session2");

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message4", "test-session1");

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message4", "test-session2");

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message5", "test-session1");

                    await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message5", "test-session2");

                    Assert.True(_waitHandle1.WaitOne(SBTimeout));
                    Assert.True(_waitHandle2.WaitOne(SBTimeout));

                    IEnumerable <LogMessage> logMessages1   = host1.GetTestLoggerProvider().GetAllLogMessages();
                    List <LogMessage>        consoleOutput1 = logMessages1.Where(m => m.Category == "Function.SBSub1Trigger.User").ToList();
                    Assert.NotEmpty(logMessages1.Where(m => m.Category == "CustomMessagingProvider" && m.FormattedMessage.StartsWith("Custom processor Begin called!")));
                    Assert.NotEmpty(logMessages1.Where(m => m.Category == "CustomMessagingProvider" && m.FormattedMessage.StartsWith("Custom processor End called!")));
                    IEnumerable <LogMessage> logMessages2   = host2.GetTestLoggerProvider().GetAllLogMessages();
                    List <LogMessage>        consoleOutput2 = logMessages2.Where(m => m.Category == "Function.SBSub2Trigger.User").ToList();
                    Assert.NotEmpty(logMessages2.Where(m => m.Category == "CustomMessagingProvider" && m.FormattedMessage.StartsWith("Custom processor Begin called!")));
                    Assert.NotEmpty(logMessages2.Where(m => m.Category == "CustomMessagingProvider" && m.FormattedMessage.StartsWith("Custom processor End called!")));

                    char sessionId1 = consoleOutput1[0].FormattedMessage[consoleOutput1[0].FormattedMessage.Length - 1];
                    foreach (LogMessage m in consoleOutput1)
                    {
                        Assert.Equal(sessionId1, m.FormattedMessage[m.FormattedMessage.Length - 1]);
                    }

                    char sessionId2 = consoleOutput2[0].FormattedMessage[consoleOutput1[0].FormattedMessage.Length - 1];
                    foreach (LogMessage m in consoleOutput2)
                    {
                        Assert.Equal(sessionId2, m.FormattedMessage[m.FormattedMessage.Length - 1]);
                    }
                }
        }
Exemple #4
0
        public async Task ServiceBusSessionSub_SessionLocks()
        {
            using (var host = ServiceBusSessionsTestHelper.CreateHost <ServiceBusSessionsTestJobs1>(_nameResolver, true))
            {
                await host.StartAsync();

                _waitHandle1 = new ManualResetEvent(initialState: false);
                _waitHandle2 = new ManualResetEvent(initialState: false);

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message1", "test-session1");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message1", "test-session2");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message2", "test-session1");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message2", "test-session2");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message3", "test-session1");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message3", "test-session2");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message4", "test-session1");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message4", "test-session2");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message5", "test-session1");

                await ServiceBusEndToEndTests.WriteTopicMessage(_connectionString, _topicName, "message5", "test-session2");

                Assert.True(_waitHandle1.WaitOne(SBTimeoutMills));
                Assert.True(_waitHandle2.WaitOne(SBTimeoutMills));

                IEnumerable <LogMessage> logMessages1 = host.GetTestLoggerProvider().GetAllLogMessages();

                // filter out anything from the custom processor for easier validation.
                List <LogMessage> consoleOutput1 = logMessages1.Where(m => m.Category == "Function.SBSub1Trigger.User").ToList();
                Assert.True(consoleOutput1.Count() == 10, ServiceBusSessionsTestHelper.GetLogsAsString(consoleOutput1));
                double seconsds = (consoleOutput1[5].Timestamp - consoleOutput1[4].Timestamp).TotalSeconds;
                Assert.True(seconsds > 90 && seconsds < 110, seconsds.ToString());
                for (int i = 0; i < consoleOutput1.Count(); i++)
                {
                    if (i < 5)
                    {
                        Assert.Equal(consoleOutput1[i].FormattedMessage[consoleOutput1[0].FormattedMessage.Length - 1],
                                     consoleOutput1[0].FormattedMessage[consoleOutput1[0].FormattedMessage.Length - 1]);
                    }
                    else
                    {
                        Assert.Equal(consoleOutput1[i].FormattedMessage[consoleOutput1[0].FormattedMessage.Length - 1],
                                     consoleOutput1[5].FormattedMessage[consoleOutput1[0].FormattedMessage.Length - 1]);
                    }
                }

                await host.StopAsync();
            }
        }
        private async Task TestMultiple <T>(bool isXml = false)
        {
            IHost host = new HostBuilder()
                         .ConfigureDefaultTestHost <T>(b =>
            {
                b.AddServiceBus();
            }, nameResolver: _nameResolver)
                         .Build();

            if (isXml)
            {
                await ServiceBusEndToEndTests.WriteQueueMessage(_connectionString, _queueName, new TestPoco()
                {
                    Name = "Test1"
                }, "sessionId");

                await ServiceBusEndToEndTests.WriteQueueMessage(_connectionString, _queueName, new TestPoco()
                {
                    Name = "Test2"
                }, "sessionId");
            }
            else
            {
                await ServiceBusEndToEndTests.WriteQueueMessage(_connectionString, _queueName, "{'Name': 'Test1', 'Value': 'Value'}", "sessionId");

                await ServiceBusEndToEndTests.WriteQueueMessage(_connectionString, _queueName, "{'Name': 'Test2', 'Value': 'Value'}", "sessionId");
            }

            _waitHandle1 = new ManualResetEvent(initialState: false);

            await host.StartAsync();

            bool result = _waitHandle1.WaitOne(SBTimeout);

            Assert.True(result);

            // ensure message are completed
            await Task.Delay(2000);

            // Wait for the host to terminate
            await host.StopAsync();

            host.Dispose();
        }
Exemple #6
0
        private async Task TestMultiple <T>(bool isXml = false)
        {
            _waitHandle1 = new ManualResetEvent(initialState: false);

            if (isXml)
            {
                await ServiceBusEndToEndTests.WriteQueueMessage(_connectionString, _queueName, new TestPoco()
                {
                    Name = "Test1"
                }, "sessionId");

                await ServiceBusEndToEndTests.WriteQueueMessage(_connectionString, _queueName, new TestPoco()
                {
                    Name = "Test2"
                }, "sessionId");
            }
            else
            {
                await ServiceBusEndToEndTests.WriteQueueMessage(_connectionString, _queueName, "{'Name': 'Test1', 'Value': 'Value'}", "sessionId");

                await ServiceBusEndToEndTests.WriteQueueMessage(_connectionString, _queueName, "{'Name': 'Test2', 'Value': 'Value'}", "sessionId");
            }

            using (IHost host = ServiceBusSessionsTestHelper.CreateHost <T>(_nameResolver))
            {
                await host.StartAsync();

                bool result = _waitHandle1.WaitOne(SBTimeoutMills);
                Assert.True(result);

                // ensure message are completed
                await Task.Delay(2000);

                // Wait for the host to terminate
                await host.StopAsync();
            }
        }