/* Ċ Ġ* ĠCopyright Ġ 2 0 2 0 ĠGoogle ĠLLC . Ċ Ġ* Ċ Ġ* ĠThis Ġcode Ġmay Ġonly Ġbe Ġused Ġunder Ġthe ĠBSD Ġstyle Ġlicense Ġfound Ġat Ċ Ġ* Ġhttp :// polymer . github . io / LICENSE . txt Ċ Ġ* Ċ Ġ* ĠCode Ġdistributed Ġby ĠGoogle Ġas Ġpart Ġof Ġthis Ġproject Ġis Ġalso Ġsubject Ġto Ġan Ġadditional ĠIP Ġrights Ċ Ġ* Ġgrant Ġfound Ġat Ċ Ġ* Ġhttp :// polymer . github . io / PAT ENTS . txt Ċ Ġ*/ Ċ Ċ package Ġar cs . core . storage Ċ Ċ import Ġar cs . core . cr dt . Cr dt Data Ċ import Ġar cs . core . cr dt . Cr dt Operation Ċ import Ġar cs . core . type . Type Ċ import Ġar cs . core . util . Scheduler Ċ import Ġar cs . core . util . testutil . Log Rule Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġjava . util . concurrent . Executors Ċ import Ġkotlinx . coroutines . Comp letable Deferred Ċ import Ġkotlinx . coroutines . Experimental Cor outines Api Ċ import Ġkotlinx . coroutines . Job Ċ import Ġkotlinx . coroutines . as Coroutine Dispatcher Ċ import Ġkotlinx . coroutines . delay Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . After Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ import Ġorg . mockito . Mock Ċ import Ġorg . mockito . Mockito Annotations Ċ Ċ @ Opt In ( Experimental Cor outines Api :: class ) Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠStorage Proxy Impl Base Test Ġ{ ĊĠ Ġ@ get : Rule ĊĠ Ġval Ġlog Ġ= ĠLog Rule () ĊĊĠ Ġprivate Ġval Ġfake Store Endpoint Ġ= ĠStore Endpoint Fake < Cr dt Data , ĠCr dt Operation , ĠString >() ĊĠ Ġprivate Ġval Ġfake Storage Endpoint Manager Ġ= ĠFake Storage Endpoint Manager ( fake Store Endpoint ) ĊĊĠ Ġ@ Mock ĊĠ Ġprivate Ġlateinit Ġvar Ġmock Storage Key : ĠStorage Key ĊĊĠ Ġ@ Mock ĊĠ Ġprivate Ġlateinit Ġvar Ġmock Type : ĠType ĊĊĠ Ġprivate Ġlateinit Ġvar Ġscheduler : ĠScheduler ĊĊĠ Ġ@ Before ĊĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠ Ġscheduler Ġ= ĠScheduler ( Executors . new Single Thread Executor (). as Coroutine Dispatcher () Ġ+ ĠJob ()) ĊĠĠĠ ĠMockito Annotations . init Mocks ( this ) ĊĠ Ġ} ĊĊĠ Ġ@ After ĊĠ Ġfun ĠtearDown () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġscheduler . waitFor Idle () ĊĠĠĠ Ġscheduler . cancel () ĊĠ Ġ} ĊĊĠ Ġclass ĠTest Storage Proxy Impl Base ( ĊĠĠĠ Ġscheduler : ĠScheduler ĊĠ Ġ) Ġ: ĠStorage Proxy Impl Base < Cr dt Data , ĠCr dt Operation , ĠString >( scheduler ) Ġ{ ĊĠĠĠ Ġvar Ġclose Called Ġ= Ġfalse ĊĠĠĠ Ġoverride Ġfun Ġclose Internal () Ġ{ ĊĠĠĠĠĠ Ġclose Called Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġis Closed (): ĠBoolean Ġ= Ġclose Called ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠ Ġsuspend Ġfun Ġcreate ( ĊĠĠĠĠĠĠĠ Ġstore Options : ĠStore Options , ĊĠĠĠĠĠĠĠ Ġstorage Endpoint Manager : ĠStorage Endpoint Manager , ĊĠĠĠĠĠĠĠ Ġscheduler : ĠScheduler ĊĠĠĠĠĠ Ġ): ĠTest Storage Proxy Impl Base Ġ{ ĊĠĠĠĠĠĠĠ Ġ/** ĊĠĠĠĠĠĠĠĠ Ġ* ĠSince Ġ[ storage Endpoint Manager . get ] Ġis Ġa Ġsus pending Ġmethod , Ġwe Ġneed Ġto Ġbe Ġin Ġa ĊĠĠĠĠĠĠĠĠ Ġ* Ġsus pending Ġcontext Ġin Ġorder Ġto Ġattach Ġits Ġcallback . ĊĠĠĠĠĠĠĠĠ Ġ*/ ĊĠĠĠĠĠĠĠ Ġreturn ĠTest Storage Proxy Impl Base ( scheduler ). also Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġit . store Ġ= Ġstorage Endpoint Manager . get ( store Options , Ġ{ Ġ}) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġsuspend Ġfun Ġtest Proxy () Ġ= ĠTest Storage Proxy Impl Base . create ( ĊĠĠĠ ĠStore Options ( ĊĠĠĠĠĠ Ġstorage Key Ġ= Ġmock Storage Key , ĊĠĠĠĠĠ Ġtype Ġ= Ġmock Type ĊĠĠĠ Ġ), ĊĠĠĠ Ġfake Storage Endpoint Manager , ĊĠĠĠ Ġscheduler ĊĠ Ġ) ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġstorage Proxy _ initialized _ is Idle () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ ĠassertThat ( test Proxy (). is Idle ()). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġstorage Proxy _ close _ inv okes Close Internal And Closes Store () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġproxy Ġ= Ġtest Proxy () ĊĠĠĠ Ġproxy . close () ĊĠĠĠ ĠassertThat ( proxy . is Closed ()). isTrue () ĊĠĠĠ ĠassertThat ( fake Store Endpoint . closed ). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġstorage Proxy _ sendMessage _ isNot Idle () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġproxy Ġ= Ġtest Proxy () ĊĠĠĠ Ġfake Store Endpoint . onNext Proxy Message Ġ{ ĊĠĠĠĠĠ ĠassertThat ( proxy . is Idle ()). isFalse () ĊĠĠĠ Ġ} ĊĠĠĠ Ġproxy . sendMessage To Store ( Proxy Message . Sync Request ( null )) ĊĠĠĠ Ġproxy . waitFor Idle () ĊĠĠĠ ĠassertThat ( proxy . is Idle ()). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġstorage Proxy _ with Store Timeout _ still Res olves To Idle () Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġproxy Ġ= Ġtest Proxy () ĊĠĠĠ Ġval Ġdeferred Ġ= ĠComp letable Deferred < Boolean >() ĊĊĠĠĠ Ġfake Store Endpoint . onNext Proxy Message Ġ{ ĊĠĠĠĠĠ Ġdelay ( 5 1 0 0 ) Ġ// Ġoutgoing Ġmessage Ġqueue Ġhas Ġ 5 Ġsecond Ġtimeout ĊĠĠĠ Ġ} ĊĠĠĠ Ġproxy . sendMessage To Store ( Proxy Message . Sync Request ( null ), Ġdeferred ) ĊĠĠĠ Ġproxy . waitFor Idle () ĊĠĠĠ ĠassertThat ( proxy . is Idle ()). isTrue () ĊĠĠĠ ĠassertThat ( deferred . await ()). isTrue () ĊĠ Ġ} Ċ } Ċ