Merge branch 'stable-3.1' into 'stable-3.2' * stable-3.1: Upgrade bazlets to latest stable-3.1 to build with 3.1.11 API Upgrade bazlets to latest stable-3.1 to build with 3.1.10 API Bump Bazel version to 3.7.0 Upgrade bazlets to latest stable-3.0 to build with 3.0.13 API Bump Bazel version to 3.5.0 Upgrade bazlets to latest stable-3.1 to build with 3.1.8 API Upgrade bazlets to latest stable-3.0 to build with 3.0.12 API Upgrade bazlets to latest stable-2.16 to build with 2.16.22 API Bump Bazel version to 3.4.1 Change-Id: I00ee047de8d772415178783f41e9ff0bfbbaa324
diff --git a/WORKSPACE b/WORKSPACE index a1b6cf1..db6d082 100644 --- a/WORKSPACE +++ b/WORKSPACE
@@ -3,7 +3,7 @@ load("//:bazlets.bzl", "load_bazlets") load_bazlets( - commit = "20079f696c22c733053077b13c0dc6d9902e6b8e", + commit = "74f9d8e76d5014d218ae6fe55127a5288c9a32c3", #local_path = "/home/<user>/projects/bazlets", )
diff --git a/src/test/java/com/googlesource/gerrit/plugins/quota/RateLimitUploadListenerTest.java b/src/test/java/com/googlesource/gerrit/plugins/quota/RateLimitUploadListenerTest.java index fc6a196..fc4dc76 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/quota/RateLimitUploadListenerTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/quota/RateLimitUploadListenerTest.java
@@ -19,14 +19,20 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.google.common.cache.CacheBuilder; import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.RateLimiter; import com.google.gerrit.entities.Account; import com.google.gerrit.server.CurrentUser; +import com.google.gerrit.server.IdentifiedUser.GenericFactory; +import com.google.gerrit.server.config.GerritServerConfig; +import com.google.gerrit.server.group.SystemGroupBackend; import com.google.gerrit.server.validators.ValidationException; import com.google.inject.Provider; +import com.googlesource.gerrit.plugins.quota.AccountLimitsConfig.Type; import com.googlesource.gerrit.plugins.quota.Module.Holder; import java.util.concurrent.ExecutionException; +import org.eclipse.jgit.lib.Config; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -39,9 +45,13 @@ private static final String LIMIT_EXCEEDED_MSG = "test exceeded message: {0,number,##.##}"; private static final String REMOTE_HOST = "host"; private RateLimitUploadListener uploadHook; + private LoadingCache<Account.Id, Holder> limitsPerAccount; + private LoadingCache<String, Holder> limitsPerRemoteHost; + @Mock @GerritServerConfig Config cfg; + @Mock GenericFactory userFactory; + SystemGroupBackend systemGroupBackend; + @Mock AccountLimitsFinder finder; @Mock private Provider<CurrentUser> user; - @Mock private LoadingCache<Account.Id, Holder> limitsPerAccount; - @Mock private LoadingCache<String, Holder> limitsPerRemoteHost; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private CurrentUser currentUser; @@ -52,6 +62,17 @@ @Before public void setUp() { + systemGroupBackend = new SystemGroupBackend(cfg); + limitsPerAccount = + CacheBuilder.newBuilder() + .build(new Module.HolderCacheLoaderByAccountId(Type.UPLOADPACK, userFactory, finder)); + limitsPerAccount.put(accountId, holder); + limitsPerRemoteHost = + CacheBuilder.newBuilder() + .build( + new Module.HolderCacheLoaderByRemoteHost( + Type.UPLOADPACK, systemGroupBackend, finder)); + limitsPerRemoteHost.put(REMOTE_HOST, holder); uploadHook = spy( new RateLimitUploadListener( @@ -62,19 +83,16 @@ private void setUpRegisteredUser() throws ExecutionException { when(currentUser.isIdentifiedUser()).thenReturn(true); when(currentUser.asIdentifiedUser().getAccountId()).thenReturn(accountId); - when(limitsPerAccount.get(accountId)).thenReturn(holder); when(holder.get()).thenReturn(limiter); } private void setUpRegisteredUserExecutionException() throws ExecutionException { when(currentUser.isIdentifiedUser()).thenReturn(true); when(currentUser.asIdentifiedUser().getAccountId()).thenReturn(accountId); - when(limitsPerAccount.get(accountId)).thenThrow(new ExecutionException(null)); } private void setUpAnonymous() throws ExecutionException { when(currentUser.isIdentifiedUser()).thenReturn(false); - when(limitsPerRemoteHost.get(REMOTE_HOST)).thenReturn(holder); when(holder.get()).thenReturn(limiter); }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/quota/RestApiRateLimiterTest.java b/src/test/java/com/googlesource/gerrit/plugins/quota/RestApiRateLimiterTest.java index 4795212..7dafad3 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/quota/RestApiRateLimiterTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/quota/RestApiRateLimiterTest.java
@@ -24,11 +24,16 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.google.common.cache.CacheBuilder; import com.google.common.cache.LoadingCache; import com.google.common.util.concurrent.RateLimiter; import com.google.gerrit.entities.Account; import com.google.gerrit.server.CurrentUser; +import com.google.gerrit.server.IdentifiedUser.GenericFactory; +import com.google.gerrit.server.config.GerritServerConfig; +import com.google.gerrit.server.group.SystemGroupBackend; import com.google.inject.Provider; +import com.googlesource.gerrit.plugins.quota.AccountLimitsConfig.Type; import com.googlesource.gerrit.plugins.quota.Module.Holder; import java.io.IOException; import java.util.concurrent.ExecutionException; @@ -36,6 +41,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jgit.lib.Config; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,12 +53,11 @@ public class RestApiRateLimiterTest { private static final String LIMIT_EXCEEDED_MSG = "test exceeded message: {0,number,##.##}, {1,number,###}"; + private static final String REMOTE_HOST = "host"; @Mock private HttpServletRequest req; @Mock private HttpServletResponse res; @Mock private FilterChain chain; @Mock private Provider<CurrentUser> user; - @Mock private LoadingCache<Account.Id, Holder> limitsPerAccount; - @Mock private LoadingCache<String, Holder> limitsPerRemoteHost; @Mock(answer = Answers.RETURNS_DEEP_STUBS) private CurrentUser currentUser; @@ -63,10 +68,32 @@ private Holder holder; @Mock private RateLimiter rateLimiter; + + @Mock @GerritServerConfig Config cfg; + @Mock GenericFactory userFactory; + @Mock AccountLimitsFinder finder; + private RestApiRateLimiter restReqFilter; + private SystemGroupBackend systemGroupBackend; + private LoadingCache<Account.Id, Holder> limitsPerAccount; + private LoadingCache<String, Holder> limitsPerRemoteHost; @Before public void setUp() throws IOException, ServletException { + systemGroupBackend = new SystemGroupBackend(cfg); + + limitsPerAccount = + CacheBuilder.newBuilder() + .build(new Module.HolderCacheLoaderByAccountId(Type.UPLOADPACK, userFactory, finder)); + limitsPerAccount.put(accountId, holder); + + limitsPerRemoteHost = + CacheBuilder.newBuilder() + .build( + new Module.HolderCacheLoaderByRemoteHost( + Type.UPLOADPACK, systemGroupBackend, finder)); + limitsPerRemoteHost.put(REMOTE_HOST, holder); + restReqFilter = spy( new RestApiRateLimiter( @@ -79,19 +106,11 @@ private void setUpRegisteredUser() throws ExecutionException { when(currentUser.isIdentifiedUser()).thenReturn(true); when(currentUser.asIdentifiedUser().getAccountId()).thenReturn(accountId); - when(limitsPerAccount.get(accountId)).thenReturn(holder); - } - - private void setUpRegisteredUserExecutionException() throws ExecutionException { - when(currentUser.isIdentifiedUser()).thenReturn(true); - when(currentUser.asIdentifiedUser().getAccountId()).thenReturn(accountId); - when(limitsPerAccount.get(accountId)).thenThrow(new ExecutionException(null)); } private void setUpAnonymous() throws ExecutionException { when(currentUser.isIdentifiedUser()).thenReturn(false); - when(req.getRemoteHost()).thenReturn("host"); - when(limitsPerRemoteHost.get("host")).thenReturn(holder); + when(req.getRemoteHost()).thenReturn(REMOTE_HOST); } private void setUpNoQuotaViolation1() { @@ -132,13 +151,6 @@ } @Test - public void testDoFilterCacheMiss() throws IOException, ServletException, ExecutionException { - setUpRegisteredUserExecutionException(); - restReqFilter.doFilter(req, res, chain); - verify(res, times(0)).sendError(eq(SC_TOO_MANY_REQUESTS), anyString()); - } - - @Test public void testDoFilterAnonymQuotaViolation() throws IOException, ServletException, ExecutionException { setUpAnonymous();