Skip to content

Commit

Permalink
TTL Enhancements, PeerURI bugfixes, and dep update
Browse files Browse the repository at this point in the history
* New: `WithTimeToLive` extension methods which support taking
* a`TimeSpan?`
* Fixed: `IClusterEtcdClient.CreateMember()` call will now normalize the
* passed `WithPeerUri` values in order to conform with etcd's expected
* input format (just scheme://address:port/)
* Fixed: `IClusterEtcdClient.UpdateMemberPeerUrls()` call will now
* normalize the passed `WithPeerUri` values in order to conform with
* etcd's expected input format (just scheme://address:port/)
* Change: Updated Flurl dependency from 1.0.8 to 1.0.10
* Change: Updated Flurl.Http dependency from 0.6.2 to 0.7.0
  • Loading branch information
jordansjones committed Mar 24, 2016
1 parent 63f504c commit 48a7a08
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 66 deletions.
7 changes: 7 additions & 0 deletions ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### New in 1.0.1 (Release 2016/03/24)
* New: `WithTimeToLive` extension methods which support taking a`TimeSpan?`
* Fixed: `IClusterEtcdClient.CreateMember()` call will now normalize the passed `WithPeerUri` values in order to conform with etcd's expected input format (just scheme://address:port/)
* Fixed: `IClusterEtcdClient.UpdateMemberPeerUrls()` call will now normalize the passed `WithPeerUri` values in order to conform with etcd's expected input format (just scheme://address:port/)
* Change: Updated Flurl dependency from 1.0.8 to 1.0.10
* Change: Updated Flurl.Http dependency from 0.6.2 to 0.7.0

### New in 1.0.0 (Release 2015/07/03)
* New: `EndpointVerificationStrategy.ClusterMembers` - Similar verification as `EndpointVerificationStrategy.Any` but also adds verified cluster members to the `EndpointPool`.
* New: `IEtcdClient.Statistics`
Expand Down
19 changes: 7 additions & 12 deletions build.csx → build.cake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#tool "xunit.runner.console"

///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -124,25 +126,18 @@ Task("Build")
);
});

Task("InstallUnitTestRunner")
.Does(() =>
{
NuGetInstall("xunit.runner.console", new NuGetInstallSettings {
ExcludeVersion = true,
OutputDirectory = solutionDir.Combine("tools"),
Version = "2.0.0"
});
});

