Merge "Add helper class to register extensions in acceptance tests"

This commit is contained in:
David Pursehouse
2019-10-10 01:16:55 +00:00
committed by Gerrit Code Review
3 changed files with 521 additions and 310 deletions

View File

@@ -124,6 +124,7 @@ java_library2(
"//java/com/google/gerrit/server", "//java/com/google/gerrit/server",
"//java/com/google/gerrit/server/audit", "//java/com/google/gerrit/server/audit",
"//java/com/google/gerrit/server/git/receive", "//java/com/google/gerrit/server/git/receive",
"//java/com/google/gerrit/server/logging",
"//java/com/google/gerrit/server/restapi", "//java/com/google/gerrit/server/restapi",
"//java/com/google/gerrit/server/schema", "//java/com/google/gerrit/server/schema",
"//java/com/google/gerrit/server/util/git", "//java/com/google/gerrit/server/util/git",

View File

@@ -0,0 +1,95 @@
// Copyright (C) 2019 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.google.gerrit.acceptance;
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.git.validators.CommitValidationListener;
import com.google.gerrit.server.logging.PerformanceLogger;
import com.google.gerrit.server.rules.SubmitRule;
import com.google.gerrit.server.validators.ProjectCreationValidationListener;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.List;
public class ExtensionRegistry {
private final DynamicSet<ChangeIndexedListener> changeIndexedListeners;
private final DynamicSet<CommitValidationListener> commitValidationListeners;
private final DynamicSet<ExceptionHook> exceptionHooks;
private final DynamicSet<PerformanceLogger> performanceLoggers;
private final DynamicSet<ProjectCreationValidationListener> projectCreationValidationListeners;
private final DynamicSet<SubmitRule> submitRules;
@Inject
ExtensionRegistry(
DynamicSet<ChangeIndexedListener> changeIndexedListeners,
DynamicSet<CommitValidationListener> commitValidationListeners,
DynamicSet<ExceptionHook> exceptionHooks,
DynamicSet<PerformanceLogger> performanceLoggers,
DynamicSet<ProjectCreationValidationListener> projectCreationValidationListeners,
DynamicSet<SubmitRule> submitRules) {
this.changeIndexedListeners = changeIndexedListeners;
this.commitValidationListeners = commitValidationListeners;
this.exceptionHooks = exceptionHooks;
this.performanceLoggers = performanceLoggers;
this.projectCreationValidationListeners = projectCreationValidationListeners;
this.submitRules = submitRules;
}
public Registration newRegistration() {
return new Registration();
}
public class Registration implements AutoCloseable {
private final List<RegistrationHandle> registrationHandles = new ArrayList<>();
public Registration add(ChangeIndexedListener changeIndexedListener) {
return add(changeIndexedListeners, changeIndexedListener);
}
public Registration add(CommitValidationListener commitValidationListener) {
return add(commitValidationListeners, commitValidationListener);
}
public Registration add(ExceptionHook exceptionHook) {
return add(exceptionHooks, exceptionHook);
}
public Registration add(PerformanceLogger performanceLogger) {
return add(performanceLoggers, performanceLogger);
}
public Registration add(ProjectCreationValidationListener projectCreationListener) {
return add(projectCreationValidationListeners, projectCreationListener);
}
public Registration add(SubmitRule submitRule) {
return add(submitRules, submitRule);
}
private <T> Registration add(DynamicSet<T> dynamicSet, T extension) {
RegistrationHandle registrationHandle = dynamicSet.add("gerrit", extension);
registrationHandles.add(registrationHandle);
return this;
}
@Override
public void close() {
registrationHandles.forEach(h -> h.remove());
}
}
}

View File

@@ -26,14 +26,14 @@ import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.truth.Expect; import com.google.common.truth.Expect;
import com.google.gerrit.acceptance.AbstractDaemonTest; import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.ExtensionRegistry;
import com.google.gerrit.acceptance.ExtensionRegistry.Registration;
import com.google.gerrit.acceptance.GerritConfig; import com.google.gerrit.acceptance.GerritConfig;
import com.google.gerrit.acceptance.PushOneCommit; import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.RestResponse; import com.google.gerrit.acceptance.RestResponse;
import com.google.gerrit.common.data.SubmitRecord; import com.google.gerrit.common.data.SubmitRecord;
import com.google.gerrit.extensions.api.changes.ReviewInput; import com.google.gerrit.extensions.api.changes.ReviewInput;
import com.google.gerrit.extensions.events.ChangeIndexedListener; 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.httpd.restapi.ParameterParser; import com.google.gerrit.httpd.restapi.ParameterParser;
import com.google.gerrit.httpd.restapi.RestApiServlet; import com.google.gerrit.httpd.restapi.RestApiServlet;
import com.google.gerrit.server.ExceptionHook; import com.google.gerrit.server.ExceptionHook;
@@ -58,8 +58,6 @@ import java.util.Optional;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.SortedSet; import java.util.SortedSet;
import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicHeader;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -81,42 +79,15 @@ import org.junit.Test;
public class TraceIT extends AbstractDaemonTest { public class TraceIT extends AbstractDaemonTest {
@Rule public final Expect expect = Expect.create(); @Rule public final Expect expect = Expect.create();
@Inject private DynamicSet<ProjectCreationValidationListener> projectCreationValidationListeners; @Inject private ExtensionRegistry extensionRegistry;
@Inject private DynamicSet<CommitValidationListener> commitValidationListeners;
@Inject private DynamicSet<ChangeIndexedListener> changeIndexedListeners;
@Inject private DynamicSet<PerformanceLogger> performanceLoggers;
@Inject private DynamicSet<SubmitRule> submitRules;
@Inject private DynamicSet<ExceptionHook> exceptionHooks;
@Inject private WorkQueue workQueue; @Inject private WorkQueue workQueue;
private TraceValidatingProjectCreationValidationListener projectCreationListener;
private RegistrationHandle projectCreationListenerRegistrationHandle;
private TraceValidatingCommitValidationListener commitValidationListener;
private RegistrationHandle commitValidationRegistrationHandle;
private TestPerformanceLogger testPerformanceLogger;
private RegistrationHandle performanceLoggerRegistrationHandle;
@Before
public void setup() {
projectCreationListener = new TraceValidatingProjectCreationValidationListener();
projectCreationListenerRegistrationHandle =
projectCreationValidationListeners.add("gerrit", projectCreationListener);
commitValidationListener = new TraceValidatingCommitValidationListener();
commitValidationRegistrationHandle =
commitValidationListeners.add("gerrit", commitValidationListener);
testPerformanceLogger = new TestPerformanceLogger();
performanceLoggerRegistrationHandle = performanceLoggers.add("gerrit", testPerformanceLogger);
}
@After
public void cleanup() {
projectCreationListenerRegistrationHandle.remove();
commitValidationRegistrationHandle.remove();
performanceLoggerRegistrationHandle.remove();
}
@Test @Test
public void restCallWithoutTrace() throws Exception { public void restCallWithoutTrace() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new1"); RestResponse response = adminRestSession.put("/projects/new1");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -126,15 +97,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new1"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new1");
} }
}
@Test @Test
public void restCallForChangeSetsProjectTag() throws Exception { public void restCallForChangeSetsProjectTag() throws Exception {
String changeId = createChange().getChangeId(); String changeId = createChange().getChangeId();
TraceChangeIndexedListener changeIndexedListener = new TraceChangeIndexedListener(); TraceChangeIndexedListener changeIndexedListener = new TraceChangeIndexedListener();
RegistrationHandle registrationHandle = try (Registration registration =
changeIndexedListeners.add("gerrit", changeIndexedListener); extensionRegistry.newRegistration().add(changeIndexedListener)) {
try {
RestResponse response = RestResponse response =
adminRestSession.post( adminRestSession.post(
"/changes/" + changeId + "/revisions/current/review", ReviewInput.approve()); "/changes/" + changeId + "/revisions/current/review", ReviewInput.approve());
@@ -142,13 +113,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(changeIndexedListener.tags.get("project")).containsExactly(project.get()); assertThat(changeIndexedListener.tags.get("project")).containsExactly(project.get());
} finally {
registrationHandle.remove();
} }
} }
@Test @Test
public void restCallWithTraceRequestParam() throws Exception { public void restCallWithTraceRequestParam() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = RestResponse response =
adminRestSession.put("/projects/new2?" + ParameterParser.TRACE_PARAMETER); adminRestSession.put("/projects/new2?" + ParameterParser.TRACE_PARAMETER);
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
@@ -157,9 +130,14 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new2"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new2");
} }
}
@Test @Test
public void restCallWithTraceRequestParamAndProvidedTraceId() throws Exception { public void restCallWithTraceRequestParamAndProvidedTraceId() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = RestResponse response =
adminRestSession.put("/projects/new3?" + ParameterParser.TRACE_PARAMETER + "=issue/123"); adminRestSession.put("/projects/new3?" + ParameterParser.TRACE_PARAMETER + "=issue/123");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
@@ -168,9 +146,14 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new3"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new3");
} }
}
@Test @Test
public void restCallWithTraceHeader() throws Exception { public void restCallWithTraceHeader() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = RestResponse response =
adminRestSession.putWithHeader( adminRestSession.putWithHeader(
"/projects/new4", new BasicHeader(RestApiServlet.X_GERRIT_TRACE, null)); "/projects/new4", new BasicHeader(RestApiServlet.X_GERRIT_TRACE, null));
@@ -180,9 +163,14 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new4"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new4");
} }
}
@Test @Test
public void restCallWithTraceHeaderAndProvidedTraceId() throws Exception { public void restCallWithTraceHeaderAndProvidedTraceId() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = RestResponse response =
adminRestSession.putWithHeader( adminRestSession.putWithHeader(
"/projects/new5", new BasicHeader(RestApiServlet.X_GERRIT_TRACE, "issue/123")); "/projects/new5", new BasicHeader(RestApiServlet.X_GERRIT_TRACE, "issue/123"));
@@ -192,9 +180,14 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new5"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new5");
} }
}
@Test @Test
public void restCallWithTraceRequestParamAndTraceHeader() throws Exception { public void restCallWithTraceRequestParamAndTraceHeader() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
// trace ID only specified by trace header // trace ID only specified by trace header
RestResponse response = RestResponse response =
adminRestSession.putWithHeader( adminRestSession.putWithHeader(
@@ -208,7 +201,8 @@ public class TraceIT extends AbstractDaemonTest {
// trace ID only specified by trace request parameter // trace ID only specified by trace request parameter
response = response =
adminRestSession.putWithHeader( adminRestSession.putWithHeader(
"/projects/new7?trace=issue/123", new BasicHeader(RestApiServlet.X_GERRIT_TRACE, null)); "/projects/new7?trace=issue/123",
new BasicHeader(RestApiServlet.X_GERRIT_TRACE, null));
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isEqualTo("issue/123"); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isEqualTo("issue/123");
assertThat(projectCreationListener.traceId).isEqualTo("issue/123"); assertThat(projectCreationListener.traceId).isEqualTo("issue/123");
@@ -238,9 +232,14 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new9"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new9");
} }
}
@Test @Test
public void pushWithoutTrace() throws Exception { public void pushWithoutTrace() throws Exception {
TraceValidatingCommitValidationListener commitValidationListener =
new TraceValidatingCommitValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(commitValidationListener)) {
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo); PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
PushOneCommit.Result r = push.to("refs/heads/master"); PushOneCommit.Result r = push.to("refs/heads/master");
r.assertOkStatus(); r.assertOkStatus();
@@ -250,9 +249,14 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get()); assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get());
} }
}
@Test @Test
public void pushWithTrace() throws Exception { public void pushWithTrace() throws Exception {
TraceValidatingCommitValidationListener commitValidationListener =
new TraceValidatingCommitValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(commitValidationListener)) {
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo); PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
push.setPushOptions(ImmutableList.of("trace")); push.setPushOptions(ImmutableList.of("trace"));
PushOneCommit.Result r = push.to("refs/heads/master"); PushOneCommit.Result r = push.to("refs/heads/master");
@@ -261,9 +265,14 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(commitValidationListener.isLoggingForced).isTrue(); assertThat(commitValidationListener.isLoggingForced).isTrue();
assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get()); assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get());
} }
}
@Test @Test
public void pushWithTraceAndProvidedTraceId() throws Exception { public void pushWithTraceAndProvidedTraceId() throws Exception {
TraceValidatingCommitValidationListener commitValidationListener =
new TraceValidatingCommitValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(commitValidationListener)) {
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo); PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
push.setPushOptions(ImmutableList.of("trace=issue/123")); push.setPushOptions(ImmutableList.of("trace=issue/123"));
PushOneCommit.Result r = push.to("refs/heads/master"); PushOneCommit.Result r = push.to("refs/heads/master");
@@ -272,9 +281,14 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(commitValidationListener.isLoggingForced).isTrue(); assertThat(commitValidationListener.isLoggingForced).isTrue();
assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get()); assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get());
} }
}
@Test @Test
public void pushForReviewWithoutTrace() throws Exception { public void pushForReviewWithoutTrace() throws Exception {
TraceValidatingCommitValidationListener commitValidationListener =
new TraceValidatingCommitValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(commitValidationListener)) {
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo); PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
PushOneCommit.Result r = push.to("refs/for/master"); PushOneCommit.Result r = push.to("refs/for/master");
r.assertOkStatus(); r.assertOkStatus();
@@ -284,9 +298,14 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get()); assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get());
} }
}
@Test @Test
public void pushForReviewWithTrace() throws Exception { public void pushForReviewWithTrace() throws Exception {
TraceValidatingCommitValidationListener commitValidationListener =
new TraceValidatingCommitValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(commitValidationListener)) {
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo); PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
push.setPushOptions(ImmutableList.of("trace")); push.setPushOptions(ImmutableList.of("trace"));
PushOneCommit.Result r = push.to("refs/for/master"); PushOneCommit.Result r = push.to("refs/for/master");
@@ -295,9 +314,14 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(commitValidationListener.isLoggingForced).isTrue(); assertThat(commitValidationListener.isLoggingForced).isTrue();
assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get()); assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get());
} }
}
@Test @Test
public void pushForReviewWithTraceAndProvidedTraceId() throws Exception { public void pushForReviewWithTraceAndProvidedTraceId() throws Exception {
TraceValidatingCommitValidationListener commitValidationListener =
new TraceValidatingCommitValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(commitValidationListener)) {
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo); PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
push.setPushOptions(ImmutableList.of("trace=issue/123")); push.setPushOptions(ImmutableList.of("trace=issue/123"));
PushOneCommit.Result r = push.to("refs/for/master"); PushOneCommit.Result r = push.to("refs/for/master");
@@ -306,6 +330,7 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(commitValidationListener.isLoggingForced).isTrue(); assertThat(commitValidationListener.isLoggingForced).isTrue();
assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get()); assertThat(commitValidationListener.tags.get("project")).containsExactly(project.get());
} }
}
@Test @Test
public void workQueueCopyLoggingContext() throws Exception { public void workQueueCopyLoggingContext() throws Exception {
@@ -345,26 +370,39 @@ public class TraceIT extends AbstractDaemonTest {
@Test @Test
public void performanceLoggingForRestCall() throws Exception { public void performanceLoggingForRestCall() throws Exception {
TestPerformanceLogger testPerformanceLogger = new TestPerformanceLogger();
try (Registration registration =
extensionRegistry.newRegistration().add(testPerformanceLogger)) {
RestResponse response = adminRestSession.put("/projects/new10"); RestResponse response = adminRestSession.put("/projects/new10");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
// This assertion assumes that the server invokes the PerformanceLogger plugins before it sends // This assertion assumes that the server invokes the PerformanceLogger plugins before it
// the response to the client. If this assertion gets flaky it's likely that this got changed on // sends
// the response to the client. If this assertion gets flaky it's likely that this got changed
// on
// server-side. // server-side.
assertThat(testPerformanceLogger.logEntries()).isNotEmpty(); assertThat(testPerformanceLogger.logEntries()).isNotEmpty();
} }
}
@Test @Test
public void performanceLoggingForPush() throws Exception { public void performanceLoggingForPush() throws Exception {
TestPerformanceLogger testPerformanceLogger = new TestPerformanceLogger();
try (Registration registration =
extensionRegistry.newRegistration().add(testPerformanceLogger)) {
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo); PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo);
PushOneCommit.Result r = push.to("refs/heads/master"); PushOneCommit.Result r = push.to("refs/heads/master");
r.assertOkStatus(); r.assertOkStatus();
assertThat(testPerformanceLogger.logEntries()).isNotEmpty(); assertThat(testPerformanceLogger.logEntries()).isNotEmpty();
} }
}
@Test @Test
@GerritConfig(name = "tracing.performanceLogging", value = "false") @GerritConfig(name = "tracing.performanceLogging", value = "false")
public void noPerformanceLoggingIfDisabled() throws Exception { public void noPerformanceLoggingIfDisabled() throws Exception {
TestPerformanceLogger testPerformanceLogger = new TestPerformanceLogger();
try (Registration registration =
extensionRegistry.newRegistration().add(testPerformanceLogger)) {
RestResponse response = adminRestSession.put("/projects/new11"); RestResponse response = adminRestSession.put("/projects/new11");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
@@ -374,10 +412,15 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(testPerformanceLogger.logEntries()).isEmpty(); assertThat(testPerformanceLogger.logEntries()).isEmpty();
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.projectPattern", value = "new12") @GerritConfig(name = "tracing.issue123.projectPattern", value = "new12")
public void traceProject() throws Exception { public void traceProject() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new12"); RestResponse response = adminRestSession.put("/projects/new12");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -385,10 +428,15 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new12"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new12");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.projectPattern", value = "new.*") @GerritConfig(name = "tracing.issue123.projectPattern", value = "new.*")
public void traceProjectMatchRegEx() throws Exception { public void traceProjectMatchRegEx() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new13"); RestResponse response = adminRestSession.put("/projects/new13");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -396,10 +444,15 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new13"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new13");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.projectPattern", value = "foo.*") @GerritConfig(name = "tracing.issue123.projectPattern", value = "foo.*")
public void traceProjectNoMatch() throws Exception { public void traceProjectNoMatch() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new13"); RestResponse response = adminRestSession.put("/projects/new13");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -409,10 +462,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new13"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new13");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.projectPattern", value = "][") @GerritConfig(name = "tracing.issue123.projectPattern", value = "][")
public void traceProjectInvalidRegEx() throws Exception { public void traceProjectInvalidRegEx() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new14"); RestResponse response = adminRestSession.put("/projects/new14");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -422,10 +480,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new14"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new14");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.account", value = "1000000") @GerritConfig(name = "tracing.issue123.account", value = "1000000")
public void traceAccount() throws Exception { public void traceAccount() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new15"); RestResponse response = adminRestSession.put("/projects/new15");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -433,10 +496,15 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new15"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new15");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.account", value = "1000001") @GerritConfig(name = "tracing.issue123.account", value = "1000001")
public void traceAccountNoMatch() throws Exception { public void traceAccountNoMatch() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new16"); RestResponse response = adminRestSession.put("/projects/new16");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -446,10 +514,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new16"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new16");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.account", value = "999") @GerritConfig(name = "tracing.issue123.account", value = "999")
public void traceAccountNotFound() throws Exception { public void traceAccountNotFound() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new17"); RestResponse response = adminRestSession.put("/projects/new17");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -459,10 +532,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new17"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new17");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.account", value = "invalid") @GerritConfig(name = "tracing.issue123.account", value = "invalid")
public void traceAccountInvalidId() throws Exception { public void traceAccountInvalidId() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new18"); RestResponse response = adminRestSession.put("/projects/new18");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -472,10 +550,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new18"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new18");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.requestType", value = "REST") @GerritConfig(name = "tracing.issue123.requestType", value = "REST")
public void traceRequestType() throws Exception { public void traceRequestType() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new19"); RestResponse response = adminRestSession.put("/projects/new19");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -483,10 +566,15 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new19"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new19");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.requestType", value = "SSH") @GerritConfig(name = "tracing.issue123.requestType", value = "SSH")
public void traceRequestTypeNoMatch() throws Exception { public void traceRequestTypeNoMatch() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new20"); RestResponse response = adminRestSession.put("/projects/new20");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -496,10 +584,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new20"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new20");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.requestType", value = "FOO") @GerritConfig(name = "tracing.issue123.requestType", value = "FOO")
public void traceProjectInvalidRequestType() throws Exception { public void traceProjectInvalidRequestType() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new21"); RestResponse response = adminRestSession.put("/projects/new21");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -509,11 +602,16 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new21"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new21");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.account", value = "1000000") @GerritConfig(name = "tracing.issue123.account", value = "1000000")
@GerritConfig(name = "tracing.issue123.projectPattern", value = "new.*") @GerritConfig(name = "tracing.issue123.projectPattern", value = "new.*")
public void traceProjectForAccount() throws Exception { public void traceProjectForAccount() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new22"); RestResponse response = adminRestSession.put("/projects/new22");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -521,11 +619,16 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new22"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new22");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.account", value = "1000000") @GerritConfig(name = "tracing.issue123.account", value = "1000000")
@GerritConfig(name = "tracing.issue123.projectPattern", value = "foo.*") @GerritConfig(name = "tracing.issue123.projectPattern", value = "foo.*")
public void traceProjectForAccountNoProjectMatch() throws Exception { public void traceProjectForAccountNoProjectMatch() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new23"); RestResponse response = adminRestSession.put("/projects/new23");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -535,11 +638,16 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new23"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new23");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.account", value = "1000001") @GerritConfig(name = "tracing.issue123.account", value = "1000001")
@GerritConfig(name = "tracing.issue123.projectPattern", value = "new.*") @GerritConfig(name = "tracing.issue123.projectPattern", value = "new.*")
public void traceProjectForAccountNoAccountMatch() throws Exception { public void traceProjectForAccountNoAccountMatch() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new24"); RestResponse response = adminRestSession.put("/projects/new24");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -549,10 +657,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new24"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new24");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.requestUriPattern", value = "/projects/.*") @GerritConfig(name = "tracing.issue123.requestUriPattern", value = "/projects/.*")
public void traceRequestUri() throws Exception { public void traceRequestUri() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new23"); RestResponse response = adminRestSession.put("/projects/new23");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -560,10 +673,15 @@ public class TraceIT extends AbstractDaemonTest {
assertThat(projectCreationListener.isLoggingForced).isTrue(); assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new23"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new23");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.requestUriPattern", value = "/projects/.*/foo") @GerritConfig(name = "tracing.issue123.requestUriPattern", value = "/projects/.*/foo")
public void traceRequestUriNoMatch() throws Exception { public void traceRequestUriNoMatch() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new23"); RestResponse response = adminRestSession.put("/projects/new23");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -573,10 +691,15 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new23"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new23");
} }
}
@Test @Test
@GerritConfig(name = "tracing.issue123.requestUriPattern", value = "][") @GerritConfig(name = "tracing.issue123.requestUriPattern", value = "][")
public void traceRequestUriInvalidRegEx() throws Exception { public void traceRequestUriInvalidRegEx() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener =
new TraceValidatingProjectCreationValidationListener();
try (Registration registration =
extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new24"); RestResponse response = adminRestSession.put("/projects/new24");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED); assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
@@ -586,6 +709,7 @@ public class TraceIT extends AbstractDaemonTest {
// The logging tag with the project name is also set if tracing is off. // The logging tag with the project name is also set if tracing is off.
assertThat(projectCreationListener.tags.get("project")).containsExactly("new24"); assertThat(projectCreationListener.tags.get("project")).containsExactly("new24");
} }
}
@Test @Test
@GerritConfig(name = "retry.retryWithTraceOnFailure", value = "true") @GerritConfig(name = "retry.retryWithTraceOnFailure", value = "true")
@@ -595,15 +719,12 @@ public class TraceIT extends AbstractDaemonTest {
TraceSubmitRule traceSubmitRule = new TraceSubmitRule(); TraceSubmitRule traceSubmitRule = new TraceSubmitRule();
traceSubmitRule.failAlways = true; traceSubmitRule.failAlways = true;
RegistrationHandle submitRuleRegistrationHandle = submitRules.add("gerrit", traceSubmitRule); try (Registration registration = extensionRegistry.newRegistration().add(traceSubmitRule)) {
try {
RestResponse response = adminRestSession.post("/changes/" + changeId + "/submit"); RestResponse response = adminRestSession.post("/changes/" + changeId + "/submit");
assertThat(response.getStatusCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR); assertThat(response.getStatusCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).startsWith("retry-on-failure-"); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).startsWith("retry-on-failure-");
assertThat(traceSubmitRule.traceId).startsWith("retry-on-failure-"); assertThat(traceSubmitRule.traceId).startsWith("retry-on-failure-");
assertThat(traceSubmitRule.isLoggingForced).isTrue(); assertThat(traceSubmitRule.isLoggingForced).isTrue();
} finally {
submitRuleRegistrationHandle.remove();
} }
} }
@@ -615,25 +736,22 @@ public class TraceIT extends AbstractDaemonTest {
TraceSubmitRule traceSubmitRule = new TraceSubmitRule(); TraceSubmitRule traceSubmitRule = new TraceSubmitRule();
traceSubmitRule.failAlways = true; traceSubmitRule.failAlways = true;
RegistrationHandle submitRuleRegistrationHandle = submitRules.add("gerrit", traceSubmitRule); try (Registration registration =
RegistrationHandle exceptionHookRegistrationHandle = extensionRegistry
exceptionHooks.add( .newRegistration()
"gerrit", .add(traceSubmitRule)
.add(
new ExceptionHook() { new ExceptionHook() {
@Override @Override
public boolean shouldRetry(Throwable t) { public boolean shouldRetry(Throwable t) {
return true; return true;
} }
}); })) {
try {
RestResponse response = adminRestSession.post("/changes/" + changeId + "/submit"); RestResponse response = adminRestSession.post("/changes/" + changeId + "/submit");
assertThat(response.getStatusCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR); assertThat(response.getStatusCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
assertThat(traceSubmitRule.traceId).isNull(); assertThat(traceSubmitRule.traceId).isNull();
assertThat(traceSubmitRule.isLoggingForced).isFalse(); assertThat(traceSubmitRule.isLoggingForced).isFalse();
} finally {
submitRuleRegistrationHandle.remove();
exceptionHookRegistrationHandle.remove();
} }
} }
@@ -644,15 +762,12 @@ public class TraceIT extends AbstractDaemonTest {
TraceSubmitRule traceSubmitRule = new TraceSubmitRule(); TraceSubmitRule traceSubmitRule = new TraceSubmitRule();
traceSubmitRule.failOnce = true; traceSubmitRule.failOnce = true;
RegistrationHandle submitRuleRegistrationHandle = submitRules.add("gerrit", traceSubmitRule); try (Registration registration = extensionRegistry.newRegistration().add(traceSubmitRule)) {
try {
RestResponse response = adminRestSession.post("/changes/" + changeId + "/submit"); RestResponse response = adminRestSession.post("/changes/" + changeId + "/submit");
assertThat(response.getStatusCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR); assertThat(response.getStatusCode()).isEqualTo(SC_INTERNAL_SERVER_ERROR);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull(); assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
assertThat(traceSubmitRule.traceId).isNull(); assertThat(traceSubmitRule.traceId).isNull();
assertThat(traceSubmitRule.isLoggingForced).isFalse(); assertThat(traceSubmitRule.isLoggingForced).isFalse();
} finally {
submitRuleRegistrationHandle.remove();
} }
} }