Created
April 15, 2016 14:08
-
-
Save yaroslav-ulanovych/118b60c0e652da1f9ad4f1ee34d284ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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