Skip to content

Instantly share code, notes, and snippets.

@thecarlhall
Last active February 28, 2018 18:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecarlhall/f4e8f425cb736938e1d2 to your computer and use it in GitHub Desktop.
Save thecarlhall/f4e8f425cb736938e1d2 to your computer and use it in GitHub Desktop.
Maven setup for integration testing with DynamoDB
[INFO] --- download-maven-plugin:1.2.1:wget (install-dynamodb_local) @ app ---
[INFO] Got from cache: /home/carl/.m2/repository/.cache/maven-download-plugin/dynamodb_local_latest.zip
[INFO]
[INFO] --- process-exec-maven-plugin:0.7:start (dynamodb_local) @ app ---
[INFO] arg: java
[INFO] arg: -Djava.library.path=dynamodb/DynamoDBLocal_lib
[INFO] arg: -jar
[INFO] arg: dynamodb/DynamoDBLocal.jar
[INFO] arg: -port
[INFO] arg: 53351
[INFO] arg: -sharedDb
[INFO] arg: -inMemory
[INFO] Full command line: java -Djava.library.path=dynamodb/DynamoDBLocal_lib -jar dynamodb/DynamoDBLocal.jar -port 53351 -sharedDb -inMemory
[INFO] Starting process: dynamodb_local
[INFO] Using working directory for this process: /home/carl/src/app/target
[INFO] Initializing DynamoDB Local with the following configuration:
[INFO] Port: 53351
[INFO] InMemory: true
[INFO] DbPath: null
[INFO] SharedDb: true
[INFO] shouldDelayTransientStatuses: false
[INFO] CorsParams: *
[INFO]
[INFO] Started process: dynamodb_local
[INFO]
[INFO] --- maven-failsafe-plugin:2.18.1:integration-test (integration-test) @ app ---
[INFO] Failsafe report directory: /home/carl/src/app/target/failsafe-reports
<project>
<!-- ... -->
<properties>
<!--
Choose the region that is closest to you for fastest download.
-->
<aws.s3.region>us-west-2</aws.s3.region>
</properties>
<build>
<plugins>
<!--
Step 1: Downlaod the DynamoDB Local artifact.
This will download to a Maven cache on disk and is kept until
the cache is cleared. The artifact is unpacked to the target
directory of the build.
-->
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>install-dynamodb_local</id>
<phase>pre-integration-test</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>http://dynamodb-local.s3-website-${aws.s3.region}.amazonaws.com/dynamodb_local_latest.zip</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}/dynamodb</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<!--
Step 2: Reserve a local port for Dynamo to start on.
DynamoDB_Local normally runs on port 8000. Rather than hoping
that port is open, have this plugin reserve an available port
and set it as a property in the Maven build.
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<goals>
<goal>reserve-network-port</goal>
</goals>
<phase>initialize</phase>
<configuration>
<portNames>
<portName>dynamodblocal.port</portName>
</portNames>
</configuration>
</execution>
</executions>
</plugin>
<!--
Step 3: Start DynamoDB_Local just before integration tests are run.
This plugin will also cleanup the process during the
post-integration-test phase.
-->
<plugin>
<groupId>com.bazaarvoice.maven.plugins</groupId>
<artifactId>process-exec-maven-plugin</artifactId>
<version>0.7</version>
<executions>
<execution>
<id>dynamodb_local</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<name>dynamodb_local</name>
<!--
We need to let DynamoDB finish starting, but don't have
a good semamore. It's pretty quick to start, so 1 second
should suffice.
-->
<waitAfterLaunch>1</waitAfterLaunch>
<arguments>
<argument>java</argument>
<argument>-Djava.library.path=dynamodb/DynamoDBLocal_lib</argument>
<argument>-jar</argument>
<argument>dynamodb/DynamoDBLocal.jar</argument>
<!--
Use the port that was reserved in step 2
-->
<argument>-port</argument>
<argument>${dynamodblocal.port}</argument>
<!--
You run your tests in parallel, right?
-->
<argument>-sharedDb</argument>
<!--
Remove this to keep data between restarts of the process.
-->
<argument>-inMemory</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
<!--
Step 4: Use the failsafe plugin to run integration tests.
https://maven.apache.org/surefire/maven-failsafe-plugin/
-->
<plugin>
<groupId>org.apache.maven.plugins </groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19</version>
<configuration>
<systemPropertyVariables>
<!--
Set a system property for the test clients to use when connecting.
Something like Apache's commons-configuration can pick this up
transparently.
-->
<dynamo.endpoint>http://localhost:${dynamodblocal.port}</dynamo.endpoint>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment