// ĠCopyright Ġ 2 0 2 1 ĠThe ĠCross - Media ĠMeasurement ĠAuthors Ċ // Ċ // Ġ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 . wf an et . panel match . common . storage Ċ Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġcom . google . protobuf . kotlin . to ByteString Utf 8 Ċ import Ġkotlin . test . assert Fails Ċ import Ġkotlinx . coroutines . flow . as Flow Ċ import Ġkotlinx . coroutines . flow . toList Ċ import Ġkotlinx . coroutines . run Blocking Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ import Ġorg . wf an et . measurement . common . flatten Ċ import Ġorg . wf an et . measurement . storage . Storage Client Ċ import Ġorg . wf an et . measurement . storage . create Blob Ċ import Ġorg . wf an et . measurement . storage . read Ċ import Ġorg . wf an et . measurement . storage . testing . InMemory Storage Client Ċ import Ġorg . wf an et . panel match . common . testing . run Blocking Test Ċ Ċ private Ġconst Ġval ĠKEY Ġ= Ġ" some - blob - key " Ċ private Ġconst Ġval ĠSA FE _ CONTENTS Ġ= Ġ" 0 1 2 3 4 5 6 7 8 9 " Ċ private Ġconst Ġval ĠUNS AFE _ CONTENTS Ġ= Ġ" A 0 1 2 3 4 5 6 7 8 9 " Ċ Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠSize Limit ed Storage Client Test Ġ{ ĊĠ Ġprivate Ġval Ġdelegate Ġ= ĠIn Memory Storage Client () ĊĠ Ġprivate Ġval Ġstorage Client Ġ= ĠSize Limit ed Storage Client ( 1 0 L , Ġdelegate ) ĊĊĠ Ġprivate Ġfun Ġcreate Blob ( var arg Ġelements : ĠString ) Ġ= Ġrun Blocking Ġ{ ĊĠĠĠ Ġval Ġflow Ġ= Ġelements . map Ġ{ Ġit . to ByteString Utf 8 () Ġ}. as Flow () ĊĠĠĠ Ġstorage Client . create Blob ( KEY , Ġflow ) ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget Blob (): ĠStorage Client . Blob ? Ġ= Ġrun Blocking Ġ{ Ġstorage Client . get Blob ( KEY ) Ġ} ĊĊĠ Ġprivate Ġfun Ġget Blob From Delegate (): ĠStorage Client . Blob ? Ġ= Ġrun Blocking Ġ{ Ġdelegate . get Blob ( KEY ) Ġ} ĊĊĠ Ġprivate Ġfun Ġassert Create Blob Fails ( var arg Ġelements : ĠString ) Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġassert Fails Ġ{ Ġcreate Blob (* elements ) Ġ} ĊĠĠĠ ĠassertThat ( get Blob ()). isNull () ĊĠĠĠ ĠassertThat ( get Blob From Delegate ()). isNull () ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġcreate Blob En forces Limit () Ġ{ ĊĠĠĠ Ġassert Create Blob Fails ( UN SAFE _ CONTENTS ) ĊĠĠĠ Ġassert Create Blob Fails ( SAFE _ CONTENTS , ĠSA FE _ CONTENTS ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġcreate Under Limit Works () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġcreate Blob ( SAFE _ CONTENTS ) ĊĊĠĠĠ Ġval Ġblob Ġ= Ġget Blob () ĊĠĠĠ ĠassertThat ( blob ). isNotNull () ĊĊĠĠĠ Ġval Ġdelegate Blob Ġ= Ġget Blob From Delegate () ĊĠĠĠ ĠassertThat ( delegate Blob ). isNotNull () ĊĊĠĠĠ ĠassertThat ( blob ?. size ). isEqualTo ( SAFE _ CONTENTS . length ) ĊĠĠĠ ĠassertThat ( delegate Blob ?. size ). isEqualTo ( SAFE _ CONTENTS . length ) ĊĊĠĠĠ ĠassertThat ( blob ?. read ()?. flatten ()?. toString Utf 8 ()). isEqualTo ( SAFE _ CONTENTS ) ĊĠĠĠ ĠassertThat ( delegate Blob ?. read ()?. flatten ()?. toString Utf 8 ()). isEqualTo ( SAFE _ CONTENTS ) ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġget Blob Fails For Too Large Blob () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġdelegate . create Blob ( KEY , ĠUNS AFE _ CONTENTS . to ByteString Utf 8 ()) ĊĠĠĠ Ġval Ġblob Ġ= Ġstorage Client . get Blob ( KEY ) ĊĠĠĠ ĠassertThat ( blob ). isNotNull () ĊĠĠĠ Ġassert Fails Ġ{ Ġblob ?. size Ġ} ĊĠĠĠ Ġassert Fails Ġ{ Ġblob ?. read ()?. toList () Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġdelete Is Deleg ated () Ġ= Ġrun Blocking Test Ġ{ ĊĠĠĠ Ġcreate Blob ( SAFE _ CONTENTS ) ĊĠĠĠ ĠassertThat ( get Blob ()). isNotNull () ĊĠĠĠ ĠassertThat ( get Blob From Delegate ()). isNotNull () ĊĊĠĠĠ Ġget Blob ()?. delete () ĊĠĠĠ ĠassertThat ( get Blob ()). isNull () ĊĠĠĠ ĠassertThat ( get Blob From Delegate ()). isNull () ĊĠ Ġ} Ċ } Ċ