Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update DynamoDB integration tests #28

Merged
merged 3 commits into from
Feb 25, 2015
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: 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