Search in sources :

Example 16 with ReviewDb

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);
    }
}
Also used : ChangeBundle(com.google.gerrit.server.notedb.ChangeBundle) ArrayList(java.util.ArrayList) Change(com.google.gerrit.reviewdb.client.Change) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 17 with ReviewDb

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();
}
Also used : ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 18 with ReviewDb

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));
    }
}
Also used : ChangeBundle(com.google.gerrit.server.notedb.ChangeBundle) Change(com.google.gerrit.reviewdb.client.Change) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 19 with ReviewDb

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());
}
Also used : SystemConfig(com.google.gerrit.reviewdb.client.SystemConfig) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) SystemConfig(com.google.gerrit.reviewdb.client.SystemConfig) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) SitePaths(com.google.gerrit.server.config.SitePaths) StatementExecutor(com.google.gwtorm.server.StatementExecutor) ProvisionException(com.google.inject.ProvisionException) TypeLiteral(com.google.inject.TypeLiteral) OrmException(com.google.gwtorm.server.OrmException) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) Path(java.nio.file.Path) SchemaFactory(com.google.gwtorm.server.SchemaFactory) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) FactoryModule(com.google.gerrit.extensions.config.FactoryModule) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ConfigNotesMigration(com.google.gerrit.server.notedb.ConfigNotesMigration) AllUsersName(com.google.gerrit.server.config.AllUsersName) Test(org.junit.Test)

Example 20 with ReviewDb

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);
        }
    });
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) CurrentUser(com.google.gerrit.server.CurrentUser) Injector(com.google.inject.Injector) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) InMemoryModule(com.google.gerrit.testutil.InMemoryModule) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) Provider(com.google.inject.Provider) Before(org.junit.Before)

Aggregations

ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)63 OrmException (com.google.gwtorm.server.OrmException)25 Change (com.google.gerrit.reviewdb.client.Change)21 Account (com.google.gerrit.reviewdb.client.Account)17 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)12 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)10 Repository (org.eclipse.jgit.lib.Repository)9 Project (com.google.gerrit.reviewdb.client.Project)8 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)8 Provider (com.google.inject.Provider)8 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)7 Inject (com.google.inject.Inject)7 AllUsersName (com.google.gerrit.server.config.AllUsersName)6 ChangeControl (com.google.gerrit.server.project.ChangeControl)6 PersonIdent (org.eclipse.jgit.lib.PersonIdent)6 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 AccountGroupMember (com.google.gerrit.reviewdb.client.AccountGroupMember)5 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)5 GitReferenceUpdated (com.google.gerrit.server.extensions.events.GitReferenceUpdated)5