Merge branch 'stable-3.2' into stable-3.3

* stable-3.2:
  Revert "Set forward context for events having a different instanceId"
  Use Gerrit v3.2.14 on Ubuntu as CentOS is discontinued
  Pin haproxy to 1.8.30-buster and fix associated issues

Change-Id: I9013a93c16b7d2670630694e32414de2461c5f54
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBroker.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBroker.java
index fb651b7..700d5e1 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBroker.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBroker.java
@@ -24,7 +24,6 @@
 import com.google.gerrit.server.plugincontext.PluginSetContext;
 import com.google.gerrit.server.project.ProjectCache;
 import com.google.inject.Inject;
-import java.util.Objects;
 import javax.annotation.Nullable;
 
 class ForwardedAwareEventBroker extends EventBroker {
@@ -46,19 +45,8 @@
         gerritInstanceId);
   }
 
-  private boolean isProducedByLocalInstance(Event event) {
-    return Objects.equals(event.instanceId, gerritInstanceId);
-  }
-
   @Override
   protected void fireEventForUnrestrictedListeners(Event event) {
-    // An event should not be dispatched when it is "forwarded".
-    // Meaning, it was either produced somewhere else
-    if (!isProducedByLocalInstance(event)) {
-      Context.setForwardedEvent(true);
-    }
-    // or it was consumed by the high-availability rest endpoint and
-    // thus the context of its consumption has already been set to "forwarded".
     if (!Context.isForwardedEvent()) {
       super.fireEventForUnrestrictedListeners(event);
     }
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 2f7d41a..ff987aa 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -264,23 +264,3 @@
     Ignore the alignment with the global ref-db for AProject on refs/heads/feature.
 
     Defaults to no rule. All projects are REQUIRED to be consistent on all refs.
-
-File 'gerrit.config'
---------------------
-
-```gerrit.instanceId```
-:   Optional identifier for this Gerrit instance.
-[[docs](https://gerrit-documentation.storage.googleapis.com/Documentation/3.2.0/config-gerrit.html#gerrit.instanceId)].
-
-Whilst this is not, specifically, a high-availability plugin configuration, it plays
-an important role on which events are forwarded to peers.
-
-If `instanceId` is set, events produced by that Gerrit instance will contain its
-origin in the `instanceId` field, allowing to track where they are coming from.
-
-The high-availability plugin will check the `instanceId` value to decide whether
-an event should be forwarded: events that originated from different Gerrit instances
-will not be forwarded.
-
-When neither `gerrit.instanceId` nor `event.instanceId` are set, it is not possible
-to identify the origin of the event and thus the event is always forwarded.
diff --git a/src/test/docker/gerrit/Dockerfile b/src/test/docker/gerrit/Dockerfile
index 7269a3a..1d0ffa0 100644
--- a/src/test/docker/gerrit/Dockerfile
+++ b/src/test/docker/gerrit/Dockerfile
@@ -1,16 +1,16 @@
-FROM gerritcodereview/gerrit:3.3.7 
+FROM gerritcodereview/gerrit:3.3.7-ubuntu20
 
 ENV GERRIT_BRANCH=stable-3.3
 
-ENV GERRIT_CI_URL=https://gerrit-ci.gerritforge.com/job
+ENV GERRIT_CI_URL=https://archive-ci.gerritforge.com/job
 
 USER root
 
-RUN yum install -y iputils nmap curl lsof gettext net-tools sudo
+RUN apt update && apt install -y iputils-ping nmap curl lsof gettext net-tools sudo
 
 USER gerrit
 
-ADD --chown=gerrit:gerrit $GERRIT_CI_URL/plugin-javamelody-bazel-master-$GERRIT_BRANCH/lastSuccessfulBuild/artifact/bazel-bin/plugins/javamelody/javamelody.jar /var/gerrit/plugins/javamelody.jar
+ADD --chown=gerrit:gerrit $GERRIT_CI_URL/plugin-javamelody-bazel-$GERRIT_BRANCH/lastSuccessfulBuild/artifact/bazel-bin/plugins/javamelody/javamelody.jar /var/gerrit/plugins/javamelody.jar
 ADD --chown=gerrit:gerrit $GERRIT_CI_URL/plugin-high-availability-bazel-$GERRIT_BRANCH/lastSuccessfulBuild/artifact/bazel-bin/plugins/high-availability/high-availability.jar /var/gerrit/plugins/high-availability.jar
 
 USER root
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBrokerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBrokerTest.java
index cfe0475..ec5b1de 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBrokerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedAwareEventBrokerTest.java
@@ -30,9 +30,7 @@
 
   private EventListener listenerMock;
   private ForwardedAwareEventBroker broker;
-  private ForwardedAwareEventBroker brokerWithGerritInstanceId;
-  private Event event;
-  private String gerritInstanceId = "gerrit-instance-id";
+  private Event event = new TestEvent();
 
   @Before
   public void setUp() {
@@ -40,11 +38,8 @@
     listenerMock = mock(EventListener.class);
     DynamicSet<EventListener> set = DynamicSet.emptySet();
     set.add("high-availability", listenerMock);
-    event = new TestEvent();
     PluginSetContext<EventListener> listeners = new PluginSetContext<>(set, mockMetrics);
     broker = new ForwardedAwareEventBroker(null, listeners, null, null, null, null);
-    brokerWithGerritInstanceId =
-        new ForwardedAwareEventBroker(null, listeners, null, null, null, gerritInstanceId);
   }
 
   @Test
@@ -63,43 +58,4 @@
     }
     verifyZeroInteractions(listenerMock);
   }
-
-  @Test
-  public void shouldNotDispatchEventWhenEventInstanceIdIsDefinedButGerritInstanceIdIsNot() {
-    event.instanceId = gerritInstanceId;
-    try {
-      broker.fireEventForUnrestrictedListeners(event);
-    } finally {
-      Context.unsetForwardedEvent();
-    }
-    verifyZeroInteractions(listenerMock);
-  }
-
-  @Test
-  public void shouldNotDispatchEventWhenGerritInstanceIdIsDefinedButEventInstanceIdIsNot() {
-    try {
-      brokerWithGerritInstanceId.fireEventForUnrestrictedListeners(event);
-    } finally {
-      Context.unsetForwardedEvent();
-    }
-    verifyZeroInteractions(listenerMock);
-  }
-
-  @Test
-  public void shouldNotDispatchEventWhenInstanceIdsAreDifferent() {
-    event.instanceId = "some-other-gerrit-instance-id";
-    try {
-      brokerWithGerritInstanceId.fireEventForUnrestrictedListeners(event);
-    } finally {
-      Context.unsetForwardedEvent();
-    }
-    verifyZeroInteractions(listenerMock);
-  }
-
-  @Test
-  public void shouldDispatchEventWhenInstanceIdsAreEqual() {
-    event.instanceId = gerritInstanceId;
-    brokerWithGerritInstanceId.fireEventForUnrestrictedListeners(event);
-    verify(listenerMock).onEvent(event);
-  }
 }