Allow plugins to provide bulk PluginDefinedInfos in query results
Create a ChangePluginDefinedInfoFactory interface to allow list of ChangeData for plugins attribute to get bulk data to provide additional attributes to be output in a change query result. A common use case for this is for a class implementing ChangePluginDefinedInfoFactory to handle many changes instead of a single change, for which all have plugin-specific results added in the query output. This results into decrease of roundtrip time for the queries and increases the performance for bulk queries. Change-Id: I294f29557e98d6ff4f4d82ff3d83c4a743aa622d
This commit is contained in:
@@ -23,6 +23,7 @@ import com.google.gerrit.acceptance.AbstractPluginFieldsTest;
|
||||
import com.google.gerrit.acceptance.UseSsh;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.entities.Change;
|
||||
import com.google.gerrit.extensions.common.PluginDefinedInfo;
|
||||
import com.google.gerrit.server.query.change.OutputStreamQuery;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@@ -51,6 +52,12 @@ public class PluginChangeFieldsIT extends AbstractPluginFieldsTest {
|
||||
id -> pluginInfoFromSingletonList(adminSshSession.exec(changeQueryCmd(id))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void querySingleChangeWithBulkAttribute() throws Exception {
|
||||
getSingleChangeWithPluginDefinedBulkAttribute(
|
||||
id -> pluginInfosFromList(adminSshSession.exec(changeQueryCmd(id))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryChangeWithOption() throws Exception {
|
||||
getChangeWithOption(
|
||||
@@ -58,6 +65,43 @@ public class PluginChangeFieldsIT extends AbstractPluginFieldsTest {
|
||||
(id, opts) -> pluginInfoFromSingletonList(adminSshSession.exec(changeQueryCmd(id, opts))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryPluginDefinedAttributeChangeWithOption() throws Exception {
|
||||
getChangeWithPluginDefinedBulkAttributeOption(
|
||||
id -> pluginInfosFromList(adminSshSession.exec(changeQueryCmd(id))),
|
||||
(id, opts) -> pluginInfosFromList(adminSshSession.exec(changeQueryCmd(id, opts))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryMultipleChangesWithPluginDefinedAttribute() throws Exception {
|
||||
getMultipleChangesWithPluginDefinedBulkAttribute(
|
||||
() -> pluginInfosFromList(adminSshSession.exec("gerrit query --format json status:open")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryChangesByCommitMessageWithPluginDefinedBulkAttribute() throws Exception {
|
||||
getChangesByCommitMessageWithPluginDefinedBulkAttribute(
|
||||
() -> pluginInfosFromList(adminSshSession.exec("gerrit query --format json status:open")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMultipleChangesWithPluginDefinedAndChangeAttributes() throws Exception {
|
||||
getMultipleChangesWithPluginDefinedBulkAndChangeAttributes(
|
||||
() -> pluginInfosFromList(adminSshSession.exec("gerrit query --format json status:open")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMultipleChangesWithPluginDefinedAttributeInSingleCall() throws Exception {
|
||||
getMultipleChangesWithPluginDefinedBulkAttributeInSingleCall(
|
||||
() -> pluginInfosFromList(adminSshSession.exec("gerrit query --format json status:open")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getChangeWithPluginDefinedException() throws Exception {
|
||||
getChangeWithPluginDefinedBulkAttributeWithException(
|
||||
id -> pluginInfosFromList(adminSshSession.exec(changeQueryCmd(id))));
|
||||
}
|
||||
|
||||
private String changeQueryCmd(Change.Id id) {
|
||||
return changeQueryCmd(id, ImmutableListMultimap.of());
|
||||
}
|
||||
@@ -72,7 +116,22 @@ public class PluginChangeFieldsIT extends AbstractPluginFieldsTest {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static List<MyInfo> pluginInfoFromSingletonList(String sshOutput) throws Exception {
|
||||
private static List<PluginDefinedInfo> pluginInfoFromSingletonList(String sshOutput)
|
||||
throws Exception {
|
||||
List<Map<String, Object>> changeAttrs = getChangeAttrs(sshOutput);
|
||||
|
||||
assertThat(changeAttrs).hasSize(1);
|
||||
return decodeRawPluginsList(GSON, changeAttrs.get(0).get("plugins"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Map<Change.Id, List<PluginDefinedInfo>> pluginInfosFromList(String sshOutput)
|
||||
throws Exception {
|
||||
List<Map<String, Object>> changeAttrs = getChangeAttrs(sshOutput);
|
||||
return getPluginInfosFromChangeInfos(GSON, changeAttrs);
|
||||
}
|
||||
|
||||
private static List<Map<String, Object>> getChangeAttrs(String sshOutput) throws Exception {
|
||||
List<Map<String, Object>> changeAttrs = new ArrayList<>();
|
||||
for (String line : CharStreams.readLines(new StringReader(sshOutput))) {
|
||||
Map<String, Object> changeAttr =
|
||||
@@ -81,8 +140,6 @@ public class PluginChangeFieldsIT extends AbstractPluginFieldsTest {
|
||||
changeAttrs.add(changeAttr);
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(changeAttrs).hasSize(1);
|
||||
return decodeRawPluginsList(GSON, changeAttrs.get(0).get("plugins"));
|
||||
return changeAttrs;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user