Merge branch 'stable-2.14' into stable-2.15

* stable-2.14:
  Upgrade mockito-core to 2.27.0

Change-Id: Ic553ae164a76447bfa867b02fd68c1e6ce793651
diff --git a/WORKSPACE b/WORKSPACE
index 4f6557b..6a25731 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "8d7664e169100e537340aed89345c3245cf12f22",
+    commit = "8386b3fbf80e375f0a10c8386c0a8dfe260c5c1b",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/quota/MaxRepositorySizeQuota.java b/src/main/java/com/googlesource/gerrit/plugins/quota/MaxRepositorySizeQuota.java
index f01255a..d1f1505 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/quota/MaxRepositorySizeQuota.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/quota/MaxRepositorySizeQuota.java
@@ -36,6 +36,7 @@
 import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.Collection;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
@@ -51,7 +52,8 @@
 import org.slf4j.LoggerFactory;
 
 @Singleton
-class MaxRepositorySizeQuota implements ReceivePackInitializer, PostReceiveHook, RepoSizeCache {
+public class MaxRepositorySizeQuota
+    implements ReceivePackInitializer, PostReceiveHook, RepoSizeCache {
   private static final Logger log = LoggerFactory.getLogger(MaxRepositorySizeQuota.class);
 
   static final String REPO_SIZE_CACHE = "repo_size";
@@ -68,13 +70,13 @@
     };
   }
 
+  protected final LoadingCache<Project.NameKey, AtomicLong> cache;
   private final QuotaFinder quotaFinder;
-  private final LoadingCache<Project.NameKey, AtomicLong> cache;
   private final ProjectCache projectCache;
   private final ProjectNameResolver projectNameResolver;
 
   @Inject
-  MaxRepositorySizeQuota(
+  protected MaxRepositorySizeQuota(
       QuotaFinder quotaFinder,
       @Named(REPO_SIZE_CACHE) LoadingCache<Project.NameKey, AtomicLong> cache,
       ProjectCache projectCache,
@@ -87,15 +89,22 @@
 
   @Override
   public void init(Project.NameKey project, ReceivePack rp) {
+    Optional<Long> maxPackSize = getMaxPackSize(project);
+    if (maxPackSize.isPresent()) {
+      rp.setMaxPackSizeLimit(maxPackSize.get());
+    }
+  }
+
+  protected Optional<Long> getMaxPackSize(Project.NameKey project) {
     QuotaSection quotaSection = quotaFinder.firstMatching(project);
     if (quotaSection == null) {
-      return;
+      return Optional.empty();
     }
 
     Long maxRepoSize = quotaSection.getMaxRepoSize();
     Long maxTotalSize = quotaSection.getMaxTotalSize();
     if (maxRepoSize == null && maxTotalSize == null) {
-      return;
+      return Optional.empty();
     }
 
     try {
@@ -115,10 +124,11 @@
         maxPackSize2 = Math.max(0, maxTotalSize - totalSize);
       }
 
-      long maxPackSize = Ordering.<Long>natural().nullsLast().min(maxPackSize1, maxPackSize2);
-      rp.setMaxPackSizeLimit(maxPackSize);
+      return Optional.ofNullable(
+          Ordering.<Long>natural().nullsLast().min(maxPackSize1, maxPackSize2));
     } catch (ExecutionException e) {
-      log.warn("Couldn't setMaxPackSizeLimit on receive-pack for {}", project, e);
+      log.warn("Couldn't calculate maxPackSize for {}", project, e);
+      return Optional.empty();
     }
   }
 
diff --git a/src/main/java/com/googlesource/gerrit/plugins/quota/Module.java b/src/main/java/com/googlesource/gerrit/plugins/quota/Module.java
index a762579..e514334 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/quota/Module.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/quota/Module.java
@@ -76,6 +76,7 @@
     DynamicSet.bind(binder(), ProjectDeletedListener.class).to(DeletionListener.class);
     DynamicSet.bind(binder(), GarbageCollectorListener.class).to(GCListener.class);
     DynamicSet.setOf(binder(), UsageDataEventCreator.class);
+    DynamicSet.bind(binder(), UsageDataEventCreator.class).to(RepoSizeEventCreator.class);
     install(MaxRepositorySizeQuota.module());
     install(
         new RestApiModule() {