Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Jun 6, 2018
1 parent ae72bc3 commit 3480d9a
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 19 deletions.
22 changes: 22 additions & 0 deletions MQTTnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{67C28AC1
appveyor.yml = appveyor.yml
Build\build.ps1 = Build\build.ps1
Build\MQTTnet.AspNetCore.nuspec = Build\MQTTnet.AspNetCore.nuspec
Build\MQTTnet.Extensions.ManagedClient.nuspec = Build\MQTTnet.Extensions.ManagedClient.nuspec
Build\MQTTnet.Extensions.Rpc.nuspec = Build\MQTTnet.Extensions.Rpc.nuspec
Build\MQTTnet.nuspec = Build\MQTTnet.nuspec
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{B3F60ECB-45BA-4C66-8903-8BB89CA67998}"
ProjectSection(SolutionItems) = preProject
.bettercodehub.yml = .bettercodehub.yml
appveyor.yml = appveyor.yml
LICENSE = LICENSE
README.md = README.md
EndProjectSection
Expand All @@ -40,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Extensions.Rpc", "E
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Benchmarks", "Tests\MQTTnet.Benchmarks\MQTTnet.Benchmarks.csproj", "{998D04DD-7CB0-45F5-A393-E2495C16399E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MQTTnet.Extensions.ManagedClient", "Extensions\MQTTnet.Extensions.ManagedClient\MQTTnet.Extensions.ManagedClient.csproj", "{C400533A-8EBA-4F0B-BF4D-295C3708604B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -186,6 +191,22 @@ Global
{998D04DD-7CB0-45F5-A393-E2495C16399E}.Release|x64.Build.0 = Release|Any CPU
{998D04DD-7CB0-45F5-A393-E2495C16399E}.Release|x86.ActiveCfg = Release|Any CPU
{998D04DD-7CB0-45F5-A393-E2495C16399E}.Release|x86.Build.0 = Release|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Debug|ARM.ActiveCfg = Debug|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Debug|ARM.Build.0 = Debug|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Debug|x64.ActiveCfg = Debug|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Debug|x64.Build.0 = Debug|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Debug|x86.ActiveCfg = Debug|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Debug|x86.Build.0 = Debug|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Release|Any CPU.Build.0 = Release|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Release|ARM.ActiveCfg = Release|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Release|ARM.Build.0 = Release|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Release|x64.ActiveCfg = Release|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Release|x64.Build.0 = Release|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Release|x86.ActiveCfg = Release|Any CPU
{C400533A-8EBA-4F0B-BF4D-295C3708604B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -199,6 +220,7 @@ Global
{F10C4060-F7EE-4A83-919F-FF723E72F94A} = {32A630A7-2598-41D7-B625-204CD906F5FB}
{C444E9C8-95FA-430E-9126-274129DE16CD} = {12816BCC-AF9E-44A9-9AE5-C246AF2A0587}
{998D04DD-7CB0-45F5-A393-E2495C16399E} = {9248C2E1-B9D6-40BF-81EC-86004D7765B4}
{C400533A-8EBA-4F0B-BF4D-295C3708604B} = {12816BCC-AF9E-44A9-9AE5-C246AF2A0587}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {07536672-5CBC-4BE3-ACE0-708A431A7894}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MQTTnet is a high performance .NET library for MQTT based communication. It prov
* Performance optimized (processing ~60.000 messages / second)*
* Interfaces included for mocking and testing
* Access to internal trace messages
* Unit tested (~80 tests)
* Unit tested (~90 tests)

\* Tested on local machine (Intel i7 8700K) with MQTTnet client and server running in the same process using the TCP channel. The app for verification is part of this repository and stored in _/Tests/MQTTnet.TestApp.NetCore_.

Expand Down
1 change: 0 additions & 1 deletion Tests/MQTTnet.Benchmarks/ChannelAdapterBenchmark.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BenchmarkDotNet.Attributes;
using MQTTnet.Adapter;
using MQTTnet.Core.Internal;
using MQTTnet.Diagnostics;
using MQTTnet.Internal;
using MQTTnet.Packets;
Expand Down
3 changes: 1 addition & 2 deletions Tests/MQTTnet.Benchmarks/SerializerBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Threading;
using System.IO;
using MQTTnet.Adapter;
using MQTTnet.Core.Internal;

namespace MQTTnet.Benchmarks
{
Expand Down Expand Up @@ -55,7 +54,7 @@ public void Deserialize_10000_Messages()

using (var bodyStream = new MemoryStream(Join(_serializedPacket), (int)headerStream.Position, header.RemainingLength))
{
_serializer.Deserialize(new ReceivedMqttPacket(header.Flags, bodyStream));
_serializer.Deserialize(new ReceivedMqttPacket(header.Flags, new MqttPacketBodyReader(bodyStream.ToArray())));
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions Tests/MQTTnet.Benchmarks/Tcp/BufferExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Playground.Client.Mqtt.Tcp
namespace MQTTnet.Benchmarks.Tcp
{
public static class BufferExtensions
{
Expand Down
4 changes: 1 addition & 3 deletions Tests/MQTTnet.Benchmarks/Tcp/SocketAwaitable.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Pipelines;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Playground.Client.Mqtt.Tcp
namespace MQTTnet.Benchmarks.Tcp
{
public class SocketAwaitable : ICriticalNotifyCompletion
{
Expand Down
1 change: 0 additions & 1 deletion Tests/MQTTnet.Benchmarks/Tcp/SocketReceiver.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO.Pipelines;
using System.Net.Sockets;
using Playground.Client.Mqtt.Tcp;

namespace MQTTnet.Benchmarks.Tcp
{
Expand Down
1 change: 0 additions & 1 deletion Tests/MQTTnet.Benchmarks/Tcp/SocketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Diagnostics;
using System.IO.Pipelines;
using System.Net.Sockets;
using Playground.Client.Mqtt.Tcp;

namespace MQTTnet.Benchmarks.Tcp
{
Expand Down
1 change: 0 additions & 1 deletion Tests/MQTTnet.Benchmarks/Tcp/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Net.Sockets;
using System.Threading.Tasks;
using MQTTnet.Exceptions;
using Playground.Client.Mqtt.Tcp;

namespace MQTTnet.Benchmarks.Tcp
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/MQTTnet.Core.Tests/MqttPacketReaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.IO;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Core.Internal;
using MQTTnet.Exceptions;
using MQTTnet.Internal;
using MQTTnet.Serializer;

namespace MQTTnet.Core.Tests
Expand Down
4 changes: 2 additions & 2 deletions Tests/MQTTnet.Core.Tests/MqttPacketSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Adapter;
using MQTTnet.Core.Internal;
using MQTTnet.Internal;
using MQTTnet.Packets;
using MQTTnet.Protocol;
using MQTTnet.Serializer;
Expand Down Expand Up @@ -422,7 +422,7 @@ private static void DeserializeAndCompare(MqttBasePacket packet, string expected

using (var bodyStream = new MemoryStream(Join(buffer1), (int)headerStream.Position, header.RemainingLength))
{
var deserializedPacket = serializer.Deserialize(new ReceivedMqttPacket(header.Flags, bodyStream));
var deserializedPacket = serializer.Deserialize(new ReceivedMqttPacket(header.Flags, new MqttPacketBodyReader(bodyStream.ToArray())));
var buffer2 = serializer.Serialize(deserializedPacket);

Assert.AreEqual(expectedBase64Value, Convert.ToBase64String(Join(buffer2)));
Expand Down
47 changes: 47 additions & 0 deletions Tests/MQTTnet.TestApp.NetCore/ClientFlowTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Threading.Tasks;
using MQTTnet.Client;

namespace MQTTnet.TestApp.NetCore
{
public static class ClientFlowTest
{
public static async Task RunAsync()
{
MqttNetConsoleLogger.ForwardToConsole();
try
{
var factory = new MqttFactory();
var client = factory.CreateMqttClient();

var options = new MqttClientOptionsBuilder()
.WithTcpServer("localhost")
.Build();

Console.WriteLine("BEFORE CONNECT");
await client.ConnectAsync(options);
Console.WriteLine("AFTER CONNECT");

Console.WriteLine("BEFORE SUBSCRIBE");
await client.SubscribeAsync("test/topic");
Console.WriteLine("AFTER SUBSCRIBE");

Console.WriteLine("BEFORE PUBLISH");
await client.PublishAsync("test/topic", "payload");
Console.WriteLine("AFTER PUBLISH");

await Task.Delay(1000);

Console.WriteLine("BEFORE DISCONNECT");
await client.DisconnectAsync();
Console.WriteLine("AFTER DISCONNECT");

Console.WriteLine("FINISHED");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Extensions\MQTTnet.Extensions.ManagedClient\MQTTnet.Extensions.ManagedClient.csproj" />
<ProjectReference Include="..\..\Frameworks\MQTTnet.NetStandard\MQTTnet.NetStandard.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using MQTTnet.Client;
using MQTTnet.ManagedClient;
using MQTTnet.Extensions.ManagedClient;
using MQTTnet.Protocol;

namespace MQTTnet.TestApp.NetCore
Expand Down
5 changes: 5 additions & 0 deletions Tests/MQTTnet.TestApp.NetCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void Main()
Console.WriteLine("4 = Start managed client");
Console.WriteLine("5 = Start public broker test");
Console.WriteLine("6 = Start server & client");
Console.WriteLine("7 = Client flow test");

var pressedKey = Console.ReadKey(true);
if (pressedKey.KeyChar == '1')
Expand All @@ -47,6 +48,10 @@ public static void Main()
{
Task.Run(ServerAndClientTest.RunAsync);
}
else if (pressedKey.KeyChar == '7')
{
Task.Run(ClientFlowTest.RunAsync);
}

Thread.Sleep(Timeout.Infinite);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
</Page>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Extensions\MQTTnet.Extensions.ManagedClient\MQTTnet.Extensions.ManagedClient.csproj">
<Project>{C400533A-8EBA-4F0B-BF4D-295C3708604B}</Project>
<Name>MQTTnet.Extensions.ManagedClient</Name>
</ProjectReference>
<ProjectReference Include="..\..\Extensions\MQTTnet.Extensions.Rpc\MQTTnet.Extensions.Rpc.csproj">
<Project>{c444e9c8-95fa-430e-9126-274129de16cd}</Project>
<Name>MQTTnet.Extensions.Rpc</Name>
Expand Down
3 changes: 1 addition & 2 deletions Tests/MQTTnet.TestApp.UniversalWindows/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
using MQTTnet.Client;
using MQTTnet.Diagnostics;
using MQTTnet.Exceptions;
using MQTTnet.Extensions.ManagedClient;
using MQTTnet.Extensions.Rpc;
using MQTTnet.Implementations;
using MQTTnet.ManagedClient;
using MQTTnet.Protocol;
using MQTTnet.Server;
using MqttClientConnectedEventArgs = MQTTnet.Client.MqttClientConnectedEventArgs;
Expand Down Expand Up @@ -613,7 +613,6 @@ private async Task WikiCode()
await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic("my/topic").Build());
await mqttClient.StartAsync(options);
}

}
}
}

0 comments on commit 3480d9a

Please sign in to comment.