@@ -184,9 +184,9 @@ public void debugLogged() throws IOException {
184184 new DatafileLoader (datafileService , datafileClient , datafileCache , executor , logger );
185185
186186 when (client .execute (any (Client .Request .class ), anyInt (), anyInt ())).thenReturn ("{}" );
187+ when (cache .save (datafileCache .getFileName (), "{}" )).thenReturn (true );
187188 when (cache .exists (datafileCache .getFileName ())).thenReturn (true );
188- when (cache .delete (datafileCache .getFileName ())).thenReturn (false );
189- when (cache .save (datafileCache .getFileName (), "{}" )).thenReturn (false );
189+ when (cache .load (datafileCache .getFileName ())).thenReturn ("{}" );
190190
191191 datafileLoader .getDatafile ("debugLogged" , datafileLoadedListener );
192192 datafileLoader .getDatafile ("debugLogged" , datafileLoadedListener );
@@ -201,6 +201,32 @@ public void debugLogged() throws IOException {
201201 verify (datafileLoadedListener , atLeast (1 )).onDatafileLoaded ("{}" );
202202 }
203203
204+ @ Test
205+ public void downloadAllowedNoCache () throws IOException {
206+ final ListeningExecutorService executor = MoreExecutors .newDirectExecutorService ();
207+ Cache cache = mock (Cache .class );
208+ datafileCache = new DatafileCache ("downloadAllowedNoCache" , cache , logger );
209+ DatafileLoader datafileLoader =
210+ new DatafileLoader (datafileService , datafileClient , datafileCache , executor , logger );
211+
212+ when (client .execute (any (Client .Request .class ), anyInt (), anyInt ())).thenReturn ("{}" );
213+ when (cache .save (datafileCache .getFileName (), "{}" )).thenReturn (false );
214+ when (cache .exists (datafileCache .getFileName ())).thenReturn (false );
215+ when (cache .load (datafileCache .getFileName ())).thenReturn ("{}" );
216+
217+ datafileLoader .getDatafile ("downloadAllowedNoCache" , datafileLoadedListener );
218+ datafileLoader .getDatafile ("downloadAllowedNoCache" , datafileLoadedListener );
219+ try {
220+ executor .awaitTermination (5 , TimeUnit .SECONDS );
221+ } catch (InterruptedException e ) {
222+ fail ();
223+ }
224+
225+ verify (logger , never ()).debug ("Last download happened under 1 minute ago. Throttled to be at least 1 minute apart." );
226+ verify (datafileLoadedListener , atMost (2 )).onDatafileLoaded ("{}" );
227+ verify (datafileLoadedListener , atLeast (1 )).onDatafileLoaded ("{}" );
228+ }
229+
204230 @ Test
205231 public void debugLoggedMultiThreaded () throws IOException {
206232 final ListeningExecutorService executor = MoreExecutors .newDirectExecutorService ();
@@ -212,6 +238,7 @@ public void debugLoggedMultiThreaded() throws IOException {
212238 when (client .execute (any (Client .Request .class ), anyInt (), anyInt ())).thenReturn ("{}" );
213239 when (cache .exists (datafileCache .getFileName ())).thenReturn (true );
214240 when (cache .delete (datafileCache .getFileName ())).thenReturn (true );
241+ when (cache .exists (datafileCache .getFileName ())).thenReturn (true );
215242 when (cache .load (datafileCache .getFileName ())).thenReturn ("{}" );
216243 when (cache .save (datafileCache .getFileName (), "{}" )).thenReturn (true );
217244
@@ -268,9 +295,6 @@ public void allowDoubleDownload() throws IOException {
268295 setTestDownloadFrequency (datafileLoader , 1000L );
269296
270297 when (client .execute (any (Client .Request .class ), anyInt (), anyInt ())).thenReturn ("{}" );
271- when (cache .exists (datafileCache .getFileName ())).thenReturn (true );
272- when (cache .delete (datafileCache .getFileName ())).thenReturn (false );
273- when (cache .save (datafileCache .getFileName (), "{}" )).thenReturn (false );
274298
275299 datafileLoader .getDatafile ("allowDoubleDownload" , datafileLoadedListener );
276300 try {
0 commit comments