Skip to content

Commit

Permalink
Upgrading dynamodb journal plugin to Akka 2.4
Browse files Browse the repository at this point in the history
This project had a dependency on spray-aws, which had a dependency on
akka 2.3 and spray.  Spray is no longer supported moving forward, so I
changed the dependency to only require the aws sdk.

There are some substantial changes in Akka 2.4 for persistence, most
notably:
- WriteConfirmations go away, so there is no more concept of imperanent
  deletes.  A lot of code around write confirmations was removed from
the plugin
- The asyncWriteMessages signature changed.  Instead of taking a
  Seq[PersistentRepr], it instead takes a Seq[AtomicWrite].  There are
also certain guarantees around the handling of AtomicWrites that must
be implemented; namely that every AtomicWrite has an associated
Try[Unit] that is returned.  This means that every AtomicWrite should
yield a successful result.  I had to change the way we handled
asyncWriteMessages to always ensure a response.

I beleive that this plugin will be backward compatible, as I did not
alter the way the items are being built.

I created an `integration-test.sh` that will run the tests.  One of the
tests was pulled from Martin Krasser's journal plugin; the other test
uses the JournalSpec.

I did not due the JournalPerfSpec as I am only running locally, and I
was not able to get the throughput hitting the amazondb local.
  • Loading branch information
paulcleary committed Oct 15, 2015
1 parent f1a634f commit 2944e07
Show file tree
Hide file tree
Showing 14 changed files with 600 additions and 402 deletions.
22 changes: 9 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,27 @@ organization := "com.sclasen"

name := "akka-persistence-dynamodb"

version := "0.3.4-SNAPSHOT"
version := "0.4.0-SNAPSHOT"

scalaVersion := "2.11.1"

crossScalaVersions := Seq("2.11.1", "2.10.4")
scalaVersion := "2.11.7"

parallelExecution in Test := false

//resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

resolvers += "spray repo" at "http://repo.spray.io"

libraryDependencies += "com.sclasen" %% "spray-dynamodb" % "0.3.2" % "compile"
libraryDependencies += "com.amazonaws" % "aws-java-sdk-core" % "1.10.20"

libraryDependencies += "com.typesafe.akka" %% "akka-persistence-experimental" % "2.3.4" % "compile"
libraryDependencies += "com.amazonaws" % "aws-java-sdk-dynamodb" % "1.10.20"

libraryDependencies += "com.typesafe.akka" %% "akka-testkit" % "2.3.4" % "test,it"
libraryDependencies += "com.typesafe.akka" %% "akka-persistence" % "2.4.0" % "compile"

libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.7" % "test,it"
libraryDependencies += "com.typesafe.akka" %% "akka-persistence-tck" % "2.4.0" % "test,it"

libraryDependencies += "commons-io" % "commons-io" % "2.4" % "test,it"
libraryDependencies += "com.typesafe.akka" %% "akka-testkit" % "2.4.0" % "test,it"

resolvers += "krasserm at bintray" at "http://dl.bintray.com/krasserm/maven"
libraryDependencies += "org.scalatest" %% "scalatest" % "2.1.7" % "test,it"

libraryDependencies += "com.github.krasserm" %% "akka-persistence-testkit" % "0.3.2" % "test"
libraryDependencies += "commons-io" % "commons-io" % "2.4" % "test,it"

parallelExecution in Test := false

Expand Down
28 changes: 28 additions & 0 deletions integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
echo "Compiling..."
sbt clean compile

DB_DIR="target/db"
PID_FILE="target/dynamo.pid"

if [ ! -f dynamodb-local/DynamoDBLocal.jar ]; then
./bin/get-dynamodb-local
fi

echo "Initializing db directory ${DB_DIR}"
mkdir ${DB_DIR}

echo "Starting up dynamod, pid is ${PID_FILE}"
rm -f ${PID_FILE}

nohup java -Djava.library.path=./dynamodb-local -jar ./dynamodb-local/DynamoDBLocal.jar -dbPath ${DB_DIR} > target/test-output.log 2>&1 &
echo $! > ${PID_FILE}

echo "Running load test"
sbt it:test

echo "Stopping dynamo"
kill -9 `cat ${PID_FILE}`



Empty file removed perf-test.md
Empty file.
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2")

addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.5")


25 changes: 5 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
DynamoDBJournal for Akka Persistence
====================================

