Merge branch 'stable-2.14' into stable-2.15
* stable-2.14: AbstractIndexTests: Add --wide option to show-queue command invocation AbstractIndexTests: Add assertions on change index count AbstractIndexTests: Use correct command to index project acceptance/SshSession: Add helper methods to assert about success/failure dev-bazel: Add 'elastic' and 'docker' to list of test groups dev-bazel: Improve section about running Elasticsearch tests AbstractIndexTests: Add coverage for index projects command ReadOnlyChangeIndex: Reduce visibility to package AbstractIndexTests: Refactor to simplify and use Java stream API Elasticsearch: Improve introduction in elasticsearch section Elasticsearch: Add support for version 6.3.0 ElasticVersionTest: Add explicit test for 5.6.10 ElasticContainer: Update to version 5.6.10 Change-Id: I6b1c93d4dd7b3dbe6e17e6c6e323fc2c7458a39e
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.acceptance.ssh;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
@@ -62,7 +61,7 @@ public class AbandonRestoreIT extends AbstractDaemonTest {
|
||||
command.append(" --message ").append(message);
|
||||
}
|
||||
String response = adminSshSession.exec(command.toString());
|
||||
assertWithMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isFalse();
|
||||
adminSshSession.assertSuccess();
|
||||
assertThat(response.toLowerCase(Locale.US)).doesNotContain("error");
|
||||
}
|
||||
|
||||
|
||||
@@ -15,32 +15,60 @@
|
||||
package com.google.gerrit.acceptance.ssh;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.ChangeIndexedCounter;
|
||||
import com.google.gerrit.acceptance.GerritConfig;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.acceptance.UseSsh;
|
||||
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.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import java.util.List;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@NoHttpd
|
||||
@UseSsh
|
||||
public abstract class AbstractIndexTests extends AbstractDaemonTest {
|
||||
@Inject private DynamicSet<ChangeIndexedListener> changeIndexedListeners;
|
||||
|
||||
private ChangeIndexedCounter changeIndexedCounter;
|
||||
private RegistrationHandle changeIndexedCounterHandle;
|
||||
|
||||
/** @param injector injector */
|
||||
public abstract void configureIndex(Injector injector) throws Exception;
|
||||
|
||||
@Before
|
||||
public void addChangeIndexedCounter() {
|
||||
changeIndexedCounter = new ChangeIndexedCounter();
|
||||
changeIndexedCounterHandle = changeIndexedListeners.add(changeIndexedCounter);
|
||||
}
|
||||
|
||||
@After
|
||||
public void removeChangeIndexedCounter() {
|
||||
if (changeIndexedCounterHandle != null) {
|
||||
changeIndexedCounterHandle.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
|
||||
public void indexChange() throws Exception {
|
||||
configureIndex(server.getTestInjector());
|
||||
|
||||
PushOneCommit.Result change = createChange("first change", "test1.txt", "test1");
|
||||
String changeId = change.getChangeId();
|
||||
String changeLegacyId = change.getChange().getId().toString();
|
||||
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
|
||||
|
||||
disableChangeIndexWrites();
|
||||
amendChange(changeId, "second test", "test2.txt", "test2");
|
||||
@@ -48,24 +76,55 @@ public abstract class AbstractIndexTests extends AbstractDaemonTest {
|
||||
assertChangeQuery("message:second", change.getChange(), false);
|
||||
enableChangeIndexWrites();
|
||||
|
||||
changeIndexedCounter.clear();
|
||||
String cmd = Joiner.on(" ").join("gerrit", "index", "changes", changeLegacyId);
|
||||
adminSshSession.exec(cmd);
|
||||
adminSshSession.assertSuccess();
|
||||
|
||||
changeIndexedCounter.assertReindexOf(changeInfo, 1);
|
||||
|
||||
assertChangeQuery("message:second", change.getChange(), true);
|
||||
}
|
||||
|
||||
protected void assertChangeQuery(String q, ChangeData change, Boolean assertTrue)
|
||||
@Test
|
||||
@GerritConfig(name = "index.autoReindexIfStale", value = "false")
|
||||
public void indexProject() throws Exception {
|
||||
configureIndex(server.getTestInjector());
|
||||
|
||||
PushOneCommit.Result change = createChange("first change", "test1.txt", "test1");
|
||||
String changeId = change.getChangeId();
|
||||
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
|
||||
|
||||
disableChangeIndexWrites();
|
||||
amendChange(changeId, "second test", "test2.txt", "test2");
|
||||
|
||||
assertChangeQuery("message:second", change.getChange(), false);
|
||||
enableChangeIndexWrites();
|
||||
|
||||
changeIndexedCounter.clear();
|
||||
String cmd = Joiner.on(" ").join("gerrit", "index", "project", project.get());
|
||||
adminSshSession.exec(cmd);
|
||||
adminSshSession.assertSuccess();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected void assertChangeQuery(String q, ChangeData change, boolean assertTrue)
|
||||
throws Exception {
|
||||
List<ChangeInfo> result = query(q);
|
||||
Iterable<Integer> ids = ids(result);
|
||||
List<Integer> ids = query(q).stream().map(c -> c._number).collect(toList());
|
||||
if (assertTrue) {
|
||||
assertThat(ids).contains(change.getId().get());
|
||||
} else {
|
||||
assertThat(ids).doesNotContain(change.getId().get());
|
||||
}
|
||||
}
|
||||
|
||||
protected static Iterable<Integer> ids(Iterable<ChangeInfo> changes) {
|
||||
return FluentIterable.from(changes).transform(in -> in._number);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.acceptance.ssh;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
import static com.google.gerrit.acceptance.GitUtil.pushHead;
|
||||
import static org.eclipse.jgit.transport.RemoteRefUpdate.Status.REJECTED_OTHER_REASON;
|
||||
|
||||
@@ -36,7 +35,7 @@ public class BanCommitIT extends AbstractDaemonTest {
|
||||
RevCommit c = commitBuilder().add("a.txt", "some content").create();
|
||||
|
||||
String response = adminSshSession.exec("gerrit ban-commit " + project.get() + " " + c.name());
|
||||
assertWithMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isFalse();
|
||||
adminSshSession.assertSuccess();
|
||||
assertThat(response.toLowerCase(Locale.US)).doesNotContain("error");
|
||||
|
||||
RemoteRefUpdate u =
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.acceptance.ssh;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.UseSsh;
|
||||
@@ -33,7 +32,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
String newProjectName = "newProject";
|
||||
adminSshSession.exec(
|
||||
"gerrit create-project --branch master --owner " + newGroupName + " " + newProjectName);
|
||||
assertWithMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isFalse();
|
||||
adminSshSession.assertSuccess();
|
||||
ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
|
||||
assertThat(projectState).isNotNull();
|
||||
}
|
||||
@@ -46,7 +45,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
String newProjectName = "newProject";
|
||||
adminSshSession.exec(
|
||||
"gerrit create-project --branch master --owner " + wrongGroupName + " " + newProjectName);
|
||||
assertWithMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isTrue();
|
||||
adminSshSession.assertFailure();
|
||||
ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
|
||||
assertThat(projectState).isNull();
|
||||
}
|
||||
|
||||
@@ -47,10 +47,15 @@ public class ElasticIndexIT extends AbstractIndexTests {
|
||||
}
|
||||
|
||||
@ConfigSuite.Config
|
||||
public static Config elasticsearchV6() {
|
||||
public static Config elasticsearchV6_2() {
|
||||
return getConfig(ElasticVersion.V6_2);
|
||||
}
|
||||
|
||||
@ConfigSuite.Config
|
||||
public static Config elasticsearchV6_3() {
|
||||
return getConfig(ElasticVersion.V6_3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureIndex(Injector injector) throws Exception {
|
||||
ElasticTestUtils.createAllIndexes(injector);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.acceptance.ssh;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.GcAssert;
|
||||
@@ -56,7 +55,7 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
|
||||
public void testGc() throws Exception {
|
||||
String response =
|
||||
adminSshSession.exec("gerrit gc \"" + project.get() + "\" \"" + project2.get() + "\"");
|
||||
assertWithMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isFalse();
|
||||
adminSshSession.assertSuccess();
|
||||
assertNoError(response);
|
||||
gcAssert.assertHasPackFile(project, project2);
|
||||
gcAssert.assertHasNoPackFile(allProjects, project3);
|
||||
@@ -66,7 +65,7 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
|
||||
@UseLocalDisk
|
||||
public void testGcAll() throws Exception {
|
||||
String response = adminSshSession.exec("gerrit gc --all");
|
||||
assertWithMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isFalse();
|
||||
adminSshSession.assertSuccess();
|
||||
assertNoError(response);
|
||||
gcAssert.assertHasPackFile(allProjects, project, project2, project3);
|
||||
}
|
||||
@@ -74,7 +73,7 @@ public class GarbageCollectionIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void gcWithoutCapability_Error() throws Exception {
|
||||
userSshSession.exec("gerrit gc --all");
|
||||
assertThat(userSshSession.hasError()).isTrue();
|
||||
userSshSession.assertFailure();
|
||||
String error = userSshSession.getError();
|
||||
assertThat(error).isNotNull();
|
||||
assertError("maintain server not permitted", error);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.acceptance.ssh;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assertWithMessage;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
@@ -149,8 +148,7 @@ public class QueryIT extends AbstractDaemonTest {
|
||||
public void shouldFailWithFilesWithoutPatchSetsOrCurrentPatchSetsOption() throws Exception {
|
||||
String changeId = createChange().getChangeId();
|
||||
adminSshSession.exec("gerrit query --files " + changeId);
|
||||
assertThat(adminSshSession.hasError()).isTrue();
|
||||
assertThat(adminSshSession.getError()).contains("needs --patch-sets or --current-patch-set");
|
||||
adminSshSession.assertFailure("needs --patch-sets or --current-patch-set");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -305,7 +303,7 @@ public class QueryIT extends AbstractDaemonTest {
|
||||
private List<ChangeAttribute> executeSuccessfulQuery(String params, SshSession session)
|
||||
throws Exception {
|
||||
String rawResponse = session.exec("gerrit query --format=JSON " + params);
|
||||
assertWithMessage(session.getError()).that(session.hasError()).isFalse();
|
||||
session.assertSuccess();
|
||||
return getChanges(rawResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.acceptance.ssh;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth.assert_;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
@@ -52,7 +51,7 @@ public class SetReviewersIT extends AbstractDaemonTest {
|
||||
private void setReviewer(boolean add, String id) throws Exception {
|
||||
adminSshSession.exec(
|
||||
String.format("gerrit set-reviewers -%s %s %s", add ? "a" : "r", user.email, id));
|
||||
assert_().withMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isFalse();
|
||||
adminSshSession.assertSuccess();
|
||||
ImmutableSet<Id> reviewers = change.getChange().getReviewers().all();
|
||||
if (add) {
|
||||
assertThat(reviewers).contains(user.id);
|
||||
|
||||
Reference in New Issue
Block a user