public void SearchForSetsContainingFootballString() { var cmd = new UpdateSet.Builder() .WithBucketType("sets") .WithBucket("people") .WithKey("ditka") .WithAdditions(new HashSet <string> { "football", "winning" }) .Build(); RiakResult rslt = client.Execute(cmd); CheckResult(rslt); cmd = new UpdateSet.Builder() .WithBucketType("sets") .WithBucket("people") .WithKey("dio") .WithAdditions(new HashSet <string> { "wailing", "rocking", "winning" }) .Build(); rslt = client.Execute(cmd); CheckResult(rslt); WaitForSearch(); DoSearch("hobbies", "set:football"); }
private SetResponse SaveSet(string key = null) { var updateBuilder = new UpdateSet.Builder(DefaultAdds, null) .WithBucketType(BucketType) .WithBucket(Bucket) .WithTimeout(TimeSpan.FromMilliseconds(20000)); if (!string.IsNullOrEmpty(key)) { updateBuilder.WithKey(key); } UpdateSet cmd = updateBuilder.Build(); RiakResult rslt = client.Execute(cmd); Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage); SetResponse response = cmd.Response; Keys.Add(response.Key); Assert.True(EnumerableUtil.NotNullOrEmpty(response.Context)); return(response); }
public void Can_Update_A_Set() { string key = Guid.NewGuid().ToString(); SetResponse resp = SaveSet(key); var add_3 = new RiakString("add_3"); var adds = new HashSet <string> { add_3 }; var add_1 = new RiakString("add_1"); var removes = new HashSet <string> { add_1 }; var update = new UpdateSet.Builder(adds, removes) .WithBucketType(BucketType) .WithBucket(Bucket) .WithKey(key) .WithContext(resp.Context) .WithReturnBody(true) .WithTimeout(TimeSpan.FromMilliseconds(20000)) .Build(); RiakResult rslt = client.Execute(update); Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage); SetResponse response = update.Response; bool found_add_1 = false; bool found_add_3 = false; foreach (RiakString value in response.Value) { if (value.Equals(add_1)) { found_add_1 = true; } if (value.Equals(add_3)) { found_add_3 = true; } } Assert.True(found_add_3); Assert.False(found_add_1); }
public void Should_Build_DtUpdateReq_Correctly() { var updateSetCommandBuilder = new UpdateSet.Builder(DefaultAdds, DefaultRemoves); var q1 = new Quorum(1); var q2 = new Quorum(2); var q3 = new Quorum(3); updateSetCommandBuilder .WithBucketType(BucketType) .WithBucket(Bucket) .WithKey(Key) .WithW(q3) .WithPW(q1) .WithDW(q2) .WithReturnBody(true) .WithIncludeContext(false) .WithContext(Context) .WithTimeout(TimeSpan.FromSeconds(20)); UpdateSet updateSetCommand = updateSetCommandBuilder.Build(); DtUpdateReq protobuf = (DtUpdateReq)updateSetCommand.ConstructRequest(false); Assert.AreEqual(Encoding.UTF8.GetBytes(BucketType), protobuf.type); Assert.AreEqual(Encoding.UTF8.GetBytes(Bucket), protobuf.bucket); Assert.AreEqual(Encoding.UTF8.GetBytes(Key), protobuf.key); Assert.AreEqual((uint)q3, protobuf.w); Assert.AreEqual((uint)q1, protobuf.pw); Assert.AreEqual((uint)q2, protobuf.dw); Assert.IsTrue(protobuf.return_body); Assert.IsFalse(protobuf.include_context); Assert.AreEqual(20000, protobuf.timeout); SetOp setOpMsg = protobuf.op.set_op; Assert.AreEqual(DefaultAdds, setOpMsg.adds); Assert.AreEqual(DefaultRemoves, setOpMsg.removes); }
public void Should_Build_DtUpdateReq_Correctly() { var updateSetCommandBuilder = new UpdateSet.Builder(DefaultAdds, DefaultRemoves); var q1 = new Quorum(1); var q2 = new Quorum(2); var q3 = new Quorum(3); updateSetCommandBuilder .WithBucketType(BucketType) .WithBucket(Bucket) .WithKey(Key) .WithW(q3) .WithPW(q1) .WithDW(q2) .WithReturnBody(true) .WithIncludeContext(false) .WithContext(Context) .WithTimeout(TimeSpan.FromSeconds(20)); UpdateSet updateSetCommand = updateSetCommandBuilder.Build(); DtUpdateReq protobuf = (DtUpdateReq)updateSetCommand.ConstructPbRequest(); Assert.AreEqual(Encoding.UTF8.GetBytes(BucketType), protobuf.type); Assert.AreEqual(Encoding.UTF8.GetBytes(Bucket), protobuf.bucket); Assert.AreEqual(Encoding.UTF8.GetBytes(Key), protobuf.key); Assert.AreEqual(q3, protobuf.w); Assert.AreEqual(q1, protobuf.pw); Assert.AreEqual(q2, protobuf.dw); Assert.IsTrue(protobuf.return_body); Assert.IsFalse(protobuf.include_context); Assert.AreEqual(20000, protobuf.timeout); SetOp setOpMsg = protobuf.op.set_op; Assert.AreEqual(DefaultAdds, setOpMsg.adds); Assert.AreEqual(DefaultRemoves, setOpMsg.removes); }
public void Should_Construct_SetResponse_From_DtUpdateResp() { var key = new RiakString("riak_generated_key"); var updateResp = new DtUpdateResp(); updateResp.key = key; updateResp.context = Context; updateResp.set_value.AddRange(DefaultAdds); var update = new UpdateSet.Builder(DefaultAdds, null) .WithBucketType(BucketType) .WithBucket(Bucket) .Build(); update.OnSuccess(updateResp); SetResponse response = update.Response; Assert.NotNull(response); Assert.AreEqual(key, response.Key); Assert.AreEqual(Context, response.Context); Assert.AreEqual(DefaultAdds, response.Value); }
public void SearchForSetsContainingFootballString() { var cmd = new UpdateSet.Builder() .WithBucketType("sets") .WithBucket("people") .WithKey("ditka") .WithAdditions(new HashSet<string> { "football", "winning" }) .Build(); RiakResult rslt = client.Execute(cmd); CheckResult(rslt); cmd = new UpdateSet.Builder() .WithBucketType("sets") .WithBucket("people") .WithKey("dio") .WithAdditions(new HashSet<string> { "wailing", "rocking", "winning" }) .Build(); rslt = client.Execute(cmd); CheckResult(rslt); WaitForSearch(); DoSearch("hobbies", "set:football"); }
public void Can_Update_A_Set() { string key = Guid.NewGuid().ToString(); SetResponse resp = SaveSet(key); var add_3 = new RiakString("add_3"); var adds = new HashSet<string> { add_3 }; var add_1 = new RiakString("add_1"); var removes = new HashSet<string> { add_1 }; var update = new UpdateSet.Builder(adds, removes) .WithBucketType(BucketType) .WithBucket(Bucket) .WithKey(key) .WithContext(resp.Context) .WithReturnBody(true) .WithTimeout(TimeSpan.FromMilliseconds(20000)) .Build(); RiakResult rslt = client.Execute(update); Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage); SetResponse response = update.Response; bool found_add_1 = false; bool found_add_3 = false; foreach (RiakString value in response.Value) { if (value.Equals(add_1)) { found_add_1 = true; } if (value.Equals(add_3)) { found_add_3 = true; } } Assert.True(found_add_3); Assert.False(found_add_1); }
private SetResponse SaveSet(string key = null) { var updateBuilder = new UpdateSet.Builder(DefaultAdds, null) .WithBucketType(BucketType) .WithBucket(Bucket) .WithTimeout(TimeSpan.FromMilliseconds(20000)); if (!string.IsNullOrEmpty(key)) { updateBuilder.WithKey(key); } UpdateSet cmd = updateBuilder.Build(); RiakResult rslt = client.Execute(cmd); Assert.IsTrue(rslt.IsSuccess, rslt.ErrorMessage); SetResponse response = cmd.Response; Keys.Add(response.Key); Assert.True(EnumerableUtil.NotNullOrEmpty(response.Context)); return response; }
public void CitiesSetAddRemoveAndView() { var adds = new HashSet <string> { "Toronto", "Montreal" }; var builder = new UpdateSet.Builder() .WithBucketType("sets") .WithBucket("travel") .WithKey("cities") .WithAdditions(adds); UpdateSet cmd = builder.Build(); RiakResult rslt = client.Execute(cmd); CheckResult(rslt); SetResponse response = cmd.Response; Assert.Contains("Toronto", response.AsStrings.ToArray()); Assert.Contains("Montreal", response.AsStrings.ToArray()); var removes = new HashSet <string> { "Montreal" }; adds = new HashSet <string> { "Hamilton", "Ottawa" }; Assert.True(EnumerableUtil.NotNullOrEmpty(response.Context)); builder .WithAdditions(adds) .WithRemovals(removes) .WithContext(response.Context); cmd = builder.Build(); rslt = client.Execute(cmd); CheckResult(rslt); response = cmd.Response; var responseStrings = response.AsStrings.ToArray(); Assert.Contains("Toronto", responseStrings); Assert.Contains("Hamilton", responseStrings); Assert.Contains("Ottawa", responseStrings); foreach (var value in response.AsStrings) { Console.WriteLine("Cities Set Value: {0}", value); } Console.WriteLine("Cities Set Size: {0}", responseStrings.Length); bool includesVancouver = response.AsStrings.Any(v => v == "Vancouver"); bool includesOttawa = response.AsStrings.Any(v => v == "Ottawa"); Assert.False(includesVancouver); Assert.True(includesOttawa); }
public void CitiesSetAddRemoveAndView() { var adds = new HashSet<string> { "Toronto", "Montreal" }; var builder = new UpdateSet.Builder() .WithBucketType("sets") .WithBucket("travel") .WithKey("cities") .WithAdditions(adds); UpdateSet cmd = builder.Build(); RiakResult rslt = client.Execute(cmd); CheckResult(rslt); SetResponse response = cmd.Response; Assert.Contains("Toronto", response.AsStrings.ToArray()); Assert.Contains("Montreal", response.AsStrings.ToArray()); var removes = new HashSet<string> { "Montreal" }; adds = new HashSet<string> { "Hamilton", "Ottawa" }; Assert.True(EnumerableUtil.NotNullOrEmpty(response.Context)); builder .WithAdditions(adds) .WithRemovals(removes) .WithContext(response.Context); cmd = builder.Build(); rslt = client.Execute(cmd); CheckResult(rslt); response = cmd.Response; var responseStrings = response.AsStrings.ToArray(); Assert.Contains("Toronto", responseStrings); Assert.Contains("Hamilton", responseStrings); Assert.Contains("Ottawa", responseStrings); foreach (var value in response.AsStrings) { Console.WriteLine("Cities Set Value: {0}", value); } Console.WriteLine("Cities Set Size: {0}", responseStrings.Length); bool includesVancouver = response.AsStrings.Any(v => v == "Vancouver"); bool includesOttawa = response.AsStrings.Any(v => v == "Ottawa"); Assert.False(includesVancouver); Assert.True(includesOttawa); }