Skip to content

Commit 0184417

Browse files
chore: prepare for release and fix unit tests (#336)
* prepare for release * one more check added * fix tests * fix tests
1 parent a00a540 commit 0184417

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Optimizely Android X SDK Changelog
22

3+
## 3.5.2
4+
June 18th, 2020
5+
6+
Upgrade to latest stable build tools 29.0.3.
7+
8+
### Bug Fixes
9+
* Cleanup scheduled jobs to ensure that there is no jobs delayed.[335](https://github.com/optimizely/android-sdk/pull/335)
10+
* Throttle datafile downloads to ensure there is a minimum of 1 minute between them.
11+
* Clarify dispatch intervals. [323](https://github.com/optimizely/android-sdk/pull/323)
12+
313
## 3.5.1
414
April 29th, 2020
515

datafile-handler/src/androidTest/java/com/optimizely/ab/android/datafile_handler/DatafileLoaderTest.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

datafile-handler/src/main/java/com/optimizely/ab/android/datafile_handler/DatafileLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private boolean allowDownload(String url, DatafileLoadedListener datafileLoadedL
7171
long time = storage.getLong(url + datafileDownloadTime, 1);
7272
Date last = new Date(time);
7373
Date now = new Date();
74-
if (now.getTime() - last.getTime() < minTimeBetweenDownloadsMilli) {
74+
if (now.getTime() - last.getTime() < minTimeBetweenDownloadsMilli && datafileCache.exists()) {
7575
logger.debug("Last download happened under 1 minute ago. Throttled to be at least 1 minute apart.");
7676
if (datafileLoadedListener != null) {
7777
notify(datafileLoadedListener, getCachedDatafile());

0 commit comments

Comments
 (0)