Add support for retained application messages

This commit is contained in:
Christian Kratky
2017-09-30 18:42:41 +02:00
parent 3cce33415d
commit 862f76fea2
24 changed files with 454 additions and 235 deletions
+8 -8
View File
@@ -49,7 +49,7 @@ namespace MQTTnet.Core.Tests
public async Task MqttServer_WillMessage()
{
var s = new MqttServer(new MqttServerOptions(), new List<IMqttServerAdapter> { new TestMqttServerAdapter() });
s.Start();
s.StartAsync();
var willMessage = new MqttApplicationMessage("My/last/will", new byte[0], MqttQualityOfServiceLevel.AtMostOnce, false);
var c1 = ConnectTestClient("c1", null, s);
@@ -63,7 +63,7 @@ namespace MQTTnet.Core.Tests
await Task.Delay(1000);
s.Stop();
s.StopAsync();
Assert.AreEqual(1, receivedMessagesCount);
}
@@ -72,7 +72,7 @@ namespace MQTTnet.Core.Tests
public async Task MqttServer_Unsubscribe()
{
var s = new MqttServer(new MqttServerOptions(), new List<IMqttServerAdapter> { new TestMqttServerAdapter() });
s.Start();
s.StartAsync();
var c1 = ConnectTestClient("c1", null, s);
var c2 = ConnectTestClient("c2", null, s);
@@ -97,7 +97,7 @@ namespace MQTTnet.Core.Tests
await Task.Delay(500);
Assert.AreEqual(1, receivedMessagesCount);
s.Stop();
s.StopAsync();
await Task.Delay(500);
Assert.AreEqual(1, receivedMessagesCount);
@@ -107,7 +107,7 @@ namespace MQTTnet.Core.Tests
public async Task MqttServer_Publish()
{
var s = new MqttServer(new MqttServerOptions(), new List<IMqttServerAdapter> { new TestMqttServerAdapter() });
s.Start();
s.StartAsync();
var c1 = ConnectTestClient("c1", null, s);
@@ -120,7 +120,7 @@ namespace MQTTnet.Core.Tests
s.Publish(message);
await Task.Delay(500);
s.Stop();
s.StopAsync();
Assert.AreEqual(1, receivedMessagesCount);
}
@@ -146,7 +146,7 @@ namespace MQTTnet.Core.Tests
int expectedReceivedMessagesCount)
{
var s = new MqttServer(new MqttServerOptions(), new List<IMqttServerAdapter> { new TestMqttServerAdapter() });
s.Start();
s.StartAsync();
var c1 = ConnectTestClient("c1", null, s);
var c2 = ConnectTestClient("c2", null, s);
@@ -162,7 +162,7 @@ namespace MQTTnet.Core.Tests
await Task.Delay(500);
s.Stop();
s.StopAsync();
Assert.AreEqual(expectedReceivedMessagesCount, receivedMessagesCount);
}
@@ -1,4 +1,5 @@
using System;
using System.Threading.Tasks;
using MQTTnet.Core.Adapter;
using MQTTnet.Core.Server;
@@ -13,12 +14,14 @@ namespace MQTTnet.Core.Tests
ClientConnected?.Invoke(this, eventArgs);
}
public void Start(MqttServerOptions options)
public Task StartAsync(MqttServerOptions options)
{
return Task.FromResult(0);
}
public void Stop()
{
public Task StopAsync()
{
return Task.FromResult(0);
}
}
}
+2 -2
View File
@@ -153,12 +153,12 @@ namespace MQTTnet.TestApp.NetCore
};
var mqttServer = new MqttServerFactory().CreateMqttServer(options);
mqttServer.Start();
mqttServer.StartAsync();
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
mqttServer.Stop();
mqttServer.StopAsync();
}
catch (Exception e)
{
@@ -167,7 +167,7 @@ namespace MQTTnet.TestApp.NetFramework
});
}
private static void RunServerAsync()
private static async Task RunServerAsync()
{
try
{
@@ -201,12 +201,12 @@ namespace MQTTnet.TestApp.NetFramework
stopwatch.Restart();
}
};
mqttServer.Start();
await mqttServer.StartAsync();
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
mqttServer.Stop();
await mqttServer.StopAsync();
}
catch (Exception e)
{
@@ -121,7 +121,7 @@ namespace MQTTnet.TestApp.NetFramework
}
}
private static void RunServerAsync(string[] arguments)
private static async Task RunServerAsync(string[] arguments)
{
MqttTrace.TraceMessagePublished += (s, e) =>
{
@@ -151,12 +151,12 @@ namespace MQTTnet.TestApp.NetFramework
};
var mqttServer = new MqttServerFactory().CreateMqttServer(options);
mqttServer.Start();
await mqttServer.StartAsync();
Console.WriteLine("Press any key to exit.");
Console.ReadLine();
mqttServer.Stop();
await mqttServer.StopAsync();
}
catch (Exception e)
{
@@ -166,4 +166,4 @@ namespace MQTTnet.TestApp.NetFramework
Console.ReadLine();
}
}
}
}