Merge branch 'stable-3.0' into stable-3.1

* stable-3.0:
  ProjectCache: Remove declarations of unthrown IOException
  ProjectIT: Remove unused executor
  ChangeSubmitRequirementIT: Show that submit rules are cached on change query
  Update git submodules
  Update git submodules
  QueryChangeIT: Rename to QueryChangesIT
  QueryChangeIT: Backport moreChangesIndicatorDoesNotWronglyCopyToUnrelatedChanges
  Backport QueryChangeIT
  JettyServer: Stop using deprecated SslContextFactory constructor

Change-Id: I990f05374c95633a0d083bdbf0dd218bd9f6faeb
This commit is contained in:
David Pursehouse
2020-03-13 10:12:29 +09:00
8 changed files with 63 additions and 32 deletions

View File

@@ -298,7 +298,7 @@ public class ProjectResetter implements AutoCloseable {
}
/** Evict projects for which the config was changed. */
private void evictAndReindexProjects() throws IOException {
private void evictAndReindexProjects() {
if (projectCache == null) {
return;
}

View File

@@ -3060,12 +3060,7 @@ class ReceiveCommits {
}
if (isConfig(cmd)) {
logger.atFine().log("Reloading project in cache");
try {
projectCache.evict(project);
} catch (IOException e) {
logger.atWarning().withCause(e).log(
"Cannot evict from project cache, name key: %s", project.getName());
}
projectCache.evict(project);
ProjectState ps = projectCache.get(project.getNameKey());
try {
logger.atFine().log("Updating project description");

View File

@@ -63,29 +63,27 @@ public interface ProjectCache {
* Invalidate the cached information about the given project, and triggers reindexing for it
*
* @param p project that is being evicted
* @throws IOException thrown if the reindexing fails
*/
void evict(Project p) throws IOException;
void evict(Project p);
/**
* Invalidate the cached information about the given project, and triggers reindexing for it
*
* @param p the NameKey of the project that is being evicted
* @throws IOException thrown if the reindexing fails
*/
void evict(Project.NameKey p) throws IOException;
void evict(Project.NameKey p);
/**
* Remove information about the given project from the cache. It will no longer be returned from
* {@link #all()}.
*/
void remove(Project p) throws IOException;
void remove(Project p);
/**
* Remove information about the given project from the cache. It will no longer be returned from
* {@link #all()}.
*/
void remove(Project.NameKey name) throws IOException;
void remove(Project.NameKey name);
/** @return sorted iteration of projects. */
ImmutableSortedSet<Project.NameKey> all();

View File

@@ -188,12 +188,12 @@ public class ProjectCacheImpl implements ProjectCache {
}
@Override
public void evict(Project p) throws IOException {
public void evict(Project p) {
evict(p.getNameKey());
}
@Override
public void evict(Project.NameKey p) throws IOException {
public void evict(Project.NameKey p) {
if (p != null) {
logger.atFine().log("Evict project '%s'", p.get());
byName.invalidate(p.get());
@@ -202,12 +202,12 @@ public class ProjectCacheImpl implements ProjectCache {
}
@Override
public void remove(Project p) throws IOException {
public void remove(Project p) {
remove(p.getNameKey());
}
@Override
public void remove(Project.NameKey name) throws IOException {
public void remove(Project.NameKey name) {
listLock.lock();
try {
list.put(

View File

@@ -28,9 +28,13 @@ import com.google.gerrit.extensions.common.SubmitRequirementInfo;
import com.google.gerrit.extensions.config.FactoryModule;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.rules.SubmitRule;
import com.google.inject.Inject;
import com.google.inject.Module;
import com.google.inject.Singleton;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
public class ChangeSubmitRequirementIT extends AbstractDaemonTest {
@@ -56,22 +60,63 @@ public class ChangeSubmitRequirementIT extends AbstractDaemonTest {
};
}
@Inject CustomSubmitRule rule;
@Test
public void checkSubmitRequirementIsPropagated() throws Exception {
public void submitRequirementIsPropagated() throws Exception {
rule.block(false);
PushOneCommit.Result r = createChange();
ChangeInfo result = gApi.changes().id(r.getChangeId()).get();
assertThat(result.requirements).isEmpty();
rule.block(true);
result = gApi.changes().id(r.getChangeId()).get();
assertThat(result.requirements).containsExactly(reqInfo);
}
@Test
public void submitRequirementIsPropagatedInQuery() throws Exception {
rule.block(false);
PushOneCommit.Result r = createChange();
String query = "status:open project:" + project.get();
List<ChangeInfo> result = gApi.changes().query(query).get();
assertThat(result).hasSize(1);
assertThat(result.get(0).requirements).isEmpty();
// Submit rule behavior is changed, but the query still returns
// the previous result from the index
rule.block(true);
result = gApi.changes().query(query).get();
assertThat(result).hasSize(1);
assertThat(result.get(0).requirements).isEmpty();
// The submit rule result is updated after the change is reindexed
gApi.changes().id(r.getChangeId()).index();
result = gApi.changes().query(query).get();
assertThat(result).hasSize(1);
assertThat(result.get(0).requirements).containsExactly(reqInfo);
}
@Singleton
private static class CustomSubmitRule implements SubmitRule {
private final AtomicBoolean block = new AtomicBoolean(true);
public void block(boolean block) {
this.block.set(block);
}
@Override
public Optional<SubmitRecord> evaluate(ChangeData changeData) {
SubmitRecord record = new SubmitRecord();
record.labels = new ArrayList<>();
record.status = SubmitRecord.Status.NOT_READY;
record.requirements = ImmutableList.of(req);
return Optional.of(record);
if (block.get()) {
SubmitRecord record = new SubmitRecord();
record.labels = new ArrayList<>();
record.status = SubmitRecord.Status.NOT_READY;
record.requirements = ImmutableList.of(req);
return Optional.of(record);
}
return Optional.empty();
}
}
}

View File

@@ -28,7 +28,7 @@ import java.util.List;
import org.junit.Test;
@NoHttpd
public class QueryChangeIT extends AbstractDaemonTest {
public class QueryChangesIT extends AbstractDaemonTest {
@Inject private Provider<QueryChanges> queryChangesProvider;

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.acceptance.api.project;
import static com.google.common.truth.Truth.assertThat;
import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow;
import static com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block;
import static com.google.gerrit.server.git.QueueProvider.QueueType.BATCH;
import static com.google.gerrit.server.project.ProjectState.INHERITED_FROM_GLOBAL;
import static com.google.gerrit.server.project.ProjectState.INHERITED_FROM_PARENT;
import static com.google.gerrit.server.project.ProjectState.OVERRIDDEN_BY_GLOBAL;
@@ -31,7 +30,6 @@ import static org.mockito.Mockito.verify;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.AtomicLongMap;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.ExtensionRegistry;
import com.google.gerrit.acceptance.ExtensionRegistry.Registration;
@@ -65,7 +63,6 @@ import com.google.gerrit.extensions.restapi.ResourceConflictException;
import com.google.gerrit.extensions.restapi.UnprocessableEntityException;
import com.google.gerrit.server.config.ProjectConfigEntry;
import com.google.gerrit.server.group.SystemGroupBackend;
import com.google.gerrit.server.index.IndexExecutor;
import com.google.gerrit.server.project.CommentLinkInfoImpl;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
@@ -90,10 +87,6 @@ public class ProjectIT extends AbstractDaemonTest {
@Inject private RequestScopeOperations requestScopeOperations;
@Inject private ExtensionRegistry extensionRegistry;
@Inject
@IndexExecutor(BATCH)
private ListeningExecutorService executor;
@Override
public Module createModule() {
return new AbstractModule() {