/* Ċ Ġ* ĠCopyright Ġ 2 0 1 7 ĠThe ĠHy ve Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġorg . radar base . output Ċ Ċ import Ġorg . junit . jupiter . api . Assertions .* Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġorg . junit . jupiter . api . io . TempDir Ċ import Ġorg . radar base . output . accounting . Offset File Persistence Ċ import Ġorg . radar base . output . accounting . Offset Persistence Factory Ċ import Ġorg . radar base . output . accounting . Topic Partition Ċ import Ġorg . radar base . output . accounting . Topic Partition Offset Range Ċ import Ġorg . radar base . output . config . Local Config Ċ import Ġorg . radar base . output . target . Local Target Storage Ċ import Ġorg . radar base . output . target . Target Storage Ċ import Ġjava . io . IOException Ċ import Ġjava . nio . file . Files Ċ import Ġjava . nio . file . Path Ċ import Ġjava . time . Instant Ċ Ċ class ĠOffset Range File Test Ġ{ ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtest File : ĠPath ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġtarget Storage : ĠTarget Storage ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġoffset Persistence : ĠOffset Persistence Factory ĊĠĠĠ Ġprivate Ġval Ġlast Modified Ġ= ĠInstant . now () ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġfun ĠsetUp (@ TempDir Ġdir : ĠPath ) Ġ{ ĊĠĠĠĠĠĠĠ Ġtest File Ġ= Ġdir . resolve (" test ") ĊĠĠĠĠĠĠĠ ĠFiles . create File ( test File ) ĊĠĠĠĠĠĠĠ Ġtarget Storage Ġ= ĠLocal Target Storage ( Local Config ()) ĊĠĠĠĠĠĠĠ Ġoffset Persistence Ġ= ĠOffset File Persistence ( target Storage ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġfun Ġread Empty () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( java . lang . Boolean . TRUE , Ġoffset Persistence . read ( test File )?. isEmpty ) ĊĊĠĠĠĠĠĠĠ Ġtarget Storage . delete ( test File ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġwill Ġnot Ġcreate ĊĠĠĠĠĠĠĠ ĠassertNull ( offset Persistence . read ( test File )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġfun Ġwrite () Ġ{ ĊĠĠĠĠĠĠĠ Ġoffset Persistence . writer ( test File ). use Ġ{ Ġrange File Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrange File . add ( Topic Partition Offset Range . parse Filename (" a + 0 + 0 + 1 ", Ġlast Modified )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrange File . add ( Topic Partition Offset Range . parse Filename (" a + 0 + 1 + 2 ", Ġlast Modified )) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġset Ġ= Ġoffset Persistence . read ( test File ) ĊĠĠĠĠĠĠĠ ĠassertNotNull ( set ) ĊĠĠĠĠĠĠĠ Ġrequire NotNull ( set ) ĊĠĠĠĠĠĠĠ ĠassertTrue ( set . contains ( Topic Partition Offset Range . parse Filename (" a + 0 + 0 + 1 ", Ġlast Modified ))) ĊĠĠĠĠĠĠĠ ĠassertTrue ( set . contains ( Topic Partition Offset Range . parse Filename (" a + 0 + 1 + 2 ", Ġlast Modified ))) ĊĠĠĠĠĠĠĠ ĠassertTrue ( set . contains ( Topic Partition Offset Range . parse Filename (" a + 0 + 0 + 2 ", Ġlast Modified ))) ĊĠĠĠĠĠĠĠ ĠassertFalse ( set . contains ( Topic Partition Offset Range . parse Filename (" a + 0 + 0 + 3 ", Ġlast Modified ))) ĊĠĠĠĠĠĠĠ ĠassertFalse ( set . contains ( Topic Partition Offset Range . parse Filename (" a + 0 + 2 + 3 ", Ġlast Modified ))) ĊĠĠĠĠĠĠĠ ĠassertFalse ( set . contains ( Topic Partition Offset Range . parse Filename (" a + 1 + 0 + 1 ", Ġlast Modified ))) ĊĠĠĠĠĠĠĠ ĠassertFalse ( set . contains ( Topic Partition Offset Range . parse Filename (" b + 0 + 0 + 1 ", Ġlast Modified ))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Throws ( IOException :: class ) ĊĠĠĠ Ġfun Ġclean Up () Ġ{ ĊĠĠĠĠĠĠĠ Ġoffset Persistence . writer ( test File ). use Ġ{ Ġrange File Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrange File . add ( Topic Partition Offset Range . parse Filename (" a + 0 + 0 + 1 ", Ġlast Modified )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrange File . add ( Topic Partition Offset Range . parse Filename (" a + 0 + 1 + 2 ", Ġlast Modified )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrange File . add ( Topic Partition Offset Range . parse Filename (" a + 0 + 4 + 4 ", Ġlast Modified )) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġtarget Storage . new BufferedReader ( test File ). use Ġ{ Ġbr Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertEquals ( 3 , Ġbr . lines (). count ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġrange Set Ġ= Ġoffset Persistence . read ( test File ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġrange Set ?. size ( Topic Partition (" a ", Ġ 0 ))) ĊĠĠĠ Ġ} Ċ } Ċ