Axon: JUnit Test. How to change the creation time of given events by testFixture?










0














i try to test the ordering of event and i need a possibility to change a creation event time of given events by the testFixture in JUunit test.



in the test method i have already tryed following, i set the given current time of testFixture andGivenCurrentTime to yesterday



final Instant minus = Instant.now().minus(1, ChronoUnit.DAYS);

testFixture.given(someInitializationEvent, someUpdateEvent).andGivenCurrentTime(minus)
.when(reduceCommand)
.expectEvents(new ReduceApprovedEvent(anyString, order.getQuantity()));


but i if i start this test, i got an event, on event sourcing handler method on(...), with current timestamp instant yesterday. the timestamp of event was not changed



@EventSourcingHandler
protected void on(AvailableQuantityUpdatedEvent event, @Timestamp Instant timeStamp)
this.quantity = event.getQuantity();
this.lastUpdateFromPartner = Date.from(timeStamp);



what do i'm wrong?
And how can i handle this?



thx.










share|improve this question


























    0














    i try to test the ordering of event and i need a possibility to change a creation event time of given events by the testFixture in JUunit test.



    in the test method i have already tryed following, i set the given current time of testFixture andGivenCurrentTime to yesterday



    final Instant minus = Instant.now().minus(1, ChronoUnit.DAYS);

    testFixture.given(someInitializationEvent, someUpdateEvent).andGivenCurrentTime(minus)
    .when(reduceCommand)
    .expectEvents(new ReduceApprovedEvent(anyString, order.getQuantity()));


    but i if i start this test, i got an event, on event sourcing handler method on(...), with current timestamp instant yesterday. the timestamp of event was not changed



    @EventSourcingHandler
    protected void on(AvailableQuantityUpdatedEvent event, @Timestamp Instant timeStamp)
    this.quantity = event.getQuantity();
    this.lastUpdateFromPartner = Date.from(timeStamp);



    what do i'm wrong?
    And how can i handle this?



    thx.










    share|improve this question
























      0












      0








      0







      i try to test the ordering of event and i need a possibility to change a creation event time of given events by the testFixture in JUunit test.



      in the test method i have already tryed following, i set the given current time of testFixture andGivenCurrentTime to yesterday



      final Instant minus = Instant.now().minus(1, ChronoUnit.DAYS);

      testFixture.given(someInitializationEvent, someUpdateEvent).andGivenCurrentTime(minus)
      .when(reduceCommand)
      .expectEvents(new ReduceApprovedEvent(anyString, order.getQuantity()));


      but i if i start this test, i got an event, on event sourcing handler method on(...), with current timestamp instant yesterday. the timestamp of event was not changed



      @EventSourcingHandler
      protected void on(AvailableQuantityUpdatedEvent event, @Timestamp Instant timeStamp)
      this.quantity = event.getQuantity();
      this.lastUpdateFromPartner = Date.from(timeStamp);



      what do i'm wrong?
      And how can i handle this?



      thx.










      share|improve this question













      i try to test the ordering of event and i need a possibility to change a creation event time of given events by the testFixture in JUunit test.



      in the test method i have already tryed following, i set the given current time of testFixture andGivenCurrentTime to yesterday



      final Instant minus = Instant.now().minus(1, ChronoUnit.DAYS);

      testFixture.given(someInitializationEvent, someUpdateEvent).andGivenCurrentTime(minus)
      .when(reduceCommand)
      .expectEvents(new ReduceApprovedEvent(anyString, order.getQuantity()));


      but i if i start this test, i got an event, on event sourcing handler method on(...), with current timestamp instant yesterday. the timestamp of event was not changed



      @EventSourcingHandler
      protected void on(AvailableQuantityUpdatedEvent event, @Timestamp Instant timeStamp)
      this.quantity = event.getQuantity();
      this.lastUpdateFromPartner = Date.from(timeStamp);



      what do i'm wrong?
      And how can i handle this?



      thx.







      axon






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 7:52









      user1167253

      378419




      378419






















          1 Answer
          1






          active

          oldest

          votes


















          1














          The givenCurrentTime() instruction for the fixture was originally meant for testing deadlines using the deadline manager. By changing the time, one could trigger deadlines to occur.



          However, the APIs may cause confusion and make its user believe it's meant to set the clock for the events as well.



          Also, in your fixture, you set the clock to a timestamp after publishing the events. Even if the givenCurrentTime() method were to change the event's clock, it would not affect any events already recorded.






          share|improve this answer




















          • Thx, but how can I change the event‘s clock before publishing the events?
            – user1167253
            Nov 13 at 3:41










          • There is a fix to the API in AxonFramework 4.0.1 that should help. You can now set the time before registering events, and the time is now also used to set the timestamp for events.
            – Allard
            Nov 16 at 12:01










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257856%2faxon-junit-test-how-to-change-the-creation-time-of-given-events-by-testfixture%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The givenCurrentTime() instruction for the fixture was originally meant for testing deadlines using the deadline manager. By changing the time, one could trigger deadlines to occur.



          However, the APIs may cause confusion and make its user believe it's meant to set the clock for the events as well.



          Also, in your fixture, you set the clock to a timestamp after publishing the events. Even if the givenCurrentTime() method were to change the event's clock, it would not affect any events already recorded.






          share|improve this answer




















          • Thx, but how can I change the event‘s clock before publishing the events?
            – user1167253
            Nov 13 at 3:41










          • There is a fix to the API in AxonFramework 4.0.1 that should help. You can now set the time before registering events, and the time is now also used to set the timestamp for events.
            – Allard
            Nov 16 at 12:01















          1














          The givenCurrentTime() instruction for the fixture was originally meant for testing deadlines using the deadline manager. By changing the time, one could trigger deadlines to occur.



          However, the APIs may cause confusion and make its user believe it's meant to set the clock for the events as well.



          Also, in your fixture, you set the clock to a timestamp after publishing the events. Even if the givenCurrentTime() method were to change the event's clock, it would not affect any events already recorded.






          share|improve this answer




















          • Thx, but how can I change the event‘s clock before publishing the events?
            – user1167253
            Nov 13 at 3:41










          • There is a fix to the API in AxonFramework 4.0.1 that should help. You can now set the time before registering events, and the time is now also used to set the timestamp for events.
            – Allard
            Nov 16 at 12:01













          1












          1








          1






          The givenCurrentTime() instruction for the fixture was originally meant for testing deadlines using the deadline manager. By changing the time, one could trigger deadlines to occur.



          However, the APIs may cause confusion and make its user believe it's meant to set the clock for the events as well.



          Also, in your fixture, you set the clock to a timestamp after publishing the events. Even if the givenCurrentTime() method were to change the event's clock, it would not affect any events already recorded.






          share|improve this answer












          The givenCurrentTime() instruction for the fixture was originally meant for testing deadlines using the deadline manager. By changing the time, one could trigger deadlines to occur.



          However, the APIs may cause confusion and make its user believe it's meant to set the clock for the events as well.



          Also, in your fixture, you set the clock to a timestamp after publishing the events. Even if the givenCurrentTime() method were to change the event's clock, it would not affect any events already recorded.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 13:38









          Allard

          1,07165




          1,07165











          • Thx, but how can I change the event‘s clock before publishing the events?
            – user1167253
            Nov 13 at 3:41










          • There is a fix to the API in AxonFramework 4.0.1 that should help. You can now set the time before registering events, and the time is now also used to set the timestamp for events.
            – Allard
            Nov 16 at 12:01
















          • Thx, but how can I change the event‘s clock before publishing the events?
            – user1167253
            Nov 13 at 3:41










          • There is a fix to the API in AxonFramework 4.0.1 that should help. You can now set the time before registering events, and the time is now also used to set the timestamp for events.
            – Allard
            Nov 16 at 12:01















          Thx, but how can I change the event‘s clock before publishing the events?
          – user1167253
          Nov 13 at 3:41




          Thx, but how can I change the event‘s clock before publishing the events?
          – user1167253
          Nov 13 at 3:41












          There is a fix to the API in AxonFramework 4.0.1 that should help. You can now set the time before registering events, and the time is now also used to set the timestamp for events.
          – Allard
          Nov 16 at 12:01




          There is a fix to the API in AxonFramework 4.0.1 that should help. You can now set the time before registering events, and the time is now also used to set the timestamp for events.
          – Allard
          Nov 16 at 12:01

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53257856%2faxon-junit-test-how-to-change-the-creation-time-of-given-events-by-testfixture%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto