Bug 1291821 - Add onBatchComplete to a FetchRecordsDelegate r=rnewman
authorGrisha Kruglov <gkruglov@mozilla.com>
Tue, 11 Oct 2016 19:29:02 -0700
changeset 344862 3d8a46a90f237c445a7ea1e6797c909fac112604
parent 344861 07c5a4e937382e86f6baf393626f9c3dd060010a
child 344863 75035bf6dd1e705a75b8360677b26419e2b5b245
push id37970
push usergkruglov@mozilla.com
push dateSat, 25 Feb 2017 01:09:28 +0000
treeherderautoland@bd232d46a396 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1291821
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1291821 - Add onBatchComplete to a FetchRecordsDelegate r=rnewman Intended to signal that a group of records have been fetched, and more are to come after a pause. MozReview-Commit-ID: 8ozZTc6aNdA
mobile/android/services/src/main/java/org/mozilla/gecko/sync/middleware/Crypto5MiddlewareRepositorySession.java
mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java
mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java
mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/RecordsChannel.java
mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java
mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java
mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java
mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java
mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/middleware/Crypto5MiddlewareRepositorySession.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/middleware/Crypto5MiddlewareRepositorySession.java
@@ -110,16 +110,21 @@ public class Crypto5MiddlewareRepository
     }
 
     @Override
     public void onFetchCompleted(final long fetchEnd) {
       next.onFetchCompleted(fetchEnd);
     }
 
     @Override
+    public void onBatchCompleted() {
+      next.onBatchCompleted();
+    }
+
+    @Override
     public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) {
       // Synchronously perform *our* work, passing through appropriately.
       RepositorySessionFetchRecordsDelegate deferredNext = next.deferredFetchDelegate(executor);
       return new DecryptingTransformingFetchDelegate(deferredNext, keyBundle, recordFactory);
     }
   }
 
   private DecryptingTransformingFetchDelegate makeUnwrappingDelegate(RepositorySessionFetchRecordsDelegate inner) {
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/DeferredRepositorySessionFetchRecordsDelegate.java
@@ -42,15 +42,25 @@ public class DeferredRepositorySessionFe
       @Override
       public void run() {
         inner.onFetchCompleted(fetchEnd);
       }
     });
   }
 
   @Override
+  public void onBatchCompleted() {
+    executor.execute(new Runnable() {
+      @Override
+      public void run() {
+        inner.onBatchCompleted();
+      }
+    });
+  }
+
+  @Override
   public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService newExecutor) {
     if (newExecutor == executor) {
       return this;
     }
     throw new IllegalArgumentException("Can't re-defer this delegate.");
   }
 }
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/repositories/delegates/RepositorySessionFetchRecordsDelegate.java
@@ -18,10 +18,16 @@ public interface RepositorySessionFetchR
    * @param fetchEnd
    *        A millisecond-resolution timestamp indicating the *remote* timestamp
    *        at the end of the range of records. Usually this is the timestamp at
    *        which the request was received.
    *        E.g., the (normalized) value of the X-Weave-Timestamp header.
    */
   public void onFetchCompleted(final long fetchEnd);
 
-  public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor);
+  /**
+   * Called when a number of records have been returned but more are still expected to come,
+   * possibly after a certain pause.
+   */
+  void onBatchCompleted();
+
+  RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor);
 }
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/RecordsChannel.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/RecordsChannel.java
@@ -212,16 +212,20 @@ public class RecordsChannel implements
   public void onFetchCompleted(final long fetchEnd) {
     Logger.trace(LOG_TAG, "onFetchCompleted. Stopping consumer once stores are done.");
     Logger.trace(LOG_TAG, "Fetch timestamp is " + fetchEnd);
     this.fetchEnd = fetchEnd;
     this.consumer.queueFilled();
   }
 
   @Override
+  public void onBatchCompleted() {
+  }
+
+  @Override
   public void onRecordStoreFailed(Exception ex, String recordGuid) {
     Logger.trace(LOG_TAG, "Failed to store record with guid " + recordGuid);
     numStoreFailed.incrementAndGet();
     this.consumer.stored();
     delegate.onFlowStoreFailed(this, ex, recordGuid);
     // TODO: abort?
   }
 
--- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java
+++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java
@@ -660,16 +660,21 @@ public class TestBookmarks extends Andro
         public void onFetchedRecord(Record record) {
           fetchedGUIDs.add(record.guid);
         }
 
         @Override
         public void onFetchCompleted(long end) {
           finishAndNotify(session);
         }
