Skip to content

Commit

Permalink
Merge pull request akka#157 from 2m/wip-dynamodb-tests-docker
Browse files Browse the repository at this point in the history
Run DynamoDB local in docker
  • Loading branch information
patriknw authored Jan 20, 2017
2 parents 457553e + 3d94ec7 commit 2f03442
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 174 deletions.
52 changes: 25 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
lazy val alpakka = project
.in(file("."))
.enablePlugins(PublishUnidoc)
.aggregate(amqp, cassandra, docs, files, hbase, mqtt, s3, simpleCodecs, sqs, ftp, jms)
.aggregate(amqp, cassandra, dynamodb, docs, files, ftp, hbase, jms, mqtt, s3, simpleCodecs, sqs)

lazy val amqp = project
.enablePlugins(AutomateHeaderPlugin)
Expand All @@ -21,9 +21,7 @@ lazy val dynamodb = project
.enablePlugins(AutomateHeaderPlugin)
.settings(
name := "akka-stream-alpakka-dynamodb",
resolvers += "DynamoDBLocal" at "http://dynamodb-local.s3-website-us-west-2.amazonaws.com/release/",
Dependencies.DynamoDB,
parallelExecution in Test := false
Dependencies.DynamoDB
)

lazy val files = project // The name file is taken by `sbt.file`!
Expand All @@ -34,6 +32,14 @@ lazy val files = project // The name file is taken by `sbt.file`!
Dependencies.File
)

lazy val ftp = project
.enablePlugins(AutomateHeaderPlugin)
.settings(
name := "akka-stream-alpakka-ftp",
Dependencies.Ftp,
parallelExecution in Test := false
)

lazy val hbase = project
.enablePlugins(AutomateHeaderPlugin)
.settings(
Expand All @@ -42,6 +48,14 @@ lazy val hbase = project
fork in Test := true
)

lazy val jms = project
.enablePlugins(AutomateHeaderPlugin)
.settings(
name := "akka-stream-alpakka-jms",
Dependencies.Jms,
parallelExecution in Test := false
)

lazy val mqtt = project
.enablePlugins(AutomateHeaderPlugin)
.settings(
Expand All @@ -56,35 +70,19 @@ lazy val s3 = project
Dependencies.S3
)

lazy val sqs = project
.in(file("sqs"))
.enablePlugins(AutomateHeaderPlugin)
.settings(
name := "akka-stream-alpakka-sqs",
Dependencies.Sqs
)

lazy val ftp = project
.enablePlugins(AutomateHeaderPlugin)
.settings(
name := "akka-stream-alpakka-ftp",
Dependencies.Ftp,
parallelExecution in Test := false
)

lazy val jms = project
lazy val simpleCodecs = project
.in(file("simple-codecs"))
.enablePlugins(AutomateHeaderPlugin)
.settings(
name := "akka-stream-alpakka-jms",
Dependencies.Jms,
parallelExecution in Test := false
name := "akka-stream-alpakka-simple-codecs"
)

lazy val simpleCodecs = project
.in(file("simple-codecs"))
lazy val sqs = project
.in(file("sqs"))
.enablePlugins(AutomateHeaderPlugin)
.settings(
name := "akka-stream-alpakka-simple-codecs"
name := "akka-stream-alpakka-sqs",
Dependencies.Sqs
)

lazy val docs = project
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ services:
- "1883:1883"
volumes:
- ./mqtt/src/test/travis:/mqtt/config/conf.d
dynamodb:
image: deangiberson/aws-dynamodb-local
ports:
- "8001:8000"
8 changes: 4 additions & 4 deletions docs/src/main/paradox/connectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
@@@ index

* [AMQP Connector](amqp.md)
* [AWS DynamoDB Connector](dynamodb.md)
* [AWS SQS Connector](sqs.md)
* [Cassandra Connector](cassandra.md)
* [DynamoDB Connector](dynamodb.md)
* [File Connectors](file.md)
* [HBase Connectors](hbase.md)
* [MQTT Connector](mqtt.md)
* [FTP Connector](ftp.md)
* [SQS Connector](sqs.md)
* [HBase Connectors](hbase.md)
* [JMS Connectors](jms.md)
* [MQTT Connector](mqtt.md)
* [External Connectors](external-connectors.md)

