package Ġorg . ara qn id . event store . subscription Ċ Ċ import Ġcom . t img roup . clock s . testing . Manual Clock Ċ import Ġorg . ara qn id . kotlin . assert that . assertThat Ċ import Ġorg . ara qn id . kotlin . assert that . equalTo Ċ import Ġorg . junit . Test Ċ import Ġjava . time . Clock Ċ import Ġjava . time . Duration Ċ Ċ class ĠSnapshot Trigger Test Ġ{ ĊĠĠĠ Ġprivate Ġval Ġclock Ġ= ĠManual Clock . init ially At ( Clock . system Default Zone ()) ĊĠĠĠ Ġprivate Ġval Ġtrigger Ġ= ĠSnapshot Trigger ( Test Position . codec , ĠDuration . of Minutes ( 5 ), ĠDuration . of Seconds ( 3 0 ), ĠDuration . of Minutes ( 2 ), Ġclock ) ĊĊĠĠĠ Ġ@ Test Ġfun Ġno _ snapshot _ in _ default _ state () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( false )) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write Initial Snapshot (), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġno _ snapshot _ immediate ly _ after _ event _ received () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġwrite _ initial _ snapshot _ immediate ly _ after _ event _ received () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write Initial Snapshot (), ĠequalTo ( true )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġwrite _ initial _ snapshot _ after _ event _ received _ be yond _ loaded _ snapshot () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . snapshot Loaded ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 2 L )) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write Initial Snapshot (), ĠequalTo ( true )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġno _ initial _ snapshot _ when _ no _ event _ received _ be yond _ loaded _ snapshot () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . snapshot Loaded ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write Initial Snapshot (), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġwrite _ snapshot _ after _ event _ received _ and _ quiet _ period _ has _ passed () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 4 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( true )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġno _ snapshot _ when _ another _ event _ restart s _ the _ quiet _ period () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 2 0 ) ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 2 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 2 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġsnapshot _ event ually _ required _ even _ when _ events _ keep _ ar riving () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġafter Ġ 2 Ġminutes ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 2 0 ) Ġ// ĠPT 2 0 S ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 2 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 2 0 ) Ġ// ĠPT 4 0 S ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 2 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 2 0 ) Ġ// ĠPT 1 M ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 2 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 2 0 ) Ġ// ĠPT 1 M 2 0 S ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 2 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 2 0 ) Ġ// ĠPT 1 M 4 0 S ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 2 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 2 0 ) Ġ// ĠPT 2 M ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( true )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġno _ snapshot _ after _ writing _ snapshot _ at _ event _ position () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 4 0 ) ĊĠĠĠĠĠĠĠ Ġtrigger . snapshot Written ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump ( Duration . of Minutes ( 1 0 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġno _ snapshot _ immediate ly _ after _ new _ event _ after _ snapshot _ write () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 4 0 ) ĊĠĠĠĠĠĠĠ Ġtrigger . snapshot Written ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump ( Duration . of Minutes ( 1 0 )) ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 2 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġwrite _ new _ event _ after _ quiet _ period () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 4 0 ) ĊĠĠĠĠĠĠĠ Ġtrigger . snapshot Written ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump ( Duration . of Minutes ( 1 0 )) ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 2 )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 4 0 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( true )) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ@ Test Ġfun Ġno _ snapshot _ immediate ly _ after _ writing _ snapshot _ before _ event _ position () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 4 0 ) ĊĠĠĠĠĠĠĠ Ġtrigger . snapshot Written ( Test Position ( 0 L )) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( false )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġstill _ need _ snapshot _ after _ writing _ snapshot _ before _ event _ position _ but _ after _ minimum _ interval () Ġ{ ĊĠĠĠĠĠĠĠ Ġtrigger . event Received ( Test Position ( 1 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump Seconds ( 4 0 ) ĊĠĠĠĠĠĠĠ Ġtrigger . snapshot Written ( Test Position ( 0 L )) ĊĠĠĠĠĠĠĠ Ġclock . bump ( Duration . of Minutes ( 6 )) ĊĠĠĠĠĠĠĠ ĠassertThat ( trigger . write New Snapshot (), ĠequalTo ( true )) ĊĠĠĠ Ġ} Ċ } Ċ