Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made a start on asynchronous code #117

Closed
wants to merge 9 commits into from
1,264 changes: 633 additions & 631 deletions CorrugatedIron.Tests.Live/GeneralIntegrationTests.cs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions CorrugatedIron.Tests.Live/IdleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

using System.Threading.Tasks;
using CorrugatedIron.Comms;
using CorrugatedIron.Tests.Extensions;
using CorrugatedIron.Tests.Live.LiveRiakConnectionTests;
Expand All @@ -32,9 +32,9 @@ public WhenConnectionGoesIdle()

private IRiakConnection GetIdleConnection()
{
var result = Cluster.UseConnection(RiakResult<IRiakConnection>.Success, 1);
//System.Threading.Thread.Sleep(ClusterConfig.RiakNodes[0].IdleTimeout + 1000);
return result.Value;
var task = Cluster.UseConnection<IRiakConnection>(RiakResult<IRiakConnection>.SuccessTask, 1);
task.Wait();
return task.Result.Value;
}

[Test]
Expand Down
3 changes: 3 additions & 0 deletions CorrugatedIron.Tests/RiakAsyncClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace CorrugatedIron.Tests.RiakAsyncClientTests
{

/*
internal abstract class RiakAsyncClientTestBase<TResult>
{
protected Mock<IRiakClient> ClientMock;
Expand Down Expand Up @@ -141,4 +143,5 @@ public void AsyncClientReturnsCorrectResult()
Result.Count().ShouldEqual(0);
}
}
*/
}
21 changes: 14 additions & 7 deletions CorrugatedIron.Tests/RiakClientSetBucketPropertiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CorrugatedIron.Tests.RiakClientSetBucketPropertiesTests
{
Expand All @@ -50,19 +51,24 @@ public IRiakClient CreateClient(string seed)
return new Mock<IRiakClient>().Object;
}

public IRiakAsyncClient CreateAsyncClient()
{
return new Mock<IRiakAsyncClient>().Object;
}

public int RetryWaitTime { get; set; }

public RiakResult<TResult> UseConnection<TResult>(Func<IRiakConnection, RiakResult<TResult>> useFun, int retryAttempts)
public Task<RiakResult<TResult>> UseConnection<TResult>(Func<IRiakConnection, Task<RiakResult<TResult>>> useFun, int retryAttempts)
{
return useFun(ConnectionMock.Object);
}

public RiakResult UseConnection(Func<IRiakConnection, RiakResult> useFun, int retryAttempts)
public Task<RiakResult> UseConnection(Func<IRiakConnection, Task<RiakResult>> useFun, int retryAttempts)
{
return useFun(ConnectionMock.Object);
}

public RiakResult<IEnumerable<TResult>> UseDelayedConnection<TResult>(Func<IRiakConnection, Action, RiakResult<IEnumerable<TResult>>> useFun, int retryAttempts)
public Task<RiakResult<IEnumerable<TResult>>> UseDelayedConnection<TResult>(Func<IRiakConnection, Action, Task<RiakResult<IEnumerable<TResult>>>> useFun, int retryAttempts)
where TResult : RiakResult
{
throw new NotImplementedException();
Expand All @@ -79,7 +85,7 @@ protected RiakClientSetBucketPropertiesTestBase()
{
Cluster = new MockCluster();
ClientId = System.Text.Encoding.Default.GetBytes("fadjskl").Take(4).ToArray();
Client = new RiakClient(Cluster);
Client = new RiakClient(new RiakAsyncClient(Cluster));
}
}

Expand All @@ -91,7 +97,8 @@ public class WhenSettingBucketPropertiesWithExtendedProperties : RiakClientSetBu
public void SetUp()
{
var result = RiakResult<RiakRestResponse>.Success(new RiakRestResponse { StatusCode = System.Net.HttpStatusCode.NoContent });
Cluster.ConnectionMock.Setup(m => m.RestRequest(It.IsAny<RiakRestRequest>())).Returns(result);
Cluster.ConnectionMock.Setup(m => m.RestRequest(It.IsAny<RiakRestRequest>()))
.Returns(Task<RiakResult<RiakRestResponse>>.Factory.StartNew(() => result));

Response = Client.SetBucketProperties("foo", new RiakBucketProperties().SetAllowMultiple(true).SetRVal("one"));
}
Expand All @@ -112,8 +119,8 @@ public class WhenSettingBucketPropertiesWithoutExtendedProperties : RiakClientSe
public void SetUp()
{
var result = RiakResult.Success();
Cluster.ConnectionMock.Setup(m => m.PbcWriteRead(It.IsAny<RpbSetBucketReq>(), MessageCode.SetBucketResp)).Returns(result);

Cluster.ConnectionMock.Setup(m => m.PbcWriteRead(It.IsAny<RpbSetBucketReq>(), MessageCode.SetBucketResp))
.Returns(Task<RiakResult>.Factory.StartNew(() => result));
Response = Client.SetBucketProperties("foo", new RiakBucketProperties().SetAllowMultiple(true));
}

Expand Down
4 changes: 3 additions & 1 deletion CorrugatedIron.Tests/RiakClientTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using CorrugatedIron.Config;
using Moq;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace CorrugatedIron.Tests.RiakClientTests
{
Expand All @@ -40,7 +41,8 @@ protected void SetUpInternal()
ConnFactoryMock = new Mock<IRiakConnectionFactory>();
NodeConfigMock = new Mock<IRiakNodeConfiguration>();

ConnMock.Setup(m => m.PbcWriteRead<TRequest, TResult>(It.IsAny<TRequest>())).Returns(() => Result);
ConnMock.Setup(m => m.PbcWriteRead<TRequest, TResult>(It.IsAny<TRequest>()))
.Returns(() => Task<RiakResult<TResult>>.Factory.StartNew(() => Result));
ConnFactoryMock.Setup(m => m.CreateConnection(It.IsAny<IRiakNodeConfiguration>())).Returns(ConnMock.Object);
NodeConfigMock.SetupGet(m => m.PoolSize).Returns(1);
ClusterConfigMock.SetupGet(m => m.RiakNodes).Returns(new List<IRiakNodeConfiguration> { NodeConfigMock.Object });
Expand Down
5 changes: 3 additions & 2 deletions CorrugatedIron/Comms/IRiakConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
// under the License.

using System;
using System.Threading.Tasks;

namespace CorrugatedIron.Comms
{
internal interface IRiakConnectionManager : IDisposable
{
Tuple<bool, TResult> Consume<TResult>(Func<IRiakConnection, TResult> consumer);
Tuple<bool, TResult> DelayedConsume<TResult>(Func<IRiakConnection, Action, TResult> consumer);
Task<Tuple<bool, TResult>> Consume<TResult>(Func<IRiakConnection, Task<TResult>> consumer);
Task<Tuple<bool, TResult>> DelayedConsume<TResult>(Func<IRiakConnection, Action, Task<TResult>> consumer);
}
}
Loading