Merge "GroupBundle: allow to switch audits comparision off"
This commit is contained in:
@@ -103,7 +103,7 @@ public class Rebuild implements RestModifyView<GroupResource, Input> {
|
|||||||
|
|
||||||
GroupBundle noteDbBundle = bundleFactory.fromNoteDb(repo, uuid);
|
GroupBundle noteDbBundle = bundleFactory.fromNoteDb(repo, uuid);
|
||||||
|
|
||||||
List<String> diffs = GroupBundle.compare(reviewDbBundle, noteDbBundle);
|
List<String> diffs = GroupBundle.compareWithAudits(reviewDbBundle, noteDbBundle);
|
||||||
if (diffs.isEmpty()) {
|
if (diffs.isEmpty()) {
|
||||||
return BinaryResult.create("No differences between ReviewDb and NoteDb");
|
return BinaryResult.create("No differences between ReviewDb and NoteDb");
|
||||||
}
|
}
|
||||||
|
@@ -259,8 +259,18 @@ public abstract class GroupBundle {
|
|||||||
return new AutoValue_GroupBundle.Builder().members().memberAudit().byId().byIdAudit();
|
return new AutoValue_GroupBundle.Builder().members().memberAudit().byId().byIdAudit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImmutableList<String> compare(
|
public static ImmutableList<String> compareWithAudits(
|
||||||
GroupBundle reviewDbBundle, GroupBundle noteDbBundle) {
|
GroupBundle reviewDbBundle, GroupBundle noteDbBundle) {
|
||||||
|
return compare(reviewDbBundle, noteDbBundle, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ImmutableList<String> compareWithoutAudits(
|
||||||
|
GroupBundle reviewDbBundle, GroupBundle noteDbBundle) {
|
||||||
|
return compare(reviewDbBundle, noteDbBundle, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ImmutableList<String> compare(
|
||||||
|
GroupBundle reviewDbBundle, GroupBundle noteDbBundle, boolean compareAudits) {
|
||||||
// Normalize the ReviewDb bundle to what we expect in NoteDb. This means that values in error
|
// Normalize the ReviewDb bundle to what we expect in NoteDb. This means that values in error
|
||||||
// messages will not reflect the actual data in ReviewDb, but it will make it easier for humans
|
// messages will not reflect the actual data in ReviewDb, but it will make it easier for humans
|
||||||
// to see the difference.
|
// to see the difference.
|
||||||
@@ -293,7 +303,9 @@ public abstract class GroupBundle {
|
|||||||
+ ("ReviewDb: " + reviewDbBundle.members() + "\n")
|
+ ("ReviewDb: " + reviewDbBundle.members() + "\n")
|
||||||
+ ("NoteDb : " + noteDbBundle.members()));
|
+ ("NoteDb : " + noteDbBundle.members()));
|
||||||
}
|
}
|
||||||
if (!areMemberAuditsConsideredEqual(reviewDbBundle.memberAudit(), noteDbBundle.memberAudit())) {
|
if (compareAudits
|
||||||
|
&& !areMemberAuditsConsideredEqual(
|
||||||
|
reviewDbBundle.memberAudit(), noteDbBundle.memberAudit())) {
|
||||||
result.add(
|
result.add(
|
||||||
"AccountGroupMemberAudits differ\n"
|
"AccountGroupMemberAudits differ\n"
|
||||||
+ ("ReviewDb: " + reviewDbBundle.memberAudit() + "\n")
|
+ ("ReviewDb: " + reviewDbBundle.memberAudit() + "\n")
|
||||||
@@ -305,7 +317,8 @@ public abstract class GroupBundle {
|
|||||||
+ ("ReviewDb: " + reviewDbBundle.byId() + "\n")
|
+ ("ReviewDb: " + reviewDbBundle.byId() + "\n")
|
||||||
+ ("NoteDb : " + noteDbBundle.byId()));
|
+ ("NoteDb : " + noteDbBundle.byId()));
|
||||||
}
|
}
|
||||||
if (!areByIdAuditsConsideredEqual(reviewDbBundle.byIdAudit(), noteDbBundle.byIdAudit())) {
|
if (compareAudits
|
||||||
|
&& !areByIdAuditsConsideredEqual(reviewDbBundle.byIdAudit(), noteDbBundle.byIdAudit())) {
|
||||||
result.add(
|
result.add(
|
||||||
"AccountGroupByIdAudits differ\n"
|
"AccountGroupByIdAudits differ\n"
|
||||||
+ ("ReviewDb: " + reviewDbBundle.byIdAudit() + "\n")
|
+ ("ReviewDb: " + reviewDbBundle.byIdAudit() + "\n")
|
||||||
|
@@ -214,7 +214,7 @@ public class GroupRebuilderIT extends AbstractDaemonTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertMigratedCleanly(GroupBundle noteDbBundle, GroupBundle expectedReviewDbBundle) {
|
private void assertMigratedCleanly(GroupBundle noteDbBundle, GroupBundle expectedReviewDbBundle) {
|
||||||
assertThat(GroupBundle.compare(expectedReviewDbBundle, noteDbBundle)).isEmpty();
|
assertThat(GroupBundle.compareWithAudits(expectedReviewDbBundle, noteDbBundle)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImmutableList<CommitInfo> log(GroupInfo g) throws Exception {
|
private ImmutableList<CommitInfo> log(GroupInfo g) throws Exception {
|
||||||
|
@@ -66,7 +66,7 @@ public class GroupBundleTest extends GerritBaseTests {
|
|||||||
AccountGroup g2 = new AccountGroup(reviewDbBundle.group());
|
AccountGroup g2 = new AccountGroup(reviewDbBundle.group());
|
||||||
g2.setDescription("Hello!");
|
g2.setDescription("Hello!");
|
||||||
GroupBundle noteDbBundle = GroupBundle.builder().source(Source.NOTE_DB).group(g2).build();
|
GroupBundle noteDbBundle = GroupBundle.builder().source(Source.NOTE_DB).group(g2).build();
|
||||||
assertThat(GroupBundle.compare(reviewDbBundle, noteDbBundle))
|
assertThat(GroupBundle.compareWithAudits(reviewDbBundle, noteDbBundle))
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
"AccountGroups differ\n"
|
"AccountGroups differ\n"
|
||||||
+ ("ReviewDb: AccountGroup{name=group, groupId=1, description=null,"
|
+ ("ReviewDb: AccountGroup{name=group, groupId=1, description=null,"
|
||||||
@@ -93,11 +93,32 @@ public class GroupBundleTest extends GerritBaseTests {
|
|||||||
+ "NoteDb : []");
|
+ "NoteDb : []");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void compareIgnoreAudits() throws Exception {
|
||||||
|
GroupBundle reviewDbBundle = newBundle().source(Source.REVIEW_DB).build();
|
||||||
|
AccountGroup group = new AccountGroup(reviewDbBundle.group());
|
||||||
|
|
||||||
|
AccountGroupMember member =
|
||||||
|
new AccountGroupMember(new AccountGroupMember.Key(new Account.Id(1), group.getId()));
|
||||||
|
AccountGroupMemberAudit memberAudit =
|
||||||
|
new AccountGroupMemberAudit(member, new Account.Id(2), ts);
|
||||||
|
AccountGroupById byId =
|
||||||
|
new AccountGroupById(
|
||||||
|
new AccountGroupById.Key(group.getId(), new AccountGroup.UUID("subgroup-2")));
|
||||||
|
AccountGroupByIdAud byIdAudit = new AccountGroupByIdAud(byId, new Account.Id(3), ts);
|
||||||
|
|
||||||
|
GroupBundle noteDbBundle =
|
||||||
|
newBundle().source(Source.NOTE_DB).memberAudit(memberAudit).byIdAudit(byIdAudit).build();
|
||||||
|
|
||||||
|
assertThat(GroupBundle.compareWithAudits(reviewDbBundle, noteDbBundle)).isNotEmpty();
|
||||||
|
assertThat(GroupBundle.compareWithoutAudits(reviewDbBundle, noteDbBundle)).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void compareEqual() throws Exception {
|
public void compareEqual() throws Exception {
|
||||||
GroupBundle reviewDbBundle = newBundle().source(Source.REVIEW_DB).build();
|
GroupBundle reviewDbBundle = newBundle().source(Source.REVIEW_DB).build();
|
||||||
GroupBundle noteDbBundle = newBundle().source(Source.NOTE_DB).build();
|
GroupBundle noteDbBundle = newBundle().source(Source.NOTE_DB).build();
|
||||||
assertThat(GroupBundle.compare(reviewDbBundle, noteDbBundle)).isEmpty();
|
assertThat(GroupBundle.compareWithAudits(reviewDbBundle, noteDbBundle)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GroupBundle.Builder newBundle() {
|
private GroupBundle.Builder newBundle() {
|
||||||
|
@@ -592,7 +592,7 @@ public class GroupRebuilderTest extends AbstractGroupTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assertMigratedCleanly(GroupBundle noteDbBundle, GroupBundle expectedReviewDbBundle) {
|
private void assertMigratedCleanly(GroupBundle noteDbBundle, GroupBundle expectedReviewDbBundle) {
|
||||||
assertThat(GroupBundle.compare(expectedReviewDbBundle, noteDbBundle)).isEmpty();
|
assertThat(GroupBundle.compareWithAudits(expectedReviewDbBundle, noteDbBundle)).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private AccountGroup newGroup(String name) {
|
private AccountGroup newGroup(String name) {
|
||||||
|
Reference in New Issue
Block a user