AbstractIndexTests: Use ExtensionRegistry for ChangeIndexedCounter
Change-Id: I29290128a03d389993d8d747592b46cbbfe04e3f
This commit is contained in:
@@ -20,102 +20,91 @@ import static java.util.stream.Collectors.toList;
|
|||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||||
import com.google.gerrit.acceptance.ChangeIndexedCounter;
|
import com.google.gerrit.acceptance.ChangeIndexedCounter;
|
||||||
|
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.NoHttpd;
|
import com.google.gerrit.acceptance.NoHttpd;
|
||||||
import com.google.gerrit.acceptance.PushOneCommit;
|
import com.google.gerrit.acceptance.PushOneCommit;
|
||||||
import com.google.gerrit.acceptance.UseSsh;
|
import com.google.gerrit.acceptance.UseSsh;
|
||||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||||
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.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@NoHttpd
|
@NoHttpd
|
||||||
@UseSsh
|
@UseSsh
|
||||||
public abstract class AbstractIndexTests extends AbstractDaemonTest {
|
public abstract class AbstractIndexTests extends AbstractDaemonTest {
|
||||||
@Inject private DynamicSet<ChangeIndexedListener> changeIndexedListeners;
|
@Inject private ExtensionRegistry extensionRegistry;
|
||||||
|
|
||||||
private ChangeIndexedCounter changeIndexedCounter;
|
|
||||||
private RegistrationHandle changeIndexedCounterHandle;
|
|
||||||
|
|
||||||
/** @param injector injector */
|
/** @param injector injector */
|
||||||
public void configureIndex(Injector injector) {}
|
public void configureIndex(Injector injector) {}
|
||||||
|
|
||||||
@Before
|
|
||||||
public void addChangeIndexedCounter() {
|
|
||||||
changeIndexedCounter = new ChangeIndexedCounter();
|
|
||||||
changeIndexedCounterHandle = changeIndexedListeners.add("gerrit", changeIndexedCounter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void removeChangeIndexedCounter() {
|
|
||||||
if (changeIndexedCounterHandle != null) {
|
|
||||||
changeIndexedCounterHandle.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
|
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
|
||||||
public void indexChange() throws Exception {
|
public void indexChange() throws Exception {
|
||||||
configureIndex(server.getTestInjector());
|
ChangeIndexedCounter changeIndexedCounter = new ChangeIndexedCounter();
|
||||||
|
try (Registration registration =
|
||||||
|
extensionRegistry.newRegistration().add(changeIndexedCounter)) {
|
||||||
|
configureIndex(server.getTestInjector());
|
||||||
|
|
||||||
PushOneCommit.Result change = createChange("first change", "test1.txt", "test1");
|
PushOneCommit.Result change = createChange("first change", "test1.txt", "test1");
|
||||||
String changeId = change.getChangeId();
|
String changeId = change.getChangeId();
|
||||||
String changeLegacyId = change.getChange().getId().toString();
|
String changeLegacyId = change.getChange().getId().toString();
|
||||||
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
|
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
|
||||||
|
|
||||||
disableChangeIndexWrites();
|
disableChangeIndexWrites();
|
||||||
amendChange(changeId, "second test", "test2.txt", "test2");
|
amendChange(changeId, "second test", "test2.txt", "test2");
|
||||||
|
|
||||||
assertChangeQuery("message:second", change.getChange(), false);
|
assertChangeQuery("message:second", change.getChange(), false);
|
||||||
enableChangeIndexWrites();
|
enableChangeIndexWrites();
|
||||||
|
|
||||||
changeIndexedCounter.clear();
|
changeIndexedCounter.clear();
|
||||||
String cmd = Joiner.on(" ").join("gerrit", "index", "changes", changeLegacyId);
|
String cmd = Joiner.on(" ").join("gerrit", "index", "changes", changeLegacyId);
|
||||||
adminSshSession.exec(cmd);
|
adminSshSession.exec(cmd);
|
||||||
adminSshSession.assertSuccess();
|
adminSshSession.assertSuccess();
|
||||||
|
|
||||||
changeIndexedCounter.assertReindexOf(changeInfo, 1);
|
changeIndexedCounter.assertReindexOf(changeInfo, 1);
|
||||||
|
|
||||||
assertChangeQuery("message:second", change.getChange(), true);
|
assertChangeQuery("message:second", change.getChange(), true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
|
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
|
||||||
public void indexProject() throws Exception {
|
public void indexProject() throws Exception {
|
||||||
configureIndex(server.getTestInjector());
|
ChangeIndexedCounter changeIndexedCounter = new ChangeIndexedCounter();
|
||||||
|
try (Registration registration =
|
||||||
|
extensionRegistry.newRegistration().add(changeIndexedCounter)) {
|
||||||
|
configureIndex(server.getTestInjector());
|
||||||
|
|
||||||
PushOneCommit.Result change = createChange("first change", "test1.txt", "test1");
|
PushOneCommit.Result change = createChange("first change", "test1.txt", "test1");
|
||||||
String changeId = change.getChangeId();
|
String changeId = change.getChangeId();
|
||||||
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
|
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
|
||||||
|
|
||||||
disableChangeIndexWrites();
|
disableChangeIndexWrites();
|
||||||
amendChange(changeId, "second test", "test2.txt", "test2");
|
amendChange(changeId, "second test", "test2.txt", "test2");
|
||||||
|
|
||||||
assertChangeQuery("message:second", change.getChange(), false);
|
assertChangeQuery("message:second", change.getChange(), false);
|
||||||
enableChangeIndexWrites();
|
enableChangeIndexWrites();
|
||||||
|
|
||||||
changeIndexedCounter.clear();
|
changeIndexedCounter.clear();
|
||||||
String cmd = Joiner.on(" ").join("gerrit", "index", "changes-in-project", project.get());
|
String cmd = Joiner.on(" ").join("gerrit", "index", "changes-in-project", project.get());
|
||||||
adminSshSession.exec(cmd);
|
adminSshSession.exec(cmd);
|
||||||
adminSshSession.assertSuccess();
|
|
||||||
|
|
||||||
boolean indexing = true;
|
|
||||||
while (indexing) {
|
|
||||||
String out = adminSshSession.exec("gerrit show-queue --wide");
|
|
||||||
adminSshSession.assertSuccess();
|
adminSshSession.assertSuccess();
|
||||||
indexing = out.contains("Index all changes of project " + project.get());
|
|
||||||
|
boolean indexing = true;
|
||||||
|
while (indexing) {
|
||||||
|
String out = adminSshSession.exec("gerrit show-queue --wide");
|
||||||
|
adminSshSession.assertSuccess();
|
||||||
|
indexing = out.contains("Index all changes of project " + project.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
changeIndexedCounter.assertReindexOf(changeInfo, 1);
|
||||||
|
|
||||||
|
assertChangeQuery("message:second", change.getChange(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeIndexedCounter.assertReindexOf(changeInfo, 1);
|
|
||||||
|
|
||||||
assertChangeQuery("message:second", change.getChange(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertChangeQuery(String q, ChangeData change, boolean assertTrue)
|
protected void assertChangeQuery(String q, ChangeData change, boolean assertTrue)
|
||||||
|
Reference in New Issue
Block a user