Skip to content

Commit

Permalink
fix: remove value response name and list push length (#149)
Browse files Browse the repository at this point in the history
fixes:

- The ListRemoveValue response had an out of date name. Changed to CacheListRemoveValue
- Added list length to the response for ListPushFront and ListPushBack
  • Loading branch information
malandis authored Sep 13, 2022
1 parent a7b7bc9 commit 2889920
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 31 deletions.
32 changes: 16 additions & 16 deletions src/Momento.Sdk/Incubating/Internal/ScsDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,15 @@ public async Task<CacheSetDeleteResponse> SetDeleteAsync(string cacheName, strin

public async Task<CacheListPushFrontResponse> ListPushFrontAsync(string cacheName, string listName, byte[] value, bool refreshTtl, uint? truncateBackToSize = null, uint? ttlSeconds = null)
{
await SendListPushFrontAsync(cacheName, listName, value.ToByteString(), refreshTtl, truncateBackToSize, ttlSeconds);
return new CacheListPushFrontResponse();
return await SendListPushFrontAsync(cacheName, listName, value.ToByteString(), refreshTtl, truncateBackToSize, ttlSeconds);
}

public async Task<CacheListPushFrontResponse> ListPushFrontAsync(string cacheName, string listName, string value, bool refreshTtl, uint? truncateBackToSize = null, uint? ttlSeconds = null)
{
await SendListPushFrontAsync(cacheName, listName, value.ToByteString(), refreshTtl, truncateBackToSize, ttlSeconds);
return new CacheListPushFrontResponse();
return await SendListPushFrontAsync(cacheName, listName, value.ToByteString(), refreshTtl, truncateBackToSize, ttlSeconds);
}

public async Task SendListPushFrontAsync(string cacheName, string listName, ByteString value, bool refreshTtl, uint? truncateBackToSize = null, uint? ttlSeconds = null)
public async Task<CacheListPushFrontResponse> SendListPushFrontAsync(string cacheName, string listName, ByteString value, bool refreshTtl, uint? truncateBackToSize = null, uint? ttlSeconds = null)
{
_ListPushFrontRequest request = new()
{
Expand All @@ -355,30 +353,30 @@ public async Task SendListPushFrontAsync(string cacheName, string listName, Byte
RefreshTtl = refreshTtl,
TtlMilliseconds = TtlSecondsToMilliseconds(ttlSeconds)
};
_ListPushFrontResponse response;

try
{
await this.grpcManager.Client.ListPushFrontAsync(request, MetadataWithCache(cacheName), deadline: CalculateDeadline());
response = await this.grpcManager.Client.ListPushFrontAsync(request, MetadataWithCache(cacheName), deadline: CalculateDeadline());
}
catch (Exception e)
{
throw CacheExceptionMapper.Convert(e);
}
return new CacheListPushFrontResponse(response);
}

public async Task<CacheListPushBackResponse> ListPushBackAsync(string cacheName, string listName, byte[] value, bool refreshTtl, uint? truncateFrontToSize = null, uint? ttlSeconds = null)
{
await SendListPushBackAsync(cacheName, listName, value.ToByteString(), refreshTtl, truncateFrontToSize, ttlSeconds);
return new CacheListPushBackResponse();
return await SendListPushBackAsync(cacheName, listName, value.ToByteString(), refreshTtl, truncateFrontToSize, ttlSeconds);
}

public async Task<CacheListPushBackResponse> ListPushBackAsync(string cacheName, string listName, string value, bool refreshTtl, uint? truncateFrontToSize = null, uint? ttlSeconds = null)
{
await SendListPushBackAsync(cacheName, listName, value.ToByteString(), refreshTtl, truncateFrontToSize, ttlSeconds);
return new CacheListPushBackResponse();
return await SendListPushBackAsync(cacheName, listName, value.ToByteString(), refreshTtl, truncateFrontToSize, ttlSeconds);
}

public async Task SendListPushBackAsync(string cacheName, string listName, ByteString value, bool refreshTtl, uint? truncateFrontToSize = null, uint? ttlSeconds = null)
public async Task<CacheListPushBackResponse> SendListPushBackAsync(string cacheName, string listName, ByteString value, bool refreshTtl, uint? truncateFrontToSize = null, uint? ttlSeconds = null)
{
_ListPushBackRequest request = new()
{
Expand All @@ -388,15 +386,17 @@ public async Task SendListPushBackAsync(string cacheName, string listName, ByteS
RefreshTtl = refreshTtl,
TtlMilliseconds = TtlSecondsToMilliseconds(ttlSeconds)
};
_ListPushBackResponse response;

try
{
await this.grpcManager.Client.ListPushBackAsync(request, MetadataWithCache(cacheName), deadline: CalculateDeadline());
response = await this.grpcManager.Client.ListPushBackAsync(request, MetadataWithCache(cacheName), deadline: CalculateDeadline());
}
catch (Exception e)
{
throw CacheExceptionMapper.Convert(e);
}
return new CacheListPushBackResponse(response);
}

public async Task<CacheListPopFrontResponse> ListPopFrontAsync(string cacheName, string listName)
Expand Down Expand Up @@ -447,17 +447,17 @@ public async Task<CacheListFetchResponse> ListFetchAsync(string cacheName, strin
return new CacheListFetchResponse(response);
}

public async Task<CacheListRemoveAllResponse> ListRemoveValueAsync(string cacheName, string listName, byte[] value)
public async Task<CacheListRemoveValueResponse> ListRemoveValueAsync(string cacheName, string listName, byte[] value)
{
return await ListRemoveValueAsync(cacheName, listName, value.ToByteString());
}

public async Task<CacheListRemoveAllResponse> ListRemoveValueAsync(string cacheName, string listName, string value)
public async Task<CacheListRemoveValueResponse> ListRemoveValueAsync(string cacheName, string listName, string value)
{
return await ListRemoveValueAsync(cacheName, listName, value.ToByteString());
}

public async Task<CacheListRemoveAllResponse> ListRemoveValueAsync(string cacheName, string listName, ByteString value)
public async Task<CacheListRemoveValueResponse> ListRemoveValueAsync(string cacheName, string listName, ByteString value)
{
_ListRemoveRequest request = new()
{
Expand All @@ -473,7 +473,7 @@ public async Task<CacheListRemoveAllResponse> ListRemoveValueAsync(string cacheN
{
throw CacheExceptionMapper.Convert(e);
}
return new CacheListRemoveAllResponse();
return new CacheListRemoveValueResponse();
}

public async Task<CacheListLengthResponse> ListLengthAsync(string cacheName, string listName)
Expand Down
14 changes: 14 additions & 0 deletions src/Momento.Sdk/Incubating/Responses/CacheListPushBackResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
using Momento.Protos.CacheClient;

namespace Momento.Sdk.Incubating.Responses;

/// <summary>
/// The result of a <c>ListPushBack</c> command
/// </summary>
public class CacheListPushBackResponse
{
/// <summary>
/// The length of the list post-push (and post-truncate, if that applies)
/// </summary>
public int ListLength { get; private set; }

public CacheListPushBackResponse(_ListPushBackResponse response)
{
ListLength = checked((int)response.ListLength);
}
}
14 changes: 14 additions & 0 deletions src/Momento.Sdk/Incubating/Responses/CacheListPushFrontResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
using Momento.Protos.CacheClient;

namespace Momento.Sdk.Incubating.Responses;

/// <summary>
/// The result of a <c>ListPushFront</c> command
/// </summary>
public class CacheListPushFrontResponse
{
/// <summary>
/// The length of the list post-push (and post-truncate, if that applies)
/// </summary>
public int ListLength { get; private set; }

public CacheListPushFrontResponse(_ListPushFrontResponse response)
{
ListLength = checked((int)response.ListLength);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Momento.Sdk.Incubating.Responses;

public class CacheListRemoveAllResponse
public class CacheListRemoveValueResponse
{
}
4 changes: 2 additions & 2 deletions src/Momento.Sdk/Incubating/SimpleCacheClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ public async Task<CacheListFetchResponse> ListFetchAsync(string cacheName, strin
/// <param name="value">The value to completely remove from the list.</param>
/// <returns>Task representing the result of the cache operation.</returns>
/// <exception cref="ArgumentNullException">Any of <paramref name="cacheName"/>, <paramref name="listName"/>, or <paramref name="value"/> is <see langword="null"/>.</exception>
public async Task<CacheListRemoveAllResponse> ListRemoveValueAsync(string cacheName, string listName, byte[] value)
public async Task<CacheListRemoveValueResponse> ListRemoveValueAsync(string cacheName, string listName, byte[] value)
{
Utils.ArgumentNotNull(cacheName, nameof(cacheName));
Utils.ArgumentNotNull(listName, nameof(listName));
Expand All @@ -696,7 +696,7 @@ public async Task<CacheListRemoveAllResponse> ListRemoveValueAsync(string cacheN
}

/// <inheritdoc cref="ListRemoveValueAsync(string, string, byte[])"/>
public async Task<CacheListRemoveAllResponse> ListRemoveValueAsync(string cacheName, string listName, string value)
public async Task<CacheListRemoveValueResponse> ListRemoveValueAsync(string cacheName, string listName, string value)
{
Utils.ArgumentNotNull(cacheName, nameof(cacheName));
Utils.ArgumentNotNull(listName, nameof(listName));
Expand Down
32 changes: 20 additions & 12 deletions tests/Integration/Momento.Sdk.Incubating.Tests/ListTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public async Task ListPushFrontFetch_ValueIsByteArray_HappyPath()
var listName = Utils.NewGuidString();
var value1 = Utils.NewGuidByteArray();

await client.ListPushFrontAsync(cacheName, listName, value1, false);
var pushResponse = await client.ListPushFrontAsync(cacheName, listName, value1, false);
Assert.Equal(1, pushResponse.ListLength);

var fetchResponse = await client.ListFetchAsync(cacheName, listName);
Assert.Equal(CacheGetStatus.HIT, fetchResponse.Status);
Expand All @@ -36,9 +37,10 @@ public async Task ListPushFrontFetch_ValueIsByteArray_HappyPath()

// Test push semantics
var value2 = Utils.NewGuidByteArray();
await client.ListPushFrontAsync(cacheName, listName, value2, false);
fetchResponse = await client.ListFetchAsync(cacheName, listName);
pushResponse = await client.ListPushFrontAsync(cacheName, listName, value2, false);
Assert.Equal(2, pushResponse.ListLength);

fetchResponse = await client.ListFetchAsync(cacheName, listName);
list = fetchResponse.ByteArrayList!;
Assert.Equal(value2, list[0]);
Assert.Equal(value1, list[1]);
Expand Down Expand Up @@ -96,7 +98,8 @@ public async Task ListPushFrontFetch_ValueIsString_HappyPath()
var listName = Utils.NewGuidString();
var value1 = Utils.NewGuidString();

await client.ListPushFrontAsync(cacheName, listName, value1, false);
var pushResponse = await client.ListPushFrontAsync(cacheName, listName, value1, false);
Assert.Equal(1, pushResponse.ListLength);

var fetchResponse = await client.ListFetchAsync(cacheName, listName);
Assert.Equal(CacheGetStatus.HIT, fetchResponse.Status);
Expand All @@ -107,9 +110,10 @@ public async Task ListPushFrontFetch_ValueIsString_HappyPath()

// Test push semantics
var value2 = Utils.NewGuidString();
await client.ListPushFrontAsync(cacheName, listName, value2, false);
fetchResponse = await client.ListFetchAsync(cacheName, listName);
pushResponse = await client.ListPushFrontAsync(cacheName, listName, value2, false);
Assert.Equal(2, pushResponse.ListLength);

fetchResponse = await client.ListFetchAsync(cacheName, listName);
list = fetchResponse.StringList()!;
Assert.Equal(value2, list[0]);
Assert.Equal(value1, list[1]);
Expand Down Expand Up @@ -167,7 +171,8 @@ public async Task ListPushBackFetch_ValueIsByteArray_HappyPath()
var listName = Utils.NewGuidString();
var value1 = Utils.NewGuidByteArray();

await client.ListPushBackAsync(cacheName, listName, value1, false);
var pushResponse = await client.ListPushBackAsync(cacheName, listName, value1, false);
Assert.Equal(1, pushResponse.ListLength);

var fetchResponse = await client.ListFetchAsync(cacheName, listName);
Assert.Equal(CacheGetStatus.HIT, fetchResponse.Status);
Expand All @@ -178,9 +183,10 @@ public async Task ListPushBackFetch_ValueIsByteArray_HappyPath()

// Test push semantics
var value2 = Utils.NewGuidByteArray();
await client.ListPushBackAsync(cacheName, listName, value2, false);
fetchResponse = await client.ListFetchAsync(cacheName, listName);
pushResponse = await client.ListPushBackAsync(cacheName, listName, value2, false);
Assert.Equal(2, pushResponse.ListLength);

fetchResponse = await client.ListFetchAsync(cacheName, listName);
list = fetchResponse.ByteArrayList!;
Assert.Equal(value1, list[0]);
Assert.Equal(value2, list[1]);
Expand Down Expand Up @@ -302,7 +308,8 @@ public async Task ListPushBackFetch_ValueIsString_HappyPath()
var listName = Utils.NewGuidString();
var value1 = Utils.NewGuidString();

await client.ListPushBackAsync(cacheName, listName, value1, false);
var pushResponse = await client.ListPushBackAsync(cacheName, listName, value1, false);
Assert.Equal(1, pushResponse.ListLength);

var fetchResponse = await client.ListFetchAsync(cacheName, listName);
Assert.Equal(CacheGetStatus.HIT, fetchResponse.Status);
Expand All @@ -313,9 +320,10 @@ public async Task ListPushBackFetch_ValueIsString_HappyPath()

// Test push semantics
var value2 = Utils.NewGuidString();
await client.ListPushBackAsync(cacheName, listName, value2, false);
fetchResponse = await client.ListFetchAsync(cacheName, listName);
pushResponse = await client.ListPushBackAsync(cacheName, listName, value2, false);
Assert.Equal(2, pushResponse.ListLength);

fetchResponse = await client.ListFetchAsync(cacheName, listName);
list = fetchResponse.StringList()!;
Assert.Equal(value1, list[0]);
Assert.Equal(value2, list[1]);
Expand Down

0 comments on commit 2889920

Please sign in to comment.