/// <summary> /// Compress all operations in a RiakDtCounter into a single DtUpdateReq /// </summary> /// <param name="options">The RiakDtUpdateOptions</param> /// <returns>Returns a valid DtUpdateReq or null.</returns> /// <remarks>A null value will be returned when the net of all counter /// operations will produce no change to the counter value. That is: /// when the sum of all operations is 0, null will be returned. In these /// situations, the caller should not submit any changes to Riak. </remarks> internal DtUpdateReq ToDtUpdateRequest(RiakDtUpdateOptions options) { options = options ?? new RiakDtUpdateOptions(); var request = new DtUpdateReq { op = { counter_op = ToCounterOp() } }; /* We shouldn't send any operations in to Riak in this case. * This means that whatever calls ToDtUpdateRequest needs to * be aware of possible null values */ if (request.op.counter_op == null || request.op.counter_op.increment == 0) { return(null); } if (options.IncludeContext && context != null) { request.context = context; } options.Populate(request); return(request); }
public void TestFlagOperations() { string key = GetRandomKey(); var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key); const string flagName = "Name"; byte[] flagNameBytes = Serializer(flagName); var options = new RiakDtUpdateOptions(); options.SetIncludeContext(true); options.SetTimeout(new Timeout(TimeSpan.FromSeconds(60))); var flagMapUpdate = new MapUpdate { flag_op = MapUpdate.FlagOp.ENABLE, field = new MapField { name = flagNameBytes, type = MapField.MapFieldType.FLAG } }; var update = new List<MapUpdate> { flagMapUpdate }; var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, update, options); Assert.True(updatedMap1.Result.IsSuccess, updatedMap1.Result.ErrorMessage); var mapEntry = updatedMap1.Values.Single(s => s.Field.Name == flagName); Assert.NotNull(mapEntry.FlagValue); Assert.IsTrue(mapEntry.FlagValue.Value); flagMapUpdate.flag_op = MapUpdate.FlagOp.DISABLE; var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null, update, options); Assert.True(updatedMap2.Result.IsSuccess, updatedMap2.Result.ErrorMessage); mapEntry = updatedMap2.Values.Single(s => s.Field.Name == flagName); Assert.NotNull(mapEntry.FlagValue); Assert.IsFalse(mapEntry.FlagValue.Value); }
public void TestFlagOperations() { string key = GetRandomKey(); var id = new RiakObjectId(BucketTypeNames.Maps, Bucket, key); const string flagName = "Name"; byte[] flagNameBytes = Serializer(flagName); var options = new RiakDtUpdateOptions(); options.SetIncludeContext(true); options.SetTimeout(new Timeout(TimeSpan.FromSeconds(60))); var flagMapUpdate = new MapUpdate { flag_op = MapUpdate.FlagOp.ENABLE, field = new MapField { name = flagNameBytes, type = MapField.MapFieldType.FLAG } }; var update = new List <MapUpdate> { flagMapUpdate }; var updatedMap1 = Client.DtUpdateMap(id, Serializer, null, null, update, options); Assert.True(updatedMap1.Result.IsSuccess, updatedMap1.Result.ErrorMessage); var mapEntry = updatedMap1.Values.Single(s => s.Field.Name == flagName); Assert.NotNull(mapEntry.FlagValue); Assert.IsTrue(mapEntry.FlagValue.Value); flagMapUpdate.flag_op = MapUpdate.FlagOp.DISABLE; var updatedMap2 = Client.DtUpdateMap(id, Serializer, updatedMap1.Context, null, update, options); Assert.True(updatedMap2.Result.IsSuccess, updatedMap2.Result.ErrorMessage); mapEntry = updatedMap2.Values.Single(s => s.Field.Name == flagName); Assert.NotNull(mapEntry.FlagValue); Assert.IsFalse(mapEntry.FlagValue.Value); }