You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

39 rivejä
1.6 KiB

  1. using MQTTnet.Extensions.ManagedClient;
  2. using System.Threading.Tasks;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using MQTTnet.Server;
  5. namespace MQTTnet.Core.Tests
  6. {
  7. [TestClass]
  8. public class ManagedMqttClientTests
  9. {
  10. [TestMethod]
  11. public async Task Drop_New_Messages_On_Full_Queue()
  12. {
  13. var factory = new MqttFactory();
  14. var managedClient = factory.CreateManagedMqttClient();
  15. var clientOptions = new ManagedMqttClientOptionsBuilder()
  16. .WithMaxPendingMessages(5)
  17. .WithPendingMessagesOverflowStrategy(MqttPendingMessagesOverflowStrategy.DropNewMessage);
  18. clientOptions.WithClientOptions(o => o.WithTcpServer("localhost"));
  19. await managedClient.StartAsync(clientOptions.Build());
  20. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "1" });
  21. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "2" });
  22. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "3" });
  23. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "4" });
  24. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "5" });
  25. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "6" });
  26. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "7" });
  27. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "8" });
  28. Assert.AreEqual(5, managedClient.PendingApplicationMessagesCount);
  29. }
  30. }
  31. }