Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add list caches API #35

Merged
merged 4 commits into from
Jan 9, 2024
Merged

chore: add list caches API #35

merged 4 commits into from
Jan 9, 2024

Conversation

pratik151192
Copy link
Contributor

@pratik151192 pratik151192 commented Jan 4, 2024

Added list caches API

@pratik151192 pratik151192 requested a review from nand4011 January 5, 2024 10:15
@pratik151192 pratik151192 marked this pull request as ready for review January 5, 2024 10:15
@@ -0,0 +1,18 @@
package software.momento.kotlin.sdk.responses.cache.control
/** Information about a cache. */
public class CacheInfo
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a data class, and name can be a public val so it doesn't need a getter.

* copy of the message of the cause.
*/
public class Error
/**
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this comment so it matches the formatting of the other Error responses.

/** Response for a list caches operation. */
public sealed interface CacheListResponse {
/** A successful list caches operation. Contains the discovered caches. */
public class Success(caches: List<CacheInfo>) :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be a data class with caches as a public val. The internal field, init block, and getter can be removed. I think IntelliJ can autogenerate an equals and hashCode to properly do a list comparison.

@pratik151192 pratik151192 requested a review from nand4011 January 8, 2024 19:04
Copy link
Collaborator

@nand4011 nand4011 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor test issues. Looks good otherwise.

val cacheNames = caches.map { it.name }
assert(cacheNames.contains(cacheName))

var deleteResponse = cacheClient.deleteCache(cacheName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this in a finally block? The cache won't be deleted if there is a transient error with list caches.

assert(listCachesResponse is CacheListResponse.Success)

val caches = (listCachesResponse as CacheListResponse.Success).caches
assertTrue(caches.size > 1, "There should be exactly 2 caches in the response")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the assertion is correct, but we don't know that there will be only two caches.

val cacheNames = caches.map { it.name }
assertTrue(cacheName in cacheNames, "$cacheName should be one of the cache names")

var deleteResponse = cacheClient.deleteCache(cacheName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a finally as well.

@pratik151192 pratik151192 requested a review from nand4011 January 9, 2024 01:16
@pratik151192 pratik151192 merged commit ee37c98 into main Jan 9, 2024
5 checks passed
@nand4011 nand4011 deleted the add-list-caches branch January 9, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants