Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ on:
pull_request:
branches: [ main ]

env:
V1_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}
MOMENTO_API_KEY: ${{ secrets.ALPHA_API_KEY_V2 }}
MOMENTO_ENDPOINT: "cell-alpha-dev.preprod.a.momentohq.com"

jobs:
build:
runs-on: ubuntu-latest
env:
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}

steps:
- name: Checkout project
Expand Down Expand Up @@ -53,8 +56,6 @@ jobs:

build-examples:
runs-on: ubuntu-latest
env:
MOMENTO_API_KEY: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }}

steps:
- name: Checkout project
Expand Down
9 changes: 5 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
1. Run gradle build
* `./gradlew clean build`
1. To run integration tests:
* Generate API key using the [Momento Console](https://console.gomomento.com/api-keys) (if you don't already have one)
* `TEST_AUTH_TOKEN=<api key> TEST_CACHE_NAME=<cache id> TEST_ENDPOINT=<endpoint> ./gradlew integrationTest`
* `TEST_CACHE_NAME` is required. Give it any string value for now. TODO - Add a way of getting this per environment
* `TEST_ENDPOINT` is optional and defaults to alpha. TEST_ENDPOINT must belong to the cell where the auth token was generated.
* Generate API keys using the [Momento Console](https://console.gomomento.com/api-keys)
* `V1_API_KEY=<api key> MOMENTO_API_KEY=<cache id> MOMENTO_ENDPOINT=<endpoint> ./gradlew integrationTest`
* `V1_API_KEY` - required - v1 api key
* `MOMENTO_API_KEY` - required - v2 api key
* `MOMENTO_ENDPOINT` - required - Momento service [endpoint](https://docs.momentohq.com/platform/regions)

### Code Formatting
[google-java-format](https://github.com/google/google-java-format) is used for code formatting.
Expand Down
2 changes: 1 addition & 1 deletion examples/cache-with-aws/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
}

dependencies {
implementation("software.momento.java:sdk:1.21.0")
implementation("software.momento.java:sdk:1.23.0")

// For examples to store secrets in AWS Secrets Manager
implementation("software.amazon.awssdk:secretsmanager:2.20.93")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

public class BasicExample {

private static final String MOMENTO_ENDPOINT = "cache.cell-4-us-west-2-1.prod.a.momentohq.com";
private static final String API_KEY_SECRET_NAME = "MOMENTO_API_KEY";
private static final Duration DEFAULT_ITEM_TTL = Duration.ofSeconds(60);

Expand Down Expand Up @@ -85,7 +86,7 @@ private static void listCaches(CacheClient cacheClient) {
}

public static CredentialProvider getCredentialsFromSecretsManagerAuthToken() {
final Region region = Region.of("us-east-1");
final Region region = Region.of("us-west-2");

// Create a Secrets Manager client
final SecretsManagerClient client =
Expand All @@ -111,7 +112,7 @@ public static CredentialProvider getCredentialsFromSecretsManagerAuthToken() {

final String secret = getSecretValueResponse.secretString();
try {
return CredentialProvider.fromString(secret);
return CredentialProvider.fromApiKeyV2(secret, MOMENTO_ENDPOINT);
} catch (SdkException e) {
logger.error(
"An error occured while parsing the secrets manager vended"
Expand Down
15 changes: 8 additions & 7 deletions examples/cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,55 @@ _Read this in other languages_: [日本語](README.ja.md)
- JDK 14 or above is required to run the example
- To get started with Momento you will need a Momento API key. You can get one from the
[Momento Console](https://console.gomomento.com).
- A Momento service endpoint is required. Choose the one for the [region](https://docs.momentohq.com/platform/regions) you'll be using, e.g. `cache.cell-1-ap-southeast-1-1.prod.a.momentohq.com` for ap-southeast-1.

### Basic
```bash
MOMENTO_API_KEY=<YOUR API KEY> ./gradlew basic
MOMENTO_API_KEY=<YOUR API KEY> MOMENTO_ENDPOINT=<YOUR_ENDPOINT> ./gradlew basic
```

Example Code: [BasicExample.java](cache/src/main/java/momento/client/example/BasicExample.java)


### List
```bash
MOMENTO_API_KEY=<YOUR API KEY> ./gradlew list
MOMENTO_API_KEY=<YOUR API KEY> MOMENTO_ENDPOINT=<YOUR_ENDPOINT> ./gradlew list
```

Example Code: [ListExample.java](cache/src/main/java/momento/client/example/ListExample.java)

### Set
```bash
MOMENTO_API_KEY=<YOUR API KEY> ./gradlew set
MOMENTO_API_KEY=<YOUR API KEY> MOMENTO_ENDPOINT=<YOUR_ENDPOINT> ./gradlew set
```

Example Code: [SetExample.java](cache/src/main/java/momento/client/example/SetExample.java)

### Dictionary
```bash
MOMENTO_API_KEY=<YOUR API KEY> ./gradlew dictionary
MOMENTO_API_KEY=<YOUR API KEY> MOMENTO_ENDPOINT=<YOUR_ENDPOINT> ./gradlew dictionary
```

Example Code: [DictionaryExample.java](cache/src/main/java/momento/client/example/DictionaryExample.java)

### Sorted Set
```bash
MOMENTO_API_KEY=<YOUR API KEY> ./gradlew sortedSet
MOMENTO_API_KEY=<YOUR API KEY> MOMENTO_ENDPOINT=<YOUR_ENDPOINT> ./gradlew sortedSet
```

Example Code: [SortedSetExample.java](cache/src/main/java/momento/client/example/SortedSetExample.java)

### Batch Util
```bash
MOMENTO_API_KEY=<YOUR API KEY> ./gradlew sortedSet
MOMENTO_API_KEY=<YOUR API KEY> MOMENTO_ENDPOINT=<YOUR_ENDPOINT> ./gradlew sortedSet
```

Example Code: [SortedSetExample.java](cache/src/main/java/momento/client/example/SortedSetExample.java)


### With a Backing Database
```bash
MOMENTO_API_KEY=<YOUR API KEY> ./gradlew withDatabase
MOMENTO_API_KEY=<YOUR API KEY> MOMENTO_ENDPOINT=<YOUR_ENDPOINT> ./gradlew withDatabase
```

Example Code: [WithDatabaseExample.java](cache/src/main/java/momento/client/example/advanced/WithDatabaseExample.java)
Expand Down
2 changes: 1 addition & 1 deletion examples/cache/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repositories {
}

dependencies {
implementation("software.momento.java:sdk:1.21.0")
implementation("software.momento.java:sdk:1.23.0")

implementation("com.google.guava:guava:31.1-android")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.time.Duration;
import momento.sdk.CacheClient;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.auth.EnvVarCredentialProvider;
import momento.sdk.config.Configurations;
import momento.sdk.exceptions.AlreadyExistsException;
import momento.sdk.responses.cache.GetResponse;
Expand All @@ -13,7 +12,6 @@

public class BasicExample {

private static final String API_KEY_ENV_VAR = "MOMENTO_API_KEY";
private static final Duration DEFAULT_ITEM_TTL = Duration.ofSeconds(60);

private static final String CACHE_NAME = "cache";
Expand All @@ -23,7 +21,7 @@ public class BasicExample {
public static void main(String[] args) {
printStartBanner();

final CredentialProvider credentialProvider = new EnvVarCredentialProvider(API_KEY_ENV_VAR);
final CredentialProvider credentialProvider = CredentialProvider.fromEnvVarV2();

try (final CacheClient client =
CacheClient.create(credentialProvider, Configurations.Laptop.latest(), DEFAULT_ITEM_TTL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import momento.sdk.CacheClient;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.auth.EnvVarCredentialProvider;
import momento.sdk.batchutils.MomentoBatchUtils;
import momento.sdk.batchutils.request.BatchGetRequest;
import momento.sdk.batchutils.response.BatchGetResponse;
Expand All @@ -28,7 +27,6 @@
*/
public class BatchUtilsExample {

private static final String API_KEY_ENV_VAR = "MOMENTO_API_KEY";
private static final Duration DEFAULT_ITEM_TTL = Duration.ofSeconds(60);

private static final String CACHE_NAME = "cache";
Expand All @@ -40,7 +38,7 @@ public class BatchUtilsExample {

public static void main(String[] args) {

final CredentialProvider credentialProvider = new EnvVarCredentialProvider(API_KEY_ENV_VAR);
final CredentialProvider credentialProvider = CredentialProvider.fromEnvVarV2();

try (final CacheClient client =
CacheClient.create(credentialProvider, Configurations.Laptop.latest(), DEFAULT_ITEM_TTL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import java.util.stream.Collectors;
import momento.sdk.CacheClient;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.auth.EnvVarCredentialProvider;
import momento.sdk.config.Configurations;
import momento.sdk.exceptions.AlreadyExistsException;
import momento.sdk.exceptions.SdkException;
import momento.sdk.responses.cache.control.CacheCreateResponse;
import momento.sdk.responses.cache.dictionary.DictionaryFetchResponse;
import momento.sdk.responses.cache.dictionary.DictionaryRemoveFieldResponse;
Expand All @@ -19,7 +17,6 @@

public class DictionaryExample {

private static final String API_KEY_ENV_VAR = "MOMENTO_API_KEY";
private static final Duration DEFAULT_ITEM_TTL = Duration.ofSeconds(60);

private static final String CACHE_NAME = "dictionary-example-cache";
Expand All @@ -30,13 +27,7 @@ public class DictionaryExample {
public static void main(String[] args) {
logStartBanner();

final CredentialProvider credentialProvider;
try {
credentialProvider = new EnvVarCredentialProvider(API_KEY_ENV_VAR);
} catch (SdkException e) {
logger.error("Unable to load credential from environment variable " + API_KEY_ENV_VAR, e);
throw e;
}
final CredentialProvider credentialProvider = CredentialProvider.fromEnvVarV2();

try (final CacheClient client =
CacheClient.create(credentialProvider, Configurations.Laptop.latest(), DEFAULT_ITEM_TTL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import java.util.List;
import momento.sdk.CacheClient;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.auth.EnvVarCredentialProvider;
import momento.sdk.config.Configurations;
import momento.sdk.exceptions.AlreadyExistsException;
import momento.sdk.exceptions.SdkException;
import momento.sdk.responses.cache.control.CacheCreateResponse;
import momento.sdk.responses.cache.list.ListConcatenateFrontResponse;
import momento.sdk.responses.cache.list.ListFetchResponse;
Expand All @@ -19,7 +17,6 @@

public class ListExample {

private static final String API_KEY_ENV_VAR = "MOMENTO_API_KEY";
private static final Duration DEFAULT_ITEM_TTL = Duration.ofSeconds(60);

private static final String CACHE_NAME = "list-example-cache";
Expand All @@ -30,13 +27,7 @@ public class ListExample {
public static void main(String[] args) {
logStartBanner();

final CredentialProvider credentialProvider;
try {
credentialProvider = new EnvVarCredentialProvider(API_KEY_ENV_VAR);
} catch (SdkException e) {
logger.error("Unable to load credential from environment variable " + API_KEY_ENV_VAR, e);
throw e;
}
final CredentialProvider credentialProvider = CredentialProvider.fromEnvVarV2();

try (final CacheClient client =
CacheClient.create(credentialProvider, Configurations.Laptop.latest(), DEFAULT_ITEM_TTL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import java.util.function.Function;
import momento.sdk.CacheClient;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.auth.EnvVarCredentialProvider;
import momento.sdk.config.Configurations;
import momento.sdk.exceptions.MomentoErrorCode;
import momento.sdk.exceptions.SdkException;
import momento.sdk.responses.cache.GetResponse;
import momento.sdk.responses.cache.SetResponse;
import org.HdrHistogram.ConcurrentHistogram;
Expand All @@ -24,7 +22,7 @@

@SuppressWarnings("UnstableApiUsage")
public class LoadGenerator {
private static final String API_KEY_ENV_VAR = "MOMENTO_API_KEY";

private static final Duration DEFAULT_ITEM_TTL = Duration.ofSeconds(60);
private static final String CACHE_NAME = "java-loadgen";
private static final Logger logger = LoggerFactory.getLogger(LoadGenerator.class);
Expand Down Expand Up @@ -57,13 +55,7 @@ public LoadGenerator(
int warmupTime) {
cacheValue = "x".repeat(cacheValueLength);

final CredentialProvider credentialProvider;
try {
credentialProvider = new EnvVarCredentialProvider(API_KEY_ENV_VAR);
} catch (SdkException e) {
logger.error("Unable to load credential from environment variable " + API_KEY_ENV_VAR, e);
throw e;
}
final CredentialProvider credentialProvider = CredentialProvider.fromEnvVarV2();
client = CacheClient.create(credentialProvider, Configurations.Laptop.v1(), DEFAULT_ITEM_TTL);

client.createCache(CACHE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import java.util.Set;
import momento.sdk.CacheClient;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.auth.EnvVarCredentialProvider;
import momento.sdk.config.Configurations;
import momento.sdk.exceptions.AlreadyExistsException;
import momento.sdk.exceptions.SdkException;
import momento.sdk.responses.cache.control.CacheCreateResponse;
import momento.sdk.responses.cache.set.SetAddElementResponse;
import momento.sdk.responses.cache.set.SetAddElementsResponse;
Expand All @@ -29,13 +27,7 @@ public class SetExample {
public static void main(String[] args) {
logStartBanner();

final CredentialProvider credentialProvider;
try {
credentialProvider = new EnvVarCredentialProvider(API_KEY_ENV_VAR);
} catch (SdkException e) {
logger.error("Unable to load credential from environment variable " + API_KEY_ENV_VAR, e);
throw e;
}
final CredentialProvider credentialProvider = CredentialProvider.fromEnvVarV2();

try (final CacheClient client =
CacheClient.create(credentialProvider, Configurations.Laptop.latest(), DEFAULT_ITEM_TTL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import java.util.stream.Collectors;
import momento.sdk.CacheClient;
import momento.sdk.auth.CredentialProvider;
import momento.sdk.auth.EnvVarCredentialProvider;
import momento.sdk.config.Configurations;
import momento.sdk.exceptions.AlreadyExistsException;
import momento.sdk.exceptions.SdkException;
import momento.sdk.exceptions.CacheAlreadyExistsException;
import momento.sdk.responses.cache.control.CacheCreateResponse;
import momento.sdk.responses.cache.sortedset.SortedSetFetchResponse;
import momento.sdk.responses.cache.sortedset.SortedSetGetScoresResponse;
Expand All @@ -22,7 +20,6 @@

public class SortedSetExample {

private static final String API_KEY_ENV_VAR = "MOMENTO_API_KEY";
private static final Duration DEFAULT_ITEM_TTL = Duration.ofSeconds(60);

private static final String CACHE_NAME = "set-example-cache";
Expand All @@ -33,21 +30,15 @@ public class SortedSetExample {
public static void main(String[] args) {
logStartBanner();

final CredentialProvider credentialProvider;
try {
credentialProvider = new EnvVarCredentialProvider(API_KEY_ENV_VAR);
} catch (SdkException e) {
logger.error("Unable to load credential from environment variable " + API_KEY_ENV_VAR, e);
throw e;
}
final CredentialProvider credentialProvider = CredentialProvider.fromEnvVarV2();

try (final CacheClient client =
CacheClient.create(credentialProvider, Configurations.Laptop.latest(), DEFAULT_ITEM_TTL)) {

// Create a cache
final CacheCreateResponse createResponse = client.createCache(CACHE_NAME).join();
if (createResponse instanceof CacheCreateResponse.Error error) {
if (error.getCause() instanceof AlreadyExistsException) {
if (error.getCause() instanceof CacheAlreadyExistsException) {
logger.info("Cache with name '{}' already exists.", CACHE_NAME);
} else {
logger.error("Cache creation failed with error " + error.getErrorCode(), error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import momento.sdk.config.Configurations;

public class CheatSheet {

public static void main(String[] args) {
try (final CacheClient cacheClient =
CacheClient.create(
CredentialProvider.fromEnvVar("MOMENTO_API_KEY"),
CredentialProvider.fromEnvVarV2(),
Configurations.Laptop.v1(),
Duration.ofSeconds(60) /* defaultTTL for your cache items*/,
Duration.ofSeconds(10) /* eagerConnectionTimeout, default is 30 seconds */)) {
Expand Down
Loading
Loading