package Ġcom . fk or ot kov . snippets . test containers . g cloud Ċ Ċ import Ġcom . google . cloud . No Credentials Ċ import Ġcom . google . cloud . datastore . Datastore Ċ import Ġcom . google . cloud . datastore . Datastore Options Ċ import Ġorg . junit . Class Rule Ċ import Ġorg . junit . Test Ċ import Ġorg . test containers . containers . wait . Log Message Wait Strategy Ċ import Ġkotlin . test . assertTrue ĊĊ Ċ class ĠTest Datastore Ġ{ ĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġval ĠprojectName Ġ= Ġ" testing " ĊĠĠĠ Ġval Ġemulator Port Ġ= Ġ 8 8 8 8 ĊĊĠĠĠ Ġ@ Class Rule Ġ@ Jvm Field ĊĠĠĠ Ġpublic Ġval Ġdatastore Container : ĠGoogle Cloud Container Ġ= ĊĠĠĠĠĠ ĠGoogle Cloud Container () ĊĠĠĠĠĠĠĠ Ġ. with Ex posed Ports ( emulator Port ) ĊĠĠĠĠĠĠĠ Ġ. with Command ("/ bin / sh ", Ġ"- c ", ĊĠĠĠĠĠĠĠĠĠ Ġ""" ĊĠĠĠĠĠĠĠĠĠ Ġg cloud Ġbeta Ġem ulators Ġdatastore Ġstart Ġ-- no - legacy Ġ\ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ-- project Ġ$ projectName Ġ\ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ-- host - port = 0 . 0 . 0 . 0 :$ emulator Port Ġ\ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ-- consistency = 1 ĊĠĠĠĠĠĠĠ Ġ"" ") ĊĠĠĠĠĠĠĠ Ġ. waiting For ( Log Message Wait Strategy (). with Reg Ex (" (? s ). * running .* $ ")) ĊĊĠĠĠ Ġval Ġdatastore Service : ĠData store Ġby Ġlazy Ġ{ ĊĠĠĠĠĠ Ġval Ġcontainer Host Ġ= Ġ"${ datastore Container . container IpAddress }:${ datastore Container . get Mapped Port ( emulator Port )}" ĊĊĠĠĠĠĠ ĠData store Options . newBuilder () ĊĠĠĠĠĠĠĠ Ġ. set ProjectId ( projectName ) ĊĠĠĠĠĠĠĠ Ġ. set Host ( container Host ) ĊĠĠĠĠĠĠĠ Ġ. set Credentials ( No Credentials . getInstance ()) ĊĠĠĠĠĠĠĠ Ġ. build () ĊĠĠĠĠĠĠĠ Ġ. service ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġ@ Test ĊĠ Ġfun Ġtest Id Allocation () Ġ{ ĊĠĠĠ Ġval Ġkey Factory Ġ= Ġdatastore Service . new Key Factory (). set Kind (" Animal ") ĊĊĠĠĠ Ġval Ġallocated Id Ġ= Ġdatastore Service . allocate Id ( key Factory . new Key ()) ĊĠĠĠ ĠassertTrue ( allocated Id . id Ġ> Ġ 0 ) ĊĠ Ġ} Ċ }