+cdd #16799 Add Distributed Data module
Previously know as [patriknw/akka-data-replication](https://github.com/patriknw/akka-data-replication), which was originally inspired by [jboner/akka-crdt](https://github.com/jboner/akka-crdt). The functionality is very similar to akka-data-replication 0.11. Here is a list of the most important changes: * The package name changed to `akka.cluster.ddata` * The extension was renamed to `DistributedData` * The keys changed from strings to classes with unique identifiers and type information of the data values, e.g. `ORSetKey[Int]("set2")` * The optional read consistency parameter was removed from the `Update` message. If you need to read from other replicas before performing the update you have to first send a `Get` message and then continue with the ``Update`` when the ``GetSuccess`` is received. * `BigInt` is used in `GCounter` and `PNCounter` instead of `Long` * Improvements of java api * Better documentation
This commit is contained in:
parent
bf28260cd0
commit
cbe5dd2cf5
69 changed files with 40036 additions and 3 deletions
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.cluster.ddata
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import akka.actor.Actor
|
||||
import akka.actor.ActorSystem
|
||||
import akka.actor.Props
|
||||
import akka.actor.Stash
|
||||
import akka.cluster.Cluster
|
||||
import akka.testkit.ImplicitSender
|
||||
import akka.testkit.TestKit
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
import org.scalatest.Matchers
|
||||
import org.scalatest.WordSpecLike
|
||||
|
||||
object LocalConcurrencySpec {
|
||||
|
||||
final case class Add(s: String)
|
||||
|
||||
object Updater {
|
||||
val key = ORSetKey[String]("key")
|
||||
}
|
||||
|
||||
class Updater extends Actor with Stash {
|
||||
implicit val cluster = Cluster(context.system)
|
||||
val replicator = DistributedData(context.system).replicator
|
||||
|
||||
def receive = {
|
||||
case s: String ⇒
|
||||
val update = Replicator.Update(Updater.key, ORSet.empty[String], Replicator.WriteLocal)(_ + s)
|
||||
replicator ! update
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LocalConcurrencySpec(_system: ActorSystem) extends TestKit(_system)
|
||||
with WordSpecLike with Matchers with BeforeAndAfterAll with ImplicitSender {
|
||||
import LocalConcurrencySpec._
|
||||
|
||||
def this() {
|
||||
this(ActorSystem("LocalConcurrencySpec",
|
||||
ConfigFactory.parseString("""
|
||||
akka.actor.provider = "akka.cluster.ClusterActorRefProvider"
|
||||
akka.remote.netty.tcp.port=0
|
||||
""")))
|
||||
}
|
||||
|
||||
override def afterAll(): Unit = {
|
||||
shutdown(system)
|
||||
}
|
||||
|
||||
val replicator = DistributedData(system).replicator
|
||||
|
||||
"Updates from same node" must {
|
||||
|
||||
"be possible to do from two actors" in {
|
||||
val updater1 = system.actorOf(Props[Updater], "updater1")
|
||||
val updater2 = system.actorOf(Props[Updater], "updater2")
|
||||
|
||||
val numMessages = 100
|
||||
for (n ← 1 to numMessages) {
|
||||
updater1 ! s"a$n"
|
||||
updater2 ! s"b$n"
|
||||
}
|
||||
|
||||
val expected = ((1 to numMessages).map("a" + _) ++ (1 to numMessages).map("b" + _)).toSet
|
||||
awaitAssert {
|
||||
replicator ! Replicator.Get(Updater.key, Replicator.ReadLocal)
|
||||
val ORSet(elements) = expectMsgType[Replicator.GetSuccess[_]].get(Updater.key)
|
||||
elements should be(expected)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue