From 36ed10ad28eb19aa796697922a708740b099aa22 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Mon, 5 Jun 2023 17:57:37 -0700 Subject: [PATCH 1/5] feat: Add ListLength to list modification apis --- src/Momento.Sdk/Internal/ScsDataClient.cs | 7 +- .../Responses/CacheListFetchResponse.cs | 9 +- .../Responses/CacheListPopBackResponse.cs | 8 +- .../Responses/CacheListPopFrontResponse.cs | 8 +- .../Responses/CacheListRemoveValueResponse.cs | 22 ++++- .../Responses/CacheListRetainResponse.cs | 22 ++++- .../Integration/Momento.Sdk.Tests/ListTest.cs | 89 +++++++++++++++++-- 7 files changed, 149 insertions(+), 16 deletions(-) diff --git a/src/Momento.Sdk/Internal/ScsDataClient.cs b/src/Momento.Sdk/Internal/ScsDataClient.cs index fce1274e..d691cf60 100644 --- a/src/Momento.Sdk/Internal/ScsDataClient.cs +++ b/src/Momento.Sdk/Internal/ScsDataClient.cs @@ -1169,7 +1169,7 @@ private async Task SendListRetainAsync(string cacheName return this._logger.LogTraceCollectionRequestError(REQUEST_TYPE_LIST_RETAIN, cacheName, listName, new CacheListRetainResponse.Error(_exceptionMapper.Convert(e, metadata))); } - return this._logger.LogTraceCollectionRequestSuccess(REQUEST_TYPE_LIST_RETAIN, cacheName, listName, new CacheListRetainResponse.Success()); + return this._logger.LogTraceCollectionRequestSuccess(REQUEST_TYPE_LIST_RETAIN, cacheName, listName, new CacheListRetainResponse.Success(response)); } const string REQUEST_TYPE_LIST_REMOVE_VALUE = "LIST_REMOVE_VALUE"; @@ -1180,19 +1180,20 @@ private async Task SendListRemoveValueAsync(string ListName = listName.ToByteString(), AllElementsWithValue = value }; + _ListRemoveResponse response; var metadata = MetadataWithCache(cacheName); try { this._logger.LogTraceExecutingCollectionRequest(REQUEST_TYPE_LIST_REMOVE_VALUE, cacheName, listName, value, null); - await this.grpcManager.Client.ListRemoveAsync(request, new CallOptions(headers: MetadataWithCache(cacheName), deadline: CalculateDeadline())); + response = await this.grpcManager.Client.ListRemoveAsync(request, new CallOptions(headers: MetadataWithCache(cacheName), deadline: CalculateDeadline())); } catch (Exception e) { return this._logger.LogTraceCollectionRequestError(REQUEST_TYPE_LIST_REMOVE_VALUE, cacheName, listName, value, null, new CacheListRemoveValueResponse.Error(_exceptionMapper.Convert(e, metadata))); } - return this._logger.LogTraceCollectionRequestSuccess(REQUEST_TYPE_LIST_REMOVE_VALUE, cacheName, listName, value, null, new CacheListRemoveValueResponse.Success()); + return this._logger.LogTraceCollectionRequestSuccess(REQUEST_TYPE_LIST_REMOVE_VALUE, cacheName, listName, value, null, new CacheListRemoveValueResponse.Success(response)); } const string REQUEST_TYPE_LIST_LENGTH = "LIST_LENGTH"; diff --git a/src/Momento.Sdk/Responses/CacheListFetchResponse.cs b/src/Momento.Sdk/Responses/CacheListFetchResponse.cs index a7699485..9eeded14 100644 --- a/src/Momento.Sdk/Responses/CacheListFetchResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListFetchResponse.cs @@ -50,6 +50,11 @@ public class Hit : CacheListFetchResponse protected readonly Lazy> _stringList; #pragma warning restore 1591 + /// + /// The length of the list. + /// + public int ListLength { get; private set; } + /// /// /// @@ -66,6 +71,8 @@ public Hit(_ListFetchResponse response) { return new List(values.Select(v => v.ToStringUtf8())); }); + + ListLength = checked((int)values.Count); } /// @@ -83,7 +90,7 @@ public override string ToString() { var stringRepresentation = String.Join(", ", ValueListString.Select(value => $"\"{value}\"")); var byteArrayRepresentation = String.Join(", ", ValueListByteArray.Select(value => $"\"{value.ToPrettyHexString()}\"")); - return $"{base.ToString()}: ValueListString: [{stringRepresentation.Truncate()}] ValueListByteArray: [{byteArrayRepresentation.Truncate()}]"; + return $"{base.ToString()}: ValueListString: [{stringRepresentation.Truncate()}] ValueListByteArray: [{byteArrayRepresentation.Truncate()}] ListLength: {ListLength}"; } } diff --git a/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs b/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs index 8f385aa7..f5baae13 100644 --- a/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs @@ -44,6 +44,11 @@ public class Hit : CacheListPopBackResponse protected readonly ByteString value; #pragma warning restore 1591 + /// + /// The length of the list post-pop (and post-truncate, if that applies). + /// + public int ListLength { get; private set; } + /// /// /// @@ -51,6 +56,7 @@ public class Hit : CacheListPopBackResponse public Hit(_ListPopBackResponse response) { this.value = response.Found.Back; + ListLength = checked((int)response.Found.ListLength); } /// @@ -69,7 +75,7 @@ public byte[] ValueByteArray /// public override string ToString() { - return $"{base.ToString()}: ValueString: \"{ValueString.Truncate()}\" ValueByteArray: \"{ValueByteArray.ToPrettyHexString().Truncate()}\""; + return $"{base.ToString()}: ValueString: \"{ValueString.Truncate()}\" ValueByteArray: \"{ValueByteArray.ToPrettyHexString().Truncate()}\" ListLength: {ListLength}"; } } diff --git a/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs b/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs index ec74aefd..a56a304e 100644 --- a/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs @@ -44,6 +44,11 @@ public class Hit : CacheListPopFrontResponse protected readonly ByteString value; #pragma warning restore 1591 + /// + /// The length of the list post-pop (and post-truncate, if that applies). + /// + public int ListLength { get; private set; } + /// /// /// @@ -51,6 +56,7 @@ public class Hit : CacheListPopFrontResponse public Hit(_ListPopFrontResponse response) { this.value = response.Found.Front; + ListLength = checked((int)response.Found.ListLength); } /// @@ -69,7 +75,7 @@ public byte[] ValueByteArray /// public override string ToString() { - return $"{base.ToString()}: ValueString: \"{ValueString.Truncate()}\" ValueByteArray: \"{ValueByteArray.ToPrettyHexString().Truncate()}\""; + return $"{base.ToString()}: ValueString: \"{ValueString.Truncate()}\" ValueByteArray: \"{ValueByteArray.ToPrettyHexString().Truncate()}\" ListLength: {ListLength}"; } } diff --git a/src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs b/src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs index 0165993c..840b93f4 100644 --- a/src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs @@ -1,4 +1,5 @@ -using Momento.Sdk.Exceptions; +using Momento.Protos.CacheClient; +using Momento.Sdk.Exceptions; namespace Momento.Sdk.Responses; @@ -32,6 +33,25 @@ public abstract class CacheListRemoveValueResponse /// public class Success : CacheListRemoveValueResponse { + /// + /// The length of the list post-remove operation. + /// + public int ListLength { get; private set; } + + /// + /// + /// + /// The cache response + public Success(_ListRemoveResponse response) + { + ListLength = checked((int)response.Found.ListLength); + } + + /// + public override string ToString() + { + return $"{base.ToString()}: ListLength: {ListLength}"; + } } /// diff --git a/src/Momento.Sdk/Responses/CacheListRetainResponse.cs b/src/Momento.Sdk/Responses/CacheListRetainResponse.cs index f6b23b3b..2c59dd91 100644 --- a/src/Momento.Sdk/Responses/CacheListRetainResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListRetainResponse.cs @@ -1,4 +1,5 @@ -using Momento.Sdk.Exceptions; +using Momento.Protos.CacheClient; +using Momento.Sdk.Exceptions; namespace Momento.Sdk.Responses; @@ -32,6 +33,25 @@ public abstract class CacheListRetainResponse /// public class Success : CacheListRetainResponse { + /// + /// The length of the list post-retain operation. + /// + public int ListLength { get; private set; } + + /// + /// + /// + /// The cache response + public Success(_ListRetainResponse response) + { + ListLength = checked((int)response.Found.ListLength); + } + + /// + public override string ToString() + { + return $"{base.ToString()}: ListLength: {ListLength}"; + } } /// diff --git a/tests/Integration/Momento.Sdk.Tests/ListTest.cs b/tests/Integration/Momento.Sdk.Tests/ListTest.cs index f01a2ccc..d719a6df 100644 --- a/tests/Integration/Momento.Sdk.Tests/ListTest.cs +++ b/tests/Integration/Momento.Sdk.Tests/ListTest.cs @@ -66,6 +66,7 @@ public async Task ListFetchAsync_WithPositiveStartEndIndcies_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit, $"Unexpected response: {fetchResponse}"); var hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value2, value3 }, hitResponse.ValueListString); + Assert.Equal(2, hitResponse.ListLength); } [Fact] @@ -84,6 +85,7 @@ public async Task ListFetchAsync_WithNegativeStartEndIndcies_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit, $"Unexpected response: {fetchResponse}"); var hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value3 }, hitResponse.ValueListString); + Assert.Equal(1, hitResponse.ListLength); } [Fact] @@ -103,12 +105,14 @@ public async Task ListFetchAsync_WithNullStartIndex_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit, $"Unexpected response: {fetchResponse}"); var hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value1 }, hitResponse.ValueListString); + Assert.Equal(1, hitResponse.ListLength); // valid case for null startIndex and negative endIndex fetchResponse = await client.ListFetchAsync(cacheName, listName, null, -3); Assert.True(fetchResponse is CacheListFetchResponse.Hit, $"Unexpected response: {fetchResponse}"); hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value1 }, hitResponse.ValueListString); + Assert.Equal(1, hitResponse.ListLength); } [Fact] @@ -128,12 +132,14 @@ public async Task ListFetchAsync_WithNullEndIndex_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit, $"Unexpected response: {fetchResponse}"); var hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value2, value3, value4 }, hitResponse.ValueListString); + Assert.Equal(3, hitResponse.ListLength); // valid case for a positive startIndex and null endIndex fetchResponse = await client.ListFetchAsync(cacheName, listName, 2, null); Assert.True(fetchResponse is CacheListFetchResponse.Hit, $"Unexpected response: {fetchResponse}"); hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value3, value4 }, hitResponse.ValueListString); + Assert.Equal(2, hitResponse.ListLength); } [Fact] @@ -182,6 +188,7 @@ public async Task ListRetainAsync_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit); var hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value2, value3, value4 }, hitResponse.ValueListString); + Assert.Equal(3, hitResponse.ListLength); await resetList(); retainResponse = await client.ListRetainAsync(cacheName, listName, 2, -1); @@ -190,6 +197,7 @@ public async Task ListRetainAsync_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit); hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value3, value4, value5 }, hitResponse.ValueListString); + Assert.Equal(3, hitResponse.ListLength); await resetList(); retainResponse = await client.ListRetainAsync(cacheName, listName, -4, -1); @@ -198,6 +206,7 @@ public async Task ListRetainAsync_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit); hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value3, value4, value5 }, hitResponse.ValueListString); + Assert.Equal(3, hitResponse.ListLength); await resetList(); // valid case for a negative startIndex and null endIndex @@ -207,6 +216,7 @@ public async Task ListRetainAsync_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit); hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value4, value5, value6 }, hitResponse.ValueListString); + Assert.Equal(3, hitResponse.ListLength); await resetList(); // valid case for a positive startIndex and null endIndex @@ -216,6 +226,7 @@ public async Task ListRetainAsync_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit); hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value3, value4, value5, value6 }, hitResponse.ValueListString); + Assert.Equal(4, hitResponse.ListLength); await resetList(); // valid case for null startIndex and positive endIndex @@ -225,6 +236,7 @@ public async Task ListRetainAsync_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit); hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value1 }, hitResponse.ValueListString); + Assert.Equal(1, hitResponse.ListLength); await resetList(); // valid case for null startIndex and negative endIndex @@ -234,6 +246,7 @@ public async Task ListRetainAsync_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit); hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(new string[] { value1, value2, value3 }, hitResponse.ValueListString); + Assert.Equal(3, hitResponse.ListLength); } [Fact] @@ -279,6 +292,32 @@ public async Task ListConcatenateFrontFetch_ValueIsByteArray_HappyPath() Assert.Contains(value, list); } } + + [Fact] + public async Task CacheListRetainReponse_ToString_HappyPath() + { + var listName = Utils.NewGuidString(); + string value1 = Utils.NewGuidString(); + string value2 = Utils.NewGuidString(); + string value3 = Utils.NewGuidString(); + string value4 = Utils.NewGuidString(); + string value5 = Utils.NewGuidString(); + string value6 = Utils.NewGuidString(); + string[] values = new string[] { value1, value2, value3, value4, value5, value6 }; + + var resetList = async () => + { + await client.DeleteAsync(cacheName, listName); + await client.ListConcatenateFrontAsync(cacheName, listName, values); + }; + + await resetList(); + CacheListRetainResponse response = await client.ListRetainAsync(cacheName, listName, 1, 4); + Assert.True(response is CacheListRetainResponse.Success, $"Unexpected response: {response}"); + var successResponse = (CacheListRetainResponse.Success)response; + Assert.Equal("Momento.Sdk.Responses.CacheListRetainResponse+Success: ListLength: 3", successResponse.ToString()); + } + [Fact] public async Task ListConcatenateFrontFetch_ValueIsByteArray_NoRefreshTtl() { @@ -1026,6 +1065,7 @@ public async Task ListPopFrontAsync_ValueIsByteArray_HappyPath() var hitResponse = (CacheListPopFrontResponse.Hit)response; Assert.Equal(value2, hitResponse.ValueByteArray); + Assert.Equal(1, hitResponse.ListLength); } [Fact] @@ -1042,6 +1082,7 @@ public async Task ListPopFrontAsync_ValueIsString_HappyPath() var hitResponse = (CacheListPopFrontResponse.Hit)response; Assert.Equal(value2, hitResponse.ValueString); + Assert.Equal(1, hitResponse.ListLength); } [Fact] @@ -1054,7 +1095,7 @@ public async Task CacheListPopFrontReponse_ToString_HappyPath() CacheListPopFrontResponse response = await client.ListPopFrontAsync(cacheName, listName); Assert.True(response is CacheListPopFrontResponse.Hit, $"Unexpected response: {response}"); var hitResponse = (CacheListPopFrontResponse.Hit)response; - Assert.Equal("Momento.Sdk.Responses.CacheListPopFrontResponse+Hit: ValueString: \"a\" ValueByteArray: \"61\"", hitResponse.ToString()); + Assert.Equal("Momento.Sdk.Responses.CacheListPopFrontResponse+Hit: ValueString: \"a\" ValueByteArray: \"61\" ListLength: 0", hitResponse.ToString()); } [Theory] @@ -1089,6 +1130,7 @@ public async Task ListPopBackAsync_ValueIsByteArray_HappyPath() var hitResponse = (CacheListPopBackResponse.Hit)response; Assert.Equal(value2, hitResponse.ValueByteArray); + Assert.Equal(1, hitResponse.ListLength); } [Fact] @@ -1105,6 +1147,7 @@ public async Task ListPopBackAsync_ValueIsString_HappyPath() var hitResponse = (CacheListPopBackResponse.Hit)response; Assert.Equal(value2, hitResponse.ValueString); + Assert.Equal(1, hitResponse.ListLength); } [Fact] @@ -1117,7 +1160,7 @@ public async Task CacheListPopBackReponse_ToString_HappyPath() CacheListPopBackResponse response = await client.ListPopBackAsync(cacheName, listName); Assert.True(response is CacheListPopBackResponse.Hit, $"Unexpected response: {response}"); var hitResponse = (CacheListPopBackResponse.Hit)response; - Assert.Equal("Momento.Sdk.Responses.CacheListPopBackResponse+Hit: ValueString: \"a\" ValueByteArray: \"61\"", hitResponse.ToString()); + Assert.Equal("Momento.Sdk.Responses.CacheListPopBackResponse+Hit: ValueString: \"a\" ValueByteArray: \"61\" ListLength: 0", hitResponse.ToString()); } [Theory] @@ -1154,6 +1197,7 @@ public async Task ListFetchAsync_HasContentString_HappyPath() var hitResponse = (CacheListFetchResponse.Hit)fetchResponse; Assert.Equal(hitResponse.ValueListString, contentList); + Assert.Equal(hitResponse.ListLength, contentList.Count); } [Fact] @@ -1173,7 +1217,7 @@ public async Task ListFetchAsync_HasContentByteArray_HappyPath() Assert.Contains(field1, hitResponse.ValueListByteArray!); Assert.Contains(field2, hitResponse.ValueListByteArray!); - Assert.Equal(2, hitResponse.ValueListByteArray!.Count); + Assert.Equal(hitResponse.ListLength, contentList.Count); } [Fact] @@ -1186,7 +1230,7 @@ public async Task CacheListFetchResponse_ToString_HappyPath() Assert.True(fetchResponse is CacheListFetchResponse.Hit, $"Unexpected response: {fetchResponse}"); var hitResponse = (CacheListFetchResponse.Hit)fetchResponse; - Assert.Equal("Momento.Sdk.Responses.CacheListFetchResponse+Hit: ValueListString: [\"a\", \"b\"] ValueListByteArray: [\"61\", \"62\"]", hitResponse.ToString()); + Assert.Equal("Momento.Sdk.Responses.CacheListFetchResponse+Hit: ValueListString: [\"a\", \"b\"] ValueListByteArray: [\"61\", \"62\"] ListLength: 2", hitResponse.ToString()); } [Theory] @@ -1217,7 +1261,10 @@ public async Task ListRemoveValueAsync_ValueIsByteArray_HappyPath() await client.ListPushBackAsync(cacheName, listName, valueOfInterest); // Remove value of interest - await client.ListRemoveValueAsync(cacheName, listName, valueOfInterest); + var removeResponse = await client.ListRemoveValueAsync(cacheName, listName, valueOfInterest); + Assert.True(removeResponse is CacheListRemoveValueResponse.Success, $"Unexpected response: {removeResponse}"); + var successRemoveResponse = (CacheListRemoveValueResponse.Success)removeResponse; + Assert.Equal(3, successRemoveResponse.ListLength); // Test not there var response = await client.ListFetchAsync(cacheName, listName); @@ -1237,7 +1284,10 @@ public async Task ListRemoveValueAsync_ValueIsByteArray_ValueNotPresentNoop() await client.ListPushBackAsync(cacheName, listName, value); } - await client.ListRemoveValueAsync(cacheName, listName, Utils.NewGuidByteArray()); + var removeResponse = await client.ListRemoveValueAsync(cacheName, listName, Utils.NewGuidByteArray()); + Assert.True(removeResponse is CacheListRemoveValueResponse.Success, $"Unexpected response: {removeResponse}"); + var successRemoveResponse = (CacheListRemoveValueResponse.Success)removeResponse; + Assert.Equal(3, successRemoveResponse.ListLength); var response = await client.ListFetchAsync(cacheName, listName); Assert.True(response is CacheListFetchResponse.Hit, $"Unexpected response: {response}"); @@ -1282,7 +1332,10 @@ public async Task ListRemoveValueAsync_ValueIsString_HappyPath() await client.ListPushBackAsync(cacheName, listName, valueOfInterest); // Remove value of interest - await client.ListRemoveValueAsync(cacheName, listName, valueOfInterest); + var removeResponse = await client.ListRemoveValueAsync(cacheName, listName, valueOfInterest); + Assert.True(removeResponse is CacheListRemoveValueResponse.Success, $"Unexpected response: {removeResponse}"); + var successRemoveResponse = (CacheListRemoveValueResponse.Success)removeResponse; + Assert.Equal(3, successRemoveResponse.ListLength); // Test not there var response = await client.ListFetchAsync(cacheName, listName); @@ -1302,7 +1355,10 @@ public async Task ListRemoveValueAsync_ValueIsByteString_ValueNotPresentNoop() await client.ListPushBackAsync(cacheName, listName, value); } - await client.ListRemoveValueAsync(cacheName, listName, Utils.NewGuidString()); + var removeResponse = await client.ListRemoveValueAsync(cacheName, listName, Utils.NewGuidString()); + Assert.True(removeResponse is CacheListRemoveValueResponse.Success, $"Unexpected response: {removeResponse}"); + var successRemoveResponse = (CacheListRemoveValueResponse.Success)removeResponse; + Assert.Equal(3, successRemoveResponse.ListLength); var response = await client.ListFetchAsync(cacheName, listName); Assert.True(response is CacheListFetchResponse.Hit, $"Unexpected response: {response}"); @@ -1319,6 +1375,23 @@ public async Task ListRemoveValueAsync_ValueIsString_ListNotThereNoop() Assert.True(await client.ListFetchAsync(cacheName, listName) is CacheListFetchResponse.Miss); } + [Fact] + public async Task CacheListRemoveValueReponse_ToString_HappyPath() + { + var listName = Utils.NewGuidString(); + var list = new List() { Utils.NewGuidString(), Utils.NewGuidString(), Utils.NewGuidString() }; + + foreach (var value in list) + { + await client.ListPushBackAsync(cacheName, listName, value); + } + + var removeResponse = await client.ListRemoveValueAsync(cacheName, listName, Utils.NewGuidString()); + Assert.True(removeResponse is CacheListRemoveValueResponse.Success, $"Unexpected response: {removeResponse}"); + var successResponse = (CacheListRemoveValueResponse.Success)removeResponse; + Assert.Equal("Momento.Sdk.Responses.CacheListRemoveValueResponse+Success: ListLength: 3", successResponse.ToString()); + } + [Theory] [InlineData(null, "my-list")] [InlineData("cache", null)] From 21138ef1c658b2bdb337958b08056c8077c9a602 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Tue, 6 Jun 2023 10:28:07 -0700 Subject: [PATCH 2/5] fix: fix build errors --- src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs b/src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs index 840b93f4..9ca52b94 100644 --- a/src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListRemoveValueResponse.cs @@ -44,7 +44,9 @@ public class Success : CacheListRemoveValueResponse /// The cache response public Success(_ListRemoveResponse response) { - ListLength = checked((int)response.Found.ListLength); + if (response.ListCase == _ListRemoveResponse.ListOneofCase.Found) { + ListLength = checked((int)response.Found.ListLength); + } } /// From b54466b795c76de2a30bd4a873eab9f10413fa1d Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Tue, 6 Jun 2023 13:44:31 -0700 Subject: [PATCH 3/5] fix: minor code changes --- src/Momento.Sdk/Responses/CacheListFetchResponse.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Momento.Sdk/Responses/CacheListFetchResponse.cs b/src/Momento.Sdk/Responses/CacheListFetchResponse.cs index 9eeded14..fd815af4 100644 --- a/src/Momento.Sdk/Responses/CacheListFetchResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListFetchResponse.cs @@ -72,7 +72,7 @@ public Hit(_ListFetchResponse response) return new List(values.Select(v => v.ToStringUtf8())); }); - ListLength = checked((int)values.Count); + ListLength = values.Count; } /// From 41cdecf5cb4737963991ef81107a2a4875895f3d Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Thu, 8 Jun 2023 09:45:12 -0700 Subject: [PATCH 4/5] feat: remove checked from list length member access --- src/Momento.Sdk/Responses/CacheListLengthResponse.cs | 2 +- src/Momento.Sdk/Responses/CacheListPopBackResponse.cs | 2 +- src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs | 2 +- src/Momento.Sdk/Responses/CacheListRetainResponse.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Momento.Sdk/Responses/CacheListLengthResponse.cs b/src/Momento.Sdk/Responses/CacheListLengthResponse.cs index f73e3409..3c52e318 100644 --- a/src/Momento.Sdk/Responses/CacheListLengthResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListLengthResponse.cs @@ -46,7 +46,7 @@ public Success(_ListLengthResponse response) { if (response.ListCase == _ListLengthResponse.ListOneofCase.Found) { - Length = checked((int)response.Found.Length); + Length = (int)response.Found.Length; } } diff --git a/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs b/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs index f5baae13..9bdf7fbe 100644 --- a/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs @@ -56,7 +56,7 @@ public class Hit : CacheListPopBackResponse public Hit(_ListPopBackResponse response) { this.value = response.Found.Back; - ListLength = checked((int)response.Found.ListLength); + ListLength = (int)response.Found.ListLength; } /// diff --git a/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs b/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs index a56a304e..b2ba468c 100644 --- a/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs @@ -56,7 +56,7 @@ public class Hit : CacheListPopFrontResponse public Hit(_ListPopFrontResponse response) { this.value = response.Found.Front; - ListLength = checked((int)response.Found.ListLength); + ListLength = (int)response.Found.ListLength; } /// diff --git a/src/Momento.Sdk/Responses/CacheListRetainResponse.cs b/src/Momento.Sdk/Responses/CacheListRetainResponse.cs index 2c59dd91..601d4499 100644 --- a/src/Momento.Sdk/Responses/CacheListRetainResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListRetainResponse.cs @@ -44,7 +44,7 @@ public class Success : CacheListRetainResponse /// The cache response public Success(_ListRetainResponse response) { - ListLength = checked((int)response.Found.ListLength); + ListLength = (int)response.Found.ListLength; } /// From d86cee69b4279e4e87d3bd60c5ddb2e216831901 Mon Sep 17 00:00:00 2001 From: rishtigupta Date: Thu, 8 Jun 2023 10:03:21 -0700 Subject: [PATCH 5/5] feat: adding checked from list length member access --- src/Momento.Sdk/Responses/CacheListLengthResponse.cs | 2 +- src/Momento.Sdk/Responses/CacheListPopBackResponse.cs | 2 +- src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs | 2 +- src/Momento.Sdk/Responses/CacheListRetainResponse.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Momento.Sdk/Responses/CacheListLengthResponse.cs b/src/Momento.Sdk/Responses/CacheListLengthResponse.cs index 3c52e318..f73e3409 100644 --- a/src/Momento.Sdk/Responses/CacheListLengthResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListLengthResponse.cs @@ -46,7 +46,7 @@ public Success(_ListLengthResponse response) { if (response.ListCase == _ListLengthResponse.ListOneofCase.Found) { - Length = (int)response.Found.Length; + Length = checked((int)response.Found.Length); } } diff --git a/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs b/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs index 9bdf7fbe..f5baae13 100644 --- a/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListPopBackResponse.cs @@ -56,7 +56,7 @@ public class Hit : CacheListPopBackResponse public Hit(_ListPopBackResponse response) { this.value = response.Found.Back; - ListLength = (int)response.Found.ListLength; + ListLength = checked((int)response.Found.ListLength); } /// diff --git a/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs b/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs index b2ba468c..a56a304e 100644 --- a/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListPopFrontResponse.cs @@ -56,7 +56,7 @@ public class Hit : CacheListPopFrontResponse public Hit(_ListPopFrontResponse response) { this.value = response.Found.Front; - ListLength = (int)response.Found.ListLength; + ListLength = checked((int)response.Found.ListLength); } /// diff --git a/src/Momento.Sdk/Responses/CacheListRetainResponse.cs b/src/Momento.Sdk/Responses/CacheListRetainResponse.cs index 601d4499..2c59dd91 100644 --- a/src/Momento.Sdk/Responses/CacheListRetainResponse.cs +++ b/src/Momento.Sdk/Responses/CacheListRetainResponse.cs @@ -44,7 +44,7 @@ public class Success : CacheListRetainResponse /// The cache response public Success(_ListRetainResponse response) { - ListLength = (int)response.Found.ListLength; + ListLength = checked((int)response.Found.ListLength); } ///