Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions BaseSpace.SDK.Tests/BaseSpace.SDK.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<Reference Include="log4net">
<HintPath>$(SolutionDir)\packages\log4net.1.2.10\lib\2.0\log4net.dll</HintPath>
</Reference>
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath>
</Reference>
<Reference Include="ServiceStack.Common, Version=3.9.70.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(SolutionDir)\packages\ServiceStack.Common.3.9.35\lib\net35\ServiceStack.Common.dll</HintPath>
Expand Down
58 changes: 58 additions & 0 deletions BaseSpace.SDK.Tests/JsonWebClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,71 @@
using System;
using System.Diagnostics;
using Illumina.BaseSpace.SDK.Deserialization;
using Illumina.BaseSpace.SDK.ServiceModels;
using Illumina.BaseSpace.SDK.Types;
using Moq;
using Xunit;

namespace Illumina.BaseSpace.SDK.Tests
{

public class JsonWebClientTests
{
[Fact]
public void RequestOptionsAreProperlyUsed()
{
var client = new BaseSpaceClient(new BaseSpaceClientSettings()
{
BaseSpaceApiUrl = "https://api.basespace.illumina.com",
Authentication = new OAuth2Authentication("xxxxx"),
TimeoutMin = .00001
});

var sw = Stopwatch.StartNew();
try
{
var ass = client.GetAppSession(new GetAppSessionRequest("xxxx"), new RequestOptions(6,.1));
}
catch (Exception)
{

}
sw.Stop();

Assert.InRange(sw.ElapsedMilliseconds,0,10*1000);

}


[Fact(Skip = "disabled since it needs token and session")]
public void CanRespawnClientAtEachRetry()
{
var setting = new BaseSpaceClientSettings()
{
BaseSpaceApiUrl = "https://api.cloud-test.illumina.com",
Authentication = new OAuth2Authentication("xxxxx"),
TimeoutMin = .0000000001
};

var client = new Mock<JsonWebClient>(setting, null);
int retry = 0;
client.Setup(c => c.RespawnClient()).Callback(() =>
{
// this should occur only once and because of the ridiculous timeout
Assert.Equal(1, ++retry);

// respawn the client with a normal timeout
// should be proof that the newly created client
// is used on second retry
client.Object._clientFactoryMethod();
client.Object.client.Timeout = TimeSpan.FromMinutes(1);
});

var ass = client.Object.Send(new GetAppSessionRequest("xxxxx"), new RequestOptions(6, .1));
}



[Fact]
public void CanDeserializeARunCompactReference()
{
Expand Down
1 change: 1 addition & 0 deletions BaseSpace.SDK.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<packages>
<package id="Common.Logging" version="2.1.2" targetFramework="net40" />
<package id="log4net" version="1.2.10" targetFramework="net40" />
<package id="Moq" version="4.2.1409.1722" targetFramework="net452" />
<package id="ServiceStack.Common" version="3.9.35" targetFramework="net40" />
<package id="ServiceStack.Text" version="3.9.35" targetFramework="net40" />
<package id="xunit" version="1.9.1" targetFramework="net40" />
Expand Down
7 changes: 4 additions & 3 deletions BaseSpace.SDK/Infrastructure/BaseSpaceClientSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Illumina.BaseSpace.SDK
{
public class BaseSpaceClientSettings : IClientSettings
{
public const uint DEFAULT_RETRY_ATTEMPTS = 6;
{
public const uint DEFAULT_RETRY_ATTEMPTS = 6;
public const uint DEFAULT_RETRY_POWER_BASE = 5;

public const string DEFAULT_WEBSITE = "https://basespace.illumina.com";

Expand Down Expand Up @@ -48,6 +49,6 @@ public BaseSpaceClientSettings()

public IAuthentication Authentication { get; set; }

public int TimeoutMin { get; set; }
public double TimeoutMin { get; set; }
}
}
32 changes: 25 additions & 7 deletions BaseSpace.SDK/Infrastructure/JsonWebClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Runtime.Remoting.Messaging;
using System.Web.Util;
using Common.Logging;
using Illumina.BaseSpace.SDK.Deserialization;
Expand All @@ -15,16 +16,27 @@ namespace Illumina.BaseSpace.SDK
{
public class JsonWebClient : IWebClient
{
private readonly JsonServiceClient client;
private readonly JsonServiceClient clientBilling;
internal JsonServiceClient client;
private JsonServiceClient clientBilling;

private readonly ILog logger;
private ILog logger;

private readonly IClientSettings settings;
private IClientSettings settings;

public virtual void RespawnClient()
{
if (_clientFactoryMethod != null)
_clientFactoryMethod();
}


internal readonly Action _clientFactoryMethod;


public JsonWebClient(IClientSettings settings, IRequestOptions defaultOptions = null)
{
_clientFactoryMethod = () =>
{
if (settings == null)
{
throw new ArgumentNullException("settings");
Expand Down Expand Up @@ -53,6 +65,9 @@ public JsonWebClient(IClientSettings settings, IRequestOptions defaultOptions =

clientBilling = new JsonServiceClient(settings.BaseSpaceBillingApiUrl);
clientBilling.LocalHttpWebRequestFilter += WebRequestFilter;
};

_clientFactoryMethod();
}

static JsonWebClient()
Expand Down Expand Up @@ -108,10 +123,13 @@ public TReturn Send<TReturn>(AbstractRequest<TReturn> request, IRequestOptions o
TReturn result = null;
options = options ?? DefaultRequestOptions;

var clientForRequest = PickClientForApiName(request.GetApiName());

RetryLogic.DoWithRetry(options.RetryAttempts, request.GetName(),
() => result = request.GetSendFunc(clientForRequest)(), logger);
RetryLogic.DoWithRetry(options.RetryAttempts, request.GetName(), () => result = request.GetSendFunc(PickClientForApiName(request.GetApiName()))(), logger,
retryIntervalBaseSecs:options.RetryPowerBase,retryHandler: (exc) =>
{
RespawnClient();
return RetryLogic.GenericRetryHandler(exc);
});
return result;
}
catch (WebServiceException webx)
Expand Down
2 changes: 1 addition & 1 deletion BaseSpace.SDK/Interfaces/IClientSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ public interface IClientSettings

IAuthentication Authentication { get; }

int TimeoutMin { get; }
double TimeoutMin { get; }
}
}
9 changes: 7 additions & 2 deletions BaseSpace.SDK/Interfaces/IRequestOptions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
namespace Illumina.BaseSpace.SDK
{
public interface IRequestOptions
public interface IRetryOptions
{
uint RetryAttempts { get; }
double RetryPowerBase { get; }
}

public interface IRequestOptions: IRetryOptions
{
uint RetryAttempts { get; }
}
}

2 changes: 1 addition & 1 deletion BaseSpace.SDK/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
[assembly: AssemblyVersion("1.0.0.9")]
[assembly: AssemblyFileVersion("1.0.0.9")]
//[assembly: InternalsVisibleTo("Illumina.BaseSpace.SDK.Private")] //Sujit: had to comment this out to allow strong sigining TV for BaseSpaceDownloader
//[assembly: InternalsVisibleTo("Illumina.BaseSpace.SDK.Tests")] //Sujit: had to comment this out to allow strong sigining TV for BaseSpaceDownloader
[assembly: InternalsVisibleTo("Illumina.BaseSpace.SDK.Tests")] //Sujit: had to comment this out to allow strong sigining TV for BaseSpaceDownloader
//[assembly: InternalsVisibleTo("Illumina.BaseSpace.SDK.Private.Tests")]//Sujit: had to comment this out to allow strong sigining TV for BaseSpaceDownloader
7 changes: 5 additions & 2 deletions BaseSpace.SDK/Types/RequestOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
{
public class RequestOptions : IRequestOptions
{
public RequestOptions(uint retryAttempts = BaseSpaceClientSettings.DEFAULT_RETRY_ATTEMPTS)
public RequestOptions(uint retryAttempts = BaseSpaceClientSettings.DEFAULT_RETRY_ATTEMPTS,
double powerbase = BaseSpaceClientSettings.DEFAULT_RETRY_POWER_BASE)
{
RetryAttempts = retryAttempts;
RetryPowerBase = powerbase;
}

public uint RetryAttempts { get; set; }
}
public double RetryPowerBase { get; set; }
}
}