package Ġar cs . core . storage Ċ Ċ import Ġar cs . core . cr dt . Cr dt Count Ċ import Ġar cs . core . cr dt . Cr dt Data Ċ import Ġar cs . core . cr dt . Cr dt Exception Ċ import Ġar cs . core . cr dt . Cr dt Operation Ċ import Ġar cs . core . cr dt . Version Map Ċ import Ġar cs . core . data . Count Type Ċ import Ġar cs . core . storage . testutil . Dummy Storage Key Ċ import Ġar cs . core . storage . testutil . Fake Driver Ċ import Ġar cs . core . storage . testutil . Fake Driver Provider Ċ import Ġar cs . core . storage . testutil . Test Store Write Back Ċ import Ġar cs . flags . Build Flags Ċ import Ġar cs . jvm . util . Jvm Time Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġkotlinx . coroutines . Coroutine Scope Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . test . Test Coroutine Dispatcher Ċ import Ġkotlinx . coroutines . test . Test Coroutine Scope Ċ import Ġkotlinx . coroutines . test . run Blocking Test Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ Ċ @ Opt In ( Experimental Cor outines Api :: class ) Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠWrite Only Direct Store Test Ġ{ ĊĊĠ Ġprivate Ġval Ġtest Key : ĠStorage Key Ġ= ĠDummy Storage Key (" key ") ĊĠ Ġlateinit Ġvar Ġtest Store Write Back : ĠTest Store Write Back ĊĠ Ġlateinit Ġvar Ġtest Write Back Provider : ĠWrite Back Provider ĊĊĠ Ġ@ Before ĊĠ Ġfun ĠsetUp () Ġ{ ĊĠĠĠ ĠBuild Flags . WRITE _ ONLY _ STORAGE _ STACK Ġ= Ġtrue ĊĠĠĠ Ġtest Write Back Provider Ġ= Ġobject Ġ: ĠWrite Back Provider Ġ{ ĊĠĠĠĠĠ Ġoverride Ġfun Ġinvoke ( protocol : ĠStorage Key Protocol ): ĠWrite Back Ġ{ ĊĠĠĠĠĠĠĠ Ġthis @ Write Only Direct Store Test . test Store Write Back Ġ= ĊĠĠĠĠĠĠĠĠĠ ĠTest Store Write Back ( protocol , ĠTest Coroutine Scope ( Test Coroutine Dispatcher ())) ĊĠĠĠĠĠĠĠ Ġreturn Ġthis @ Write Only Direct Store Test . test Store Write Back ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ( expected Ġ= ĠCr dt Exception :: class ) ĊĠ Ġfun Ġthrows _ if Appro priate Driver C ant Be Found () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġcreate Store () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġconstructs Direct Stores _ when Required () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġ(_, Ġdriver Provider ) Ġ= Ġsetup F akes () ĊĊĠĠĠ Ġval Ġstore Ġ= Ġcreate Store ( driver Provider ) ĊĊĠĠĠ ĠassertThat ( store ). isInstanceOf ( Write Only Direct Store :: class . java ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġapplies And Propag ates Operations _ from Prox ies _ to Drivers () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġ( driver , Ġdriver Provider ) Ġ= Ġsetup F akes () ĊĠĠĠ Ġval Ġstore Ġ= Ġcreate Store ( driver Provider ) Ġas ĠWrite Only Direct Store < Cr dt Data , ĠCr dt Operation , ĠAny ?> ĊĠĠĠ Ġval Ġop Ġ= ĠCr dt Count . Operation . Increment (" me ", ĠVersion Map (" me " Ġto Ġ 1 )) ĊĊĠĠĠ Ġstore . on Proxy Message ( Proxy Message . Operations ( listOf ( op ), Ġ 1 )) ĊĊĠĠĠ ĠassertThat ( driver . ops ). contains Exactly ( op ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ( expected Ġ= ĠIllegalArgumentException :: class ) ĊĠ Ġfun Ġmodel Updates _ throw () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġ(_, Ġdriver Provider ) Ġ= Ġsetup F akes () ĊĠĠĠ Ġval Ġstore Ġ= Ġcreate Store ( driver Provider ) Ġas ĠWrite Only Direct Store < Cr dt Data , ĠCr dt Operation , ĠAny ?> ĊĊĠĠĠ Ġstore . on Proxy Message ( Proxy Message . Model Update ( Cr dt Count (). data , Ġ 1 )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ( expected Ġ= ĠIllegalArgumentException :: class ) ĊĠ Ġfun Ġsync Requests _ throw () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġ(_, Ġdriver Provider ) Ġ= Ġsetup F akes () ĊĠĠĠ Ġval Ġstore Ġ= Ġcreate Store ( driver Provider ) Ġas ĠWrite Only Direct Store < Cr dt Data , ĠCr dt Operation , ĠAny ?> ĊĊĠĠĠ Ġstore . on Proxy Message ( Proxy Message . Sync Request ( 1 )) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġclose _ set Closed _ and Close Driver () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġ( driver , Ġdriver Provider ) Ġ= Ġsetup F akes () ĊĠĠĠ Ġval Ġstore Ġ= Ġcreate Store ( driver Provider ) Ġas ĠWrite Only Direct Store < Cr dt Data , ĠCr dt Operation , ĠAny ?> ĊĠĠĠ ĠassertThat ( driver . closed ). isFalse () ĊĠĠĠ ĠassertThat ( test Store Write Back . closed ). isFalse () ĊĊĠĠĠ Ġstore . close () ĊĊĠĠĠ ĠassertThat ( driver . closed ). isTrue () ĊĠĠĠ ĠassertThat ( test Store Write Back . closed ). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġdoes Not Callback () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġval Ġ(_, Ġdriver Provider ) Ġ= Ġsetup F akes () ĊĠĠĠ Ġval Ġstore Ġ= Ġcreate Store ( driver Provider ) ĊĠĠĠ Ġstore . on Ġ{ ĊĠĠĠĠĠ ĠAssert . fail (" This Ġcallback Ġshould Ġnot Ġbe Ġcalled .") ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġid Ġ= Ġstore . on Ġ{ ĊĠĠĠĠĠ ĠAssert . fail (" This Ġcallback Ġshould Ġnot Ġbe Ġcalled .") ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġop Ġ= ĠCr dt Count . Operation . Increment (" me ", ĠVersion Map (" me " Ġto Ġ 1 )) ĊĊĠĠĠ Ġstore . on Proxy Message ( Proxy Message . Operations ( listOf ( op ), Ġid )) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġsetup F akes (): ĠPair < Fake Driver < Cr dt Count . Data >, ĠFake Driver Provider > Ġ{ ĊĠĠĠ Ġval Ġfake Driver Ġ= ĠFake Driver < Cr dt Count . Data >( test Key ) ĊĠĠĠ Ġval Ġfake Provider Ġ= ĠFake Driver Provider ( test Key Ġto Ġfake Driver ) ĊĠĠĠ Ġreturn Ġfake Driver Ġto Ġfake Provider ĊĠ Ġ} ĊĊĠ Ġprivate Ġsuspend Ġfun ĠCor outine Scope . create Store ( var arg Ġproviders : ĠDriver Provider ) Ġ= ĊĠĠĠ ĠActive Store < Cr dt Data , ĠCr dt Operation , ĠAny ? >( ĊĠĠĠĠĠ ĠStore Options ( test Key , ĠCount Type (), Ġwrite Only Ġ= Ġtrue ), ĊĠĠĠĠĠ Ġthis , ĊĠĠĠĠĠ ĠFixed Driver Factory (* providers ), ĊĠĠĠĠĠ Ġtest Write Back Provider , ĊĠĠĠĠĠ Ġnull , ĊĠĠĠĠĠ ĠJ vm Time ĊĠĠĠ Ġ) Ċ } Ċ