Skip to content

Instantly share code, notes, and snippets.

@yaroslav-ulanovych
Created April 15, 2016 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaroslav-ulanovych/118b60c0e652da1f9ad4f1ee34d284ae to your computer and use it in GitHub Desktop.
Save yaroslav-ulanovych/118b60c0e652da1f9ad4f1ee34d284ae to your computer and use it in GitHub Desktop.
package foo
import java.util.concurrent.TimeUnit
import akka.actor.{ActorSystem, Props}
import akka.pattern.ask
import akka.persistence.{PersistentActor, RecoveryCompleted}
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import org.scalatest.{FunSuite, Matchers}
import scala.collection.JavaConversions
import scala.concurrent.Await
import scala.concurrent.duration.Duration
class MiscTest extends FunSuite with Matchers {
test("it") {
implicit val timeout = Timeout(30, TimeUnit.SECONDS)
class TestActor extends PersistentActor {
var numberOfEvents = 0
def updateState(e: Any): Unit = {
println("updating")
numberOfEvents += 1
}
override def receiveRecover: Receive = {
case RecoveryCompleted =>
if (numberOfEvents == 0) {
println("persisting")
persist("foo")(updateState)
}
}
override def receiveCommand: Receive = {
case _ => {
println("answering")
sender ! numberOfEvents
}
}
override def persistenceId: String = "42"
}
val config = ConfigFactory.parseMap(JavaConversions.mapAsJavaMap(Map(
"akka.persistence.journal.plugin" -> "akka.persistence.journal.inmem"
)))
val system = ActorSystem("test", config)
val actorRef = system.actorOf(Props(new TestActor))
Await.result(actorRef ? "stats", Duration.Inf) shouldBe 0
Await.result(actorRef ? "stats", Duration.Inf) shouldBe 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment