Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

45 linhas
1.8 KiB

  1. using System.Threading.Tasks;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using MQTTnet.Extensions.ManagedClient;
  4. using MQTTnet.Server;
  5. namespace MQTTnet.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. try
  16. {
  17. var clientOptions = new ManagedMqttClientOptionsBuilder()
  18. .WithMaxPendingMessages(5)
  19. .WithPendingMessagesOverflowStrategy(MqttPendingMessagesOverflowStrategy.DropNewMessage);
  20. clientOptions.WithClientOptions(o => o.WithTcpServer("localhost"));
  21. await managedClient.StartAsync(clientOptions.Build());
  22. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "1" });
  23. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "2" });
  24. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "3" });
  25. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "4" });
  26. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "5" });
  27. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "6" });
  28. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "7" });
  29. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "8" });
  30. Assert.AreEqual(5, managedClient.PendingApplicationMessagesCount);
  31. }
  32. finally
  33. {
  34. await managedClient.StopAsync();
  35. }
  36. }
  37. }
  38. }