Skip to content

Commit

Permalink
Merge pull request #28 from dwhjames/topic/integration-test
Browse files Browse the repository at this point in the history
update DynamoDB integration tests
  • Loading branch information
dwhjames committed Feb 25, 2015
2 parents 0dfe7ae + 4c9d8ec commit 8aa3d25
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 64 deletions.
9 changes: 0 additions & 9 deletions integration/build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import LocalMode.localMode

name := "aws-wrap-test"

Expand All @@ -17,22 +16,14 @@ Defaults.itSettings
parallelExecution in IntegrationTest := false


localMode := true

// testOptions in IntegrationTest += Tests.Argument(s"-D=${localMode.value}")

testOptions in IntegrationTest += Tests.Setup { () =>
if (localMode.value) {
println("Start DynamoDB Local")
System.setProperty("DynamoDB.localMode", "true")
Process("bash start-dynamodb-local.sh").!
}
}

testOptions in IntegrationTest += Tests.Cleanup { () =>
if (localMode.value) {
println("Stop DynamoDB Local")
System.clearProperty("DynamoDB.localMode")
Process("bash stop-dynamodb-local.sh").!
}
}
1 change: 0 additions & 1 deletion integration/src/it/resources/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions integration/src/it/resources/credentials-template.properties

This file was deleted.

33 changes: 3 additions & 30 deletions integration/src/it/scala/dynamodb/DynamoDBClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

import org.scalatest.{Suite, BeforeAndAfterAll}
import org.scalatest.matchers.ShouldMatchers

import com.amazonaws.auth.PropertiesCredentials
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.services.dynamodbv2._
import com.amazonaws.services.dynamodbv2.model._

Expand All @@ -41,34 +40,8 @@ trait DynamoDBClient
private val logger: Logger = LoggerFactory.getLogger(self.getClass)

val client = {
val inputStream =
this.getClass()
.getClassLoader()
.getResourceAsStream("credentials.properties")

require(inputStream ne null, """
|*A file called credentials.properties was not found on the classpath.*
|
|Please add this file and place your AWS credentials in it. The required
|format is specified in the provided credentials-template.properties file.
""".stripMargin)

val credentials =
try {
new PropertiesCredentials(inputStream)
} catch {
case ex: IllegalArgumentException =>
throw new IllegalArgumentException("""requirement failed:
|*The credentials.properties file was not properly specified*
|
|The required format is specified in the provided
|credentials-template.properties file.
""".stripMargin)
}

val jClient = new AmazonDynamoDBAsyncClient(credentials)
if (System.getProperty("DynamoDB.localMode") == "true")
jClient.setEndpoint("http://localhost:8000")
val jClient = new AmazonDynamoDBAsyncClient(new BasicAWSCredentials("FAKE_ACCESS_KEY", "FAKE_SECRET_KEY"))
jClient.setEndpoint("http://localhost:8000")

new AmazonDynamoDBScalaClient(jClient)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._

import org.scalatest.{FlatSpec, BeforeAndAfterAll}
import org.scalatest.matchers.ShouldMatchers
import org.scalatest.{ FlatSpec, BeforeAndAfterAll, Matchers }

import com.amazonaws.AmazonClientException
import com.amazonaws.services.dynamodbv2._
Expand All @@ -32,7 +31,7 @@ import com.amazonaws.services.dynamodbv2.model._

class ReadsOnHashKeyTableSpec
extends FlatSpec
with ShouldMatchers
with Matchers
with DynamoDBClient
{
import SampleData.sampleForums
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ object Dependencies {

object IntegrationTest {

val scalaTest = "org.scalatest" % "scalatest_2.10" % "1.9.2" % "it"
val scalaTest = "org.scalatest" %% "scalatest" % "2.2.4" % "it"
}
}
5 changes: 0 additions & 5 deletions project/LocalMode.scala

This file was deleted.

24 changes: 11 additions & 13 deletions start-dynamodb-local.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
#!/bin/bash
#!/usr/bin/env bash

# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'

WORKING_DIR="dynamodb"

mkdir -p $WORKING_DIR
cd $WORKING_DIR

VERSION="dynamodb_local_2013-09-12"
VERSION="dynamodb_local_latest"
ARCHIVE="${VERSION}.tar.gz"
URL="https://s3-us-west-2.amazonaws.com/dynamodb-local/${ARCHIVE}"
URL="http://dynamodb-local.s3-website-us-west-2.amazonaws.com/${ARCHIVE}"

if [ ! -f $ARCHIVE ]
then
echo "Downloading DynamoDB Local"
curl -O $URL
fi

if [ ! -d $VERSION ]
then
curl -LO $URL
echo "Extracting DynamoDB Local"
tar -xzf $ARCHIVE
fi

NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
LOG_FILE="dynamodb-${NOW}.log"
LOG_DIR="logs"

mkdir -p $LOG_DIR
echo "DynamoDB Local output will save to ${WORKING_DIR}/${LOG_DIR}/"

echo "DynamoDB Local output will save to ${WORKING_DIR}/${LOG_DIR}/${LOG_FILE}"
nohup java -Djava.library.path=${VERSION} -jar ${VERSION}/DynamoDBLocal.jar >"${LOG_DIR}/${LOG_FILE}" 2>&1 &
NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
nohup java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -port 8000 -inMemory 1>"${LOG_DIR}/${NOW}.out.log" 2>"${LOG_DIR}/${NOW}.err.log" &
PID=$!

echo "DynamoDB Local started with pid ${PID}"
Expand Down

0 comments on commit 8aa3d25

Please sign in to comment.