use of com.google.gerrit.extensions.events.ChangeIndexedListener in project gerrit by GerritCodeReview.
the class ProjectIT method reindexChangesOfProject.
@Test
public void reindexChangesOfProject() throws Exception {
Change.Id changeId1 = createChange().getChange().getId();
Change.Id changeId2 = createChange().getChange().getId();
ChangeIndexedListener changeIndexedListener = mock(ChangeIndexedListener.class);
try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedListener)) {
gApi.projects().name(project.get()).indexChanges();
verify(changeIndexedListener, times(1)).onChangeScheduledForIndexing(project.get(), changeId1.get());
verify(changeIndexedListener, times(1)).onChangeScheduledForIndexing(project.get(), changeId2.get());
}
}
use of com.google.gerrit.extensions.events.ChangeIndexedListener in project gerrit by GerritCodeReview.
the class AbstractSubmit method submitSchedulesOpenChangesOfSameBranchForReindexing.
@Test
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "API_REF_UPDATED_AND_CHANGE_REINDEX")
public void submitSchedulesOpenChangesOfSameBranchForReindexing() throws Throwable {
// Create a merged change.
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "Merged Change", "foo.txt", "foo");
PushOneCommit.Result mergedChange = push.to("refs/for/master");
mergedChange.assertOkStatus();
approve(mergedChange.getChangeId());
submit(mergedChange.getChangeId());
// Create some open changes.
PushOneCommit.Result change1 = createChange();
PushOneCommit.Result change2 = createChange();
PushOneCommit.Result change3 = createChange();
// Create a branch with one open change.
BranchInput in = new BranchInput();
in.revision = projectOperations.project(project).getHead("master").name();
gApi.projects().name(project.get()).branch("dev").create(in);
PushOneCommit.Result changeOtherBranch = createChange("refs/for/dev");
ChangeIndexedListener changeIndexedListener = mock(ChangeIndexedListener.class);
try (Registration registration = extensionRegistry.newRegistration().add(changeIndexedListener)) {
// submit a change, this should trigger asynchronous reindexing of the open changes on the
// same branch
approve(change1.getChangeId());
submit(change1.getChangeId());
assertThat(gApi.changes().id(change1.getChangeId()).get().status).isEqualTo(ChangeStatus.MERGED);
// on submit the change that is submitted gets reindexed synchronously
verify(changeIndexedListener, atLeast(1)).onChangeScheduledForIndexing(project.get(), change1.getChange().getId().get());
verify(changeIndexedListener, atLeast(1)).onChangeIndexed(project.get(), change1.getChange().getId().get());
// the open changes on the same branch get reindexed asynchronously
verify(changeIndexedListener, times(1)).onChangeScheduledForIndexing(project.get(), change2.getChange().getId().get());
verify(changeIndexedListener, times(1)).onChangeScheduledForIndexing(project.get(), change3.getChange().getId().get());
// merged changes don't get reindexed
verify(changeIndexedListener, times(0)).onChangeScheduledForIndexing(project.get(), mergedChange.getChange().getId().get());
// open changes on other branches don't get reindexed
verify(changeIndexedListener, times(0)).onChangeScheduledForIndexing(project.get(), changeOtherBranch.getChange().getId().get());
}
}
use of com.google.gerrit.extensions.events.ChangeIndexedListener in project gerrit by GerritCodeReview.
the class RevisionIT method mergeable.
@Test
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "API_REF_UPDATED_AND_CHANGE_REINDEX")
public void mergeable() throws Exception {
ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
PushOneCommit push1 = pushFactory.create(admin.newIdent(), testRepo, PushOneCommit.SUBJECT, PushOneCommit.FILE_NAME, "push 1 content");
PushOneCommit.Result r1 = push1.to("refs/for/master");
assertMergeable(r1.getChangeId(), true);
merge(r1);
// Reset client HEAD to initial so the new change is a merge conflict.
testRepo.reset(initial);
PushOneCommit push2 = pushFactory.create(admin.newIdent(), testRepo, PushOneCommit.SUBJECT, PushOneCommit.FILE_NAME, "new contents");
PushOneCommit.Result r2 = push2.to("refs/for/master");
Change.Id id2 = r2.getChange().getId();
assertMergeable(r2.getChangeId(), false);
// Search shows change is not mergeable.
Callable<List<ChangeInfo>> search = () -> gApi.changes().query("is:mergeable change:" + r2.getChangeId()).get();
assertThat(search.call()).isEmpty();
// will not reindex any open changes.
try (Repository repo = repoManager.openRepository(project);
TestRepository<Repository> tr = new TestRepository<>(repo)) {
String ref = "refs/heads/master";
assertThat(repo.exactRef(ref).getObjectId()).isEqualTo(r1.getCommit());
tr.update(ref, tr.getRevWalk().parseCommit(initial));
tr.branch(ref).commit().message("Side update").add(PushOneCommit.FILE_NAME, "new contents").create();
}
// Search shows change is still not mergeable.
assertThat(search.call()).isEmpty();
// Using the API returns the correct value, and reindexes as well.
CountDownLatch reindexed = new CountDownLatch(1);
ChangeIndexedListener listener = new ChangeIndexedListener() {
@Override
public void onChangeIndexed(String projectName, int id) {
if (id == id2.get()) {
reindexed.countDown();
}
}
@Override
public void onChangeDeleted(int id) {
}
};
try (Registration registration = extensionRegistry.newRegistration().add(listener)) {
assertMergeable(r2.getChangeId(), true);
reindexed.await();
}
List<ChangeInfo> changes = search.call();
assertThat(changes).hasSize(1);
assertThat(changes.get(0).changeId).isEqualTo(r2.getChangeId());
assertThat(changes.get(0).mergeable).isEqualTo(Boolean.TRUE);
}
Aggregations