Sign inSign up

gomomento/momento-local

By gomomento

•Updated 12 months ago

Image
0

10K+

gomomento/momento-local repository overview

⁠Quickstart

Use momento-local in CI and/or unit tests of the Momento Cache⁠ and Momento Topics⁠ services!

To get the momento-local server started with default port 8080, run:

docker run -p 8080:8080 gomomento/momento-local

If you need to specify the platform, use:

docker run --platform=linux/amd64 -p 8080:8080 gomomento/momento-local

Currently supported architectures: amd64, arm64

⁠Test Clients

In your tests, configure your CacheClient and/or TopicClient to use the momento-local endpoint:

const cacheClient = await CacheClient.create({
    credentialProvider: CredentialProvider.forMomentoLocal({
      port: 8080,
    }),
    defaultTtlSeconds: 60,
});

const topicClient = await TopicClient.create({
    credentialProvider: CredentialProvider.forMomentoLocal({
      port: 8080,
    }),
});

Note: CredentialProvider.forMomentoLocal() method is currently available in the Node.js, Go, and Java SDKs, additional SDKs coming soon.

⁠Testing non-happy path cases

Starting a momento-local server with default options will allow you to test happy-path cases. If you wish to test error scenarios as well (e.g. the service returns an error, network delays cause the client to retry requests, etc), you may configure momento-local to do that in one of two ways:

  1. Using command-line arguments to configure a specific set of behaviors upon start-up that will apply to all requests momento-local receives. All of these command-line arguments are optional. Here are all the existing options:

    docker run -p <port>:<port> gomomento/momento-local \
        --port <port> \
        --hostname <hostname> \
        --error-rpcs <space-separated list of method names> \
        --return-error <error name> \
        --error-count <number of times to return an error> \
        --delay-rpcs <space-separated list of method names>
        --delay-ms <how long to delay> \
        --delay-count <number of times to delay response> 
        --stream-error-rpcs topic-subscribe \
        --stream-error <error name> \
        --stream-error-message-limit <number of messages before returning an error on the stream>
    
  2. Using a momento-local middleware to set specific error behaviors for each test using metadata. Each test should provide a unique "request-id" value to ensure the error behavior is isolated to only the requests containing that ID. Currently, only the Node.js SDK has an ExperimentalMomentoLocalTestConfigMiddleware⁠ available to configure per-test error behaviors.

⁠Topics Subscription Keepalive Tests

To silence keepalive pings in order to test the resiliency of Topics subscriptions, first start up a test admin service that runs alongside momento-local:

docker run --cap-add=NET_ADMIN --rm -p 8080:8080 -p 9090:9090 -e LOG_LEVEL=debug gomomento/momento-local --enable-test-admin

In your tests, alongside the CacheClient and/or TopicClient, you can send basic GET requests to these test admin endpoints to block and unblock the momento-local port on the Docker container, thereby blocking/unblocking the keepalive pings:

# block the momento-local port, silence keepalive pings, disrupt Topics subscriptions
curl https://127.0.0.1:9090/block

# unblock the momento-local port, allow keepalive pings, allow Topics subscriptions to resume
curl https://127.0.0.1:9090/unblock

⁠Learn More

Questions or comments? Reach out to us on Discord⁠.

For more info, visit our website at https://gomomento.com⁠!

Tag summary

Content type

Image

Digest

sha256:91d285f87…

Size

33.1 MB

Last updated

12 months ago

docker pull gomomento/momento-local