Remove events from beforeStartupEventsQueue in-memory queue

Before replication plugin is fully loaded it can receive
events. These events are stored in an in-memory queue called
`beforeStartupEventsQueue`. After plugin is fully loaded those
events are processed but never removed from the queue. This can
cause issue processing the same event multiple times.

Replication done with apply-object may not be idempotent if
the event generated at a point in time is processed later.

To avoid that remove event from the queue and then process it.

Bug: Issue 307554728
Change-Id: Ic075c9dfa0a2e984762fed0aaf7481f035fdd662
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
index 5691ac2..4663702 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java
@@ -303,7 +303,8 @@
 
   private void fireBeforeStartupEvents() {
     Set<String> eventsReplayed = new HashSet<>();
-    for (ReferencesUpdatedEvent event : beforeStartupEventsQueue) {
+    ReferencesUpdatedEvent event;
+    while ((event = beforeStartupEventsQueue.poll()) != null) {
       String eventKey = String.format("%s:%s", event.projectName(), event.getRefNames());
       if (!eventsReplayed.contains(eventKey)) {
         repLog.atInfo().log("Firing pending task %s", event);