async Task OnSessionTestAsync(string queueName, int maxConcurrentCalls, ReceiveMode mode, bool autoComplete) { TestUtility.Log($"Queue: {queueName}, MaxConcurrentCalls: {maxConcurrentCalls}, Receive Mode: {mode.ToString()}, AutoComplete: {autoComplete}"); var queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName, mode); try { SessionHandlerOptions handlerOptions = new SessionHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentSessions = maxConcurrentCalls, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = autoComplete }; TestSessionHandler testSessionHandler = new TestSessionHandler( queueClient.ReceiveMode, handlerOptions, queueClient.InnerSender, queueClient.SessionPumpHost); // Send messages to Session first await testSessionHandler.SendSessionMessages(); // Register handler testSessionHandler.RegisterSessionHandler(handlerOptions); // Verify messages were received. await testSessionHandler.VerifyRun(); } finally { await queueClient.CloseAsync(); } }
public async Task OnSessionCanStartWithNullMessageButReturnSessionLater() { await ServiceBusScope.UsingQueueAsync(partitioned : false, sessionEnabled : true, async queueName => { var queueClient = new QueueClient( TestUtility.NamespaceConnectionString, queueName, ReceiveMode.PeekLock); try { var sessionHandlerOptions = new SessionHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentSessions = 5, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = true }; var testSessionHandler = new TestSessionHandler( queueClient.ReceiveMode, sessionHandlerOptions, queueClient.InnerSender, queueClient.SessionPumpHost); // Register handler first without any messages testSessionHandler.RegisterSessionHandler(sessionHandlerOptions); // Send messages to Session await testSessionHandler.SendSessionMessages(); // Verify messages were received. await testSessionHandler.VerifyRun(); // Clear the data and re-run the scenario. testSessionHandler.ClearData(); await testSessionHandler.SendSessionMessages(); // Verify messages were received. await testSessionHandler.VerifyRun(); } finally { await queueClient.CloseAsync(); } }); }
async Task OnSessionCanStartWithNullMessageButReturnSessionLater() { var queueClient = new QueueClient( TestUtility.NamespaceConnectionString, TestConstants.SessionNonPartitionedQueueName, ReceiveMode.PeekLock); try { SessionHandlerOptions handlerOptions = new SessionHandlerOptions() { MaxConcurrentSessions = 5, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = true }; TestSessionHandler testSessionHandler = new TestSessionHandler( queueClient.ReceiveMode, handlerOptions, queueClient.InnerSender, queueClient.SessionPumpHost); // Register handler first without any messages testSessionHandler.RegisterSessionHandler(handlerOptions); // Send messages to Session await testSessionHandler.SendSessionMessages(); // Verify messages were received. await testSessionHandler.VerifyRun(); // Clear the data and re-run the scenario. testSessionHandler.ClearData(); await testSessionHandler.SendSessionMessages(); // Verify messages were received. await testSessionHandler.VerifyRun(); } finally { await queueClient.CloseAsync(); } }
private async Task OnSessionTestAsync(bool partitioned, bool sessionEnabled, int maxConcurrentCalls, ReceiveMode mode, bool autoComplete) { await ServiceBusScope.UsingTopicAsync(partitioned, sessionEnabled, async (topicName, subscriptionName) => { TestUtility.Log($"Topic: {topicName}, MaxConcurrentCalls: {maxConcurrentCalls}, Receive Mode: {mode.ToString()}, AutoComplete: {autoComplete}"); var topicClient = new TopicClient(TestUtility.NamespaceConnectionString, topicName); var subscriptionClient = new SubscriptionClient( TestUtility.NamespaceConnectionString, topicClient.TopicName, subscriptionName, ReceiveMode.PeekLock); try { var sessionHandlerOptions = new SessionHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentSessions = 5, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = true }; var testSessionHandler = new TestSessionHandler( subscriptionClient.ReceiveMode, sessionHandlerOptions, topicClient.InnerSender, subscriptionClient.SessionPumpHost); // Send messages to Session await testSessionHandler.SendSessionMessages(); // Register handler testSessionHandler.RegisterSessionHandler(sessionHandlerOptions); // Verify messages were received. await testSessionHandler.VerifyRun(); } finally { await subscriptionClient.CloseAsync(); await topicClient.CloseAsync(); } }); }
async Task OnSessionTestAsync(string topicName, int maxConcurrentCalls, ReceiveMode mode, bool autoComplete) { TestUtility.Log($"Topic: {topicName}, MaxConcurrentCalls: {maxConcurrentCalls}, Receive Mode: {mode.ToString()}, AutoComplete: {autoComplete}"); var topicClient = new TopicClient(TestUtility.NamespaceConnectionString, topicName); var subscriptionClient = new SubscriptionClient( TestUtility.NamespaceConnectionString, topicClient.TopicName, this.SubscriptionName, ReceiveMode.PeekLock); try { SessionHandlerOptions handlerOptions = new SessionHandlerOptions() { MaxConcurrentSessions = 5, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = true }; TestSessionHandler testSessionHandler = new TestSessionHandler( subscriptionClient.ReceiveMode, handlerOptions, topicClient.InnerSender, subscriptionClient.SessionPumpHost); // Send messages to Session await testSessionHandler.SendSessionMessages(); // Register handler testSessionHandler.RegisterSessionHandler(handlerOptions); // Verify messages were received. await testSessionHandler.VerifyRun(); } finally { await subscriptionClient.CloseAsync(); await topicClient.CloseAsync(); } }
private async Task OnSessionTestAsync(bool partitioned, bool sessionEnabled, int maxConcurrentCalls, ReceiveMode mode, bool autoComplete) { await ServiceBusScope.UsingQueueAsync(partitioned, sessionEnabled, async queueName => { TestUtility.Log($"Queue: {queueName}, MaxConcurrentCalls: {maxConcurrentCalls}, Receive Mode: {mode.ToString()}, AutoComplete: {autoComplete}"); var queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName, mode); try { var handlerOptions = new SessionHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentSessions = maxConcurrentCalls, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = autoComplete }; var testSessionHandler = new TestSessionHandler( queueClient.ReceiveMode, handlerOptions, queueClient.InnerSender, queueClient.SessionPumpHost); // Send messages to Session first await testSessionHandler.SendSessionMessages(); // Register handler testSessionHandler.RegisterSessionHandler(handlerOptions); // Verify messages were received. await testSessionHandler.VerifyRun(); testSessionHandler.ClearData(); } finally { await queueClient.CloseAsync(); } }); // test UnregisterSessionHandler can wait for message handling upto the timeout user defined. await ServiceBusScope.UsingQueueAsync(partitioned, sessionEnabled, async queueName => { TestUtility.Log($"Queue: {queueName}, MaxConcurrentCalls: {maxConcurrentCalls}, Receive Mode: {mode.ToString()}, AutoComplete: {autoComplete}"); var queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName, mode); try { var sessionHandlerOptions = new SessionHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentSessions = maxConcurrentCalls, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = autoComplete }; var testSessionHandler = new TestSessionHandler( queueClient.ReceiveMode, sessionHandlerOptions, queueClient.InnerSender, queueClient.SessionPumpHost); // Send messages to Session first await testSessionHandler.SendSessionMessages(); // Register handler var count = 0; testSessionHandler.RegisterSessionHandler( async(session, message, token) => { await Task.Delay(TimeSpan.FromSeconds(8)); TestUtility.Log($"Received Session: {session.SessionId} message: SequenceNumber: {message.SystemProperties.SequenceNumber}"); if (queueClient.ReceiveMode == ReceiveMode.PeekLock && !sessionHandlerOptions.AutoComplete) { await session.CompleteAsync(message.SystemProperties.LockToken); } Interlocked.Increment(ref count); }, sessionHandlerOptions); await Task.Delay(TimeSpan.FromSeconds(2)); // UnregisterSessionHandler should wait up to the provided timeout to finish the message handling tasks await testSessionHandler.UnregisterSessionHandler(TimeSpan.FromSeconds(10)); Assert.True(count == maxConcurrentCalls); testSessionHandler.ClearData(); } finally { await queueClient.CloseAsync(); } }); // test UnregisterSessionHandler can close down in time when message handling takes longer than wait timeout user defined. await ServiceBusScope.UsingQueueAsync(partitioned, sessionEnabled, async queueName => { TestUtility.Log($"Queue: {queueName}, MaxConcurrentCalls: {maxConcurrentCalls}, Receive Mode: {mode.ToString()}, AutoComplete: {autoComplete}"); var queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName, mode); try { var sessionHandlerOptions = new SessionHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentSessions = maxConcurrentCalls, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = autoComplete }; var testSessionHandler = new TestSessionHandler( queueClient.ReceiveMode, sessionHandlerOptions, queueClient.InnerSender, queueClient.SessionPumpHost); // Send messages to Session first await testSessionHandler.SendSessionMessages(); // Register handler var count = 0; testSessionHandler.RegisterSessionHandler( async(session, message, token) => { await Task.Delay(TimeSpan.FromSeconds(8)); TestUtility.Log($"Received Session: {session.SessionId} message: SequenceNumber: {message.SystemProperties.SequenceNumber}"); if (queueClient.ReceiveMode == ReceiveMode.PeekLock && !sessionHandlerOptions.AutoComplete) { await session.CompleteAsync(message.SystemProperties.LockToken); } Interlocked.Increment(ref count); }, sessionHandlerOptions); await Task.Delay(TimeSpan.FromSeconds(2)); // UnregisterSessionHandler should wait up to the provided timeout to finish the message handling tasks await testSessionHandler.UnregisterSessionHandler(TimeSpan.FromSeconds(2)); Assert.True(count == 0); testSessionHandler.ClearData(); } finally { await queueClient.CloseAsync(); } }); }
private async Task OnSessionTestAsync(bool partitioned, bool sessionEnabled, int maxConcurrentCalls, ReceiveMode mode, bool autoComplete) { await ServiceBusScope.UsingQueueAsync(partitioned, sessionEnabled, async queueName => { TestUtility.Log($"Queue: {queueName}, MaxConcurrentCalls: {maxConcurrentCalls}, Receive Mode: {mode.ToString()}, AutoComplete: {autoComplete}"); var queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName, mode); try { var handlerOptions = new SessionHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentSessions = maxConcurrentCalls, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = autoComplete }; var testSessionHandler = new TestSessionHandler( queueClient.ReceiveMode, handlerOptions, queueClient.InnerSender, queueClient.SessionPumpHost); // Send messages to Session first await testSessionHandler.SendSessionMessages(); // Register handler testSessionHandler.RegisterSessionHandler(handlerOptions); // Verify messages were received. await testSessionHandler.VerifyRun(); testSessionHandler.ClearData(); } finally { await queueClient.CloseAsync(); } }); // test UnregisterSessionHandler can wait for message handling upto the timeout user defined. await ServiceBusScope.UsingQueueAsync(partitioned, sessionEnabled, async queueName => { TestUtility.Log($"Queue: {queueName}, MaxConcurrentCalls: {maxConcurrentCalls}, Receive Mode: {mode.ToString()}, AutoComplete: {autoComplete}"); var queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName, mode); try { var sessionHandlerOptions = new SessionHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentSessions = maxConcurrentCalls, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = autoComplete }; var testSessionHandler = new TestSessionHandler( queueClient.ReceiveMode, sessionHandlerOptions, queueClient.InnerSender, queueClient.SessionPumpHost); // Send messages to Session first await testSessionHandler.SendSessionMessages(); // Register handler testSessionHandler.RegisterSessionHandlerAndRecordReceivedMessageCount(queueClient.ReceiveMode == ReceiveMode.PeekLock, 8); // Session handler set up has greater latency than message handler. Delay here to enable some processing time of the session pump. await Task.Delay(TimeSpan.FromSeconds(2)); // UnregisterSessionHandler should wait up to the provided timeout to finish the message handling tasks await testSessionHandler.UnregisterSessionHandler(TimeSpan.FromSeconds(10)); Assert.True(testSessionHandler.ReceivedMessageCount == maxConcurrentCalls); // Reregister won't have any problems testSessionHandler.RegisterSessionHandlerAndRecordReceivedMessageCount(queueClient.ReceiveMode == ReceiveMode.PeekLock, 0); await testSessionHandler.WaitForAllMessagesReceived(ExpectedMessageCount); Assert.True(testSessionHandler.ReceivedMessageCount == ExpectedMessageCount); testSessionHandler.ClearData(); } finally { await queueClient.CloseAsync(); } }); // test UnregisterSessionHandler can close down in time when message handling takes longer than wait timeout user defined. await ServiceBusScope.UsingQueueAsync(partitioned, sessionEnabled, async queueName => { TestUtility.Log($"Queue: {queueName}, MaxConcurrentCalls: {maxConcurrentCalls}, Receive Mode: {mode.ToString()}, AutoComplete: {autoComplete}"); var queueClient = new QueueClient(TestUtility.NamespaceConnectionString, queueName, mode); try { var sessionHandlerOptions = new SessionHandlerOptions(ExceptionReceivedHandler) { MaxConcurrentSessions = maxConcurrentCalls, MessageWaitTimeout = TimeSpan.FromSeconds(5), AutoComplete = autoComplete }; var testSessionHandler = new TestSessionHandler( queueClient.ReceiveMode, sessionHandlerOptions, queueClient.InnerSender, queueClient.SessionPumpHost); // Send messages to Session first await testSessionHandler.SendSessionMessages(); // Register handler testSessionHandler.RegisterSessionHandlerAndRecordReceivedMessageCount(queueClient.ReceiveMode == ReceiveMode.PeekLock, 8); // UnregisterSessionHandler should wait up to the provided timeout to finish the message handling tasks await testSessionHandler.UnregisterSessionHandler(TimeSpan.FromSeconds(2)); Assert.True(testSessionHandler.ReceivedMessageCount == 0); // Reregister won't have any problems testSessionHandler.RegisterSessionHandlerAndRecordReceivedMessageCount(queueClient.ReceiveMode == ReceiveMode.PeekLock, 0); await testSessionHandler.WaitForAllMessagesReceived(ExpectedMessageCount); Assert.True(testSessionHandler.ReceivedMessageCount == ExpectedMessageCount); testSessionHandler.ClearData(); } finally { await queueClient.CloseAsync(); } }); }