Skip to content
Amazon DynamoDB Local Server for Testing
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
NOTICE
README.md
pom.xml

README.md

Latest release: Pre Release
License: Apache 2.0

Aws DynamoDB Server

A simple wrapper of the AWS DynamoDBLocal project to make easy to test DynamoDB applications.

Easy to use

Start the server and use it is easy.

DynamoDBServer server = new DynamoDBServer();
// Start the server
server.start();
// Create the client
String serverEndpoint = server.getEndpoint();
AmazonDynamoDBClient client = new AmazonDynamoDBClient();
client.setEndpoint(serverEndpoint);
// Use the client
...
// Stop the server
server.stop();

The server constructor takes the port as parameter, otherwise it would choose a free one (suggested behaviour).

How to get it

The server would be soon available directly from maven.

<dependency>
    <groupId>io.exemplary.aws</groupId>
    <artifactId>aws-dynamodb-server</artifactId>
    <version>${aws.version}</version>
</dependency>

Full example

This is a full example that can be use to start testing with Aws DynamoDB Server.

import junit.Test;
import io.exemplary.aws.DynamoDBServer;

public class DynamoDBTest {

  @Test
  public void createATableAndStore() {
    DynamoDBServer server = new DynamoDBServer();
    server.start();
    String serverEndpoint = server.getEndpoint();
    server.stop();
  }

}

Inject errors

The server behaviour can be controlled specifying the error. The error can be one of the Amazon service exceptions or an http error code.

DynamoDBServer server = new DynamoDBServer();
// Amazon exception
server.failsWith(AmazonServiceExceptionType.THROTTLING_EXCEPTION);
// Error code
server.failsWithResponseCode(501);

The error would apply to all the server request until the normal behaviour is restored.

server.doesNotFail();

Also is possible to specify the request that triggers the error with a condition.

server.failsWith(AmazonServiceExceptionType.THROTTLING_EXCEPTION)
      .withErrorCondition(new ErrorCondition<CreateTableRequest>() {
    @Override
    public boolean shouldFail(CreateTableRequest request) {
        return request.getTableName().equals("myTable");
    }
});

In this example the request fails with a throttling exception only for the table "myTable" creation.

You can’t perform that action at this time.