@@ -184,9 +184,9 @@ public void debugLogged() throws IOException {
184
184
new DatafileLoader (datafileService , datafileClient , datafileCache , executor , logger );
185
185
186
186
when (client .execute (any (Client .Request .class ), anyInt (), anyInt ())).thenReturn ("{}" );
187
+ when (cache .save (datafileCache .getFileName (), "{}" )).thenReturn (true );
187
188
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 ("{}" );
190
190
191
191
datafileLoader .getDatafile ("debugLogged" , datafileLoadedListener );
192
192
datafileLoader .getDatafile ("debugLogged" , datafileLoadedListener );
@@ -201,6 +201,32 @@ public void debugLogged() throws IOException {
201
201
verify (datafileLoadedListener , atLeast (1 )).onDatafileLoaded ("{}" );
202
202
}
203
203
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
+
204
230
@ Test
205
231
public void debugLoggedMultiThreaded () throws IOException {
206
232
final ListeningExecutorService executor = MoreExecutors .newDirectExecutorService ();
@@ -212,6 +238,7 @@ public void debugLoggedMultiThreaded() throws IOException {
212
238
when (client .execute (any (Client .Request .class ), anyInt (), anyInt ())).thenReturn ("{}" );
213
239
when (cache .exists (datafileCache .getFileName ())).thenReturn (true );
214
240
when (cache .delete (datafileCache .getFileName ())).thenReturn (true );
241
+ when (cache .exists (datafileCache .getFileName ())).thenReturn (true );
215
242
when (cache .load (datafileCache .getFileName ())).thenReturn ("{}" );
216
243
when (cache .save (datafileCache .getFileName (), "{}" )).thenReturn (true );
217
244
@@ -268,9 +295,6 @@ public void allowDoubleDownload() throws IOException {
268
295
setTestDownloadFrequency (datafileLoader , 1000L );
269
296
270
297
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 );
274
298
275
299
datafileLoader .getDatafile ("allowDoubleDownload" , datafileLoadedListener );
276
300
try {
0 commit comments