+
+        @Override
+        public void onBatchCompleted() {
+
+        }
       };
       session.fetchSince(0, fetchDelegate);
     }
   }
 
   /**
    * Simple helper class for fetching a single record by GUID.
    * The fetched record is stored in `fetchedRecord`.
@@ -690,16 +695,21 @@ public class TestBookmarks extends Andro
         public void onFetchedRecord(Record record) {
           fetchedRecord = record;
         }
 
         @Override
         public void onFetchCompleted(long end) {
           finishAndNotify(session);
         }
+
+        @Override
+        public void onBatchCompleted() {
+
+        }
       };
       try {
         session.fetch(new String[] { guid }, fetchDelegate);
       } catch (InactiveSessionException e) {
         performNotify("Session is inactive.", e);
       }
     }
   }
--- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java
+++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java
@@ -99,18 +99,28 @@ public class TestStoreTracking extends A
                                                     RepositorySessionBundle bundle) {
                         performNotify();
                       }
                     });
                   } catch (InactiveSessionException e) {
                     performNotify(e);
                   }
                 }
+
+                @Override
+                public void onBatchCompleted() {
+
+                }
               });
             }
+
+            @Override
+            public void onBatchCompleted() {
+
+            }
           });
         } catch (InactiveSessionException e) {
           performNotify(e);
         }
       }
     };
 
     session.setStoreDelegate(storeDelegate);
@@ -151,16 +161,21 @@ public class TestStoreTracking extends A
                         // Hooray!
                         performNotify();
                       }
                     });
                   } catch (InactiveSessionException e) {
                     performNotify(e);
                   }
                 }
+
+                @Override
+                public void onBatchCompleted() {
+
+                }
               });
             }
           });
         } catch (InvalidSessionTransitionException e) {
           performNotify(e);
         }
       }
     };
--- a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java
+++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java
@@ -95,12 +95,17 @@ public class DefaultFetchDelegate extend
   }
 
   @Override
   public void onFetchCompleted(final long fetchEnd) {
     Logger.debug(LOG_TAG, "onFetchCompleted. Doing nothing.");
   }
 
   @Override
+  public void onBatchCompleted() {
+    Logger.debug(LOG_TAG, "onBatchCompleted. Doing nothing.");
+  }
+
+  @Override
   public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(final ExecutorService executor) {
     return new DeferredRepositorySessionFetchRecordsDelegate(this, executor);
   }
 }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java
@@ -50,16 +50,21 @@ public class SynchronizerHelpers {
             }
 
             @Override
             public void onFetchCompleted(long fetchEnd) {
               delegate.onFetchCompleted(fetchEnd);
             }
 
             @Override
+            public void onBatchCompleted() {
+
+            }
+
+            @Override
             public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) {
               return this;
             }
           });
         }
       });
     }
   }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java
@@ -33,12 +33,17 @@ public class ExpectSuccessRepositorySess
 
   @Override
   public void onFetchCompleted(long end) {
     log("Fetch completed.");
     performNotify();
   }
 
   @Override
+  public void onBatchCompleted() {
+    log("Batch completed.");
+  }
+
+  @Override
   public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) {
     return this;
   }
 }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java
@@ -82,16 +82,21 @@ public class BatchingDownloaderDelegateT
         }
 
         @Override
         public void onFetchCompleted(long fetchEnd) {
 
         }
 
         @Override
+        public void onBatchCompleted() {
+
+        }
+
+        @Override
         public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) {
             return null;
         }
     }
 
     @Before
     public void setUp() throws Exception {
         server11Repository = new Server11Repository(
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java
@@ -47,16 +47,17 @@ public class BatchingDownloaderTest {
     private String DEFAULT_SORT = "index";
     private String DEFAULT_IDS = "1";
     private String DEFAULT_LMHEADER = "12345678";
 
     class MockSessionFetchRecordsDelegate implements RepositorySessionFetchRecordsDelegate {
         public boolean isFailure;
         public boolean isFetched;
         public boolean isSuccess;
+        public int batchesCompleted;
         public Exception ex;
         public Record record;
 
         @Override
         public void onFetchFailed(Exception ex, Record record) {
             this.isFailure = true;
             this.ex = ex;
             this.record = record;
@@ -69,16 +70,21 @@ public class BatchingDownloaderTest {
         }
 
         @Override
         public void onFetchCompleted(long fetchEnd) {
             this.isSuccess = true;
         }
 
         @Override
+        public void onBatchCompleted() {
+            this.batchesCompleted += 1;
+        }
+
+        @Override
         public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) {
             return null;
         }
     }
 
     class MockRequest extends SyncStorageCollectionRequest {
 
         public MockRequest(URI uri) {