diff --git a/.gitignore b/.gitignore
index 0fc91b84..5db82efd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -276,6 +276,9 @@ _TeamCity*
*.coverage
*.coveragexml
+# Coverlet
+coverage.*
+
# NCrunch
_NCrunch_*
.*crunch*.local.xml
diff --git a/Build.ps1 b/Build.ps1
index da1f7f08..6914d30b 100644
--- a/Build.ps1
+++ b/Build.ps1
@@ -59,8 +59,8 @@ else {
}
function DotNetBuild {
- param([string]$Project, [string]$Configuration, [string]$Framework)
- & $dotnet build $Project --output (Join-Path $OutputPath $Framework) --framework $Framework --configuration $Configuration
+ param([string]$Project, [string]$Configuration)
+ & $dotnet build $Project --output $OutputPath --configuration $Configuration
if ($LASTEXITCODE -ne 0) {
throw "dotnet build failed with exit code $LASTEXITCODE"
}
@@ -131,8 +131,8 @@ $packageProjects = @(
Write-Host "Building $($projects.Count) projects..." -ForegroundColor Green
ForEach ($project in $projects) {
- DotNetBuild $project $Configuration "netstandard2.0"
- DotNetBuild $project $Configuration "net451"
+ DotNetBuild $project $Configuration
+ DotNetBuild $project $Configuration
}
if ($SkipTests -eq $false) {
diff --git a/Directory.Build.props b/Directory.Build.props
index 6b04b582..2996a9eb 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -2,16 +2,18 @@
2.9.6
+ 1.0.0-preview.2
+
-
-
+
+
$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
@@ -24,9 +26,9 @@
false
true
latest
- $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
en-US
- https://avatars3.githubusercontent.com/u/1516790?s=64
+ enable
+ package-icon.png
Apache-2.0
https://github.com/justeat/JustEat.StatsD
$(PackageProjectUrl)/releases
@@ -44,7 +46,7 @@
true
$(OutputPath)\
cobertura,json
- [*.Benchmark]*,[*.Tests]*,[xunit.*]*
+ [Benchmark]*,[*.Tests]*,[xunit.*]*
System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute
90
diff --git a/Directory.Build.targets b/Directory.Build.targets
index 4a635631..8c211f79 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -1,8 +1,5 @@
-
- $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
-
-
+
diff --git a/JustEat.StatsD.sln b/JustEat.StatsD.sln
index 37d30d49..e43d39a9 100644
--- a/JustEat.StatsD.sln
+++ b/JustEat.StatsD.sln
@@ -19,7 +19,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{06BE4D
JustEat.StatsD.ruleset = JustEat.StatsD.ruleset
LICENSE = LICENSE
README.md = README.md
- ReferenceAssemblies.props = ReferenceAssemblies.props
version.props = version.props
EndProjectSection
EndProject
diff --git a/README.md b/README.md
index d2af0f07..d5223ebc 100644
--- a/README.md
+++ b/README.md
@@ -13,10 +13,11 @@ We use this library within our components to publish [StatsD](http://github.com/
### Supported platforms
-`JustEat.Statsd` version 4 is built for these target frameworks:
+`JustEat.StatsD` version 4.1.0 is built for these target frameworks:
-* `net451`
+* `net461`
* `netstandard2.0`
+* `netstandard2.1`
* `netcoreapp2.1`
* `netcoreapp2.2`
diff --git a/appveyor.yml b/appveyor.yml
index 79eb6b4e..ef61c11a 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -1,5 +1,5 @@
-os: Visual Studio 2017
-version: 4.0.1.{build}
+os: Visual Studio 2019
+version: 4.1.0.{build}
configuration: Release
environment:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
diff --git a/build.sh b/build.sh
index 3cb33222..61f34395 100755
--- a/build.sh
+++ b/build.sh
@@ -40,8 +40,9 @@ if [ "$dotnet_version" != "$CLI_VERSION" ]; then
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version "$CLI_VERSION" --install-dir "$DOTNET_INSTALL_DIR"
fi
-dotnet build src/JustEat.StatsD/JustEat.StatsD.csproj --output $artifacts --configuration $configuration || exit 1
+dotnet build ./JustEat.StatsD.sln --output $artifacts --configuration $configuration || exit 1
+dotnet pack ./src/JustEat.StatsD/JustEat.StatsD.csproj --output $artifacts --configuration $configuration || exit 1
if [ $skipTests == 0 ]; then
- dotnet test tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj --output $artifacts --configuration $configuration --framework "netcoreapp2.2" || exit 1
+ dotnet test ./tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj --output $artifacts --configuration $configuration || exit 1
fi
diff --git a/global.json b/global.json
index 3d26ee65..79422f0c 100644
--- a/global.json
+++ b/global.json
@@ -1,5 +1,5 @@
{
"sdk": {
- "version": "2.2.401"
+ "version": "3.0.100"
}
}
diff --git a/package-icon.png b/package-icon.png
new file mode 100644
index 00000000..c8af7ebd
Binary files /dev/null and b/package-icon.png differ
diff --git a/src/JustEat.StatsD/Buffered/BufferBasedStatsDPublisher.cs b/src/JustEat.StatsD/Buffered/BufferBasedStatsDPublisher.cs
index 3be5072b..d27fb217 100644
--- a/src/JustEat.StatsD/Buffered/BufferBasedStatsDPublisher.cs
+++ b/src/JustEat.StatsD/Buffered/BufferBasedStatsDPublisher.cs
@@ -8,19 +8,24 @@ internal sealed class BufferBasedStatsDPublisher : IStatsDPublisher
private const int SafeUdpPacketSize = 512;
[ThreadStatic]
- private static byte[] _buffer;
+ private static byte[]? _buffer;
private static byte[] Buffer => _buffer ?? (_buffer = new byte[SafeUdpPacketSize]);
[ThreadStatic]
- private static Random _random;
+ private static Random? _random;
private static Random Random => _random ?? (_random = new Random());
private readonly StatsDUtf8Formatter _formatter;
private readonly IStatsDTransport _transport;
- private readonly Func _onError;
+ private readonly Func? _onError;
- public BufferBasedStatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport)
+ internal BufferBasedStatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport)
{
+ if (configuration == null)
+ {
+ throw new ArgumentNullException(nameof(configuration));
+ }
+
_onError = configuration.OnError;
_transport = transport;
_formatter = new StatsDUtf8Formatter(configuration.Prefix);
diff --git a/src/JustEat.StatsD/Buffered/BufferExtensions.cs b/src/JustEat.StatsD/Buffered/BufferExtensions.cs
index 9b610abe..42cd7caf 100644
--- a/src/JustEat.StatsD/Buffered/BufferExtensions.cs
+++ b/src/JustEat.StatsD/Buffered/BufferExtensions.cs
@@ -25,13 +25,18 @@ public static bool TryWriteBytes(this ref Buffer src, Span destination)
public static bool TryWriteUtf8String(this ref Buffer src, string str)
{
-#if NETCOREAPP2_1 || NETCOREAPP2_2
+#if NETSTANDARD2_0 || NET461
+ var bucketBytes = Encoding.UTF8.GetBytes(str);
+ return src.TryWriteBytes(bucketBytes);
+#else
int written = 0;
try
{
written = Encoding.UTF8.GetBytes(str, src.Tail);
}
+#pragma warning disable CA1031
catch (ArgumentException)
+#pragma warning restore CA1031
{
return false;
}
@@ -39,9 +44,6 @@ public static bool TryWriteUtf8String(this ref Buffer src, string str)
src.Tail = src.Tail.Slice(written);
src.Written += written;
return true;
-#else
- var bucketBytes = Encoding.UTF8.GetBytes(str);
- return src.TryWriteBytes(bucketBytes);
#endif
}
diff --git a/src/JustEat.StatsD/Buffered/StatsDUtf8Formatter.cs b/src/JustEat.StatsD/Buffered/StatsDUtf8Formatter.cs
index ff1a067a..9ee3e151 100644
--- a/src/JustEat.StatsD/Buffered/StatsDUtf8Formatter.cs
+++ b/src/JustEat.StatsD/Buffered/StatsDUtf8Formatter.cs
@@ -11,11 +11,7 @@ internal sealed class StatsDUtf8Formatter
public StatsDUtf8Formatter(string prefix)
{
_utf8Prefix = string.IsNullOrWhiteSpace(prefix) ?
-#if NET451
- new byte[0] :
-#else
Array.Empty() :
-#endif
Encoding.UTF8.GetBytes(prefix + ".");
}
diff --git a/src/JustEat.StatsD/ConnectedSocketPool.cs b/src/JustEat.StatsD/ConnectedSocketPool.cs
index 38a956da..b34358cb 100644
--- a/src/JustEat.StatsD/ConnectedSocketPool.cs
+++ b/src/JustEat.StatsD/ConnectedSocketPool.cs
@@ -46,7 +46,7 @@ private Socket CreateSocket()
/// Retrieves an object from the pool if one is available.
/// return null if the pool is empty
/// An object from the pool.
- private Socket Pop()
+ private Socket? Pop()
{
if (_pool.TryTake(out Socket result))
{
diff --git a/src/JustEat.StatsD/DisposableTimer.cs b/src/JustEat.StatsD/DisposableTimer.cs
index 0931bcb4..beb83e52 100644
--- a/src/JustEat.StatsD/DisposableTimer.cs
+++ b/src/JustEat.StatsD/DisposableTimer.cs
@@ -5,10 +5,10 @@ namespace JustEat.StatsD
{
internal sealed class DisposableTimer : IDisposableTimer
{
- private bool _disposed;
+ private readonly IStatsDPublisher _publisher;
+ private readonly Stopwatch _stopwatch;
- private IStatsDPublisher _publisher;
- private Stopwatch _stopwatch;
+ private bool _disposed;
public string Bucket { get; set; }
@@ -38,9 +38,6 @@ public void Dispose()
}
_publisher.Timing(_stopwatch.Elapsed, Bucket);
-
- _stopwatch = null;
- _publisher = null;
}
}
}
diff --git a/src/JustEat.StatsD/EndpointLookups/CachedEndpointSource.cs b/src/JustEat.StatsD/EndpointLookups/CachedEndpointSource.cs
index 8b8d59b1..78d1a67b 100644
--- a/src/JustEat.StatsD/EndpointLookups/CachedEndpointSource.cs
+++ b/src/JustEat.StatsD/EndpointLookups/CachedEndpointSource.cs
@@ -11,7 +11,7 @@ public class CachedEndpointSource : IEndPointSource
{
private readonly IEndPointSource _inner;
private readonly TimeSpan _cacheDuration;
- private EndPoint _cachedValue;
+ private EndPoint? _cachedValue;
private DateTime _expiry;
///
@@ -46,7 +46,8 @@ public EndPoint GetEndpoint()
_cachedValue = _inner.GetEndpoint();
_expiry = DateTime.UtcNow.Add(_cacheDuration);
}
- return _cachedValue;
+
+ return _cachedValue!;
}
private bool NeedsRead()
diff --git a/src/JustEat.StatsD/EndpointLookups/DnsLookupIpEndpointSource.cs b/src/JustEat.StatsD/EndpointLookups/DnsLookupIpEndpointSource.cs
index a820844e..18a9bb72 100644
--- a/src/JustEat.StatsD/EndpointLookups/DnsLookupIpEndpointSource.cs
+++ b/src/JustEat.StatsD/EndpointLookups/DnsLookupIpEndpointSource.cs
@@ -44,7 +44,7 @@ private static IPAddress GetIpAddressOfHost(string hostName)
throw new Exception($"Failed to resolve any IP addresses for StatsD host '${hostName}' using DNS.");
}
- IPAddress result = null;
+ IPAddress? result = null;
if (endpoints.Length > 1)
{
diff --git a/src/JustEat.StatsD/JustEat.StatsD.csproj b/src/JustEat.StatsD/JustEat.StatsD.csproj
index 992cbd87..8742564f 100644
--- a/src/JustEat.StatsD/JustEat.StatsD.csproj
+++ b/src/JustEat.StatsD/JustEat.StatsD.csproj
@@ -1,5 +1,4 @@
-
-
+
A .NET library for publishing metrics to StatsD.
true
@@ -8,20 +7,16 @@
JustEat.StatsD
JustEat.StatsD
A .NET library for publishing metrics to StatsD.
- net451;netstandard2.0;netcoreapp2.1;netcoreapp2.2
+ net461;netstandard2.0;netstandard2.1;netcoreapp2.1;netcoreapp2.2
-
-
-
-
-
-
+
+
-
+
-
+
diff --git a/src/JustEat.StatsD/SocketFactory.cs b/src/JustEat.StatsD/SocketFactory.cs
index 9c8aacfc..9e260490 100644
--- a/src/JustEat.StatsD/SocketFactory.cs
+++ b/src/JustEat.StatsD/SocketFactory.cs
@@ -8,32 +8,25 @@ internal static class SocketFactory
{
internal static Socket For(SocketProtocol socketProtocol)
{
- switch (socketProtocol)
+ return socketProtocol switch
{
- case SocketProtocol.IP:
- return ForIp();
+ SocketProtocol.IP => ForIp(),
- case SocketProtocol.Udp:
- return ForUdp();
+ SocketProtocol.Udp => ForUdp(),
- default:
- throw new InvalidOperationException($"Unknown {nameof(SocketProtocol)} value {socketProtocol} specified.");
- }
+ _ => throw new InvalidOperationException($"Unknown {nameof(SocketProtocol)} value {socketProtocol} specified."),
+ };
}
internal static Socket ForUdp()
{
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
-#if !NET451
// See https://github.com/dotnet/corefx/pull/17853#issuecomment-291371266
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
socket.SendBufferSize = 0;
}
-#else
- socket.SendBufferSize = 0;
-#endif
return socket;
}
diff --git a/src/JustEat.StatsD/SocketTransport.cs b/src/JustEat.StatsD/SocketTransport.cs
index 8e5b8460..9187be82 100644
--- a/src/JustEat.StatsD/SocketTransport.cs
+++ b/src/JustEat.StatsD/SocketTransport.cs
@@ -13,9 +13,9 @@ namespace JustEat.StatsD
///
public sealed class SocketTransport : IStatsDTransport, IDisposable
{
- private ConnectedSocketPool _pool;
private readonly IEndPointSource _endpointSource;
private readonly SocketProtocol _socketProtocol;
+ private ConnectedSocketPool? _pool;
///
/// Initializes a new instance of the class.
@@ -96,7 +96,7 @@ private ConnectedSocketPool GetPool(EndPoint endPoint)
else
{
newPool.Dispose();
- return _pool;
+ return _pool!;
}
}
}
diff --git a/src/JustEat.StatsD/StatsDConfiguration.cs b/src/JustEat.StatsD/StatsDConfiguration.cs
index 192e7472..e02cd2e8 100644
--- a/src/JustEat.StatsD/StatsDConfiguration.cs
+++ b/src/JustEat.StatsD/StatsDConfiguration.cs
@@ -23,7 +23,7 @@ public class StatsDConfiguration
///
/// A value must be provided for this property.
///
- public string Host { get; set; }
+ public string? Host { get; set; }
///
/// Gets or sets the port on the StatsD server to use.
@@ -62,6 +62,6 @@ public class StatsDConfiguration
///
/// The default behaviour is to ignore the exception.
///
- public Func OnError { get; set; }
+ public Func? OnError { get; set; }
}
}
diff --git a/src/JustEat.StatsD/StatsDPublisher.cs b/src/JustEat.StatsD/StatsDPublisher.cs
index 2d170a02..293a42ca 100644
--- a/src/JustEat.StatsD/StatsDPublisher.cs
+++ b/src/JustEat.StatsD/StatsDPublisher.cs
@@ -71,7 +71,7 @@ public StatsDPublisher(StatsDConfiguration configuration)
}
var endpointSource = EndPointFactory.MakeEndPointSource(
- configuration.Host, configuration.Port, configuration.DnsLookupInterval);
+ configuration.Host!, configuration.Port, configuration.DnsLookupInterval);
var transport = new SocketTransport(endpointSource, configuration.SocketProtocol);
diff --git a/src/JustEat.StatsD/StatsDServiceCollectionExtensions.cs b/src/JustEat.StatsD/StatsDServiceCollectionExtensions.cs
index a609b005..2a7704f5 100644
--- a/src/JustEat.StatsD/StatsDServiceCollectionExtensions.cs
+++ b/src/JustEat.StatsD/StatsDServiceCollectionExtensions.cs
@@ -1,4 +1,3 @@
-#if !NET451
using System;
using JustEat.StatsD.EndpointLookups;
using Microsoft.Extensions.DependencyInjection;
@@ -46,7 +45,7 @@ public static IServiceCollection AddStatsD(this IServiceCollection services)
///
/// or is .
///
- public static IServiceCollection AddStatsD(this IServiceCollection services, string host, string prefix = null)
+ public static IServiceCollection AddStatsD(this IServiceCollection services, string host, string? prefix = null)
{
if (services == null)
{
@@ -112,7 +111,7 @@ private static IEndPointSource ResolveEndPointSource(IServiceProvider provider)
var config = provider.GetRequiredService();
return EndPointFactory.MakeEndPointSource(
- config.Host,
+ config.Host!,
config.Port,
config.DnsLookupInterval);
}
@@ -132,4 +131,3 @@ private static IStatsDTransport ResolveStatsDTransport(IServiceProvider provider
}
}
}
-#endif
diff --git a/tests/Benchmark/Benchmark.csproj b/tests/Benchmark/Benchmark.csproj
index 88ea6bab..c497853c 100644
--- a/tests/Benchmark/Benchmark.csproj
+++ b/tests/Benchmark/Benchmark.csproj
@@ -2,10 +2,11 @@
$(NoWarn);CA1001;CA1822
Exe
- netcoreapp2.0;netcoreapp2.1;netcoreapp2.2
+ netcoreapp2.1;netcoreapp2.2;netcoreapp3.0
true
+
diff --git a/tests/Benchmark/StatSendingBenchmark.cs b/tests/Benchmark/StatSendingBenchmark.cs
index b2b1a48e..0b1f5fd3 100644
--- a/tests/Benchmark/StatSendingBenchmark.cs
+++ b/tests/Benchmark/StatSendingBenchmark.cs
@@ -7,13 +7,41 @@
namespace Benchmark
{
[MemoryDiagnoser]
- public class StatSendingBenchmark
+ public class StatSendingBenchmark : IDisposable
{
- private BufferBasedStatsDPublisher _udpSender;
- private BufferBasedStatsDPublisher _ipSender;
+ private bool _disposed;
+ private SocketTransport? _udpTransport;
+ private BufferBasedStatsDPublisher? _udpSender;
+ private SocketTransport? _ipTransport;
+ private BufferBasedStatsDPublisher? _ipSender;
private static readonly TimeSpan Timed = TimeSpan.FromMinutes(1);
+ ~StatSendingBenchmark()
+ {
+ Dispose(false);
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!_disposed)
+ {
+ if (disposing)
+ {
+ _udpTransport?.Dispose();
+ _ipTransport?.Dispose();
+ }
+
+ _disposed = true;
+ }
+ }
+
[GlobalSetup]
public void Setup()
{
@@ -28,12 +56,12 @@ public void Setup()
var endpointSource = EndPointFactory.MakeEndPointSource(
config.Host, config.Port, config.DnsLookupInterval);
- var ipTransport = new SocketTransport(endpointSource, SocketProtocol.IP);
- _ipSender = new BufferBasedStatsDPublisher(config, ipTransport);
+ _ipTransport = new SocketTransport(endpointSource, SocketProtocol.IP);
+ _ipSender = new BufferBasedStatsDPublisher(config, _ipTransport);
_ipSender.Increment("startup.i");
- var udpTransport = new SocketTransport(endpointSource, SocketProtocol.Udp);
- _udpSender = new BufferBasedStatsDPublisher(config, udpTransport);
+ _udpTransport = new SocketTransport(endpointSource, SocketProtocol.Udp);
+ _udpSender = new BufferBasedStatsDPublisher(config, _udpTransport);
_udpSender.Increment("startup.u");
}
@@ -41,34 +69,34 @@ public void Setup()
[Benchmark]
public void RunIp()
{
- _ipSender.Increment("hello.i");
- _ipSender.Increment(20, "increment.i");
- _ipSender.Timing(Timed, "timer.i");
- _ipSender.Gauge(354654, "gauge.i");
+ _ipSender!.Increment("hello.i");
+ _ipSender!.Increment(20, "increment.i");
+ _ipSender!.Timing(Timed, "timer.i");
+ _ipSender!.Gauge(354654, "gauge.i");
_ipSender.Gauge(25.1, "free-space.i");
}
[Benchmark]
public void RunIPWithSampling()
{
- _ipSender.Increment(2, 0.2, "increment.i");
+ _ipSender!.Increment(2, 0.2, "increment.i");
_ipSender.Timing(2, 0.2, "increment.i");
}
[Benchmark]
public void RunUdp()
{
- _udpSender.Increment("hello.u");
- _udpSender.Increment(20, "increment.u");
- _udpSender.Timing(Timed, "timer.u");
- _udpSender.Gauge(354654, "gauge.u");
+ _udpSender!.Increment("hello.u");
+ _udpSender!.Increment(20, "increment.u");
+ _udpSender!.Timing(Timed, "timer.u");
+ _udpSender!.Gauge(354654, "gauge.u");
_udpSender.Gauge(25.1, "free-space.u");
}
[Benchmark]
public void RunUdpWithSampling()
{
- _udpSender.Increment(2, 0.2, "increment.u");
+ _udpSender!.Increment(2, 0.2, "increment.u");
_udpSender.Timing(2, 0.2, "increment.u");
}
}
diff --git a/tests/Benchmark/UdpStatSendingBenchmark.cs b/tests/Benchmark/UdpStatSendingBenchmark.cs
index b4d08002..075aeb17 100644
--- a/tests/Benchmark/UdpStatSendingBenchmark.cs
+++ b/tests/Benchmark/UdpStatSendingBenchmark.cs
@@ -11,9 +11,9 @@ public class UdpStatSendingBenchmark
{
private static readonly TimeSpan Timed = TimeSpan.FromMinutes(1);
- private SocketTransport _transport;
- private BufferBasedStatsDPublisher _udpSender;
- private StatsDPublisher _adaptedStatsDPublisher;
+ private SocketTransport? _transport;
+ private BufferBasedStatsDPublisher? _udpSender;
+ private StatsDPublisher? _adaptedStatsDPublisher;
[GlobalSetup]
public void Setup()
@@ -50,15 +50,15 @@ public void Cleanup()
[Benchmark]
public void SendStatUdp()
{
- _udpSender.Increment("increment.ud");
- _udpSender.Timing(Timed, "timer.ud");
+ _udpSender!.Increment("increment.ud");
+ _udpSender!.Timing(Timed, "timer.ud");
}
[Benchmark]
public void SendStatUdpCoveredByAdapter()
{
- _adaptedStatsDPublisher.Increment("increment.ud");
- _adaptedStatsDPublisher.Timing(Timed, "timer.ud");
+ _adaptedStatsDPublisher!.Increment("increment.ud");
+ _adaptedStatsDPublisher!.Timing(Timed, "timer.ud");
}
}
}
diff --git a/tests/Benchmark/UdpTransportBenchmark.cs b/tests/Benchmark/UdpTransportBenchmark.cs
index 0a0088d8..be391f83 100644
--- a/tests/Benchmark/UdpTransportBenchmark.cs
+++ b/tests/Benchmark/UdpTransportBenchmark.cs
@@ -11,8 +11,8 @@ public class UdpTransportBenchmark
{
private const string MetricName = "this.is.a.metric:1|c";
- private SocketTransport _transport;
- private SocketTransport _transportSwitched;
+ private SocketTransport? _transport;
+ private SocketTransport? _transportSwitched;
private class MillisecondSwitcher : IEndPointSource
{
@@ -67,13 +67,13 @@ public void Cleanup()
[Benchmark]
public void Send()
{
- _transport.Send(MetricName);
+ _transport!.Send(MetricName);
}
[Benchmark]
public void SendWithSwitcher()
{
- _transportSwitched.Send(MetricName);
+ _transportSwitched!.Send(MetricName);
}
}
}
diff --git a/tests/JustEat.StatsD.Tests/BufferBasedStatsDPublisherTests.cs b/tests/JustEat.StatsD.Tests/BufferBasedStatsDPublisherTests.cs
index 621a9d7c..fa39818d 100644
--- a/tests/JustEat.StatsD.Tests/BufferBasedStatsDPublisherTests.cs
+++ b/tests/JustEat.StatsD.Tests/BufferBasedStatsDPublisherTests.cs
@@ -58,7 +58,7 @@ private class FakeTransport : IStatsDTransport
public void Send(in ArraySegment metric)
{
- Messages.Add(Encoding.UTF8.GetString(metric.Array, metric.Offset, metric.Count));
+ Messages.Add(Encoding.UTF8.GetString(metric.Array!, metric.Offset, metric.Count));
}
}
}
diff --git a/tests/JustEat.StatsD.Tests/Buffered/BufferBasedStatsDPublisherTests.cs b/tests/JustEat.StatsD.Tests/Buffered/BufferBasedStatsDPublisherTests.cs
index af583819..497820af 100644
--- a/tests/JustEat.StatsD.Tests/Buffered/BufferBasedStatsDPublisherTests.cs
+++ b/tests/JustEat.StatsD.Tests/Buffered/BufferBasedStatsDPublisherTests.cs
@@ -16,7 +16,7 @@ public static void Increment_Is_Noop_If_Bucket_Is_Null()
var publisher = new BufferBasedStatsDPublisher(configuration, transport.Object);
// Act
- publisher.Increment(1, 1, null);
+ publisher.Increment(1, 1, null!);
// Assert
transport.Verify((p) => p.Send(It.Ref>.IsAny), Times.Never());
diff --git a/tests/JustEat.StatsD.Tests/EndpointLookups/CachedEndpointSourceTests.cs b/tests/JustEat.StatsD.Tests/EndpointLookups/CachedEndpointSourceTests.cs
index 7684a0af..4c027240 100644
--- a/tests/JustEat.StatsD.Tests/EndpointLookups/CachedEndpointSourceTests.cs
+++ b/tests/JustEat.StatsD.Tests/EndpointLookups/CachedEndpointSourceTests.cs
@@ -81,11 +81,11 @@ public static void ConstructorThrowsIfCacheDurationIsInvalid(long ticks)
public static void ConstructorThrowsIfInnerIsNull()
{
// Arrange
- IEndPointSource inner = null;
+ IEndPointSource? inner = null;
var cacheDuration = TimeSpan.FromHours(1);
// Act and Assert
- Assert.Throws("inner", () => new CachedEndpointSource(inner, cacheDuration));
+ Assert.Throws("inner", () => new CachedEndpointSource(inner!, cacheDuration));
}
private static IPEndPoint MakeTestIpEndPoint()
diff --git a/tests/JustEat.StatsD.Tests/EndpointLookups/DnsLookupIpEndpointSourceTests.cs b/tests/JustEat.StatsD.Tests/EndpointLookups/DnsLookupIpEndpointSourceTests.cs
index 780bf31d..ee713ddf 100644
--- a/tests/JustEat.StatsD.Tests/EndpointLookups/DnsLookupIpEndpointSourceTests.cs
+++ b/tests/JustEat.StatsD.Tests/EndpointLookups/DnsLookupIpEndpointSourceTests.cs
@@ -24,7 +24,7 @@ public static void GetEndpointPrefersIPV4WhenHostnameIsLocalhost()
var ipActual = actual as IPEndPoint;
ipActual.ShouldNotBeNull();
- ipActual.Address.ShouldBe(IPAddress.Parse("127.0.0.1"));
+ ipActual!.Address.ShouldBe(IPAddress.Parse("127.0.0.1"));
ipActual.Port.ShouldBe(8125);
}
@@ -32,11 +32,11 @@ public static void GetEndpointPrefersIPV4WhenHostnameIsLocalhost()
public static void ConstructorThrowsIfHostNameIsNull()
{
// Arrange
- string hostName = null;
+ string? hostName = null;
int port = 123;
// Act and Assert
- Assert.Throws("hostName", () => new DnsLookupIpEndpointSource(hostName, port));
+ Assert.Throws("hostName", () => new DnsLookupIpEndpointSource(hostName!, port));
}
}
}
diff --git a/tests/JustEat.StatsD.Tests/EndpointLookups/EndPointFactoryTests.cs b/tests/JustEat.StatsD.Tests/EndpointLookups/EndPointFactoryTests.cs
index 01378c24..8dd53cb4 100644
--- a/tests/JustEat.StatsD.Tests/EndpointLookups/EndPointFactoryTests.cs
+++ b/tests/JustEat.StatsD.Tests/EndpointLookups/EndPointFactoryTests.cs
@@ -70,23 +70,23 @@ public static void CanParseCachedLocalhostValueNoPort()
public static void MakeEndPointSourceThrowsIfEndpointIsNull()
{
// Arrange
- EndPoint endpoint = null;
+ EndPoint? endpoint = null;
var endpointCacheDuration = TimeSpan.FromHours(1);
// Act and Assert
- Assert.Throws("endpoint", () => EndPointFactory.MakeEndPointSource(endpoint, endpointCacheDuration));
+ Assert.Throws("endpoint", () => EndPointFactory.MakeEndPointSource(endpoint!, endpointCacheDuration));
}
[Fact]
public static void MakeEndPointSourceThrowsIfHostIsNull()
{
// Arrange
- string host = null;
+ string? host = null;
int port = 8125;
var endpointCacheDuration = TimeSpan.FromHours(1);
// Act and Assert
- Assert.Throws("host", () => EndPointFactory.MakeEndPointSource(host, port, endpointCacheDuration));
+ Assert.Throws("host", () => EndPointFactory.MakeEndPointSource(host!, port, endpointCacheDuration));
}
}
}
diff --git a/tests/JustEat.StatsD.Tests/EndpointLookups/SimpleEndpointTests.cs b/tests/JustEat.StatsD.Tests/EndpointLookups/SimpleEndpointTests.cs
index b56110fa..f6ab1fbb 100644
--- a/tests/JustEat.StatsD.Tests/EndpointLookups/SimpleEndpointTests.cs
+++ b/tests/JustEat.StatsD.Tests/EndpointLookups/SimpleEndpointTests.cs
@@ -28,10 +28,10 @@ public static void ValueIsConsistent()
public static void ConstructorThrowsIfValueIsNull()
{
// Arrange
- EndPoint value = null;
+ EndPoint? value = null;
// Act and Assert
- Assert.Throws("value", () => new SimpleEndpointSource(value));
+ Assert.Throws("value", () => new SimpleEndpointSource(value!));
}
private static IPEndPoint MakeTestIpEndPoint()
diff --git a/tests/JustEat.StatsD.Tests/Extensions/SimpleTimerStatNameTests.cs b/tests/JustEat.StatsD.Tests/Extensions/SimpleTimerStatNameTests.cs
index e08c2cb3..c8a04980 100644
--- a/tests/JustEat.StatsD.Tests/Extensions/SimpleTimerStatNameTests.cs
+++ b/tests/JustEat.StatsD.Tests/Extensions/SimpleTimerStatNameTests.cs
@@ -66,11 +66,11 @@ public static void StatWithoutNameAtEndThrows()
Assert.Throws(() =>
{
- using (var timer = publisher.StartTimer("valid.Stat"))
- {
- Delay();
- timer.Bucket = null;
- }
+ using var timer = publisher.StartTimer("valid.Stat");
+
+ Delay();
+
+ timer.Bucket = null!;
});
publisher.CallCount.ShouldBe(0);
@@ -85,13 +85,15 @@ public static void StatNameIsInitialValueWhenExceptionIsThrown()
try
{
- using (var timer = publisher.StartTimer("initialStat"))
- {
- Fail();
- timer.Bucket = "changedValue";
- }
+ using var timer = publisher.StartTimer("initialStat");
+
+ Fail();
+
+ timer.Bucket = "changedValue";
}
+#pragma warning disable CA1031
catch (InvalidOperationException)
+#pragma warning restore CA1031
{
failCount++;
}
diff --git a/tests/JustEat.StatsD.Tests/IStatsDTransportExtensionsTests.cs b/tests/JustEat.StatsD.Tests/IStatsDTransportExtensionsTests.cs
index b7b46e25..86c0bbea 100644
--- a/tests/JustEat.StatsD.Tests/IStatsDTransportExtensionsTests.cs
+++ b/tests/JustEat.StatsD.Tests/IStatsDTransportExtensionsTests.cs
@@ -11,22 +11,22 @@ public static class IStatsDTransportExtensionsTests
public static void SendThrowsIfTransportIsNullMetric()
{
// Arrange
- IStatsDTransport transport = null;
+ IStatsDTransport? transport = null;
string metric = "metric";
// Act and Assert
- Assert.Throws("transport", () => transport.Send(metric));
+ Assert.Throws("transport", () => transport!.Send(metric));
}
[Fact]
public static void SendThrowsIfTransportIsNullMetrics()
{
// Arrange
- IStatsDTransport transport = null;
+ IStatsDTransport? transport = null;
IEnumerable metrics = Array.Empty();
// Act and Assert
- Assert.Throws("transport", () => transport.Send(metrics));
+ Assert.Throws("transport", () => transport!.Send(metrics));
}
[Fact]
@@ -34,10 +34,10 @@ public static void SendThrowsIfTransportIfMetricIsNull()
{
// Arrange
var transport = Mock.Of();
- string metric = null;
+ string? metric = null;
// Act and Assert
- Assert.Throws("metric", () => transport.Send(metric));
+ Assert.Throws("metric", () => transport.Send(metric!));
}
[Fact]
@@ -45,10 +45,10 @@ public static void SendThrowsIfMetricsIsNull()
{
// Arrange
var transport = Mock.Of();
- IEnumerable metrics = null;
+ IEnumerable? metrics = null;
// Act and Assert
- Assert.Throws("metrics", () => transport.Send(metrics));
+ Assert.Throws("metrics", () => transport.Send(metrics!));
}
[Fact]
diff --git a/tests/JustEat.StatsD.Tests/IntegrationTests.cs b/tests/JustEat.StatsD.Tests/IntegrationTests.cs
index 3ca159c1..3afe835b 100644
--- a/tests/JustEat.StatsD.Tests/IntegrationTests.cs
+++ b/tests/JustEat.StatsD.Tests/IntegrationTests.cs
@@ -30,11 +30,10 @@ public static async Task Can_Send_Metrics_To_StatsD_Using_Udp(
SocketProtocol = socketProtocol,
};
- using (var publisher = new StatsDPublisher(config))
- {
- // Act and Assert
- await AssertMetrics(config, publisher);
- }
+ using var publisher = new StatsDPublisher(config);
+
+ // Act and Assert
+ await AssertMetrics(config, publisher);
}
private static async Task AssertMetrics(StatsDConfiguration config, IStatsDPublisher publisher)
diff --git a/tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj b/tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj
index 6700c744..235d410b 100644
--- a/tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj
+++ b/tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj
@@ -2,7 +2,7 @@
$(NoWarn);CA1707;CA2007
JustEat.StatsD
- netcoreapp2.2
+ netcoreapp3.0
@@ -11,7 +11,7 @@
-
+
diff --git a/tests/JustEat.StatsD.Tests/SocketTransportTests.cs b/tests/JustEat.StatsD.Tests/SocketTransportTests.cs
index 9d1356ef..65f764b8 100644
--- a/tests/JustEat.StatsD.Tests/SocketTransportTests.cs
+++ b/tests/JustEat.StatsD.Tests/SocketTransportTests.cs
@@ -12,29 +12,26 @@ public static class SocketTransportTests
[Fact]
public static void ValidSocketTransportCanBeConstructed()
{
- using (var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.Udp))
- {
- transport.ShouldNotBeNull();
- }
+ using var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.Udp);
+ transport.ShouldNotBeNull();
}
[Fact]
public static void SocketTransportCanSendOverUdpWithoutError()
{
- // using block not used here so the finalizer gets some code coverage
- using (var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.Udp))
- {
- transport.Send("teststat:1|c");
- }
+ // Using block not used here so the finalizer gets some code coverage
+#pragma warning disable CA2000
+ var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.Udp);
+#pragma warning restore CA2000
+
+ transport.Send("teststat:1|c");
}
[Fact]
public static void SocketTransportCanSendOverIPWithoutError()
{
- using (var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.IP))
- {
- transport.Send("teststat:1|c");
- }
+ using var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.IP);
+ transport.Send("teststat:1|c");
}
[Fact]
@@ -42,7 +39,7 @@ public static void NullEndpointSourceThrowsInConstructor()
{
Assert.Throws(
"endPointSource",
- () => new SocketTransport(null, SocketProtocol.IP));
+ () => new SocketTransport(null!, SocketProtocol.IP));
}
[Fact]
@@ -60,19 +57,15 @@ public static void InvalidSocketProtocolThrowsInConstructor()
[Fact]
public static void SocketTransportIsNoopForNullArray()
{
- using (var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.IP))
- {
- transport.Send(new ArraySegment());
- }
+ using var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.IP);
+ transport.Send(new ArraySegment());
}
[Fact]
public static void SocketTransportIsNoopForEmptyArray()
{
- using (var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.IP))
- {
- transport.Send(new ArraySegment(Array.Empty()));
- }
+ using var transport = new SocketTransport(LocalStatsEndpoint(), SocketProtocol.IP);
+ transport.Send(new ArraySegment(Array.Empty()));
}
[Fact]
@@ -80,10 +73,8 @@ public static void SocketTransportIsNoopForNullEndpoint()
{
var endpointSource = Mock.Of();
- using (var transport = new SocketTransport(endpointSource, SocketProtocol.IP))
- {
- transport.Send("teststat:1|c");
- }
+ using var transport = new SocketTransport(endpointSource, SocketProtocol.IP);
+ transport.Send("teststat:1|c");
}
private static IEndPointSource LocalStatsEndpoint()
diff --git a/tests/JustEat.StatsD.Tests/StatsDPublisherTests.cs b/tests/JustEat.StatsD.Tests/StatsDPublisherTests.cs
index e6ed55e9..a283d5df 100644
--- a/tests/JustEat.StatsD.Tests/StatsDPublisherTests.cs
+++ b/tests/JustEat.StatsD.Tests/StatsDPublisherTests.cs
@@ -27,7 +27,6 @@ public static void Decrement_Sends_Multiple_Metrics()
publisher.Decrement(-10, 1, "orange");
publisher.Decrement(10, 1, new[] { "white", "blue" });
publisher.Decrement(10, 1, new List() { "green", "red" });
- publisher.Decrement(10, 1, null as IEnumerable);
}
// Assert
@@ -54,7 +53,6 @@ public static void Increment_Sends_Multiple_Metrics()
publisher.Increment(-10, 1, "orange");
publisher.Increment(10, 1, new[] { "white", "blue" });
publisher.Increment(10, 1, new List() { "green", "red" });
- publisher.Increment(10, 1, null as IEnumerable);
}
// Assert
@@ -71,6 +69,7 @@ public static void Metrics_Not_Sent_If_Array_Is_Null_Or_Empty()
using (var publisher = new StatsDPublisher(config, mock.Object))
{
// Act
+#nullable disable
publisher.Decrement(-1, 1, null as string[]);
publisher.Increment(-1, 1, null as string[]);
publisher.Decrement(1, 1, null as string[]);
@@ -85,6 +84,7 @@ public static void Metrics_Not_Sent_If_Array_Is_Null_Or_Empty()
publisher.Increment(1, 1, null as IEnumerable);
publisher.Decrement(1, 1, new[] { string.Empty });
publisher.Increment(1, 1, new[] { string.Empty });
+#nullable enable
}
// Assert
@@ -113,13 +113,13 @@ public static void Metrics_Not_Sent_If_No_Metrics()
public static void Constructor_Throws_If_Configuration_Is_Null()
{
// Arrange
- StatsDConfiguration configuration = null;
+ StatsDConfiguration? configuration = null;
var transport = Mock.Of();
// Act and Assert
Assert.Throws(
"configuration",
- () => new StatsDPublisher(configuration, transport));
+ () => new StatsDPublisher(configuration!, transport));
}
[Fact]
@@ -127,12 +127,12 @@ public static void Constructor_Throws_If_Transport_Is_Null()
{
// Arrange
var configuration = new StatsDConfiguration();
- IStatsDTransport transport = null;
+ IStatsDTransport? transport = null;
// Act and Assert
Assert.Throws(
"transport",
- () => new StatsDPublisher(configuration, transport));
+ () => new StatsDPublisher(configuration, transport!));
}
}
}
diff --git a/tests/JustEat.StatsD.Tests/TimerExtensionsTests.cs b/tests/JustEat.StatsD.Tests/TimerExtensionsTests.cs
index 3bd1952f..be234208 100644
--- a/tests/JustEat.StatsD.Tests/TimerExtensionsTests.cs
+++ b/tests/JustEat.StatsD.Tests/TimerExtensionsTests.cs
@@ -12,11 +12,11 @@ public static class TimerExtensionsTests
public static void StartTimerThrowsIfPublisherIsNull()
{
// Arrange
- IStatsDPublisher publisher = null;
+ IStatsDPublisher? publisher = null;
string bucket = "bucket";
// Act and Assert
- Assert.Throws("publisher", () => publisher.StartTimer(bucket));
+ Assert.Throws("publisher", () => publisher!.StartTimer(bucket));
}
[Fact]
@@ -26,10 +26,10 @@ public static void TimeThrowsIfActionIsNull()
var publisher = Mock.Of();
string bucket = "bucket";
- Action action = null;
+ Action? action = null;
// Act and Assert
- Assert.Throws("action", () => publisher.Time(bucket, action));
+ Assert.Throws("action", () => publisher.Time(bucket, action!));
}
[Fact]
@@ -39,10 +39,10 @@ public static void TimeThrowsIfActionForTimerIsNull()
var publisher = Mock.Of();
string bucket = "bucket";
- Action action = null;
+ Action? action = null;
// Act and Assert
- Assert.Throws("action", () => publisher.Time(bucket, action));
+ Assert.Throws("action", () => publisher.Time(bucket, action!));
}
[Fact]
@@ -52,10 +52,10 @@ public static async Task TimeThrowsIfFuncForTaskIsNull()
var publisher = Mock.Of();
string bucket = "bucket";
- Func action = null;
+ Func? action = null;
// Act and Assert
- await Assert.ThrowsAsync("action", () => publisher.Time(bucket, action));
+ await Assert.ThrowsAsync("action", () => publisher.Time(bucket, action!));
}
[Fact]
@@ -65,10 +65,10 @@ public static async Task TimeThrowsIfFuncForTaskWithTimerIsNull()
var publisher = Mock.Of();
string bucket = "bucket";
- Func action = null;
+ Func? action = null;
// Act and Assert
- await Assert.ThrowsAsync("action", () => publisher.Time(bucket, action));
+ await Assert.ThrowsAsync("action", () => publisher.Time(bucket, action!));
}
[Fact]
@@ -78,10 +78,10 @@ public static void TimeThrowsIfFuncOfTIsNull()
var publisher = Mock.Of();
string bucket = "bucket";
- Func func = null;
+ Func? func = null;
// Act and Assert
- Assert.Throws("func", () => publisher.Time(bucket, func));
+ Assert.Throws("func", () => publisher.Time(bucket, func!));
}
[Fact]
@@ -91,10 +91,10 @@ public static void TimeThrowsIfFuncOfTWithTimerIsNull()
var publisher = Mock.Of();
string bucket = "bucket";
- Func func = null;
+ Func? func = null;
// Act and Assert
- Assert.Throws("func", () => publisher.Time(bucket, func));
+ Assert.Throws("func", () => publisher.Time(bucket, func!));
}
[Fact]
@@ -104,10 +104,10 @@ public static async Task TimeThrowsIfFuncForTaskOfTIsNull()
var publisher = Mock.Of();
string bucket = "bucket";
- Func> func = null;
+ Func>? func = null;
// Act and Assert
- await Assert.ThrowsAsync("func", () => publisher.Time(bucket, func));
+ await Assert.ThrowsAsync("func", () => publisher.Time(bucket, func!));
}
[Fact]
@@ -117,10 +117,10 @@ public static async Task TimeThrowsIfFuncForTaskOfTWithTimerIsNull()
var publisher = Mock.Of();
string bucket = "bucket";
- Func> func = null;
+ Func>? func = null;
// Act and Assert
- await Assert.ThrowsAsync("func", () => publisher.Time(bucket, func));
+ await Assert.ThrowsAsync("func", () => publisher.Time(bucket, func!));
}
[Fact]
diff --git a/tests/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs b/tests/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs
index c35a25b2..b6565665 100644
--- a/tests/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs
+++ b/tests/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs
@@ -26,19 +26,17 @@ public void ConfigurationIsValidWithHostIp()
Host = "10.0.1.2"
};
- using (var stats = new StatsDPublisher(validConfig))
- {
- }
+ using var stats = new StatsDPublisher(validConfig);
}
[Fact]
public void ConfigurationIsNull()
{
- StatsDConfiguration configuration = null;
+ StatsDConfiguration? configuration = null;
Assert.Throws(
"configuration",
- () => new StatsDPublisher(configuration));
+ () => new StatsDPublisher(configuration!));
}
[Fact]
diff --git a/tests/JustEat.StatsD.Tests/WhenRegisteringStatsD.cs b/tests/JustEat.StatsD.Tests/WhenRegisteringStatsD.cs
index 92c5cfe4..4233f5b7 100644
--- a/tests/JustEat.StatsD.Tests/WhenRegisteringStatsD.cs
+++ b/tests/JustEat.StatsD.Tests/WhenRegisteringStatsD.cs
@@ -1,4 +1,3 @@
-#if !NET451
using System;
using JustEat.StatsD.EndpointLookups;
using Microsoft.Extensions.DependencyInjection;
@@ -233,20 +232,20 @@ public static void CanRegisterServicesWithoutFirstConfiguringTheHost()
public static void ParametersAreCheckedForNull()
{
// Arrange
- IServiceCollection services = new ServiceCollection();
- Func configurationFactory = null;
- string host = null;
+ IServiceCollection? services = new ServiceCollection();
+ Func? configurationFactory = null;
+ string? host = null;
// Act and Assert
- Should.Throw(() => services.AddStatsD(configurationFactory)).ParamName.ShouldBe("configurationFactory");
- Should.Throw(() => services.AddStatsD(host)).ParamName.ShouldBe("host");
+ Should.Throw(() => services.AddStatsD(configurationFactory!)).ParamName.ShouldBe("configurationFactory");
+ Should.Throw(() => services.AddStatsD(host!)).ParamName.ShouldBe("host");
// Arrange
services = null;
// Act and Assert
- Should.Throw(() => services.AddStatsD(configurationFactory)).ParamName.ShouldBe("services");
- Should.Throw(() => services.AddStatsD(host)).ParamName.ShouldBe("services");
+ Should.Throw(() => services!.AddStatsD(configurationFactory!)).ParamName.ShouldBe("services");
+ Should.Throw(() => services!.AddStatsD(host!)).ParamName.ShouldBe("services");
}
[Fact]
@@ -317,10 +316,10 @@ public static void CanRegisterServicesWithIPTransport()
public static void AddStatsDThrowsIfServicesIsNull()
{
// Arrange
- IServiceCollection services = null;
+ IServiceCollection? services = null;
// Act and Assert
- Assert.Throws("services", () => services.AddStatsD());
+ Assert.Throws("services", () => services!.AddStatsD());
}
private static IServiceProvider Configure(Action registration)
@@ -334,7 +333,7 @@ private static IServiceProvider Configure(Action registratio
private sealed class MyOptions
{
- public string StatsDHost { get; set; }
+ public string? StatsDHost { get; set; }
}
#pragma warning disable CA1812 // Instantiated via DI
@@ -342,6 +341,7 @@ private sealed class MyTransport : IStatsDTransport
{
#pragma warning disable CA1801 // Used to validate that IEndPointSource is in DI
+#pragma warning disable IDE0060
public MyTransport(IEndPointSource endpointSource)
{
}
@@ -354,4 +354,3 @@ public void Send(in ArraySegment metrics)
#pragma warning restore CA1812
}
}
-#endif
diff --git a/tests/JustEat.StatsD.Tests/WhenTheTransportThrows.cs b/tests/JustEat.StatsD.Tests/WhenTheTransportThrows.cs
index 9f6d1400..e61f8e25 100644
--- a/tests/JustEat.StatsD.Tests/WhenTheTransportThrows.cs
+++ b/tests/JustEat.StatsD.Tests/WhenTheTransportThrows.cs
@@ -111,7 +111,7 @@ public void FalseReturningErrorHandlerThrowsExceptions(string name, Func factory)
{
var validConfig = MakeValidConfig();
- Exception capturedEx = null;
+ Exception? capturedEx = null;
validConfig.OnError = e =>
{
capturedEx = e;
diff --git a/tests/JustEat.StatsD.Tests/WhenUsingUdpTransport.cs b/tests/JustEat.StatsD.Tests/WhenUsingUdpTransport.cs
index 5295bf83..2193344f 100644
--- a/tests/JustEat.StatsD.Tests/WhenUsingUdpTransport.cs
+++ b/tests/JustEat.StatsD.Tests/WhenUsingUdpTransport.cs
@@ -24,11 +24,10 @@ public void AMetricCanBeSentWithoutAnExceptionBeingThrown()
UdpListeners.EndpointA,
null);
- using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp))
- {
- // Act and Assert
- target.Send("mycustommetric");
- }
+ using var target = new SocketTransport(endPointSource, SocketProtocol.Udp);
+
+ // Act and Assert
+ target.Send("mycustommetric");
}
[Fact]
@@ -39,13 +38,12 @@ public void MultipleMetricsCanBeSentWithoutAnExceptionBeingThrownSerial()
UdpListeners.EndpointA,
null);
- using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp))
+ using var target = new SocketTransport(endPointSource, SocketProtocol.Udp);
+
+ for (int i = 0; i < 10_000; i++)
{
- for (int i = 0; i < 10_000; i++)
- {
- // Act and Assert
- target.Send("mycustommetric:1|c");
- }
+ // Act and Assert
+ target.Send("mycustommetric:1|c");
}
}
@@ -57,14 +55,13 @@ public void MultipleMetricsCanBeSentWithoutAnExceptionBeingThrownParallel()
UdpListeners.EndpointA,
null);
- using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp))
- {
- Parallel.For(0, 10_000, _ =>
+ using var target = new SocketTransport(endPointSource, SocketProtocol.Udp);
+
+ Parallel.For(0, 10_000, _ =>
{
// Act and Assert
target.Send("mycustommetric:1|c");
});
- }
}
[Fact]
@@ -79,13 +76,12 @@ public static void EndpointSwitchShouldNotCauseExceptionsSequential()
UdpListeners.EndpointB,
null);
- using (var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp))
+ using var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp);
+
+ for (int i = 0; i < 10_000; i++)
{
- for (int i = 0; i < 10_000; i++)
- {
- // Act and Assert
- target.Send("mycustommetric:1|c");
- }
+ // Act and Assert
+ target.Send("mycustommetric:1|c");
}
}
@@ -101,14 +97,13 @@ public static void EndpointSwitchShouldNotCauseExceptionsParallel()
UdpListeners.EndpointB,
null);
- using (var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp))
- {
- Parallel.For(0, 10_000, _ =>
+ using var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp);
+
+ Parallel.For(0, 10_000, _ =>
{
// Act and Assert
target.Send("mycustommetric");
});
- }
}
private class MillisecondSwitcher : IEndPointSource
diff --git a/version.props b/version.props
index b68a2e4a..d0b5d849 100644
--- a/version.props
+++ b/version.props
@@ -1,8 +1,7 @@
- $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
4.0.0.0
- 4.0.1
+ 4.1.0
$(APPVEYOR_BUILD_NUMBER)