From bc7ff0cee1d877731cf1328be98d0d0055a12e5b Mon Sep 17 00:00:00 2001 From: Nate Anderson Date: Tue, 3 Sep 2024 14:56:05 -0700 Subject: [PATCH] fix: fix failing storage tests (#390) Stop looking at error metadata to determine whether an already exists error is for a store or cache. We can check it when that is added on the server side. Update a test that was checking that the server could support empty keys in the store client. That changed on the server side. --- .../src/intTest/java/momento/sdk/storage/DataTests.java | 8 ++++---- .../sdk/exceptions/CacheServiceExceptionMapper.java | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/momento-sdk/src/intTest/java/momento/sdk/storage/DataTests.java b/momento-sdk/src/intTest/java/momento/sdk/storage/DataTests.java index bbe44f7f..e5b7f331 100644 --- a/momento-sdk/src/intTest/java/momento/sdk/storage/DataTests.java +++ b/momento-sdk/src/intTest/java/momento/sdk/storage/DataTests.java @@ -102,11 +102,11 @@ public void badStoreNameReturnsError() { } @Test - public void allowEmptyKeyValuesOnGet() throws Exception { - final String emptyKey = ""; + public void allowEmptyValuesOnGet() throws Exception { + final String key = randomString("key"); final String emptyValue = ""; - storageClient.put(storeName, emptyKey, emptyValue).get(); - final GetResponse response = storageClient.get(storeName, emptyKey).get(); + storageClient.put(storeName, key, emptyValue).get(); + final GetResponse response = storageClient.get(storeName, key).get(); assertThat(response).isInstanceOf(GetResponse.Found.class); assert response.valueWhenFound().get().getString().get().isEmpty(); } diff --git a/momento-sdk/src/main/java/momento/sdk/exceptions/CacheServiceExceptionMapper.java b/momento-sdk/src/main/java/momento/sdk/exceptions/CacheServiceExceptionMapper.java index d3fa3683..4df14d59 100644 --- a/momento-sdk/src/main/java/momento/sdk/exceptions/CacheServiceExceptionMapper.java +++ b/momento-sdk/src/main/java/momento/sdk/exceptions/CacheServiceExceptionMapper.java @@ -77,7 +77,9 @@ public static SdkException convert(Throwable e) { return new CacheNotFoundException(grpcException, errorDetails); } case ALREADY_EXISTS: - if (errorCause.contains("Store with name")) { + // TODO: Switch to use the metadata when that can distinguish between a store and cache + // already exists + if (grpcException.getMessage().contains("Store with name")) { return new StoreAlreadyExistsException(grpcException, errorDetails); } else { return new CacheAlreadyExistsException(grpcException, errorDetails);