-
Notifications
You must be signed in to change notification settings - Fork 5
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
refactor: java cache and topics integration tests should use random cache names #379
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6a8acf
refactor: ci
malandis fe4e3b3
refactor: rewrite java integration tests to use a random test cache
malandis 7e8e828
fix: already exists cache test
malandis 5b596f1
refactor: create the test cache only once
malandis 4eb3b71
refactor: use ArrayList instead of Vector
malandis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
572 changes: 313 additions & 259 deletions
572
momento-sdk/src/intTest/java/momento/sdk/AuthClientCacheTests.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 41 additions & 17 deletions
58
momento-sdk/src/intTest/java/momento/sdk/BaseTestClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,59 @@ | ||
package momento.sdk; | ||
|
||
import java.time.Duration; | ||
import java.util.UUID; | ||
import momento.sdk.auth.CredentialProvider; | ||
import momento.sdk.config.Configurations; | ||
import momento.sdk.responses.cache.control.CacheCreateResponse; | ||
import momento.sdk.responses.cache.control.CacheDeleteResponse; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
public class BaseTestClass { | ||
public static final Duration FIVE_SECONDS = Duration.ofSeconds(5); | ||
protected static final Duration DEFAULT_TTL_SECONDS = Duration.ofSeconds(60); | ||
protected static final Duration FIVE_SECONDS = Duration.ofSeconds(5); | ||
protected static CredentialProvider credentialProvider; | ||
|
||
public static final CredentialProvider credentialProvider = | ||
CredentialProvider.fromEnvVar("TEST_AUTH_TOKEN"); | ||
protected static CacheClient cacheClient; | ||
protected static String cacheName; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
if (System.getenv("TEST_AUTH_TOKEN") == null) { | ||
throw new IllegalArgumentException( | ||
"Integration tests require TEST_AUTH_TOKEN env var; see README for more details."); | ||
} | ||
if (System.getenv("TEST_CACHE_NAME") == null) { | ||
throw new IllegalArgumentException( | ||
"Integration tests require TEST_CACHE_NAME env var; see README for more details."); | ||
credentialProvider = CredentialProvider.fromEnvVar("TEST_AUTH_TOKEN"); | ||
cacheClient = | ||
CacheClient.builder(credentialProvider, Configurations.Laptop.latest(), DEFAULT_TTL_SECONDS) | ||
.build(); | ||
cacheName = testCacheName(); | ||
ensureTestCacheExists(cacheName); | ||
} | ||
|
||
@AfterAll | ||
static void afterAll() { | ||
cleanupTestCache(cacheName); | ||
cacheClient.close(); | ||
} | ||
|
||
protected static void ensureTestCacheExists(String cacheName) { | ||
CacheCreateResponse response = cacheClient.createCache(cacheName).join(); | ||
if (response instanceof CacheCreateResponse.Error) { | ||
throw new RuntimeException( | ||
"Failed to test create cache: " + ((CacheCreateResponse.Error) response).getMessage()); | ||
} | ||
ensureTestCacheExists(); | ||
} | ||
|
||
private static void ensureTestCacheExists() { | ||
try (CacheClient client = | ||
CacheClient.builder( | ||
credentialProvider, Configurations.Laptop.latest(), Duration.ofSeconds(10)) | ||
.build()) { | ||
client.createCache(System.getenv("TEST_CACHE_NAME")).join(); | ||
public static void cleanupTestCache(String cacheName) { | ||
CacheDeleteResponse response = cacheClient.deleteCache(cacheName).join(); | ||
if (response instanceof CacheDeleteResponse.Error) { | ||
throw new RuntimeException( | ||
"Failed to test delete cache: " + ((CacheDeleteResponse.Error) response).getMessage()); | ||
} | ||
} | ||
|
||
public static String testCacheName() { | ||
return "java-integration-test-default-" + UUID.randomUUID(); | ||
} | ||
|
||
public static String testStoreName() { | ||
return "java-integration-test-default-" + UUID.randomUUID(); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth changing TEST_AUTH_TOKEN to MOMENTO_API_KEY in this pr? I thought we were slowly changing to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to change the CI / env vars in a separate PR. This one is pretty busy already.