package Ġcom . graph ene . writer . store . key . property Ċ Ċ import Ġcom . graph ene . common . key . Rotation Property Ċ import Ġcom . graph ene . common . key . Time Based Rotation Strategy Ċ import Ġio . kot lint est . tables . for All Ċ import Ġio . kot lint est . tables . headers Ċ import Ġio . kot lint est . tables . row Ċ import Ġio . kot lint est . tables . table Ċ import Ġjava . text . SimpleDateFormat Ċ import Ġkotlin . test . assertEquals Ċ import Ġorg . joda . time . DateTime Utils Ċ import Ġorg . junit . jupiter . api . Test Ċ Ċ internal Ġclass ĠTime Based Rotation Strategy Test Ġ{ ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` should Ġreturn Ġcurrent Ġtime Ġwith Ġday Ġunit `() Ġ{ ĊĠĠĠ Ġtable ( ĊĠĠĠĠĠ Ġheaders (" currentTime ", Ġ" expected Index Date "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 1 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 1 0 0 1 "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 2 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 1 0 0 2 "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 2 - 3 1 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 1 2 3 1 ") ĊĠĠĠ Ġ). for All Ġ{ ĠcurrentTime , Ġexpected Index Date Ġ-> ĊĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠ Ġval Ġrotation Property Ġ= ĠRotation Property ( period Ġ= Ġ" 1 d ") ĊĠĠĠĠĠ ĠsetCurrent Millis Fixed ( currentTime ) ĊĊĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠ Ġval Ġtime Based Rotation Strategy Ġ= ĠTime Based Rotation Strategy ( rotation Property ) ĊĊĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠ ĠassertEquals ( expected Index Date , Ġtime Based Rotation Strategy . getIndex With Current Date (" index ", Ġ" tenant ")) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` should Ġreturn Ġcurrent Ġtime Ġwith Ġweek Ġunit `() Ġ{ ĊĠĠĠ Ġtable ( ĊĠĠĠĠĠ Ġheaders (" currentTime ", Ġ" expected Index Date "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 1 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 2 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 3 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 4 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 5 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 6 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 7 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 1 "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 2 - 3 1 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 2 0 - w 0 1 "), ĊĠĠĠĠĠ Ġrow (" 2 0 2 0 - 0 1 - 0 1 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 2 0 - w 0 1 "), ĊĠĠĠĠĠ Ġrow (" 2 0 2 0 - 0 1 - 0 8 Ġ 0 0 : 0 0 : 0 0 ", Ġ" index _ tenant _ 2 0 2 0 - w 0 2 ") ĊĠĠĠ Ġ). for All Ġ{ ĠcurrentTime , Ġexpected Index Date Ġ-> ĊĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠ Ġval Ġrotation Property Ġ= ĠRotation Property ( period Ġ= Ġ" 1 w ") ĊĠĠĠĠĠ ĠsetCurrent Millis Fixed ( currentTime ) ĊĊĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠ Ġval Ġtime Based Rotation Strategy Ġ= ĠTime Based Rotation Strategy ( rotation Property ) ĊĊĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠ ĠassertEquals ( expected Index Date , Ġtime Based Rotation Strategy . getIndex With Current Date (" index ", Ġ" tenant ")) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` should Ġcalculate Ġweeks Ġbetween Ġfrom Ġand Ġuntil `() Ġ{ ĊĠĠĠ Ġtable ( ĊĠĠĠĠĠ Ġheaders (" from ", Ġ" to ", Ġ" expected Indexes "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 7 Ġ 1 0 : 0 0 : 0 0 ", Ġ" 2 0 1 9 - 1 0 - 0 7 Ġ 1 1 : 0 0 : 0 0 ", Ġset Of (" index _ tenant _ 2 0 1 9 - w 4 1 ")), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 7 Ġ 1 0 : 0 0 : 0 0 ", Ġ" 2 0 1 9 - 1 0 - 1 4 Ġ 1 1 : 0 0 : 0 0 ", Ġset Of (" index _ tenant _ 2 0 1 9 - w 4 1 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 2 ")), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 0 - 0 7 Ġ 1 0 : 0 0 : 0 0 ", Ġ" 2 0 1 9 - 1 0 - 2 1 Ġ 1 1 : 0 0 : 0 0 ", Ġset Of (" index _ tenant _ 2 0 1 9 - w 4 1 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 2 ", Ġ" index _ tenant _ 2 0 1 9 - w 4 3 ")), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 2 - 3 0 Ġ 1 0 : 0 0 : 0 0 ", Ġ" 2 0 1 9 - 1 2 - 3 1 Ġ 1 1 : 0 0 : 0 0 ", Ġset Of (" index _ tenant _ 2 0 2 0 - w 0 1 ")) ĊĠĠĠ Ġ). for All Ġ{ Ġfrom , Ġto , Ġexpected Indexes Ġ-> ĊĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠ Ġval Ġtime Based Rotation Strategy Ġ= ĠTime Based Rotation Strategy ( Rotation Property ( period Ġ= Ġ" 1 w ")) ĊĊĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠ Ġval Ġindexes Ġ= Ġtime Based Rotation Strategy . get Range Index (" index ", Ġ" tenant ", Ġcom . graph ene . common . utils . DateTime Utils . from ( from ), Ġcom . graph ene . common . utils . DateTime Utils . from ( to )) ĊĊĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠ ĠassertEquals ( expected Indexes , Ġindexes ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` should Ġcalculate Ġweeks Ġbetween Ġfrom Ġand Ġuntil Ġwhen Ġyear Ġis Ġdifferent `() Ġ{ ĊĠĠĠ Ġtable ( ĊĠĠĠĠĠ Ġheaders (" from ", Ġ" to ", Ġ" expected Indexes "), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 2 - 2 3 Ġ 1 0 : 0 0 : 0 0 ", Ġ" 2 0 2 0 - 0 1 - 0 6 Ġ 1 1 : 0 0 : 0 0 ", Ġset Of (" index _ tenant _ 2 0 1 9 - w 5 2 ", Ġ" index _ tenant _ 2 0 2 0 - w 0 1 ", Ġ" index _ tenant _ 2 0 2 0 - w 0 2 ")), ĊĠĠĠĠĠ Ġrow (" 2 0 1 9 - 1 2 - 3 0 Ġ 1 0 : 0 0 : 0 0 ", Ġ" 2 0 2 0 - 0 1 - 0 6 Ġ 1 1 : 0 0 : 0 0 ", Ġset Of (" index _ tenant _ 2 0 2 0 - w 0 1 ", Ġ" index _ tenant _ 2 0 2 0 - w 0 2 ")) ĊĠĠĠ Ġ). for All Ġ{ Ġfrom , Ġto , Ġexpected Indexes Ġ-> ĊĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠ Ġval Ġtime Based Rotation Strategy Ġ= ĠTime Based Rotation Strategy ( Rotation Property ( period Ġ= Ġ" 1 w ")) ĊĊĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠ Ġval Ġindexes Ġ= Ġtime Based Rotation Strategy . get Range Index (" index ", Ġ" tenant ", Ġcom . graph ene . common . utils . DateTime Utils . from ( from ), Ġcom . graph ene . common . utils . DateTime Utils . from ( to )) ĊĊĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠ ĠassertEquals ( expected Indexes , Ġindexes ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` should Ġcalculate Ġweeks Ġbetween Ġfrom Ġand Ġuntil Ġwhen Ġyear Ġis Ġdifferent 2 `() Ġ{ ĊĠĠĠ Ġ// Ġgiven ĊĠĠĠ Ġval Ġtime Based Rotation Strategy Ġ= ĠTime Based Rotation Strategy ( Rotation Property ( period Ġ= Ġ" 1 w ")) ĊĊĠĠĠ Ġ// Ġwhen ĊĠĠĠ Ġval Ġindexes Ġ= Ġtime Based Rotation Strategy . get Range Index (" index ", Ġ" tenant ", Ġcom . graph ene . common . utils . DateTime Utils . from (" 2 0 1 9 - 1 2 - 2 3 Ġ 1 0 : 0 0 : 0 0 "), Ġcom . graph ene . common . utils . DateTime Utils . from (" 2 0 2 1 - 0 1 - 0 8 Ġ 1 0 : 0 0 : 0 0 ")) ĊĊĠĠĠ Ġ// Ġthen ĊĠĠĠ Ġval Ġgiven Week Of 2 0 1 9 Ġ= Ġ 1 ĊĠĠĠ Ġval Ġgiven Week Of 2 0 2 1 Ġ= Ġ 1 ĊĠĠĠ ĠassertEquals ( given Week Of 2 0 1 9 Ġ+ ĠMAX IMUM _ WEEK _ OF _ YEAR Ġ+ Ġgiven Week Of 2 0 2 1 , Ġindexes . size ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġinternal Ġfun Ġ` should Ġcalculate Ġweeks Ġbased Ġon Ġtime Ġmilliseconds `() Ġ{ ĊĠĠĠ Ġtable ( ĊĠĠĠĠĠ Ġheaders (" currentTime ", Ġ" expected Index Date "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 1 9 - 1 0 - 0 1 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 1 9 - 1 0 - 0 2 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 1 9 - 1 0 - 0 3 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 1 9 - 1 0 - 0 4 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 1 9 - 1 0 - 0 5 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 1 9 - 1 0 - 0 6 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 1 9 - w 4 0 "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 1 9 - 1 0 - 0 7 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 1 9 - w 4 1 "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 1 9 - 1 2 - 3 1 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 2 0 - w 0 1 "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 2 0 - 0 1 - 0 1 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 2 0 - w 0 1 "), ĊĠĠĠĠĠ Ġrow ( com . graph ene . common . utils . DateTime Utils . from (" 2 0 2 0 - 0 1 - 0 8 Ġ 0 0 : 0 0 : 0 0 "), Ġ" index _ tenant _ 2 0 2 0 - w 0 2 ") ĊĠĠĠ Ġ). for All Ġ{ ĠcurrentTime , Ġexpected Index Date Ġ-> ĊĠĠĠĠĠ Ġ// Ġgiven ĊĠĠĠĠĠ Ġval Ġrotation Property Ġ= ĠRotation Property ( period Ġ= Ġ" 1 w ") ĊĊĠĠĠĠĠ Ġ// Ġwhen ĊĠĠĠĠĠ Ġval Ġtime Based Rotation Strategy Ġ= ĠTime Based Rotation Strategy ( rotation Property ) ĊĊĠĠĠĠĠ Ġ// Ġthen ĊĠĠĠĠĠ ĠassertEquals ( expected Index Date , Ġtime Based Rotation Strategy . getIndex With Date (" index ", Ġ" tenant ", ĠcurrentTime )) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġconst Ġval ĠMAX IMUM _ WEEK _ OF _ YEAR Ġ= Ġ 5 2 ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun ĠsetCurrent Millis Fixed ( date : ĠString ) Ġ{ ĊĠĠĠ Ġval ĠcurrentTime Ġ= ĠSimpleDateFormat (" yyyy - MM - dd ĠHH : mm : ss "). parse ( date ). time ĊĠĠĠ ĠDateTime Utils . setCurrent Millis Fixed ( currentTime ) ĊĠ Ġ} Ċ } Ċ