Skip to content

Commit

Permalink
optimized imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Damon Rolfs committed Sep 28, 2014
1 parent 72a6926 commit 7b41ceb
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 38 deletions.
3 changes: 1 addition & 2 deletions examples/src/test/scala/blog/post/PostModuleSpec.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package blog.post

import akka.testkit.{TestActorRef, TestProbe}
import akka.testkit.TestProbe
//import contoso.conference.registration.OrderModule
import demesne._
import demesne.testkit.AggregateRootSpec
import org.scalatest.Tag
import peds.akka.envelope.Envelope
import peds.akka.publish.ReliableMessage
import peds.commons.log.Trace
import sample.blog.post.PostModule.PostState
import sample.blog.post._

import scala.concurrent.duration._
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/demesne/AggregateRootRef.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package demesne

import akka.actor.{ActorSystem, ActorContext, ActorPath, ActorRef}
import akka.actor.{ActorContext, ActorPath, ActorRef, ActorSystem}
import peds.akka.envelope._
import peds.commons.log.Trace

Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/demesne/AggregateStateSpecification.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package demesne

import scala.reflect.ClassTag
import akka.persistence.SnapshotOffer
import com.typesafe.scalalogging.LazyLogging
import peds.commons.util._

import scala.reflect.ClassTag


trait AggregateStateSpecification[S] extends LazyLogging { outer =>
type Acceptance = PartialFunction[Any, S]
Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/demesne/PassivationSpecification.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package demesne

import scala.concurrent.duration._
import akka.contrib.pattern.ShardRegion.Passivate

import scala.concurrent.duration._


object PassivationSpecification {
case object DoNotPassivate extends PassivationSpecification {
override def inactivityTimeout: Duration = Duration.Undefined
}
}

trait PassivationSpecification {
trait PassivationSpecification {
def inactivityTimeout: Duration
def passivationMessage( message: Any ): Any = Passivate( stopMessage = message )
}
17 changes: 9 additions & 8 deletions src/main/scala/demesne/SnapshotSpecification.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package demesne

import akka.actor.{ActorRef, ActorSystem, Cancellable}

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
import akka.actor.{ ActorRef, ActorSystem, Cancellable }


object SnapshotSpecification {
Expand All @@ -12,18 +13,18 @@ object SnapshotSpecification {
}
}

trait SnapshotSpecification {
trait SnapshotSpecification {
def snapshotInitialDelay: FiniteDuration
def snapshotInterval: FiniteDuration

private[this] var cancellable: Option[Cancellable] = None

final def schedule(
system: ActorSystem,
target: ActorRef,
saveSnapshotCommand: Any = SaveSnapshot
)(
implicit executor: ExecutionContext
final def schedule(
system: ActorSystem,
target: ActorRef,
saveSnapshotCommand: Any = SaveSnapshot
)(
implicit executor: ExecutionContext
): Unit = {
cancellable = Option( system.scheduler.schedule( snapshotInitialDelay, snapshotInterval, target, saveSnapshotCommand ) )
}
Expand Down
24 changes: 12 additions & 12 deletions src/main/scala/demesne/aggregateRootRepository.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package demesne

import akka.actor.{ Actor, ActorRef, ActorLogging, Props }
import akka.actor.{Actor, ActorLogging, ActorRef, Props}
import akka.contrib.pattern.ShardRegion
import akka.event.LoggingReceive
import peds.akka.envelope._
Expand Down Expand Up @@ -28,9 +28,9 @@ object EnvelopingAggregateRootRepository {
val name = rootType.name

AggregateRootRepository.ClusterShardingSpecification(
name = s"${name}Repository",
name = s"${name}Repository",
props = props( rootType ),
idExtractor = { case c => ( name, c ) },
idExtractor = { case c => ( name, c ) },
shardResolver = { case c => ( math.abs( name.hashCode ) % 100 ).toString }
)
}
Expand All @@ -40,9 +40,9 @@ object EnvelopingAggregateRootRepository {
/**
* Supervisor for aggregate root actors. All client commands will go through this actor, who resolves/extracts the aggregate's id
* from the command and either finds the aggregate or (if there is no such aggregate) creates the new aggregate and delegates the
* command.
* command.
*
* In addition to connecting clients with aggregates, this actor is a supervisor responsible for taking care of its child
* In addition to connecting clients with aggregates, this actor is a supervisor responsible for taking care of its child
* aggregates, handling fault handling and recovery actions.
*/
class AggregateRootRepository( aggregateRootType: AggregateRootType ) extends Actor with EnvelopingActor with ActorLogging {
Expand Down Expand Up @@ -70,24 +70,24 @@ class AggregateRootRepository( aggregateRootType: AggregateRootType ) extends Ac

object AggregateRootRepository {
val trace = Trace[AggregateRootRepository.type]
def props( rootType: AggregateRootType ): Props = trace.block( "AggregateRootRepository" ) {
def props( rootType: AggregateRootType ): Props = trace.block( "AggregateRootRepository" ) {
Props( classOf[AggregateRootRepository], rootType )
}

case class ClusterShardingSpecification(
name: String,
case class ClusterShardingSpecification(
name: String,
props: Props,
idExtractor: ShardRegion.IdExtractor,
shardResolver: ShardRegion.ShardResolver
idExtractor: ShardRegion.IdExtractor,
shardResolver: ShardRegion.ShardResolver
)

def specificationFor( rootType: AggregateRootType ): ClusterShardingSpecification = {
val name = rootType.name

ClusterShardingSpecification(
name = s"${name}Repository",
name = s"${name}Repository",
props = props( rootType ),
idExtractor = { case c => ( name, c ) },
idExtractor = { case c => ( name, c ) },
shardResolver = { case c => ( math.abs( name.hashCode ) % 100 ).toString }
)
}
Expand Down
10 changes: 3 additions & 7 deletions testkit/src/main/scala/demesne/testkit/AggregateRootSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ package demesne.testkit

import java.util.concurrent.atomic.AtomicInteger

import akka.actor.{ActorRef, ActorSystem, PoisonPill, Terminated}
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import akka.util.Timeout
import demesne.{DomainModel, AggregateRootModule}
import demesne.{AggregateRootModule, DomainModel}
import org.scalatest._
import org.scalatest.mock.MockitoSugar
import peds.commons.log.Trace

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.reflect.ClassTag
import scala.util.Failure
import peds.commons.log.Trace


object AggregateRootSpec {
Expand Down
5 changes: 2 additions & 3 deletions testkit/src/main/scala/demesne/testkit/ParallelAkkaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger

import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.MustMatchers
import org.scalatest.{Outcome, ParallelTestExecution, fixture}
import org.scalatest.{MustMatchers, Outcome, ParallelTestExecution, fixture}


object ParallelAkkaTest {
Expand All @@ -15,7 +14,7 @@ object ParallelAkkaTest {

// Runs each individual test in parallel. Only possible with Fixture isolation
trait ParallelAkkaSpec extends fixture.WordSpec with MustMatchers with ParallelTestExecution {
import ParallelAkkaTest._
import demesne.testkit.ParallelAkkaTest._

type Fixture <: AkkaFixture
type FixtureParam = Fixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger

import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{Outcome, MustMatchers, fixture}
import org.scalatest.{MustMatchers, Outcome, fixture}


object SequentialAkkaSpecWithIsolatedFixture {
Expand All @@ -13,7 +13,7 @@ object SequentialAkkaSpecWithIsolatedFixture {

// Runs each test sequentially but provides fixture isolation
trait SequentialAkkaSpecWithIsolatedFixture extends fixture.WordSpec with MustMatchers {
import SequentialAkkaSpecWithIsolatedFixture._
import demesne.testkit.SequentialAkkaSpecWithIsolatedFixture._

type Fixture <: TestKit
type FixtureParam = Fixture
Expand Down

0 comments on commit 7b41ceb

Please sign in to comment.