use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class NoteDbChecker method rebuildAndCheckChanges.
private void rebuildAndCheckChanges(Stream<Change.Id> changeIds) throws Exception {
ReviewDb db = getUnwrappedDb();
List<ChangeBundle> allExpected = readExpected(changeIds);
boolean oldWrite = notesMigration.rawWriteChangesSetting();
boolean oldRead = notesMigration.readChanges();
try {
notesMigration.setWriteChanges(true);
notesMigration.setReadChanges(true);
List<String> msgs = new ArrayList<>();
for (ChangeBundle expected : allExpected) {
Change c = expected.getChange();
try {
changeRebuilder.rebuild(db, c.getId());
} catch (RepositoryNotFoundException e) {
msgs.add("Repository not found for change, cannot convert: " + c);
}
}
checkActual(allExpected, msgs);
} finally {
notesMigration.setReadChanges(oldRead);
notesMigration.setWriteChanges(oldWrite);
}
}
use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class NoteDbChecker method assertNoReviewDbChanges.
public void assertNoReviewDbChanges(Description desc) throws Exception {
ReviewDb db = getUnwrappedDb();
assertThat(db.changes().all().toList()).named("Changes in " + desc.getTestClass()).isEmpty();
assertThat(db.changeMessages().all().toList()).named("ChangeMessages in " + desc.getTestClass()).isEmpty();
assertThat(db.patchSets().all().toList()).named("PatchSets in " + desc.getTestClass()).isEmpty();
assertThat(db.patchSetApprovals().all().toList()).named("PatchSetApprovals in " + desc.getTestClass()).isEmpty();
assertThat(db.patchComments().all().toList()).named("PatchLineComments in " + desc.getTestClass()).isEmpty();
}
use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class NoteDbChecker method checkActual.
private void checkActual(List<ChangeBundle> allExpected, List<String> msgs) throws Exception {
ReviewDb db = getUnwrappedDb();
boolean oldRead = notesMigration.readChanges();
boolean oldWrite = notesMigration.rawWriteChangesSetting();
try {
notesMigration.setWriteChanges(true);
notesMigration.setReadChanges(true);
for (ChangeBundle expected : allExpected) {
Change c = expected.getChange();
ChangeBundle actual;
try {
actual = ChangeBundle.fromNotes(commentsUtil, notesFactory.create(db, c.getProject(), c.getId()));
} catch (Throwable t) {
String msg = "Error converting change: " + c;
msgs.add(msg);
log.error(msg, t);
continue;
}
List<String> diff = expected.differencesFrom(actual);
if (!diff.isEmpty()) {
msgs.add("Differences between ReviewDb and NoteDb for " + c + ":");
msgs.addAll(diff);
msgs.add("");
} else {
System.err.println("NoteDb conversion of change " + c.getId() + " successful");
}
}
} finally {
notesMigration.setReadChanges(oldRead);
notesMigration.setWriteChanges(oldWrite);
}
if (!msgs.isEmpty()) {
throw new AssertionError(Joiner.on('\n').join(msgs));
}
}
use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class SchemaUpdaterTest method update.
@Test
public void update() throws OrmException, FileNotFoundException, IOException {
db.create();
final Path site = Paths.get(UUID.randomUUID().toString());
final SitePaths paths = new SitePaths(site);
SchemaUpdater u = Guice.createInjector(new FactoryModule() {
@Override
protected void configure() {
TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
};
bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
bind(Key.get(schemaFactory, ReviewDbFactory.class)).toInstance(db);
bind(SitePaths.class).toInstance(paths);
Config cfg = new Config();
cfg.setString("user", null, "name", "Gerrit Code Review");
cfg.setString("user", null, "email", "gerrit@localhost");
//
bind(Config.class).annotatedWith(//
GerritServerConfig.class).toInstance(cfg);
//
bind(PersonIdent.class).annotatedWith(//
GerritPersonIdent.class).toProvider(GerritPersonIdentProvider.class);
bind(AllProjectsName.class).toInstance(new AllProjectsName("All-Projects"));
bind(AllUsersName.class).toInstance(new AllUsersName("All-Users"));
bind(GitRepositoryManager.class).toInstance(new InMemoryRepositoryManager());
//
bind(String.class).annotatedWith(//
AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
bind(DataSourceType.class).to(InMemoryH2Type.class);
bind(SystemGroupBackend.class);
install(new ConfigNotesMigration.Module());
}
}).getInstance(SchemaUpdater.class);
for (SchemaVersion s = u.getLatestSchemaVersion(); s.getVersionNbr() > 1; s = s.getPrior()) {
try {
assertThat(s.getPrior().getVersionNbr()).named("schema %s has prior version %s. Not true that", s.getVersionNbr(), s.getPrior().getVersionNbr()).isEqualTo(s.getVersionNbr() - 1);
} catch (ProvisionException e) {
// version.
break;
}
}
u.update(new UpdateUI() {
@Override
public void message(String msg) {
}
@Override
public boolean yesno(boolean def, String msg) {
return def;
}
@Override
public boolean isBatch() {
return true;
}
@Override
public void pruneSchema(StatementExecutor e, List<String> pruneList) throws OrmException {
for (String sql : pruneList) {
e.execute(sql);
}
}
});
db.assertSchemaVersion();
final SystemConfig sc = db.getSystemConfig();
assertThat(sc.sitePath).isEqualTo(paths.site_path.toAbsolutePath().toString());
}
use of com.google.gerrit.reviewdb.server.ReviewDb in project gerrit by GerritCodeReview.
the class Schema_150_to_151_Test method setUp.
@Before
public void setUp() throws Exception {
Injector injector = Guice.createInjector(new InMemoryModule());
injector.injectMembers(this);
lifecycle = new LifecycleManager();
lifecycle.add(injector);
lifecycle.start();
try (ReviewDb underlyingDb = inMemoryDatabase.getDatabase().open()) {
schemaCreator.create(underlyingDb);
}
db = schemaFactory.open();
Account.Id userId = accountManager.authenticate(AuthRequest.forUser("user")).getAccountId();
IdentifiedUser user = userFactory.create(userId);
requestContext.setContext(new RequestContext() {
@Override
public CurrentUser getUser() {
return user;
}
@Override
public Provider<ReviewDb> getReviewDbProvider() {
return Providers.of(db);
}
});
}
Aggregations