A replicated [Akka Persistence](http://doc.akka.io/docs/akka/2.3.0-RC3/scala/persistence.html) journal backed by
A replicated [Akka Persistence](http://doc.akka.io/docs/akka/2.4.0/scala/persistence.html) journal backed by
[Amazon DynamoDB](http://aws.amazon.com/dynamodb/).

Scala: `2.10.4` and `2.11.1` Akka: `2.3.3`
Scala: `2.11.7` Akka: `2.4.0`

Installation
------------
Expand All @@ -15,7 +15,7 @@ Installation

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"

libraryDependencies += "com.sclasen" %% "akka-persistence-dynamodb" % "0.3.4" % "compile"
libraryDependencies += "com.sclasen" %% "akka-persistence-dynamodb" % "0.4.0" % "compile"

```

Expand Down Expand Up @@ -58,23 +58,8 @@ Development

### dev setup

* install [forego](https://github.com/ddollar/forego) if you dont have it.

* run `bin/get-dynamodb-local`

this downloads and unpacks the dynamodb local to a subdir of ./dynamodb-local

* `cp .env.sample .env`

* make sure the DYNAMODB_RELEASE var in .env matches the date of the distro that was placed in ./dynamodb-local

* `forego start`

This starts the local dynamodb instance

In another shell

* forego run sbt test
* run `integration-test.sh` to run the integration tests. This will download dynamodb local if it is not already
installed, start up dynamo, and then run the integration tests to validate the plugin.

### dynamodb table structure discussion

Expand Down
13 changes: 9 additions & 4 deletions src/it/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
dynamodb-journal {
journal-table = ${JOURNAL_TABLE}
aws-access-key-id = ${AWS_ACCESS_KEY_ID}
aws-secret-access-key = ${AWS_SECRET_ACCESS_KEY}
journal-table = "journal"
aws-access-key-id = "perfTest"
aws-secret-access-key = "notNeededForLocal"
operation-timeout = 30 seconds
sequence-shards = 10000

# asserts running dynamodb local
endpoint = "http://localhost:8000"
}

akka.persistence.journal.plugin = "dynamodb-journal"
akka.persistence.publish-confirmations = on
akka.persistence.publish-plugin-commands = on
akka.loglevel = ${LOG_LEVEL}

akka.loglevel = "INFO"

akka.event-handlers = ["akka.event.Logging$DefaultLogger"]
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
package akka.persistence.journal.dynamodb

import DynamoDBJournal._
import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.amazonaws.services.dynamodbv2.model._
import scala.concurrent.Await
import scala.concurrent.duration._
import org.scalatest.{Suite, BeforeAndAfterEach}
import com.typesafe.config.{ConfigFactory, Config}
import akka.persistence.journal.JournalSpec
import akka.persistence.journal.dynamodb.DynamoDBJournal._
import com.amazonaws.services.dynamodbv2.model.{CreateTableRequest, DeleteTableRequest, ListTablesRequest, ProvisionedThroughput}
import com.typesafe.config.ConfigFactory

trait DynamoDBSpec extends BeforeAndAfterEach {
this: Suite =>
import scala.concurrent.Await
import scala.concurrent.duration._

val system:ActorSystem
class DynamoDBJournalSpec extends JournalSpec(ConfigFactory.load()) {

override def beforeEach(): Unit = {
override def beforeAll(): Unit = {
super.beforeAll()
val config = system.settings.config.getConfig(Conf)
val table = config.getString(JournalTable)
val client = dynamoClient(system, system, config)
val create = new CreateTableRequest()
.withTableName(table)
.withKeySchema(DynamoDBJournal.schema)
.withAttributeDefinitions(DynamoDBJournal.schemaAttributes)
.withProvisionedThroughput(new ProvisionedThroughput(10, 10))
.withProvisionedThroughput(new ProvisionedThroughput(10L, 10L))
import system.dispatcher

val setup = client.sendListTables(new ListTablesRequest()).flatMap {
Expand All @@ -38,14 +34,5 @@ trait DynamoDBSpec extends BeforeAndAfterEach {
}
}
Await.result(setup, 5 seconds)
super.beforeEach()
}

override protected def afterEach(): Unit = {
super.afterEach()
}
}

class DynamoDBJournalSpec extends JournalSpec with DynamoDBSpec{
override lazy val config: Config = ConfigFactory.load()
}
Loading

0 comments on commit 2944e07

Please sign in to comment.