API changes related to DataDeleted, #27371

* The reason for this change is that `DataDeleted` didn't extend the
  `UpdateResponse` and `GetResponse` types and could therefore cause problems
  when `Update` and `Get` were used with `ask`. This was also a problem for
  Akka Typed.
* Introduce new messages types UpdateDataDeleted and GetDataDeleted
* Introduce SubscribeResponse because the responses can be both `Changed`
  and `Deleted` are responses to subscriptions. Important for Typed.
This commit is contained in:
Patrik Nordwall 2019-08-16 07:33:41 +02:00
parent 4576835cce
commit 1d09d2725b
11 changed files with 228 additions and 97 deletions

View file

@ -86,7 +86,7 @@ class ReplicatorChaosSpec extends MultiNodeSpec(ReplicatorChaosSpec) with STMult
within(5.seconds) {
awaitAssert {
replicator ! Get(key, ReadLocal)
expectMsg(DataDeleted(key, None))
expectMsg(GetDataDeleted(key, None))
}
}

View file

@ -4,14 +4,17 @@
package akka.cluster.ddata
import scala.concurrent.Await
import scala.concurrent.duration._
import akka.pattern.ask
import akka.cluster.Cluster
import akka.remote.testconductor.RoleName
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
import akka.remote.transport.ThrottlerTransportAdapter.Direction
import akka.testkit._
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
object ReplicatorSpec extends MultiNodeConfig {
@ -74,6 +77,8 @@ class ReplicatorSpec extends MultiNodeSpec(ReplicatorSpec) with STMultiNodeSpec
enterBarrier("after-" + afterCounter)
}
private implicit val askTimeout: Timeout = 5.seconds
def join(from: RoleName, to: RoleName): Unit = {
runOn(from) {
cluster.join(node(to).address)
@ -144,13 +149,24 @@ class ReplicatorSpec extends MultiNodeSpec(ReplicatorSpec) with STMultiNodeSpec
expectMsg(DeleteSuccess(KeyX, Some(777)))
changedProbe.expectMsg(Deleted(KeyX))
replicator ! Get(KeyX, ReadLocal, Some(789))
expectMsg(DataDeleted(KeyX, Some(789)))
expectMsg(GetDataDeleted(KeyX, Some(789)))
replicator ! Get(KeyX, readAll, Some(456))
expectMsg(DataDeleted(KeyX, Some(456)))
expectMsg(GetDataDeleted(KeyX, Some(456)))
// verify ask-mapTo for GetDataDeleted, issue #27371
Await
.result((replicator ? Get(KeyX, ReadLocal, None)).mapTo[GetResponse[GCounter]], askTimeout.duration)
.getClass should be(classOf[GetDataDeleted[GCounter]])
replicator ! Update(KeyX, GCounter(), WriteLocal, Some(123))(_ :+ 1)
expectMsg(DataDeleted(KeyX, Some(123)))
expectMsg(UpdateDataDeleted(KeyX, Some(123)))
replicator ! Delete(KeyX, WriteLocal, Some(555))
expectMsg(DataDeleted(KeyX, Some(555)))
// verify ask-mapTo for UpdateDataDeleted, issue #27371
Await
.result(
(replicator ? Update(KeyX, GCounter(), WriteLocal, Some(123))(_ :+ 1)).mapTo[UpdateResponse[GCounter]],
askTimeout.duration)
.getClass should be(classOf[UpdateDataDeleted[GCounter]])
replicator ! GetKeyIds
expectMsg(GetKeyIdsResult(Set("A")))
@ -309,7 +325,7 @@ class ReplicatorSpec extends MultiNodeSpec(ReplicatorSpec) with STMultiNodeSpec
c.value should be(31)
replicator ! Get(KeyY, ReadLocal, Some(777))
expectMsg(DataDeleted(KeyY, Some(777)))
expectMsg(GetDataDeleted(KeyY, Some(777)))
}
}
changedProbe.expectMsgPF() { case c @ Changed(KeyC) => c.get(KeyC).value } should be(31)