Permalink
Browse files

Merge branch 'release/v0.2.2'

  • Loading branch information...
OJ committed Aug 12, 2012
2 parents 3056e13 + 8a42fd3 commit 976f77c5575a599cf65181ff2ee88098de9ec655
Showing with 1,373 additions and 160 deletions.
  1. +1 −0 .gitignore
  2. +4 −4 CorrugatedIron.Tests.Live/BucketPropertyTests.cs
  3. +7 −9 CorrugatedIron.Tests.Live/CorrugatedIron.Tests.Live.csproj
  4. +2 −2 CorrugatedIron.Tests.Live/GeneralIntegrationTests.cs
  5. +11 −0 CorrugatedIron.Tests.Live/RiakClientTests.cs
  6. +33 −7 CorrugatedIron.Tests.Live/RiakSearchMapReduceInputTests.cs
  7. +95 −0 CorrugatedIron.Tests.Live/SolrTests.cs
  8. +4 −0 CorrugatedIron.Tests.Live/packages.config
  9. +6 −7 CorrugatedIron.Tests/CorrugatedIron.Tests.csproj
  10. +10 −0 CorrugatedIron.Tests/Extensions/UnitTestExtensions.cs
  11. +38 −2 CorrugatedIron.Tests/Json/RiakObjectConversionTests.cs
  12. +199 −0 CorrugatedIron.Tests/Models/SolrTests.cs
  13. +3 −3 CorrugatedIron.Tests/RiakClientTestBase.cs
  14. +2 −2 CorrugatedIron.Tests/RiakClientTests.cs
  15. +13 −6 CorrugatedIron.sln
  16. +12 −2 CorrugatedIron/Comms/RiakPbcSocket.cs
  17. +2 −2 CorrugatedIron/Config/RiakNodeConfiguration.cs
  18. +37 −37 CorrugatedIron/Containers/Either.cs
  19. +24 −9 CorrugatedIron/CorrugatedIron.csproj
  20. +2 −2 CorrugatedIron/Extensions/JsonExtensions.cs
  21. +27 −0 CorrugatedIron/Extensions/StringExtensions.cs
  22. +0 −9 CorrugatedIron/Messages/RpbDelReq.cs
  23. +1 −1 CorrugatedIron/Messages/RpbPutResp.cs
  24. +49 −0 CorrugatedIron/Models/MapReduce/Inputs/RiakBucketSearchInput.cs
  25. +6 −0 CorrugatedIron/Models/MapReduce/RiakMapReduceQuery.cs
  26. +14 −12 CorrugatedIron/Models/RiakBucketProperties.cs
  27. +98 −28 CorrugatedIron/Models/RiakObject.cs
  28. +30 −0 CorrugatedIron/Models/RiakSearch/And.cs
  29. +35 −0 CorrugatedIron/Models/RiakSearch/BaseSearchQuery.cs
  30. +50 −0 CorrugatedIron/Models/RiakSearch/Group.cs
  31. +25 −0 CorrugatedIron/Models/RiakSearch/IRiakSearchQueryPart.cs
  32. +29 −0 CorrugatedIron/Models/RiakSearch/Or.cs
  33. +47 −0 CorrugatedIron/Models/RiakSearch/RiakSearchBinaryLogicTerm.cs
  34. +39 −0 CorrugatedIron/Models/RiakSearch/RiakSearchPhraseToken.cs
  35. +31 −0 CorrugatedIron/Models/RiakSearch/RiakSearchQuery.cs
  36. +34 −0 CorrugatedIron/Models/RiakSearch/RiakSearchRangeToken.cs
  37. +38 −0 CorrugatedIron/Models/RiakSearch/RiakSearchTerm.cs
  38. +70 −0 CorrugatedIron/Models/RiakSearch/RiakSearchToken.cs
  39. +107 −0 CorrugatedIron/Models/RiakSearch/Solr/SolrQuery.cs
  40. +40 −10 CorrugatedIron/RiakClient.cs
  41. +1 −1 CorrugatedIron/Util/RiakConstants.cs
  42. +5 −0 CorrugatedIron/packages.config
  43. +2 −2 Metadata/VersionInfo.cs
  44. +3 −3 NuGet/CorrugatedIron.nuspec
  45. +87 −0 RELEASE_NOTES.md
View
@@ -27,3 +27,4 @@ test-results/*
*.dotCover
*.nupkg
test-results
+packages/*
@@ -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.ShouldBeNull();
- result.Value.RwVal.ShouldBeNull();
- result.Value.DwVal.ShouldBeNull();
- result.Value.WVal.ShouldBeNull();
+ result.Value.RVal.ShouldNotBeNull();
+ result.Value.RwVal.ShouldNotBeNull();
+ result.Value.DwVal.ShouldNotBeNull();
+ result.Value.WVal.ShouldNotBeNull();
}
[Test]
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -10,7 +10,6 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CorrugatedIron.Tests.Live</RootNamespace>
<AssemblyName>CorrugatedIron.Tests.Live</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -37,21 +36,19 @@
<AssemblyOriginatorKeyFile>..\Metadata\CorrugatedIron.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\packages\Newtonsoft.Json.4.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
- <Reference Include="nunit.framework, Version=2.5.9.10348, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\lib\nunit.framework.dll</HintPath>
- </Reference>
<Reference Include="System.Configuration" />
- <Reference Include="Newtonsoft.Json, Version=4.0.2.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\lib\Newtonsoft.Json.dll</HintPath>
+ <Reference Include="nunit.framework">
+ <HintPath>..\lib\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@@ -89,6 +86,7 @@
<None Include="App.config">
<SubType>Designer</SubType>
</None>
+ <None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -348,10 +348,10 @@ private static void DoAllowMultProducesMultipleTest(IRiakBatchClient client)
doc = new RiakObject(MultiBucket, MultiKey, MultiBodyTwo, RiakConstants.ContentTypes.ApplicationJson);
var writeResult2 = client.Put(doc);
writeResult2.IsSuccess.ShouldBeTrue();
- writeResult2.Value.Siblings.Count.ShouldEqual(2);
+ writeResult2.Value.Siblings.Count.ShouldBeGreaterThan(2);
var result = client.Get(MultiBucket, MultiKey);
- result.Value.Siblings.Count.ShouldEqual(2);
+ result.Value.Siblings.Count.ShouldBeGreaterThan(2);
}
[Test]
@@ -16,6 +16,8 @@
using System.Collections;
using System.Collections.Generic;
+using System.Linq;
+using System.Text;
using System.Threading;
using CorrugatedIron.Extensions;
using CorrugatedIron.Models;
@@ -29,6 +31,15 @@ namespace CorrugatedIron.Tests.Live
[TestFixture]
public class RiakClientTests : LiveRiakConnectionTestBase
{
+ [Test]
+ public void WritingLargeObjectIsSuccessful()
+ {
+ var text = Enumerable.Range(0, 2000000).Aggregate(new StringBuilder(), (sb, i) => sb.Append(i.ToString())).ToString();
+ var riakObject = new RiakObject(TestBucket, "large", text, RiakConstants.ContentTypes.TextPlain);
+ var result = Client.Put(riakObject);
+ result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
+ }
+
[Test]
public void DeleteIsSuccessful()
{
@@ -20,6 +20,7 @@
using CorrugatedIron.Models;
using CorrugatedIron.Models.MapReduce;
using CorrugatedIron.Models.MapReduce.Inputs;
+using CorrugatedIron.Models.RiakSearch;
using CorrugatedIron.Tests.Extensions;
using NUnit.Framework;
@@ -70,21 +71,46 @@ public void SearchingByNameReturnsTheObjectId()
Function = "mapred_search",
Arg = new[] {Bucket, "name:Al*"}
};
-
- 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));
+
+ mr.Inputs(modFunArg);
var result = Client.MapReduce(mr);
result.IsSuccess.ShouldBeTrue();
var mrResult = result.Value;
- mrResult.PhaseResults.Count().ShouldEqual(2);
+ mrResult.PhaseResults.Count().ShouldEqual(1);
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.
}
+
+ [Test]
+ public void SearchingByNameUsingRiakSearchObjectReturnsTheObjectid()
+ {
+ 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 rspt = new RiakSearchPhraseToken {Field = "name", Term = "Al*"};
+ var rspt = new RiakSearchPhraseToken("Al*");
+
+ var mfa = new RiakModuleFunctionArgInput
+ {
+ Module = "riak_search",
+ Function = "mapred_search",
+ Arg = new[] {Bucket, rspt.ToString()}
+ };
+
+ mr.Inputs(mfa);
+
+ var result = Client.MapReduce(mr);
+ result.IsSuccess.ShouldBeTrue();
+
+ var mrResult = result.Value;
+ mrResult.PhaseResults.Count().ShouldEqual(1);
+
+ mrResult.PhaseResults.ElementAt(0).Values.ShouldNotBeNull();
+ }
}
}
-
@@ -0,0 +1,95 @@
+// 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("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.
+ }
+ }
+}
+
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+ <package id="Newtonsoft.Json" version="4.0.8" />
+</packages>
@@ -10,7 +10,6 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CorrugatedIron.Tests</RootNamespace>
<AssemblyName>CorrugatedIron.Tests</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -37,6 +36,10 @@
<AssemblyOriginatorKeyFile>..\Metadata\CorrugatedIron.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="Newtonsoft.Json, Version=4.0.8.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\packages\Newtonsoft.Json.4.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
@@ -48,14 +51,9 @@
<Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920">
<HintPath>..\lib\Moq.dll</HintPath>
</Reference>
- <Reference Include="nunit.framework, Version=2.5.9.10348, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
- <SpecificVersion>False</SpecificVersion>
+ <Reference Include="nunit.framework">
<HintPath>..\lib\nunit.framework.dll</HintPath>
</Reference>
- <Reference Include="Newtonsoft.Json, Version=4.0.2.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\lib\Newtonsoft.Json.dll</HintPath>
- </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\Metadata\VersionInfo.cs">
@@ -76,6 +74,7 @@
<Compile Include="Models\RiakObjectTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="KeyFilters\KeyFilterTests.cs" />
+ <Compile Include="Models\SolrTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\Metadata\CorrugatedIron.snk">
@@ -38,6 +38,16 @@ public static void ShouldBe<T>(this object actual)
{
Assert.IsInstanceOf<T>(actual);
}
+
+ public static void ShouldBeGreaterThan(this int actual, int expected)
+ {
+ Assert.GreaterOrEqual(actual, expected);
+ }
+
+ public static void ShouldBeLessThan(this int actual, int expected)
+ {
+ Assert.LessOrEqual(actual, expected);
+ }
public static void ShouldBeFalse(this bool value, string message = null)
{
@@ -22,6 +22,7 @@
using CorrugatedIron.Tests.Extensions;
using CorrugatedIron.Util;
using NUnit.Framework;
+using Newtonsoft.Json;
namespace CorrugatedIron.Tests.Json.RiakObjectConversionTests
{
@@ -70,8 +71,7 @@ public void NonJsonObjectsCantBeDeserialisedFromJson()
}
[Test]
- [Ignore("Only run this if you're interested in some perf stats for Json conversio" +
- "n")]
+ [Ignore("Only run this if you're interested in some perf stats for Json conversion")]
public void JsonConversionTimerTest()
{
var testPerson = new Person
@@ -116,5 +116,41 @@ public void JsonConversionTimerTest()
Console.WriteLine("De" +
"serialisation took a total of {0} - {1} per iteration", sw.Elapsed, new TimeSpan(sw.ElapsedTicks / iterations));
}
+
+ [Test]
+ public void CustomSerializerWillSerializeJson()
+ {
+ var testPerson = new Person
+ {
+ DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
+ Email = "oj@buffered.io",
+ Name = new Name
+ {
+ FirstName = "OJ",
+ Surname = "Reeves"
+ },
+ PhoneNumbers = new List<PhoneNumber>
+ {
+ new PhoneNumber
+ {
+ Number = "12345678",
+ NumberType = PhoneNumberType.Home
+ }
+ }
+ };
+
+ var sots = new SerializeObjectToString<Person>(JsonConvert.SerializeObject);
+
+ var obj = new RiakObject("bucket", "key");
+ obj.SetObject(testPerson, RiakConstants.ContentTypes.ApplicationJson, sots);
+ obj.Value.ShouldNotBeNull();
+ obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);
+
+ var json = obj.Value.FromRiakString();
+ json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"\\/Date(281664000000)\\/\",\"Email\":\"oj@buffered.io\"}");
+
+ var deserialisedPerson = obj.GetObject<Person>();
+ deserialisedPerson.ShouldEqual(testPerson);
+ }
}
}
Oops, something went wrong.

0 comments on commit 976f77c

Please sign in to comment.