Task("UnitTests")
.IsDependentOn("Build")
.IsDependentOn("InstallUnitTestRunner")
.Does(() =>
{
Information("Running Tests in {0}", solution);

var testAssemblies = GetFiles(testsDir + "/**/bin/" + configuration + "/**/*.Tests*.dll").ToList();

testAssemblies.ForEach(x => Information("Test File: {0}", x.GetFilename()));

XUnit2(
solutionDir + "/**/bin/" + configuration + "/**/*.Tests*.dll",
testAssemblies,
new XUnit2Settings {
OutputDirectory = testResultsDir,
HtmlReport = true,
Expand Down
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Param(
)

$SelfRoot = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$Script = Join-Path $SelfRoot "build.csx"
$Script = Join-Path $SelfRoot "build.cake"

$TOOLS_DIR = Join-Path $SelfRoot "tools"
$CAKE_DIR = Join-Path $TOOLS_DIR "Cake"
Expand Down
2 changes: 1 addition & 1 deletion meta/Draft.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<group targetFramework="net45">
<dependency id="Flurl" version="1.0.8" />
<dependency id="Flurl.Http" version="0.6.2" />
<dependency id="Newtonsoft.Json" version="6.0.8" />
<dependency id="Newtonsoft.Json" version="(6.0.8,)" />
<dependency id="Rx-Core" version="2.2.5" />
<dependency id="Rx-Interfaces" version="2.2.5" />
<dependency id="Rx-Linq" version="2.2.5" />
Expand Down
9 changes: 5 additions & 4 deletions source/Draft/Draft-Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Flurl, Version=1.0.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.1.0.8\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Flurl.dll</HintPath>
<Reference Include="Flurl, Version=1.0.10.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.1.0.10\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Flurl.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Flurl.Http, Version=0.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.0.6.2\lib\net45\Flurl.Http.dll</HintPath>
<Reference Include="Flurl.Http, Version=0.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.0.7.0\lib\net45\Flurl.Http.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand Down Expand Up @@ -118,6 +118,7 @@
<Compile Include="Exceptions\ValueRequiredException.cs" />
<Compile Include="Exceptions\WatcherClearedException.cs" />
<Compile Include="Extensions\FormBodyBuilder.Extensions.cs" />
<Compile Include="Extensions\TimeToLiveExtensions.cs" />
<Compile Include="Extensions\ValueConverter.RequestExtensions.cs" />
<Compile Include="Extensions\ValueConverter.ResponseExtensions.cs" />
<Compile Include="Extensions\VerificationStrategyExtensions.cs" />
Expand Down
70 changes: 70 additions & 0 deletions source/Draft/Extensions/TimeToLiveExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Linq;

using Draft.Requests;

namespace Draft
{
/// <summary>
/// Additional TimeToLive extensions methods for request operations
/// </summary>
public static class TimeToLiveExtensions
{

private static T ApplyTimeToLive<T>(this T This, TimeSpan? timeSpan, Func<T, long, T> func)
{
return timeSpan.HasValue
? func(This, Convert.ToInt64(timeSpan.Value.TotalSeconds))
: This;
}

/// <summary>
/// An optional expiration for this key.
/// </summary>
public static ICompareAndSwapByIndexRequest WithTimeToLive(this ICompareAndSwapByIndexRequest This, TimeSpan? timeSpan)
{
return This.ApplyTimeToLive(timeSpan, (x, y) => x.WithTimeToLive(y));
}

/// <summary>
/// An optional expiration for this key.
/// </summary>
public static ICompareAndSwapByValueRequest WithTimeToLive(this ICompareAndSwapByValueRequest This, TimeSpan? timeSpan)
{
return This.ApplyTimeToLive(timeSpan, (x, y) => x.WithTimeToLive(y));
}

/// <summary>
/// An optional expiration for this key.
/// </summary>
public static ICreateDirectoryRequest WithTimeToLive(this ICreateDirectoryRequest This, TimeSpan? timeSpan)
{
return This.ApplyTimeToLive(timeSpan, (x, y) => x.WithTimeToLive(y));
}

/// <summary>
/// An optional expiration for this key.
/// </summary>
public static IQueueRequest WithTimeToLive(this IQueueRequest This, TimeSpan? timeSpan)
{
return This.ApplyTimeToLive(timeSpan, (x, y) => x.WithTimeToLive(y));
}

/// <summary>
/// An optional expiration for this key.
/// </summary>
public static IUpdateDirectoryRequest WithTimeToLive(this IUpdateDirectoryRequest This, TimeSpan? timeSpan)
{
return This.ApplyTimeToLive(timeSpan, (x, y) => x.WithTimeToLive(y));
}

/// <summary>
/// An optional expiration for this key.
/// </summary>
public static IUpsertKeyRequest WithTimeToLive(this IUpsertKeyRequest This, TimeSpan? timeSpan)
{
return This.ApplyTimeToLive(timeSpan, (x, y) => x.WithTimeToLive(y));
}

}
}
2 changes: 1 addition & 1 deletion source/Draft/Helpers/FormBodyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public FormBodyBuilder Add<TKey, TValue>(TKey key, TValue value)
return this;
}

public IDictionary Build()
public IDictionary<object, object> Build()
{
return _items;
}
Expand Down
7 changes: 5 additions & 2 deletions source/Draft/Requests/Cluster/CreateMemberRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public async Task<IClusterMember> Execute()
{
var values = new FormBodyBuilder()
.Add(Constants.Etcd.Parameter_Name, Name)
.Add(Constants.Etcd.Parameter_PeerURLs, Uris.ToArray())
.Add(Constants.Etcd.Parameter_PeerURLs, Uris.Select(x => x.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped)).ToArray())
.Build();

try
Expand Down Expand Up @@ -57,7 +57,10 @@ public ICreateMemberRequest WithName(string name)

public ICreateMemberRequest WithPeerUri(params Uri[] uris)
{
Uris.AddRange(uris);
if (uris != null && uris.Any())
{
Uris.AddRange(uris);
}
return this;
}

Expand Down
7 changes: 5 additions & 2 deletions source/Draft/Requests/Cluster/UpdateMemberPeerUrlsRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public UpdateMemberPeerUrlsRequest(IEtcdClient etcdClient, EndpointPool endpoint
public async Task<IClusterMember> Execute()
{
var values = new FormBodyBuilder()
.Add(Constants.Etcd.Parameter_PeerURLs, Uris.ToArray())
.Add(Constants.Etcd.Parameter_PeerURLs, Uris.Select(x => x.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped)).ToArray())
.Build();

try
Expand Down Expand Up @@ -57,7 +57,10 @@ public IUpdateMemberPeerUrlsRequest WithMemberId(string memberId)

public IUpdateMemberPeerUrlsRequest WithPeerUri(params Uri[] uris)
{
Uris.AddRange(uris);
if (uris != null && uris.Any())
{
Uris.AddRange(uris);
}
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions source/Draft/packages.Draft-Net45.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Flurl" version="1.0.8" targetFramework="net45" />
<package id="Flurl.Http" version="0.6.2" targetFramework="net45" />
<package id="Flurl" version="1.0.10" targetFramework="net45" />
<package id="Flurl.Http" version="0.7.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="Rx-Core" version="2.2.5" targetFramework="net45" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="net45" />
Expand Down
42 changes: 20 additions & 22 deletions tests/Draft.Tests/Draft-Net45.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -15,7 +14,8 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>97d4e88c</NuGetPackageImportStamp>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -37,28 +37,28 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="FluentAssertions, Version=3.4.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\..\packages\FluentAssertions.3.4.1\lib\net45\FluentAssertions.dll</HintPath>
<Reference Include="FluentAssertions, Version=4.2.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\..\packages\FluentAssertions.4.2.1\lib\net45\FluentAssertions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="FluentAssertions.Core, Version=3.4.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\..\packages\FluentAssertions.3.4.1\lib\net45\FluentAssertions.Core.dll</HintPath>
<Reference Include="FluentAssertions.Core, Version=4.2.1.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\..\packages\FluentAssertions.4.2.1\lib\net45\FluentAssertions.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Flurl, Version=1.0.8.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.1.0.8\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Flurl.dll</HintPath>
<Reference Include="Flurl, Version=1.0.10.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.1.0.10\lib\portable-net40+sl50+win+wpa81+wp80+MonoAndroid10+MonoTouch10\Flurl.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Flurl.Http, Version=0.6.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.0.6.2\lib\net45\Flurl.Http.dll</HintPath>
<Reference Include="Flurl.Http, Version=0.7.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Flurl.Http.0.7.0\lib\net45\Flurl.Http.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Ploeh.AutoFixture, Version=3.30.8.0, Culture=neutral, PublicKeyToken=b24654c590009d4f, processorArchitecture=MSIL">
<HintPath>..\..\packages\AutoFixture.3.30.8\lib\net40\Ploeh.AutoFixture.dll</HintPath>
<Reference Include="Ploeh.AutoFixture, Version=3.38.1.0, Culture=neutral, PublicKeyToken=b24654c590009d4f, processorArchitecture=MSIL">
<HintPath>..\..\packages\AutoFixture.3.38.1\lib\net40\Ploeh.AutoFixture.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -83,12 +83,16 @@
<HintPath>..\..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.assert, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
<Reference Include="xunit.assert, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.assert.2.1.0\lib\dotnet\xunit.assert.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.core, Version=2.0.0.2929, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
<Reference Include="xunit.core, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.core.2.1.0\lib\dotnet\xunit.core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.1.0.3179, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\..\packages\xunit.extensibility.execution.2.1.0\lib\net45\xunit.execution.desktop.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
Expand Down Expand Up @@ -154,12 +158,6 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
17 changes: 15 additions & 2 deletions tests/Draft.Tests/Extensions/FormUrlEncodedExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Flurl;
using Flurl.Http.Content;
using Flurl.Util;

namespace Draft.Tests
{
Expand All @@ -14,9 +18,18 @@ public static string AsRequestBody(this FormBodyBuilder This)
return This.Build().AsRequestBody();
}

public static string AsRequestBody(this IDictionary This)
public static string AsRequestBody(this IEnumerable<KeyValuePair<object, object>> This)
{
return new CapturedUrlEncodedContent(This).Content;
return new CapturedUrlEncodedContent(AsUrlEncodedContent(This)).Content;
}

private static string AsUrlEncodedContent(IEnumerable<KeyValuePair<object, object>> collection)
{
var kvItems = (collection ?? Enumerable.Empty<KeyValuePair<object, object>>())
.Where(x => x.Value != null)
.Select(kv => string.Join("=", Url.EncodeQueryParamValue(kv.Key.ToInvariantString(), true), Url.EncodeQueryParamValue(kv.Value, true)));

return string.Join("&", kvItems);
}

}
Expand Down
10 changes: 8 additions & 2 deletions tests/Draft.Tests/Fixtures/Fixtures.Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static partial class Fixtures
public static class Key
{

public const int DefaultTtl = 300;
public const long DefaultTtl = 300;

public const string DefaultValue = "{DBAEDC45-175B-4310-8387-4F02F988253F}";

Expand All @@ -34,13 +34,19 @@ public static string ExistingRequest(string value = DefaultValue, bool existing
.AsRequestBody();
}

public static string TtlRequest(string value = DefaultValue, int ttl = DefaultTtl)
public static string TtlRequest(string value = DefaultValue, long ttl = DefaultTtl)
{
return WithValue(value)
.Add(Constants.Etcd.Parameter_Ttl, ttl)
.AsRequestBody();
}

public static string TtlTimeSpanRequest(string value = DefaultValue, TimeSpan? ttl = null)
{
var ttlValue = ttl ?? TimeSpan.FromSeconds(DefaultTtl);
return TtlRequest(value, Convert.ToInt64(ttlValue.TotalSeconds));
}

public static object UpsertResponse(string keyPath, string value, string previousValue = null)
{
var hasPreviousValue = !string.IsNullOrWhiteSpace(previousValue);
Expand Down
Loading

0 comments on commit 48a7a08

Please sign in to comment.