mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-25 23:53:07 +08:00
Additional performance improvements
This commit is contained in:
@@ -403,24 +403,24 @@ namespace MQTTnet.Core.Tests
|
||||
_stream.Position = 0;
|
||||
}
|
||||
|
||||
public async Task ConnectAsync(MqttClientOptions options)
|
||||
public Task ConnectAsync(MqttClientOptions options)
|
||||
{
|
||||
await Task.FromResult(0);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public async Task DisconnectAsync()
|
||||
public Task DisconnectAsync()
|
||||
{
|
||||
await Task.FromResult(0);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public async Task WriteAsync(byte[] buffer)
|
||||
public Task WriteAsync(byte[] buffer)
|
||||
{
|
||||
await _stream.WriteAsync(buffer, 0, buffer.Length);
|
||||
return _stream.WriteAsync(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public async Task ReadAsync(byte[] buffer)
|
||||
public Task ReadAsync(byte[] buffer)
|
||||
{
|
||||
await _stream.ReadAsync(buffer, 0, buffer.Length);
|
||||
return _stream.ReadAsync(buffer, 0, buffer.Length);
|
||||
}
|
||||
|
||||
public byte[] ToArray()
|
||||
@@ -429,7 +429,7 @@ namespace MQTTnet.Core.Tests
|
||||
}
|
||||
}
|
||||
|
||||
private void SerializeAndCompare(MqttBasePacket packet, string expectedBase64Value, MqttProtocolVersion protocolVersion = MqttProtocolVersion.V311)
|
||||
private static void SerializeAndCompare(MqttBasePacket packet, string expectedBase64Value, MqttProtocolVersion protocolVersion = MqttProtocolVersion.V311)
|
||||
{
|
||||
var serializer = new MqttPacketSerializer { ProtocolVersion = protocolVersion };
|
||||
var channel = new TestChannel();
|
||||
@@ -439,7 +439,7 @@ namespace MQTTnet.Core.Tests
|
||||
Assert.AreEqual(expectedBase64Value, Convert.ToBase64String(buffer));
|
||||
}
|
||||
|
||||
private void DeserializeAndCompare(MqttBasePacket packet, string expectedBase64Value)
|
||||
private static void DeserializeAndCompare(MqttBasePacket packet, string expectedBase64Value)
|
||||
{
|
||||
var serializer = new MqttPacketSerializer();
|
||||
|
||||
|
||||
@@ -13,36 +13,36 @@ namespace MQTTnet.Core.Tests
|
||||
public class MqttServerTests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task MqttServer_PublishSimple_AtMostOnce()
|
||||
public void MqttServer_PublishSimple_AtMostOnce()
|
||||
{
|
||||
await TestPublishAsync(
|
||||
TestPublishAsync(
|
||||
"A/B/C",
|
||||
MqttQualityOfServiceLevel.AtMostOnce,
|
||||
"A/B/C",
|
||||
MqttQualityOfServiceLevel.AtMostOnce,
|
||||
1);
|
||||
1).Wait();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task MqttServer_PublishSimple_AtLeastOnce()
|
||||
public void MqttServer_PublishSimple_AtLeastOnce()
|
||||
{
|
||||
await TestPublishAsync(
|
||||
TestPublishAsync(
|
||||
"A/B/C",
|
||||
MqttQualityOfServiceLevel.AtLeastOnce,
|
||||
"A/B/C",
|
||||
MqttQualityOfServiceLevel.AtLeastOnce,
|
||||
1);
|
||||
1).Wait();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task MqttServer_PublishSimple_ExactlyOnce()
|
||||
public void MqttServer_PublishSimple_ExactlyOnce()
|
||||
{
|
||||
await TestPublishAsync(
|
||||
TestPublishAsync(
|
||||
"A/B/C",
|
||||
MqttQualityOfServiceLevel.ExactlyOnce,
|
||||
"A/B/C",
|
||||
MqttQualityOfServiceLevel.ExactlyOnce,
|
||||
1);
|
||||
1).Wait();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -16,29 +16,29 @@ namespace MQTTnet.Core.Tests
|
||||
|
||||
public IMqttPacketSerializer PacketSerializer { get; } = new MqttPacketSerializer();
|
||||
|
||||
public async Task ConnectAsync(MqttClientOptions options, TimeSpan timeout)
|
||||
public Task ConnectAsync(MqttClientOptions options, TimeSpan timeout)
|
||||
{
|
||||
await Task.FromResult(0);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public async Task DisconnectAsync()
|
||||
public Task DisconnectAsync()
|
||||
{
|
||||
await Task.FromResult(0);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public async Task SendPacketAsync(MqttBasePacket packet, TimeSpan timeout)
|
||||
public Task SendPacketAsync(MqttBasePacket packet, TimeSpan timeout)
|
||||
{
|
||||
ThrowIfPartnerIsNull();
|
||||
|
||||
Partner.SendPacketInternal(packet);
|
||||
await Task.FromResult(0);
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public async Task<MqttBasePacket> ReceivePacketAsync(TimeSpan timeout)
|
||||
public Task<MqttBasePacket> ReceivePacketAsync(TimeSpan timeout)
|
||||
{
|
||||
ThrowIfPartnerIsNull();
|
||||
|
||||
return await Task.Run(() => _incomingPackets.Take());
|
||||
return Task.Run(() => _incomingPackets.Take());
|
||||
}
|
||||
|
||||
private void SendPacketInternal(MqttBasePacket packet)
|
||||
|
||||
Reference in New Issue
Block a user