ChangeIT: Use ExtensionRegistry for ChangeETagComputation

Add the necessary support in ExtensionRegistry and modify the
tests to use it.

Change-Id: I6770e7d854898659c6a72a37b7e45c76179e3e5f
This commit is contained in:
David Pursehouse
2019-10-10 13:59:36 +09:00
parent cec1fd0b6c
commit 79ebe17037
2 changed files with 18 additions and 22 deletions

View File

@@ -18,6 +18,7 @@ import com.google.gerrit.extensions.events.ChangeIndexedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.registration.RegistrationHandle;
import com.google.gerrit.server.ExceptionHook;
import com.google.gerrit.server.change.ChangeETagComputation;
import com.google.gerrit.server.git.ChangeMessageModifier;
import com.google.gerrit.server.git.validators.CommitValidationListener;
import com.google.gerrit.server.logging.PerformanceLogger;
@@ -35,6 +36,7 @@ public class ExtensionRegistry {
private final DynamicSet<ProjectCreationValidationListener> projectCreationValidationListeners;
private final DynamicSet<SubmitRule> submitRules;
private final DynamicSet<ChangeMessageModifier> changeMessageModifiers;
private final DynamicSet<ChangeETagComputation> changeETagComputations;
@Inject
ExtensionRegistry(
@@ -44,7 +46,8 @@ public class ExtensionRegistry {
DynamicSet<PerformanceLogger> performanceLoggers,
DynamicSet<ProjectCreationValidationListener> projectCreationValidationListeners,
DynamicSet<SubmitRule> submitRules,
DynamicSet<ChangeMessageModifier> changeMessageModifiers) {
DynamicSet<ChangeMessageModifier> changeMessageModifiers,
DynamicSet<ChangeETagComputation> changeETagComputations) {
this.changeIndexedListeners = changeIndexedListeners;
this.commitValidationListeners = commitValidationListeners;
this.exceptionHooks = exceptionHooks;
@@ -52,6 +55,7 @@ public class ExtensionRegistry {
this.projectCreationValidationListeners = projectCreationValidationListeners;
this.submitRules = submitRules;
this.changeMessageModifiers = changeMessageModifiers;
this.changeETagComputations = changeETagComputations;
}
public Registration newRegistration() {
@@ -89,6 +93,10 @@ public class ExtensionRegistry {
return add(changeMessageModifiers, changeMessageModifier);
}
public Registration add(ChangeETagComputation changeETagComputation) {
return add(changeETagComputations, changeETagComputation);
}
private <T> Registration add(DynamicSet<T> dynamicSet, T extension) {
RegistrationHandle registrationHandle = dynamicSet.add("gerrit", extension);
registrationHandles.add(registrationHandle);

View File

@@ -140,8 +140,6 @@ import com.google.gerrit.extensions.common.MergePatchSetInput;
import com.google.gerrit.extensions.common.PureRevertInfo;
import com.google.gerrit.extensions.common.RevisionInfo;
import com.google.gerrit.extensions.common.TrackingIdInfo;
import com.google.gerrit.extensions.registration.DynamicSet;
import com.google.gerrit.extensions.registration.RegistrationHandle;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
@@ -162,7 +160,6 @@ import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.StarredChangesUtil;
import com.google.gerrit.server.change.ChangeETagComputation;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.group.SystemGroupBackend;
import com.google.gerrit.server.index.change.ChangeIndex;
@@ -220,7 +217,6 @@ public class ChangeIT extends AbstractDaemonTest {
@Inject private IndexConfig indexConfig;
@Inject private ProjectOperations projectOperations;
@Inject private RequestScopeOperations requestScopeOperations;
@Inject private DynamicSet<ChangeETagComputation> changeETagComputations;
@Inject private ExtensionRegistry extensionRegistry;
@Inject
@@ -2260,11 +2256,8 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result r = createChange();
String oldETag = parseResource(r).getETag();
RegistrationHandle registrationHandle = changeETagComputations.add("gerrit", (p, id) -> "foo");
try {
try (Registration registration = extensionRegistry.newRegistration().add((p, id) -> "foo")) {
assertThat(parseResource(r).getETag()).isNotEqualTo(oldETag);
} finally {
registrationHandle.remove();
}
assertThat(parseResource(r).getETag()).isEqualTo(oldETag);
@@ -2275,11 +2268,8 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result r = createChange();
String oldETag = parseResource(r).getETag();
RegistrationHandle registrationHandle = changeETagComputations.add("gerrit", (p, id) -> null);
try {
try (Registration registration = extensionRegistry.newRegistration().add((p, id) -> null)) {
assertThat(parseResource(r).getETag()).isEqualTo(oldETag);
} finally {
registrationHandle.remove();
}
}
@@ -2288,16 +2278,14 @@ public class ChangeIT extends AbstractDaemonTest {
PushOneCommit.Result r = createChange();
String oldETag = parseResource(r).getETag();
RegistrationHandle registrationHandle =
changeETagComputations.add(
"gerrit",
(p, id) -> {
throw new StorageException("exception during test");
});
try {
try (Registration registration =
extensionRegistry
.newRegistration()
.add(
(p, id) -> {
throw new StorageException("exception during test");
})) {
assertThat(parseResource(r).getETag()).isEqualTo(oldETag);
} finally {
registrationHandle.remove();
}
}