@@@
Expand Down
26 changes: 23 additions & 3 deletions docs/src/main/paradox/dynamodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,40 @@ Scala
: @@snip (../../../../dynamodb/src/test/scala/akka/stream/alpakka/dynamodb/ExampleSpec.scala) { #init-client }

Java
: @@snip (../../../../dynamodb/src/test/java/akka/stream/alpakka/dynamodb/ExampleJavaSpec.java) { #init-client }
: @@snip (../../../../dynamodb/src/test/java/akka/stream/alpakka/dynamodb/ExampleTest.java) { #init-client }

You can then create the client with a settings object.

Scala
: @@snip (../../../../dynamodb/src/test/scala/akka/stream/alpakka/dynamodb/ExampleSpec.scala) { #client-construct }

Java
: @@snip (../../../../dynamodb/src/test/java/akka/stream/alpakka/dynamodb/ExampleJavaSpec.java) { #client-construct }
: @@snip (../../../../dynamodb/src/test/java/akka/stream/alpakka/dynamodb/ExampleTest.java) { #client-construct }

We can now send requests to DynamoDB across the connection.

Scala
: @@snip (../../../../dynamodb/src/test/scala/akka/stream/alpakka/dynamodb/ExampleSpec.scala) { #simple-request }

Java
: @@snip (../../../../dynamodb/src/test/java/akka/stream/alpakka/dynamodb/ExampleJavaSpec.java) { #simple-request }
: @@snip (../../../../dynamodb/src/test/java/akka/stream/alpakka/dynamodb/ExampleTest.java) { #simple-request }

### Running the example code

The code in this guide is part of runnable tests of this project. You are welcome to edit the code and run it in sbt.

> Test code requires DynamoDB server running in the background. You can start one quickly using docker:
>
> `docker run --rm -p 8001:8000 deangiberson/aws-dynamodb-local`
Scala
: ```
sbt
> dynamodb/testOnly *Spec
```

Java
: ```
sbt
> dynamodb/testOnly *Test
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
*/
package akka.stream.alpakka.dynamodb.impl

import java.io.{ ByteArrayInputStream, InputStream }
import java.io.{ByteArrayInputStream, InputStream}
import java.util.concurrent.atomic.AtomicInteger

import akka.NotUsed
import akka.actor.ActorSystem
import akka.http.scaladsl.Http.HostConnectionPool
import akka.http.scaladsl.model.{ ContentType, HttpEntity, _ }
import akka.http.scaladsl.model.{ContentType, HttpEntity, _}
import akka.stream.alpakka.dynamodb.AwsOp
import akka.stream.alpakka.dynamodb.impl.AwsClient.{ AwsConnect, AwsRequestMetadata }
import akka.stream.alpakka.dynamodb.impl.AwsClient.{AwsConnect, AwsRequestMetadata}
import akka.stream.scaladsl.Flow
import akka.stream.{ ActorAttributes, ActorMaterializer, Supervision }
import com.amazonaws.auth.{ AWS4Signer, DefaultAWSCredentialsProviderChain }
import com.amazonaws.http.{ HttpMethodName, HttpResponseHandler, HttpResponse => AWSHttpResponse }
import com.amazonaws.{ DefaultRequest, HttpMethod => _, _ }
import akka.stream.{ActorAttributes, ActorMaterializer, Supervision}
import com.amazonaws.auth.{AWS4Signer, DefaultAWSCredentialsProviderChain}
import com.amazonaws.http.{HttpMethodName, HttpResponseHandler, HttpResponse => AWSHttpResponse}
import com.amazonaws.{DefaultRequest, HttpMethod => _, _}

import scala.concurrent.{ ExecutionContext, Future }
import scala.util.{ Failure, Success, Try }
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

private[alpakka] object AwsClient {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package akka.stream.alpakka.dynamodb.impl
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.MediaType.NotCompressible
import akka.http.scaladsl.model.{ ContentType, MediaType }
import akka.http.scaladsl.model.{ContentType, MediaType}
import akka.stream.ActorMaterializer
import akka.stream.alpakka.dynamodb.AwsOp
import akka.stream.alpakka.dynamodb.impl.AwsClient.{ AwsConnect, AwsRequestMetadata }
import akka.stream.scaladsl.{ Sink, Source }
import akka.stream.alpakka.dynamodb.impl.AwsClient.{AwsConnect, AwsRequestMetadata}
import akka.stream.scaladsl.{Sink, Source}
import com.amazonaws.AmazonServiceException
import com.amazonaws.http.HttpResponseHandler

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package akka.stream.alpakka.dynamodb.javadsl
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.alpakka.dynamodb.AwsOp
import akka.stream.alpakka.dynamodb.impl.{ DynamoClientImpl, DynamoSettings }
import akka.stream.alpakka.dynamodb.impl.{DynamoClientImpl, DynamoSettings}
import akka.stream.alpakka.dynamodb.scaladsl.DynamoImplicits
import akka.stream.scaladsl.{ Sink, Source }
import akka.stream.scaladsl.{Sink, Source}
import com.amazonaws.services.dynamodbv2.model._

import scala.concurrent.Future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package akka.stream.alpakka.dynamodb.scaladsl
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.alpakka.dynamodb.AwsOp
import akka.stream.alpakka.dynamodb.impl.{ DynamoClientImpl, DynamoSettings }
import akka.stream.scaladsl.{ Sink, Source }
import akka.stream.alpakka.dynamodb.impl.{DynamoClientImpl, DynamoSettings}
import akka.stream.scaladsl.{Sink, Source}

object DynamoClient {
def apply(settings: DynamoSettings)(implicit system: ActorSystem, materializer: ActorMaterializer) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import akka.stream.alpakka.dynamodb.impl.DynamoProtocol
import com.amazonaws.http.HttpResponseHandler
import com.amazonaws.services.dynamodbv2.model._
import com.amazonaws.transform.Marshaller
import com.amazonaws.{ AmazonWebServiceResponse, Request }
import com.amazonaws.{AmazonWebServiceResponse, Request}

object DynamoImplicits extends DynamoProtocol {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2016 Lightbend Inc. <http://www.lightbend.com>
*/
package akka.stream.alpakka.dynamodb;

import akka.actor.ActorSystem;
import akka.japi.Pair;
import akka.stream.ActorMaterializer;
import akka.stream.alpakka.dynamodb.impl.DynamoSettings;
import akka.stream.alpakka.dynamodb.javadsl.DynamoClient;
import com.amazonaws.services.dynamodbv2.model.ListTablesRequest;
import com.amazonaws.services.dynamodbv2.model.ListTablesResult;
import org.junit.BeforeClass;
import org.junit.Test;
import scala.concurrent.Await;
import scala.concurrent.Future;
import scala.concurrent.duration.Duration;

public class ExampleTest {

static ActorSystem system;
static ActorMaterializer materializer;
static DynamoSettings settings;
static DynamoClient client;

public static Pair<ActorSystem, ActorMaterializer> setupMaterializer() {
//#init-client
final ActorSystem system = ActorSystem.create();
final ActorMaterializer materializer = ActorMaterializer.create(system);
//#init-client
return Pair.create(system, materializer);
}

public static Pair<DynamoSettings, DynamoClient> setupClient() {
//#client-construct
final DynamoSettings settings = DynamoSettings.apply(system);
final DynamoClient client = DynamoClient.create(settings, system, materializer);
//#client-construct
return Pair.create(settings, client);
}

@BeforeClass
public static void setup() throws Exception {
System.setProperty("aws.accessKeyId", "someKeyId");
System.setProperty("aws.secretKey", "someSecretKey");

final Pair<ActorSystem, ActorMaterializer> sysmat = setupMaterializer();
system = sysmat.first();
materializer = sysmat.second();

final Pair<DynamoSettings, DynamoClient> setclient = setupClient();
settings = setclient.first();
client = setclient.second();
}

@Test
public void listTables() throws Exception {
//#simple-request
final Future<ListTablesResult> listTablesResultFuture = client.listTables(new ListTablesRequest());
//#simple-request
final Duration duration = Duration.create(5, "seconds");
ListTablesResult result = Await.result(listTablesResultFuture, duration);
}

}
Loading

0 comments on commit 2f03442

Please sign in to comment.