package Ġcom . github . fr ank far re ll . d ynam ob atch Ċ Ċ import Ġcom . amazonaws . services . dynamodb v 2 . Amazon D ynamoDB Ċ import Ġcom . amazonaws . services . dynamodb v 2 . model .* Ċ import Ġio . mock k . clear Mocks Ċ import Ġio . mock k . every Ċ import Ġio . mock k . mock k Ċ import Ġio . mock k . slot Ċ import Ġio . reactivex . schedul ers . Test Scheduler Ċ import Ġjunit . framework . Assert . assertEquals Ċ import Ġorg . junit . Before Ċ import Ġorg . junit . Test Ċ import Ġjava . util .* Ċ import Ġjava . util . concurrent . TimeUnit Ċ Ċ /** Ċ Ġ* ĠCreated Ġby Ġfr ank far re ll Ġon Ġ 1 0 / 0 7 / 2 0 1 8 . Ċ Ġ*/ Ċ class ĠD ynamo Batch Executor Test Ġ{ ĊĊĠĠĠ Ġval Ġmock Amazon D ynamoDB : ĠAmazon D ynamoDB Ġ= Ġmock k () ĊĊĠĠĠ Ġlateinit Ġvar Ġd ynamo Batch Service UnderTest : ĠD ynamo Batch Executor < Any > ĊĊĠĠĠ Ġvar Ġtest Scheduler : ĠTest Scheduler Ġ= ĠTest Scheduler () ĊĠĠĠ Ġvar Ġtest Random : ĠRandom Ġ= ĠRandom ( 1 ) ĊĊĠĠĠ Ġ@ Before ĊĠĠĠ Ġfun Ġinit () Ġ{ ĊĠĠĠĠĠĠĠ Ġclear Mocks ( mock Amazon D ynamoDB ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` persist Ġdoes Ġnot Ġretry Ġif Ġthere Ġare Ġno Ġun processed Ġitems `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġd ynamo Batch Service UnderTest Ġ= ĠD ynamo Batch Executor < Any >( mock Amazon D ynamoDB , Ġtest Scheduler , Ġtest Random , Ġattempt Limit Ġ= Ġ 1 0 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmock Result With NoUn processed Items Ġ= ĠBatch Write Item Result (). with Un processed Items ( empty Map < String , ĠList < Write Request >> ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġcapt or Ġ= Ġslot < Batch Write Item Request >() ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock Amazon D ynamoDB . batch Write Item ( capture < Batch Write Item Request >( capt or )) ĊĠĠĠĠĠĠĠ Ġ} Ġanswers Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock Result With NoUn processed Items ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġinitial Request Ġ= ĠArrayList < Map < String , ĠAttribute Value >>() ĊĠĠĠĠĠĠĠ Ġinitial Request . add ( Collections . singleton Map (" pk ", ĠAttribute Value (" test "))) ĊĠĠĠĠĠĠĠ Ġinitial Request . add ( Collections . singleton Map (" pk ", ĠAttribute Value (" test 2 "))) ĊĊĠĠĠĠĠĠĠ Ġd ynamo Batch Service UnderTest . persist ( initial Request , Ġ" test table ") ĊĊĠĠĠĠĠĠĠ Ġtest Scheduler . advance Time By ( 1 0 0 0 , ĠTimeUnit . MIN UTES ) ĊĠĠĠĠĠĠĠ Ġtest Scheduler . trigger Actions () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( capt or . captured . request Items [" test table "] ?. size , Ġ 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġ` persist Ġretries Ġif Ġthere Ġare Ġun processed Ġitems `() Ġ{ ĊĊĠĠĠĠĠĠĠ Ġd ynamo Batch Service UnderTest Ġ= ĠD ynamo Batch Executor < Any >( mock Amazon D ynamoDB , Ġtest Scheduler , Ġtest Random , Ġattempt Limit Ġ= Ġ 1 0 0 0 ) ĊĊĠĠĠĠĠĠĠ Ġval Ġmock Result With Un processed Items Ġ= ĠBatch Write Item Result () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Un processed Items ( Collections . singleton Map (" test table ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( Write Request ( Put Request (). with Item ( Collections . singleton Map (" pk ", ĠAttribute Value (" test ")) ))))) ĊĊĠĠĠĠĠĠĠ Ġval Ġmock Result With NoUn processed Items Ġ= ĠBatch Write Item Result (). with Un processed Items ( empty Map < String , ĠList < Write Request >> ()) ĊĊĠĠĠĠĠĠĠ Ġval Ġcapt or Ġ= Ġmutable ListOf < Batch Write Item Request >() ĊĊĠĠĠĠĠĠĠ Ġevery Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock Amazon D ynamoDB . batch Write Item ( capture < Batch Write Item Request >( capt or )) ĊĠĠĠĠĠĠĠ Ġ} Ġanswers Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock Result With Un processed Items ĊĠĠĠĠĠĠĠ Ġ} Ġand Then Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmock Result With NoUn processed Items ĊĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġinitial Request Ġ= ĠArrayList < Map < String , ĠAttribute Value >>() ĊĠĠĠĠĠĠĠ Ġinitial Request . add ( Collections . singleton Map (" pk ", ĠAttribute Value (" test "))) ĊĠĠĠĠĠĠĠ Ġinitial Request . add ( Collections . singleton Map (" pk ", ĠAttribute Value (" test 2 "))) ĊĊĠĠĠĠĠĠĠ Ġd ynamo Batch Service UnderTest . persist ( initial Request , Ġ" test table ") ĊĊĠĠĠĠĠĠĠ Ġtest Scheduler . advance Time By ( 1 0 0 0 , ĠTimeUnit . MIN UTES ) ĊĠĠĠĠĠĠĠ Ġtest Scheduler . trigger Actions () ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( capt or . get ( 0 ). request Items [" test table "] ?. size , Ġ 2 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( capt or . get ( 1 ). request Items [" test table "] ?. size , Ġ 1 ) ĊĊĠĠĠ Ġ} Ċ }