package Ġorg . ara qn id . event store . filesystem . flat pack Ċ Ċ import Ġorg . ara qn id . event store . Gu ava Blob Ċ import Ġorg . ara qn id . event store . New Event Ċ import Ġorg . ara qn id . event store . Stream Id Ċ import Ġorg . ara qn id . event store . Wrong Expected Version Exception Ċ import Ġorg . ara qn id . event store . filesystem . e quivalent To Ċ import Ġorg . ara qn id . event store . testutil . NI OT emp orary Folder Ċ import Ġorg . ara qn id . kotlin . assert that . assertThat Ċ import Ġorg . ara qn id . kotlin . assert that . contains Substring Ċ import Ġorg . ara qn id . kotlin . assert that . contains The Item Ċ import Ġorg . ara qn id . kotlin . assert that . equalTo Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġjava . time . Clock Ċ import Ġjava . time . Instant Ċ import Ġjava . time . Zone Offset . UTC Ċ Ċ class ĠFlat Pack Filesystem Event Stream Writer Test Ġ{ ĊĠĠĠ Ġ@ get : Rule ĊĠĠĠ Ġval Ġfolder Ġ= ĠNI OT emp orary Folder () ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` writes Ġevent Ġas Ġloose Ġfiles `() Ġ{ ĊĠĠĠĠĠĠĠ Ġevent Stream Writer At ( Instant . parse (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. write ( Stream Id (" category ", Ġ" stream "), ĠlistOf ( New Event (" EventType ", ĠGu ava Blob . fromString (""" {" key ":" value "} "" ")) )) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z . category . stream . 0 . EventType . json "), Ġequivalent To ("{ key :\" value \" } ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . files (), Ġ! contains The Item ( contains Substring (" LOCK "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` writes Ġusing Ġnext Ġevent Ġnumber Ġafter Ġloose Ġfile `() Ġ{ ĊĠĠĠĠĠĠĠ Ġfolder . given L oose File (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . category . stream . 0 . EventType . json ", Ġ""" {" when ":" early "} """) ĊĠĠĠĠĠĠĠ Ġevent Stream Writer At ( Instant . parse (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. write ( Stream Id (" category ", Ġ" stream "), ĠlistOf ( New Event (" EventType ", ĠGu ava Blob . fromString (""" {" when ":" late "} "" ")) )) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z . category . stream . 1 . EventType . json "), Ġequivalent To ("{ when :\" late \" } ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . files (), Ġ! contains The Item ( contains Substring (" LOCK "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` writes Ġevent Ġwith Ġsatisfied Ġexpectation `() Ġ{ ĊĠĠĠĠĠĠĠ Ġfolder . given L oose File (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . category . stream . 0 . EventType . json ", Ġ""" {" when ":" early "} """) ĊĠĠĠĠĠĠĠ Ġevent Stream Writer At ( Instant . parse (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. write ( Stream Id (" category ", Ġ" stream "), Ġ 0 L , ĠlistOf ( New Event (" EventType ", ĠGu ava Blob . fromString (""" {" when ":" late "} "" ")) )) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z . category . stream . 1 . EventType . json "), Ġequivalent To ("{ when :\" late \" } ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . files (), Ġ! contains The Item ( contains Substring (" LOCK "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` ref uses Ġto Ġwrite Ġevent Ġwith Ġun satisfied Ġexpectation `() Ġ{ ĊĠĠĠĠĠĠĠ Ġfolder . given L oose File (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . category . stream . 0 . EventType . json ", Ġ""" {" when ":" early "} """) ĊĠĠĠĠĠĠĠ ĠassertThrows < Wrong Expected Version Exception > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġevent Stream Writer At ( Instant . parse (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. write ( Stream Id (" category ", Ġ" stream "), Ġ 2 L , ĠlistOf ( New Event (" EventType ", ĠGu ava Blob . fromString (""" {" when ":" late "} "" ")) )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertThat ( folder . files (), ĠequalTo ( set Of (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . category . stream . 0 . EventType . json "))) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` writes Ġusing Ġdistinct Ġevent Ġnumbers Ġin Ġa Ġsingle Ġcall `() Ġ{ ĊĠĠĠĠĠĠĠ Ġfolder . given L oose File (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . category . stream . 0 . EventType . json ", Ġ""" {" when ":" early "} """) ĊĠĠĠĠĠĠĠ Ġevent Stream Writer At ( Instant . parse (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. write ( Stream Id (" category ", Ġ" stream "), ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠNew Event (" EventType ", ĠGu ava Blob . fromString (""" {" when ":" medium "} "" ")), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠNew Event (" EventType ", ĠGu ava Blob . fromString (""" {" when ":" late "} "" ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ)) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z . category . stream . 1 . EventType . json "), Ġequivalent To ("{ when :\" medium \" } ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z . category . stream . 2 . EventType . json "), Ġequivalent To ("{ when :\" late \" } ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . files (), Ġ! contains The Item ( contains Substring (" LOCK "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` writes Ġusing Ġdistinct Ġevent Ġnumbers Ġacross Ġtwo Ġcalls `() Ġ{ ĊĠĠĠĠĠĠĠ Ġfolder . given L oose File (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . category . stream . 0 . EventType . json ", Ġ""" {" when ":" early "} """) ĊĠĠĠĠĠĠĠ Ġevent Stream Writer At ( Instant . parse (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z ")). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwrite ( Stream Id (" category ", Ġ" stream "), ĠlistOf ( New Event (" EventType ", ĠGu ava Blob . fromString (""" {" when ":" medium "} "" ")) )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwrite ( Stream Id (" category ", Ġ" stream "), ĠlistOf ( New Event (" EventType ", ĠGu ava Blob . fromString (""" {" when ":" late "} "" ")) )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z . category . stream . 1 . EventType . json "), Ġequivalent To ("{ when :\" medium \" } ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z . category . stream . 2 . EventType . json "), Ġequivalent To ("{ when :\" late \" } ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . files (), Ġ! contains The Item ( contains Substring (" LOCK "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` writes Ġusing Ġnext Ġevent Ġnumber Ġafter Ġpacked Ġfile Ġand Ġcreates Ġmanifest `() Ġ{ ĊĠĠĠĠĠĠĠ Ġfolder . given Pack File (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . cp io . xz ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Entry (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . category . stream . 0 . EventType . json ", Ġ""" { Ġ" type ": Ġ" packed " Ġ} """) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġevent Stream Writer At ( Instant . parse (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. write ( Stream Id (" category ", Ġ" stream "), ĠlistOf ( New Event (" EventType ", ĠGu ava Blob . fromString (""" {" when ":" late "} "" ")) )) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 2 3 : 4 5 . 1 2 3 Z . category . stream . 1 . EventType . json "), Ġequivalent To ("{ when :\" late \" } ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . manifest "), ĠequalTo (" category Ġstream Ġ 0 ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . files (), Ġ! contains The Item ( contains Substring (" LOCK "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test Ġfun Ġ` only Ġscans Ġmost Ġrecent Ġpack Ġfile Ġcontaining Ġevent Ġin Ġrelevant Ġstream `() Ġ{ ĊĠĠĠĠĠĠĠ Ġfolder . given Pack File (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . cp io . xz ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Entry (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . category . stream A . 0 . EventType . json ", Ġ""" { Ġ" type ": Ġ" packed " Ġ} """) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġfolder . given Pack File (" 2 0 1 7 - 0 3 - 1 3 T 2 0 : 0 0 : 0 0 . 0 0 0 Z . cp io . xz ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Entry (" 2 0 1 7 - 0 3 - 1 3 T 2 0 : 0 0 : 0 0 . 0 0 0 Z . category . stream A . 1 . EventType . json ", Ġ""" { Ġ" type ": Ġ" packed " Ġ} """) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġevent Stream Writer At ( Instant . parse (" 2 0 1 7 - 0 8 - 0 1 T 0 0 : 0 0 : 0 0 Z ")) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. write ( Stream Id (" category ", Ġ" stream A "), ĠlistOf ( New Event (" EventType ", ĠGu ava Blob . fromString (""" {" when ":" late "} "" ")) )) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 8 - 0 1 T 0 0 : 0 0 : 0 0 Z . category . stream A . 2 . EventType . json "), Ġequivalent To ("{ when :\" late \" } ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . text FileContent (" 2 0 1 7 - 0 3 - 1 3 T 2 0 : 0 0 : 0 0 . 0 0 0 Z . manifest "), ĠequalTo (" category Ġstream A Ġ 1 ")) ĊĠĠĠĠĠĠĠ ĠassertThat ( folder . files (), Ġ! contains The Item ( equalTo (" 2 0 1 7 - 0 3 - 1 3 T 1 9 : 0 0 : 0 0 . 0 0 0 Z . manifest "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġevent Stream Writer At ( now : ĠInstant ) Ġ= ĠFlat Pack Filesystem Event Stream Writer ( folder . root , ĠClock . fixed ( now , ĠUTC ), ĠLock able ()) Ċ } Ċ Ċ private Ġinline Ġfun Ġ< re ified ĠX Ġ: ĠThrowable > ĠassertThrows ( cross inline Ġbody : Ġ() Ġ-> ĠUnit ) Ġ{ ĊĠĠĠ ĠAssert . assert Throws ( X :: class . java ) Ġ{ Ġbody () Ġ} Ċ } Ċ