Propagate instanceId in Events

Add instanceId in the Events payload when defined.
The value won't be present in the JSON payload
if the value is not set in the Gerrit config

Reference design: https://gerrit-review.googlesource.com/c/homepage/+/263710

Feature: Issue 12685
Change-Id: I507db3f0efba5649ad519361f88ee3f60ab27205
This commit is contained in:
Fabio Ponciroli
2020-05-07 13:22:00 +02:00
parent ba19b98081
commit 214b8963e1
5 changed files with 149 additions and 2 deletions

View File

@@ -40,7 +40,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
public class EventRecorder {
private final RegistrationHandle eventListenerRegistration;
private final ListMultimap<String, RefEvent> recordedEvents;
private final ListMultimap<String, Event> recordedEvents;
@Singleton
public static class Factory {
@@ -79,6 +79,8 @@ public class EventRecorder {
refEventKey(
event.getType(), event.getProjectNameKey().get(), event.getRefName());
recordedEvents.put(key, event);
} else {
recordedEvents.put(e.type, e);
}
}
@@ -158,6 +160,17 @@ public class EventRecorder {
return events;
}
public ImmutableList<Event> getGenericEvents(String type, int expectedSize) {
if (expectedSize == 0) {
assertThat(recordedEvents).doesNotContainKey(type);
return ImmutableList.of();
}
assertThat(recordedEvents).containsKey(type);
ImmutableList<Event> events = FluentIterable.from(recordedEvents.get(type)).toList();
assertThat(events).hasSize(expectedSize);
return events;
}
public void assertNoRefUpdatedEvents(String project, String branch) throws Exception {
getRefUpdatedEvents(project, branch, 0);
}