Merge "Configure ProjectResetter through a plain data class."

This commit is contained in:
Edwin Kempin
2018-03-14 10:10:05 +00:00
committed by Gerrit Code Review
6 changed files with 78 additions and 35 deletions

View File

@@ -201,7 +201,12 @@ public abstract class AbstractDaemonTest {
firstTest = description;
}
beforeTest(description);
try (ProjectResetter resetter = resetProjects(projectResetter.builder())) {
ProjectResetter.Config input = resetProjects();
if (input == null) {
input = defaultResetProjects();
}
try (ProjectResetter resetter = projectResetter.builder().build(input)) {
AbstractDaemonTest.this.resetter = resetter;
base.evaluate();
} finally {
@@ -317,8 +322,12 @@ public abstract class AbstractDaemonTest {
}
/** Controls which project and branches should be reset after each test case. */
protected ProjectResetter resetProjects(ProjectResetter.Builder resetter) throws IOException {
return resetter
protected ProjectResetter.Config resetProjects() {
return null;
}
private ProjectResetter.Config defaultResetProjects() {
return new ProjectResetter.Config()
// Don't reset all refs so that refs/sequences/changes is not touched and change IDs are
// not reused.
.reset(allProjects, RefNames.REFS_CONFIG)
@@ -331,8 +340,7 @@ public abstract class AbstractDaemonTest {
RefNames.REFS_USERS + "*",
RefNames.REFS_EXTERNAL_IDS,
RefNames.REFS_STARRED_CHANGES + "*",
RefNames.REFS_DRAFT_COMMENTS + "*")
.build();
RefNames.REFS_DRAFT_COMMENTS + "*");
}
protected void restartAsSlave() throws Exception {

View File

@@ -25,7 +25,6 @@ import com.google.common.collect.ImmutableList;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
import com.google.common.truth.Truth;
import com.google.gerrit.acceptance.ProjectResetter.Builder;
import com.google.gerrit.common.Nullable;
import com.google.gerrit.extensions.api.changes.RecipientType;
import com.google.gerrit.extensions.api.changes.ReviewInput;
@@ -63,10 +62,10 @@ public abstract class AbstractNotificationTest extends AbstractDaemonTest {
}
@Override
protected ProjectResetter resetProjects(Builder resetter) throws IOException {
protected ProjectResetter.Config resetProjects() {
// Don't reset anything so that stagedUsers can be cached across all tests.
// Without this caching these tests become much too slow.
return resetter.build();
return new ProjectResetter.Config();
}
protected static FakeEmailSenderSubject assertThat(FakeEmailSender sender) {

View File

@@ -88,8 +88,6 @@ public class ProjectResetter implements AutoCloseable {
@Nullable private final AccountCache accountCache;
@Nullable private final ProjectCache projectCache;
private final Multimap<Project.NameKey, String> refsByProject;
@Inject
public Builder(
GitRepositoryManager repoManager,
@@ -102,10 +100,27 @@ public class ProjectResetter implements AutoCloseable {
this.accountCreator = accountCreator;
this.accountCache = accountCache;
this.projectCache = projectCache;
}
public ProjectResetter build(ProjectResetter.Config input) throws IOException {
return new ProjectResetter(
repoManager,
allUsersName,
accountCreator,
accountCache,
projectCache,
input.refsByProject);
}
}
public static class Config {
private final Multimap<Project.NameKey, String> refsByProject;
public Config() {
this.refsByProject = MultimapBuilder.hashKeys().arrayListValues().build();
}
public Builder reset(Project.NameKey project, String... refPatterns) {
public Config reset(Project.NameKey project, String... refPatterns) {
List<String> refPatternList = Arrays.asList(refPatterns);
if (refPatternList.isEmpty()) {
refPatternList = ImmutableList.of(RefNames.REFS + "*");
@@ -113,11 +128,6 @@ public class ProjectResetter implements AutoCloseable {
refsByProject.putAll(project, refPatternList);
return this;
}
public ProjectResetter build() throws IOException {
return new ProjectResetter(
repoManager, allUsersName, accountCreator, accountCache, projectCache, refsByProject);
}
}
@Inject private GitRepositoryManager repoManager;