{"action":"created","issue":{"url":"https://api.github.com/repos/AxonFramework/AxonFramework/issues/435","repository_url":"https://api.github.com/repos/AxonFramework/AxonFramework","labels_url":"https://api.github.com/repos/AxonFramework/AxonFramework/issues/435/labels{/name}","comments_url":"https://api.github.com/repos/AxonFramework/AxonFramework/issues/435/comments","events_url":"https://api.github.com/repos/AxonFramework/AxonFramework/issues/435/events","html_url":"https://github.com/AxonFramework/AxonFramework/issues/435","id":273486759,"number":435,"title":"Allow for an arbitrary Instant to be specified as the initial currentDateTime of the StubEventScheduler in a SagaTestFixture ","user":{"login":"martijnvanderwoud","id":1244238,"avatar_url":"https://avatars2.githubusercontent.com/u/1244238?v=4","gravatar_id":"","url":"https://api.github.com/users/martijnvanderwoud","html_url":"https://github.com/martijnvanderwoud","followers_url":"https://api.github.com/users/martijnvanderwoud/followers","following_url":"https://api.github.com/users/martijnvanderwoud/following{/other_user}","gists_url":"https://api.github.com/users/martijnvanderwoud/gists{/gist_id}","starred_url":"https://api.github.com/users/martijnvanderwoud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martijnvanderwoud/subscriptions","organizations_url":"https://api.github.com/users/martijnvanderwoud/orgs","repos_url":"https://api.github.com/users/martijnvanderwoud/repos","events_url":"https://api.github.com/users/martijnvanderwoud/events{/privacy}","received_events_url":"https://api.github.com/users/martijnvanderwoud/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-11-13T16:13:58Z","updated_at":"2017-11-14T13:12:11Z","closed_at":null,"author_association":"NONE","body":"It would be very nice if we could instantiate a `SagaTestFixture` with a `StubEventScheduler` initiated at an arbitrary point in time. \r\n\r\nThe current implementation of `SagaTestFixture` creates a `StubEventScheduler` inside its constructor. The `StubEventScheduler`, in turn, is initiated at the current system time. Additionally, the `advanceTimeTo` method refuses to set the current time to anything before the current value (as the name would suggest). There is no way to move the `StubEventScheduler` back in time once it is created (which makes sense). \r\n\r\nThe consequence of the current implementation: if you have time-sensitive Sagas, you cannot always test them reliably with arbitrary example dates, because the behavior of the test will change once the example date has passed. For example this test was working for me last week, but this week it fails: \r\n\r\n````\r\nZoneId timeZone = ZoneId.of(\"Europe/Amsterdam\");\r\n\t\tInstant challengeOpenedAt = LocalDateTime.of(2017, 11, 7, 11, 45)\r\n\t\t\t\t.atZone(timeZone).toInstant();\r\n\t\tInstant fourDaysAfterChallengeOpened = challengeOpenedAt.plus(4, ChronoUnit.DAYS);\r\n\t\tInstant fiveDaysAfterChallengeOpened = challengeOpenedAt.plus(5, ChronoUnit.DAYS);\r\n\t\tInstant sixDaysAfterChallengeOpened = challengeOpenedAt.plus(6, ChronoUnit.DAYS);\r\n\r\n\t\t/*\r\n\t\tThe event handling Saga looks at the Clock twice for each repetition: one time for constructing the\r\n\t\tTriggerFiringContext, and one time when activating the next DateTimeTrigger (it checks weather the\r\n\t\tdateTime specified in the trigger has already passed).\r\n\t\t*/\r\n\t\twhen(clock.instant())\r\n\t\t\t\t.thenReturn(fourDaysAfterChallengeOpened)\r\n\t\t\t\t.thenReturn(fourDaysAfterChallengeOpened)\r\n\t\t\t\t.thenReturn(fiveDaysAfterChallengeOpened)\r\n\t\t\t\t.thenReturn(fiveDaysAfterChallengeOpened)\r\n\t\t\t\t.thenReturn(sixDaysAfterChallengeOpened)\r\n\t\t;\r\n\r\n\t\tfixture\r\n\t\t\t\t.givenAPublished(new ChallengeOpened(\r\n\t\t\t\t\t\tchallengeId,\r\n\t\t\t\t\t\tchallengeTypeIdentifier,\r\n\t\t\t\t\t\tuserId,\r\n\t\t\t\t\t\tchallengePlanId,\r\n\t\t\t\t\t\tpresentBadgeRule,\r\n\t\t\t\t\t\tawardBadgeRule,\r\n\t\t\t\t\t\tnotificationRules\r\n\t\t\t\t))\r\n\t\t\t\t.andThenTimeElapses(Duration.ofDays(5))\r\n\t\t\t\t.andThenAPublished(new BadgeAwarded(challengeId, challengeTypeIdentifier, userId))\r\n\t\t\t\t.whenTimeElapses(Duration.ofDays(1))\r\n\t\t\t\t.expectNoDispatchedCommands()\r\n\t\t\t\t.expectActiveSagas(0);\r\n````\r\n\r\nOf course I can easily fix this test by replacing\r\n````\r\nInstant challengeOpenedAt = LocalDateTime.of(2017, 11, 7, 11, 45)\r\n\t\t\t\t.atZone(timeZone).toInstant();\r\n````\r\n\r\nwith \r\n````\r\n\t\tInstant challengeOpenedAt = fixture.currentTime();\r\n````\r\n\r\nwhich is fine in this case. But what if there is something special about my initial date (for instance, it is the last day of the week, month or year or something)? Then it would be nice if I could either do something like this:\r\n\r\n````\r\nfixture.givenCurrentTime(someInstant).andThenAPublished(...)\r\n````\r\nor, alternatively, provide a way to specify the initial date for the  StubEventScheduler inside the `SagaTestFixture` constructor\r\n\r\nI would be more than happy to spend some time working on a pull request if you like the idea\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/AxonFramework/AxonFramework/issues/comments/344254512","html_url":"https://github.com/AxonFramework/AxonFramework/issues/435#issuecomment-344254512","issue_url":"https://api.github.com/repos/AxonFramework/AxonFramework/issues/435","id":344254512,"user":{"login":"martijnvanderwoud","id":1244238,"avatar_url":"https://avatars2.githubusercontent.com/u/1244238?v=4","gravatar_id":"","url":"https://api.github.com/users/martijnvanderwoud","html_url":"https://github.com/martijnvanderwoud","followers_url":"https://api.github.com/users/martijnvanderwoud/followers","following_url":"https://api.github.com/users/martijnvanderwoud/following{/other_user}","gists_url":"https://api.github.com/users/martijnvanderwoud/gists{/gist_id}","starred_url":"https://api.github.com/users/martijnvanderwoud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martijnvanderwoud/subscriptions","organizations_url":"https://api.github.com/users/martijnvanderwoud/orgs","repos_url":"https://api.github.com/users/martijnvanderwoud/repos","events_url":"https://api.github.com/users/martijnvanderwoud/events{/privacy}","received_events_url":"https://api.github.com/users/martijnvanderwoud/received_events","type":"User","site_admin":false},"created_at":"2017-11-14T13:12:11Z","updated_at":"2017-11-14T13:12:11Z","author_association":"NONE","body":"Ok nice, what is the deadline for 3.1?"}}
{"actor":{"display_login":"martijnvanderwoud"}}