Merge branch 'stable-3.3' * stable-3.3: Stop broadcasting accounts cache eviction CachePatternMatcher: Adapt the code to removal of account caches Upgrade bazlets to latest stable-2.16 to build with 2.16.23 API Change-Id: I29c9a2afb0dc9aca53dcb93069d8e11457bcacb8
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java index 9af312d..4ce15eb 100644 --- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java +++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java
@@ -88,7 +88,7 @@ } @VisibleForTesting - Configuration(Config cfg, SitePaths site) { + public Configuration(Config cfg, SitePaths site) { main = new Main(site, cfg); autoReindex = new AutoReindex(cfg); peerInfo = new PeerInfo(cfg);
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/CachePatternMatcher.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/CachePatternMatcher.java index 9a8adce..baf512f 100644 --- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/CachePatternMatcher.java +++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/CachePatternMatcher.java
@@ -26,7 +26,7 @@ @Singleton class CachePatternMatcher { private static final List<String> DEFAULT_PATTERNS = - ImmutableList.of("^accounts.*", "^groups.*", "ldap_usernames", "projects", "sshkeys"); + ImmutableList.of("^groups.*", "ldap_usernames", "projects", "sshkeys"); private final Pattern pattern;
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionHandlerTest.java new file mode 100644 index 0000000..e6633d8 --- /dev/null +++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionHandlerTest.java
@@ -0,0 +1,60 @@ +// Copyright (C) 2020 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.ericsson.gerrit.plugins.highavailability.cache; + +import static org.mockito.Mockito.verifyZeroInteractions; + +import com.ericsson.gerrit.plugins.highavailability.Configuration; +import com.ericsson.gerrit.plugins.highavailability.forwarder.Forwarder; +import com.google.common.cache.RemovalCause; +import com.google.common.cache.RemovalNotification; +import com.google.gerrit.server.config.PluginConfigFactory; +import com.google.gerrit.server.config.SitePaths; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.concurrent.Executor; +import org.eclipse.jgit.lib.Config; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class CacheEvictionHandlerTest { + @Mock private Executor executorMock; + @Mock private Forwarder forwarder; + @Mock private PluginConfigFactory pluginConfigFactoryMock; + + private static final String PLUGIN_NAME = "high-availability"; + private static final Path SITE_PATH = Paths.get("/site_path"); + private CachePatternMatcher defaultCacheMatcher; + + @Before + public void setUp() throws IOException { + defaultCacheMatcher = + new CachePatternMatcher(new Configuration(new Config(), new SitePaths(SITE_PATH))); + } + + @Test + public void shouldNotPublishAccountsCacheEvictions() { + CacheEvictionHandler<String, String> handler = + new CacheEvictionHandler<>(forwarder, executorMock, PLUGIN_NAME, defaultCacheMatcher); + handler.onRemoval( + "test", "accounts", RemovalNotification.create("test", "accounts", RemovalCause.EXPLICIT)); + verifyZeroInteractions(executorMock); + } +}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CachePatternMatcherTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CachePatternMatcherTest.java index 0aac3e4..caf50b9 100644 --- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CachePatternMatcherTest.java +++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/CachePatternMatcherTest.java
@@ -38,9 +38,6 @@ CachePatternMatcher matcher = new CachePatternMatcher(configurationMock); for (String cache : ImmutableList.of( - "accounts", - "accounts_byemail", - "accounts_byname", "groups", "groups_byinclude", "groups_byname", @@ -57,6 +54,7 @@ } for (String cache : ImmutableList.of( + "accounts", "adv_bases", "change_kind", "change_notes",
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/CacheEntryTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/CacheEntryTest.java index 5cdcf5a..a9bcfd7 100644 --- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/CacheEntryTest.java +++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/CacheEntryTest.java
@@ -16,19 +16,13 @@ import static com.google.common.truth.Truth.assertThat; -import com.ericsson.gerrit.plugins.highavailability.cache.Constants; import org.junit.Test; public class CacheEntryTest { @Test public void cacheEntry() throws Exception { - CacheEntry entry = CacheEntry.from("accounts_by_name", "someKey"); - assertThat(entry.getPluginName()).isEqualTo(Constants.GERRIT); - assertThat(entry.getCacheName()).isEqualTo("accounts_by_name"); - assertThat(entry.getKey()).isEqualTo("someKey"); - - entry = CacheEntry.from("my_plugin.my_cache", "someOtherKey"); + CacheEntry entry = CacheEntry.from("my_plugin.my_cache", "someOtherKey"); assertThat(entry.getPluginName()).isEqualTo("my_plugin"); assertThat(entry.getCacheName()).isEqualTo("my_cache"); assertThat(entry.getKey()).isEqualTo("someOtherKey");