Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dmrolfs committed Jun 10, 2016
1 parent 8cbab34 commit bb4b1c8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
@@ -1,15 +1,20 @@
package demesne

import scala.concurrent.{ ExecutionContext, Future }
import scala.concurrent.{ExecutionContext, Future}
import scala.reflect.ClassTag
import akka.actor.ActorSystem
import akka.util.Timeout
import scalaz._, Scalaz._
import shapeless.syntax.typeable._

import scalaz._
import Scalaz._
import shapeless._
import peds.commons.Valid
import peds.commons.log.Trace
import peds.commons.util._
import demesne.factory._



trait CommonInitializeAggregateActorType extends InitializeAggregateActorType { self: AggregateRootType.Provider =>
import CommonInitializeAggregateActorType._

Expand Down Expand Up @@ -41,20 +46,33 @@ trait CommonInitializeAggregateActorType extends InitializeAggregateActorType {
}

private def checkSystem( props: Map[Symbol, Any] ): Valid[ActorSystem] = trace.block( "checkSystem" ) {
props get demesne.SystemKey flatMap { _.cast[ActorSystem] } map { _.successNel[Throwable] } getOrElse {
Validation.failureNel( UnspecifiedActorSystemError(demesne.SystemKey) )
val System = TypeCase[ActorSystem]

props.get( demesne.SystemKey ) match {
case Some( System(sys) ) => sys.successNel[Throwable]
case Some( x ) => Validation failureNel IncompatibleTypeForPropertyError[ActorSystem]( demesne.SystemKey, x )
case None => Validation failureNel UnspecifiedActorSystemError( demesne.SystemKey )
}
}

private def checkModel( props: Map[Symbol, Any] ): Valid[DomainModel] = trace.block( "checkModel" ) {
props get demesne.ModelKey flatMap { _.cast[DomainModel] } map { _.successNel[Throwable] } getOrElse {
Validation.failureNel( UnspecifiedDomainModelError(demesne.ModelKey) )
val Model = TypeCase[DomainModel]

props.get( demesne.ModelKey ) match {
case Some( Model(m) ) => m.successNel[Throwable]
case Some( x ) => Validation failureNel IncompatibleTypeForPropertyError[DomainModel]( demesne.ModelKey, x )
case None => Validation failureNel UnspecifiedDomainModelError( demesne.ModelKey )
}
}

private def checkFactory( props: Map[Symbol, Any] ): Valid[ActorFactory] = trace.block( "checkFactory" ) {
val factory = props get demesne.FactoryKey flatMap { _.cast[ActorFactory] } getOrElse { demesne.factory.systemFactory }
factory.successNel
val Factory = TypeCase[ActorFactory]

props.get( demesne.FactoryKey ) match {
case Some( Factory(f) ) => f.successNel[Throwable]
case Some( x ) => Validation failureNel IncompatibleTypeForPropertyError[ActorFactory]( demesne.FactoryKey, x )
case None => demesne.factory.systemFactory.successNel[Throwable]
}
}

private def registerWithModel(
Expand All @@ -71,6 +89,12 @@ trait CommonInitializeAggregateActorType extends InitializeAggregateActorType {
object CommonInitializeAggregateActorType {
val trace = Trace[CommonInitializeAggregateActorType.type]

final case class IncompatibleTypeForPropertyError[T: ClassTag] private[demesne]( key: Symbol, value: Any )
extends IllegalArgumentException(
s"For key[${key.name}] expected type:[${implicitly[ClassTag[T]].runtimeClass.safeSimpleName}] " +
s"but got type:[${value.getClass.safeSimpleName}]"
)

final case class UnspecifiedActorSystemError private[demesne]( expectedKey: Symbol )
extends IllegalArgumentException( s"ActorSystem required at initialization property [$expectedKey]" ) with DemesneError

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/demesne/aggregateRootRepository.scala
Expand Up @@ -24,7 +24,7 @@ class EnvelopingAggregateRootRepository(
case message => {
val originalSender = sender()
trace( s"in EnvelopingAggregateRootRepository RECEIVE" )
aggregateFor( message ).send( message )( originalSender )
aggregateFor( message ).sendEnvelope( message )( originalSender )
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/test/resources/logback.xml
Expand Up @@ -17,7 +17,8 @@
</encoder>
</appender>

<root level="DEBUG">
<root level="INFO">
<!--<root level="DEBUG">-->
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
Expand Down
10 changes: 5 additions & 5 deletions examples/src/test/scala/blog/post/PostModuleSpec.scala
Expand Up @@ -98,7 +98,7 @@ class PostModuleSpec extends AggregateRootSpec[PostModuleSpec] with ScalaFutures

val id = PostModule.nextId.toOption.get
val post = PostModule aggregateOf id
post.send( GetContent( id ) )( author.ref )
post.sendEnvelope( GetContent( id ) )( author.ref )
author.expectMsgPF( max = 200.millis.dilated, hint = "empty contents" ){
case Envelope( payload: PostContent, h ) => {
payload mustBe PostContent( "", "", "" )
Expand All @@ -118,7 +118,7 @@ class PostModuleSpec extends AggregateRootSpec[PostModuleSpec] with ScalaFutures

val clientProbe = TestProbe()
post !+ AddPost( id, content )
post.send( GetContent( id ))( clientProbe.ref )
post.sendEnvelope( GetContent( id ))( clientProbe.ref )
clientProbe.expectMsgPF( max = 400.millis.dilated, hint = "initial contents" ){
case Envelope( payload: PostContent, h ) if payload == content => true
}
Expand Down Expand Up @@ -146,7 +146,7 @@ class PostModuleSpec extends AggregateRootSpec[PostModuleSpec] with ScalaFutures
case Envelope( payload: BodyChanged, _ ) => payload.body mustBe updated
}

post.send( GetContent( id ) )( clientProbe.ref )
post.sendEnvelope( GetContent( id ) )( clientProbe.ref )
clientProbe.expectMsgPF( max = 200.millis.dilated, hint = "changed contents" ){
case Envelope( payload: PostContent, h ) => payload mustBe content.copy( body = updated )
}
Expand All @@ -164,7 +164,7 @@ class PostModuleSpec extends AggregateRootSpec[PostModuleSpec] with ScalaFutures
post !+ AddPost( id, content )
post !+ ChangeBody( id, updated )
post !+ Publish( id )
post.send( GetContent( id ) )( clientProbe.ref )
post.sendEnvelope( GetContent( id ) )( clientProbe.ref )
clientProbe.expectMsgPF( max = 400.millis.dilated, hint = "changed contents" ){
case Envelope( payload: PostContent, h ) => payload mustBe content.copy( body = updated )
}
Expand All @@ -183,7 +183,7 @@ class PostModuleSpec extends AggregateRootSpec[PostModuleSpec] with ScalaFutures
post !+ ChangeBody( id, updated )
post !+ Publish( id )
post !+ ChangeBody( id, "BAD CONTENT" )
post.send( GetContent( id ) )( clientProbe.ref )
post.sendEnvelope( GetContent( id ) )( clientProbe.ref )
clientProbe.expectMsgPF( max = 400.millis.dilated, hint = "changed contents" ){
case Envelope( payload: PostContent, h ) => payload mustBe content.copy( body = updated )
}
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Expand Up @@ -48,7 +48,7 @@ object Dependencies {
object facility {
val uuid = "com.eaio.uuid" % "uuid" % "3.4"
val config = "com.typesafe" % "config" % "1.3.0"
val shapeless = "com.chuusai" %% "shapeless" % "2.2.5"
val shapeless = "com.chuusai" %% "shapeless" % "2.3.1"
val inflector = "org.atteo" % "evo-inflector" % "1.2.1"
val squants = "com.squants" %% "squants" % "0.5.3"
val accord = "com.wix" %% "accord-core" % "0.5"
Expand Down
4 changes: 3 additions & 1 deletion project/plugins.sbt
Expand Up @@ -27,4 +27,6 @@ addSbtPlugin("com.typesafe.sbt" % "sbt-multi-jvm" % "0.3.11")

addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")

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

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M12")

0 comments on commit bb4b1c8

Please sign in to comment.