Skip to content

Commit 861eef5

Browse files
committed
address comments
1 parent efbf213 commit 861eef5

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

AndroidSDKCore/src/main/java/com/leanplum/internal/Request.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,12 @@ protected Void doInBackground(Void... params) {
481481
}
482482

483483

484+
/**
485+
* This class wraps the unsent requests, requests that we need to send
486+
* and the JSON encoded string. Wrapping it in the class allows us to
487+
* retain consistency in the requests we are sending and the actual
488+
* JSON string.
489+
*/
484490
static class RequestsWithEncoding {
485491
List<Map<String, Object>> unsentRequests;
486492
List<Map<String, Object>> requestsToSend;
@@ -517,7 +523,7 @@ protected RequestsWithEncoding getRequestsWithEncodedStringStoredRequests(double
517523
String jsonEncodedRequestsToSend;
518524
RequestsWithEncoding requestsWithEncoding = new RequestsWithEncoding();
519525

520-
if (fraction < 0.01) {
526+
if (fraction < 0.01) { //base case
521527
unsentRequests = new ArrayList<>(0);
522528
requestsToSend = new ArrayList<>(0);
523529
} else {
@@ -532,6 +538,7 @@ protected RequestsWithEncoding getRequestsWithEncodedStringStoredRequests(double
532538

533539
return requestsWithEncoding;
534540
} catch (OutOfMemoryError E) {
541+
// half the requests will need less memory, recursively
535542
return getRequestsWithEncodedStringStoredRequests(0.5 * fraction);
536543
}
537544
}

AndroidSDKTests/src/test/java/com/leanplum/LeanplumTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,11 @@ public void testCrashes() throws Exception {
403403

404404
request1.sendEventually();
405405
request2.sendEventually();
406+
407+
final double fraction = 1.0;
406408
// Get a number of events in the database.
407409
// Expectation: 2 events.
408-
List unsentRequests = request1.getUnsentRequests(1.0);
410+
List unsentRequests = request1.getUnsentRequests(fraction);
409411
assertNotNull(unsentRequests);
410412
assertEquals(2, unsentRequests.size());
411413

@@ -427,7 +429,7 @@ public void testCrashes() throws Exception {
427429

428430
// Get a number of events in the database. Checks if ours two events still here.
429431
// Expectation: 2 events.
430-
unsentRequests = request1.getUnsentRequests(1.0);
432+
unsentRequests = request1.getUnsentRequests(fraction);
431433
assertNotNull(unsentRequests);
432434
assertEquals(2, unsentRequests.size());
433435

@@ -444,7 +446,7 @@ public void onRequest(String httpMethod, String apiMethod, Map<String, Object> p
444446

445447
// Get a number of events in the database. Make sure we sent all events.
446448
// Expectation: 0 events.
447-
unsentRequests = request1.getUnsentRequests(1.0);
449+
unsentRequests = request1.getUnsentRequests(fraction);
448450
assertNotNull(unsentRequests);
449451
assertEquals(0, unsentRequests.size());
450452

AndroidSDKTests/src/test/java/com/leanplum/internal/RequestTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ public void testJsonEncodeUnsentRequestsWithExceptionLargeNumbers() throws NoSuc
249249
requestsWithEncoding = request.getRequestsWithEncodedStringStoredRequests(1.0);
250250
assertEquals(1250, requestsWithEncoding.unsentRequests.size());
251251

252-
// Throw OOM on > 0 requests
253-
// Expectation: 0 requests returned but no crash
254-
252+
// Throw OOM on serializing any finite number of requests (extreme condition)
253+
// Expectation: Determine only 0 requests to be sent
255254
when(request.getUnsentRequests(not(eq(0)))).thenThrow(OutOfMemoryError.class);
256255
requestsWithEncoding = request.getRequestsWithEncodedStringStoredRequests(1.0);
257256

0 commit comments

Comments
 (0)