Permalink
Browse files

* Adding changes to unit tests.

* Removed SolrTests
* Updated JsonExtensions with Either<TLeft, TRight> support.
  • Loading branch information...
1 parent b33b339 commit 6c57a81536ab245e35f9c40c502773ad570486d8 @peschkaj peschkaj committed Feb 26, 2012
@@ -59,10 +59,10 @@ public void GettingWithoutExtendedFlagDoesNotReturnExtraProperties()
result.Value.AllowMultiple.HasValue.ShouldBeTrue();
result.Value.NVal.HasValue.ShouldBeTrue();
result.Value.LastWriteWins.HasValue.ShouldBeFalse();
- result.Value.RVal.HasValue.ShouldBeFalse();
- result.Value.RwVal.HasValue.ShouldBeFalse();
- result.Value.DwVal.HasValue.ShouldBeFalse();
- result.Value.WVal.HasValue.ShouldBeFalse();
+ result.Value.RVal.ShouldNotBeNull();
+ result.Value.RwVal.ShouldNotBeNull();
+ result.Value.DwVal.ShouldNotBeNull();
+ result.Value.WVal.ShouldNotBeNull();
}
[Test]
@@ -73,10 +73,10 @@ public void GettingWithExtendedFlagReturnsExtraProperties()
result.Value.AllowMultiple.HasValue.ShouldBeTrue();
result.Value.NVal.HasValue.ShouldBeTrue();
result.Value.LastWriteWins.HasValue.ShouldBeTrue();
- result.Value.RVal.HasValue.ShouldBeTrue();
- result.Value.RwVal.HasValue.ShouldBeTrue();
- result.Value.DwVal.HasValue.ShouldBeTrue();
- result.Value.WVal.HasValue.ShouldBeTrue();
+ result.Value.RVal.ShouldNotBeNull();
+ result.Value.RwVal.ShouldNotBeNull();
+ result.Value.DwVal.ShouldNotBeNull();
+ result.Value.WVal.ShouldNotBeNull();
}
[Test]
@@ -1,95 +0,0 @@
-// Copyright (c) 2010 - OJ Reeves & Jeremiah Peschka
-//
-// This file is provided to you under the Apache License,
-// Version 2.0 (the "License"); you may not use this file
-// except in compliance with the License. You may obtain
-// a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-
-using System.Linq;
-using CorrugatedIron.Comms;
-using CorrugatedIron.Models.RiakSearch;
-using CorrugatedIron.Models.RiakSearch.Solr;
-using CorrugatedIron.Util;
-using CorrugatedIron.Models;
-using CorrugatedIron.Models.MapReduce;
-using CorrugatedIron.Models.MapReduce.Inputs;
-using CorrugatedIron.Tests.Extensions;
-using NUnit.Framework;
-
-namespace CorrugatedIron.Tests.Live
-{
- [TestFixture]
- public class SolrTests : RiakMapReduceTests
- {
- // N.B. You need to install the search hooks on the riak_search_bucket first via `bin/search-cmd install riak_search_bucket`
- private const string RiakSearchKey = "a.hacker";
- private const string RiakSearchKey2 = "a.public";
- private const string RiakSearchDoc = "{\"name\":\"Alyssa P. Hacker\", \"bio\":\"I'm an engineer, making awesome things.\", \"favorites\":{\"book\":\"The Moon is a Harsh Mistress\",\"album\":\"Magical Mystery Tour\", }}";
- private const string RiakSearchDoc2 = "{\"name\":\"Alan Q. Public\", \"bio\":\"I'm an exciting mathematician\", \"favorites\":{\"book\":\"Prelude to Mathematics\",\"album\":\"The Fame Monster\"}}";
-
- public SolrTests ()
- {
- Bucket = "riak_search_bucket";
- }
-
- [SetUp]
- public void SetUp()
- {
- Cluster = new RiakCluster(ClusterConfig, new RiakConnectionFactory());
- Client = Cluster.CreateClient();
-
- var props = Client.GetBucketProperties(Bucket, true).Value;
- props.SetSearch(true);
- Client.SetBucketProperties(Bucket, props);
- }
-
- [TearDown]
- public void TearDown()
- {
- Client.DeleteBucket(Bucket);
- }
-
- [Test]
- public void SearchingByNameReturnsTheObjectId()
- {
- Client.Put(new RiakObject(Bucket, RiakSearchKey, RiakSearchDoc, RiakConstants.ContentTypes.ApplicationJson));
- Client.Put(new RiakObject(Bucket, RiakSearchKey2, RiakSearchDoc2, RiakConstants.ContentTypes.ApplicationJson));
-
- var mr = new RiakMapReduceQuery();
-
- var token = new RiakSearchPhraseToken {Term = "Al*"};
- var solr = new SolrQuery { Fieldname = "name", QueryPart = token };
-
- var modFunArg = new RiakModuleFunctionArgInput
- {
- Module = "riak_search",
- Function = "mapred_search",
- Arg = new[] {Bucket, solr.ToString()}
- };
-
- mr.Inputs(modFunArg)
- .MapJs(m => m.Source(@"function(value, keydata, arg) { return [value]; }").Keep(true))
- .ReduceJs(r => r.Source(@"function(values, arg) { return values; }").Keep(true));
-
- var result = Client.MapReduce(mr);
- result.IsSuccess.ShouldBeTrue();
-
- var mrResult = result.Value;
- mrResult.PhaseResults.Count().ShouldEqual(2);
-
- mrResult.PhaseResults.ElementAt(0).Values.ShouldNotBeNull();
- mrResult.PhaseResults.ElementAt(1).Values.ShouldNotBeNull();
- // TODO Add data introspection to test - need to verify the results, after all.
- }
- }
-}
-
@@ -88,7 +88,7 @@ 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);
- Response = Client.SetBucketProperties("foo", new RiakBucketProperties().SetAllowMultiple(true).SetRVal(RiakConstants.QuorumOptions.One));
+ Response = Client.SetBucketProperties("foo", new RiakBucketProperties().SetAllowMultiple(true).SetRVal("one"));
}
[Test]
@@ -71,6 +71,7 @@
<Compile Include="Containers\ConcurrentEnumerable.cs" />
<Compile Include="Containers\ConcurrentEnumerator.cs" />
<Compile Include="Comms\RiakConnectionPool.cs" />
+ <Compile Include="Containers\Either.cs" />
<Compile Include="Exceptions\RiakInvalidDataException.cs" />
<Compile Include="Exceptions\RiakException.cs" />
<Compile Include="IRiakBatchClient.cs" />
@@ -48,6 +48,22 @@ public static JsonWriter WriteNonNullProperty<T>(this JsonWriter writer, string
return writer;
}
+ public static JsonWriter WriteEither<TLeft, TRight>(this JsonWriter writer, string name, Either<TLeft, TRight> either)
+ {
+ if (either != null)
+ {
+ if (either.IsLeft)
+ {
+ writer.WriteProperty(name, either.Left);
+ }
+ else
+ {
+ writer.WriteProperty(name, either.Right);
+ }
+ }
+ return writer;
+ }
+
public static JsonWriter WriteNullableProperty<T>(this JsonWriter writer, string name, T? value)
where T : struct
{
@@ -19,6 +19,7 @@
using System.IO;
using System.Linq;
using System.Text;
+using CorrugatedIron.Containers;
using CorrugatedIron.Extensions;
using CorrugatedIron.Messages;
using CorrugatedIron.Models.CommitHook;
@@ -66,37 +67,37 @@ public bool CanUsePbc
/// <value>
/// The R value. Possible values include 'default', 'one', 'quorum', 'all', or any integer.
/// </value>
- public uint? RVal { get; private set; }
+ public Either<uint, string> RVal { get; private set; }
/// <summary>
/// The number of replicas that must return before a delete is considered a success.
/// </summary>
/// <value>The RW Value. Possible values include 'default', 'one', 'quorum', 'all', or any integer.</value>
- public uint? RwVal { get; private set; }
+ public Either<uint, string> RwVal { get; private set; }
/// <summary>
/// The number of replicas that must commit to durable storage and respond before a write is considered a success.
/// </summary>
/// <value>The DW value. Possible values include 'default', 'one', 'quorum', 'all', or any integer.</value>
- public uint? DwVal { get; private set; }
+ public Either<uint, string> DwVal { get; private set; }
/// <summary>
/// The number of replicas that must respond before a write is considered a success.
/// </summary>
/// <value>The W value. Possible values include 'default', 'one', 'quorum', 'all', or any integer.</value>
- public uint? WVal { get; private set; }
+ public Either<uint, string> WVal { get; private set; }
/// <summary>
/// The number of primary replicas that must respond before a read is considered a success.
/// </summary>
/// <value>The PR value. Possible values include 'default', 'one', 'quorum', 'all', or any integer.</value>
- public uint? PrVal { get; private set; }
+ public Either<uint, string> PrVal { get; private set; }
/// <summary>
/// The number of primary replicas that must respond before a write is considered a success.
/// </summary>
/// <value>The PW value. Possible values include 'default', 'one', 'quorum', 'all', or any integer.</value>
- public uint? PwVal { get; private set; }
+ public Either<uint, string> PwVal { get; private set; }
public RiakBucketProperties SetBasicQuorum(bool value)
{
@@ -128,31 +129,61 @@ public RiakBucketProperties SetNVal(uint value)
return this;
}
+ public RiakBucketProperties SetRVal(string value)
+ {
+ return WriteQuorum(value, v => RVal = v);
+ }
+
public RiakBucketProperties SetRVal(uint value)
{
return WriteQuorum(value, v => RVal = v);
}
+ public RiakBucketProperties SetRwVal(string value)
+ {
+ return WriteQuorum(value, v => RwVal = v);
+ }
+
public RiakBucketProperties SetRwVal(uint value)
{
return WriteQuorum(value, v => RwVal = v);
}
+ public RiakBucketProperties SetDwVal(string value)
+ {
+ return WriteQuorum(value, v => DwVal = v);
+ }
+
public RiakBucketProperties SetDwVal(uint value)
{
return WriteQuorum(value, v => DwVal = v);
}
+ public RiakBucketProperties SetWVal(string value)
+ {
+ return WriteQuorum(value, v => WVal = v);
+ }
+
public RiakBucketProperties SetWVal(uint value)
{
return WriteQuorum(value, v => WVal = v);
}
+ public RiakBucketProperties SetPrVal(string value)
+ {
+ return WriteQuorum(value, v => PrVal = v);
+ }
+
public RiakBucketProperties SetPrVal(uint value)
{
return WriteQuorum(value, v => PrVal = v);
}
+ public RiakBucketProperties SetPwVal(string value)
+ {
+ return WriteQuorum(value, var => PwVal = var);
+ }
+
public RiakBucketProperties SetPwVal(uint value)
{
return WriteQuorum(value, var => PwVal = var);
@@ -194,9 +225,19 @@ public RiakBucketProperties ClearPostCommitHooks()
return this;
}
- private RiakBucketProperties WriteQuorum(uint value, Action<uint?> setter)
+ private RiakBucketProperties WriteQuorum(string value, Action<Either<uint, string>> setter)
{
- setter(value);
+ System.Diagnostics.Debug.Assert(new HashSet<string> { "all", "quorum", "one" }.Contains(value), "Incorrect quorum value");
+
+ setter(new Either<uint, string>(value));
+ return this;
+ }
+
+ private RiakBucketProperties WriteQuorum(uint value, Action<Either<uint, string>> setter)
+ {
+ System.Diagnostics.Debug.Assert(value >= 1);
+
+ setter(new Either<uint, string>(value));
return this;
}
@@ -257,9 +298,16 @@ private static IRiakPostCommitHook LoadPostCommitHook(JObject hook)
return new RiakErlangCommitHook(hook.Value<string>("mod"), hook.Value<string>("fun"));
}
- private static void ReadQuorum(JObject props, string key, Action<uint?> setter)
+ private static void ReadQuorum(JObject props, string key, Action<Either<uint, string>> setter)
{
- setter(props.Value<uint>(key));
+ if(props[key].Type == JTokenType.String)
+ {
+ setter(new Either<uint, string>(props.Value<string>(key)));
+ }
+ else
+ {
+ setter(new Either<uint, string>(props.Value<uint>(key)));
+ }
}
internal RiakBucketProperties(RpbBucketProps bucketProps)
@@ -296,12 +344,12 @@ internal string ToJsonString()
jw.WriteNullableProperty("n_val", NVal)
.WriteNullableProperty("allow_mult", AllowMultiple)
.WriteNullableProperty("last_write_wins", LastWriteWins)
- .WriteNullableProperty("r", RVal)
- .WriteNullableProperty("rw", RwVal)
- .WriteNullableProperty("dw", DwVal)
- .WriteNullableProperty("w", WVal)
- .WriteNullableProperty("pr", PrVal)
- .WriteNullableProperty("pw", PwVal)
+ .WriteEither("r", RVal)
+ .WriteEither("rw", RwVal)
+ .WriteEither("dw", DwVal)
+ .WriteEither("w", WVal)
+ .WriteEither("pr", PrVal)
+ .WriteEither("pw", PwVal)
.WriteNonNullProperty("backend", Backend)
.WriteNullableProperty("search", Search)
.WriteNullableProperty("notfound_ok", NotFoundOk)

0 comments on commit 6c57a81

Please sign in to comment.