401279 (2) [Avatar] Offline
#1
Hello Debasish,

First of all, I want to thank you for this great book. It take some time to understand fully these difficult topics but it really opens new ways of thinking about program design.

I'am trying to implement a CQRS-ES approach and thus I explore in details examples from chapter 8.

I am encountering a strange behavior when trying to run some of these examples. More specifically, my problem is with cqrs.service and cqrs.memrepo, namely both examples that build Task when interpreting commands.

In cqrs.service.Scripts, I added the following main:

  def main(args:Array[String]) {
    import Event._
    val t = RepositoryBackedAccountInterpreter(composite)
    println(t)
    println(RepositoryBackedAccountInterpreter.eventLog.allEvents)
    t.run
    println(RepositoryBackedAccountInterpreter.eventLog.allEvents)
  }


and the output is this:
Task: scalaz.concurrent.Task@6166e06f
Events after task creation: \/-(List(Opened(a-123,debasish ghosh,Some(2016-08-05T15:22:43.047+02:00),2016-08-05T15:22:43.047+02:00,<function1>)))
Events after task execution: \/-(List(Debited(a-123,23000,2016-08-05T15:22:43.047+02:00,<function1>), Credited(a-123,30000,2016-08-05T15:22:43.047+02:00,<function1>), Credited(a-123,10000,2016-08-05T15:22:43.047+02:00,<function1>), Opened(a-123,debasish ghosh,Some(2016-08-05T15:22:43.047+02:00),2016-08-05T15:22:43.047+02:00,<function1>)))


So, in summary, the create command was handled before the task execution. More specifically, it was executed at task creation time.
Adding some println in the handleCommand function confirmed the fact:

handle create
Task: scalaz.concurrent.Task@6166e06f
Events after task creation: \/-(List(Opened(a-123,debasish ghosh,Some(2016-08-05T15:22:43.047+02:00),2016-08-05T15:22:43.047+02:00,<function1>)))
handle credit
handle credit
handle debit
Events after task execution: \/-(List(Debited(a-123,23000,2016-08-05T15:22:43.047+02:00,<function1>), Credited(a-123,30000,2016-08-05T15:22:43.047+02:00,<function1>), Credited(a-123,10000,2016-08-05T15:22:43.047+02:00,<function1>), Opened(a-123,debasish ghosh,Some(2016-08-05T15:22:43.047+02:00),2016-08-05T15:22:43.047+02:00,<function1>)))


As we can see, "Handle create" occurs during command interpretation, i.e. task creation...while other commands are handled during task execution, as expected


This sounds like a bug to me. No command should be executed before effective task execution. Isn'it ?

Thanks in advance for your answer!

Best regards,
Marc-Antoine
Debasish Ghosh (116) [Avatar] Offline
#2
Thanks for reporting .. I will take a look soon and get back to you.
Debasish Ghosh (116) [Avatar] Offline
#3
Indeed we had a bug there. Now fixed by the latest commit .. https://github.com/debasishg/frdomain/commit/48664c35b2e583aeacfcacd5d740687afb2ed1de .. Please try again and report if u still find any problem.

Thanks a lot.