Search in sources :

Example 1 with SchemaFactory

use of com.google.gwtorm.server.SchemaFactory 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 2 with SchemaFactory

use of com.google.gwtorm.server.SchemaFactory in project gerrit by GerritCodeReview.

the class InMemoryTestingDatabaseModule method configure.

@Override
protected void configure() {
    bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
    // TODO(dborowitz): Use jimfs.
    Path p = Paths.get(cfg.getString("gerrit", null, "tempSiteDir"));
    bind(Path.class).annotatedWith(SitePath.class).toInstance(p);
    makeSiteDirs(p);
    bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
    bind(InMemoryRepositoryManager.class).in(SINGLETON);
    bind(MetricMaker.class).to(DisabledMetricMaker.class);
    bind(DataSourceType.class).to(InMemoryH2Type.class);
    bind(NotesMigration.class).to(TestNotesMigration.class);
    TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
    };
    bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
    bind(Key.get(schemaFactory, ReviewDbFactory.class)).to(InMemoryDatabase.class);
    bind(InMemoryDatabase.class).in(SINGLETON);
    bind(ChangeBundleReader.class).to(GwtormChangeBundleReader.class);
    listener().to(CreateDatabase.class);
    bind(SitePaths.class);
    bind(TrackingFooters.class).toProvider(TrackingFootersProvider.class).in(SINGLETON);
    install(new SchemaModule());
    bind(SchemaVersion.class).to(SchemaVersion.C);
}
Also used : Path(java.nio.file.Path) SitePath(com.google.gerrit.server.config.SitePath) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) MetricMaker(com.google.gerrit.metrics.MetricMaker) NotesMigrationSchemaFactory(com.google.gerrit.server.schema.NotesMigrationSchemaFactory) SchemaFactory(com.google.gwtorm.server.SchemaFactory) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) SchemaModule(com.google.gerrit.server.schema.SchemaModule) SchemaVersion(com.google.gerrit.server.schema.SchemaVersion) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) InMemoryDatabase(com.google.gerrit.testutil.InMemoryDatabase) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) TestNotesMigration(com.google.gerrit.testutil.TestNotesMigration) NotesMigration(com.google.gerrit.server.notedb.NotesMigration) GwtormChangeBundleReader(com.google.gerrit.server.notedb.GwtormChangeBundleReader) ChangeBundleReader(com.google.gerrit.server.notedb.ChangeBundleReader) TypeLiteral(com.google.inject.TypeLiteral) DataSourceType(com.google.gerrit.server.schema.DataSourceType) SitePath(com.google.gerrit.server.config.SitePath) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb)

Example 3 with SchemaFactory

use of com.google.gwtorm.server.SchemaFactory in project gerrit by GerritCodeReview.

the class AcceptanceTestRequestScope method disableDb.

public Context disableDb() {
    Context old = current.get();
    SchemaFactory<ReviewDb> sf = new SchemaFactory<ReviewDb>() {

        @Override
        public ReviewDb open() {
            return new DisabledReviewDb();
        }
    };
    Context ctx = new Context(sf, old.session, old.user, old.created);
    current.set(ctx);
    local.setContext(ctx);
    return old;
}
Also used : RequestContext(com.google.gerrit.server.util.RequestContext) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) SchemaFactory(com.google.gwtorm.server.SchemaFactory) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb)

Example 4 with SchemaFactory

use of com.google.gwtorm.server.SchemaFactory in project gerrit by GerritCodeReview.

the class InMemoryModule method configure.

@Override
protected void configure() {
    // Do NOT bind @RemotePeer, as it is bound in a child injector of
    // ChangeMergeQueue (bound via GerritGlobalModule below), so there cannot be
    // a binding in the parent injector. If you need @RemotePeer, you must bind
    // it in a child injector of the one containing InMemoryModule. But unless
    // you really need to test something request-scoped, you likely don't
    // actually need it.
    // For simplicity, don't create child injectors, just use this one to get a
    // few required modules.
    Injector cfgInjector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
        }
    });
    bind(MetricMaker.class).to(DisabledMetricMaker.class);
    install(cfgInjector.getInstance(GerritGlobalModule.class));
    install(new DefaultPermissionBackendModule());
    install(new SearchingChangeCacheImpl.Module());
    factory(GarbageCollection.Factory.class);
    bindScope(RequestScoped.class, PerThreadRequestScope.REQUEST);
    // TODO(dborowitz): Use jimfs.
    bind(Path.class).annotatedWith(SitePath.class).toInstance(Paths.get("."));
    bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
    bind(GerritOptions.class).toInstance(new GerritOptions(cfg, false, false, false));
    bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toProvider(GerritPersonIdentProvider.class);
    bind(String.class).annotatedWith(AnonymousCowardName.class).toProvider(AnonymousCowardNameProvider.class);
    bind(String.class).annotatedWith(GerritServerId.class).toInstance("gerrit");
    bind(AllProjectsName.class).toProvider(AllProjectsNameProvider.class);
    bind(AllUsersName.class).toProvider(AllUsersNameProvider.class);
    bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
    bind(InMemoryRepositoryManager.class).in(SINGLETON);
    bind(TrackingFooters.class).toProvider(TrackingFootersProvider.class).in(SINGLETON);
    bind(NotesMigration.class).toInstance(notesMigration);
    bind(ListeningExecutorService.class).annotatedWith(ChangeUpdateExecutor.class).toInstance(MoreExecutors.newDirectExecutorService());
    bind(DataSourceType.class).to(InMemoryH2Type.class);
    bind(ChangeBundleReader.class).to(GwtormChangeBundleReader.class);
    bind(SecureStore.class).to(DefaultSecureStore.class);
    TypeLiteral<SchemaFactory<ReviewDb>> schemaFactory = new TypeLiteral<SchemaFactory<ReviewDb>>() {
    };
    bind(schemaFactory).to(NotesMigrationSchemaFactory.class);
    bind(Key.get(schemaFactory, ReviewDbFactory.class)).to(InMemoryDatabase.class);
    install(NoSshKeyCache.module());
    install(new CanonicalWebUrlModule() {

        @Override
        protected Class<? extends Provider<String>> provider() {
            return CanonicalWebUrlProvider.class;
        }
    });
    //Replacement of DiffExecutorModule to not use thread pool in the tests
    install(new AbstractModule() {

        @Override
        protected void configure() {
        }

        @Provides
        @Singleton
        @DiffExecutor
        public ExecutorService createDiffExecutor() {
            return MoreExecutors.newDirectExecutorService();
        }
    });
    install(new DefaultCacheFactory.Module());
    install(new FakeEmailSender.Module());
    install(new SignedTokenEmailTokenVerifier.Module());
    install(new GpgModule(cfg));
    install(new H2AccountPatchReviewStore.InMemoryModule());
    bind(AllAccountsIndexer.class).toProvider(Providers.of(null));
    bind(AllChangesIndexer.class).toProvider(Providers.of(null));
    bind(AllGroupsIndexer.class).toProvider(Providers.of(null));
    IndexType indexType = null;
    try {
        indexType = cfg.getEnum("index", null, "type", IndexType.LUCENE);
    } catch (IllegalArgumentException e) {
    // Custom index type, caller must provide their own module.
    }
    if (indexType != null) {
        switch(indexType) {
            case LUCENE:
                install(luceneIndexModule());
                break;
            case ELASTICSEARCH:
                install(elasticIndexModule());
                break;
            default:
                throw new ProvisionException("index type unsupported in tests: " + indexType);
        }
    }
}
Also used : MetricMaker(com.google.gerrit.metrics.MetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) GerritServerId(com.google.gerrit.server.config.GerritServerId) GwtormChangeBundleReader(com.google.gerrit.server.notedb.GwtormChangeBundleReader) ChangeBundleReader(com.google.gerrit.server.notedb.ChangeBundleReader) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) Injector(com.google.inject.Injector) DataSourceType(com.google.gerrit.server.schema.DataSourceType) DefaultPermissionBackendModule(com.google.gerrit.server.project.DefaultPermissionBackendModule) NotesMigrationSchemaFactory(com.google.gerrit.server.schema.NotesMigrationSchemaFactory) SchemaFactory(com.google.gwtorm.server.SchemaFactory) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) DefaultCacheFactory(com.google.gerrit.server.cache.h2.DefaultCacheFactory) GerritOptions(com.google.gerrit.server.config.GerritOptions) SecureStore(com.google.gerrit.server.securestore.SecureStore) DefaultSecureStore(com.google.gerrit.server.securestore.DefaultSecureStore) ChangeUpdateExecutor(com.google.gerrit.server.update.ChangeUpdateExecutor) Singleton(com.google.inject.Singleton) SitePath(com.google.gerrit.server.config.SitePath) DiffExecutor(com.google.gerrit.server.patch.DiffExecutor) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) AllChangesIndexer(com.google.gerrit.server.index.change.AllChangesIndexer) GarbageCollection(com.google.gerrit.server.git.GarbageCollection) AllAccountsIndexer(com.google.gerrit.server.index.account.AllAccountsIndexer) SignedTokenEmailTokenVerifier(com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier) ProvisionException(com.google.inject.ProvisionException) TypeLiteral(com.google.inject.TypeLiteral) GpgModule(com.google.gerrit.gpg.GpgModule) IndexType(com.google.gerrit.server.index.IndexModule.IndexType) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) SearchingChangeCacheImpl(com.google.gerrit.server.git.SearchingChangeCacheImpl) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AnonymousCowardName(com.google.gerrit.server.config.AnonymousCowardName) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) Provides(com.google.inject.Provides) H2AccountPatchReviewStore(com.google.gerrit.server.schema.H2AccountPatchReviewStore) AbstractModule(com.google.inject.AbstractModule) NotesMigration(com.google.gerrit.server.notedb.NotesMigration) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) AllUsersNameProvider(com.google.gerrit.server.config.AllUsersNameProvider) CanonicalWebUrlProvider(com.google.gerrit.server.config.CanonicalWebUrlProvider) GerritPersonIdentProvider(com.google.gerrit.server.GerritPersonIdentProvider) AllProjectsNameProvider(com.google.gerrit.server.config.AllProjectsNameProvider) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) AnonymousCowardNameProvider(com.google.gerrit.server.config.AnonymousCowardNameProvider) Provider(com.google.inject.Provider) AllGroupsIndexer(com.google.gerrit.server.index.group.AllGroupsIndexer) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ExecutorService(java.util.concurrent.ExecutorService) AllUsersName(com.google.gerrit.server.config.AllUsersName)

Aggregations

ReviewDb (com.google.gerrit.reviewdb.server.ReviewDb)4 SchemaFactory (com.google.gwtorm.server.SchemaFactory)4 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)3 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)3 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)2 MetricMaker (com.google.gerrit.metrics.MetricMaker)2 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)2 AllProjectsName (com.google.gerrit.server.config.AllProjectsName)2 AllUsersName (com.google.gerrit.server.config.AllUsersName)2 AnonymousCowardName (com.google.gerrit.server.config.AnonymousCowardName)2 SitePath (com.google.gerrit.server.config.SitePath)2 TrackingFootersProvider (com.google.gerrit.server.config.TrackingFootersProvider)2 ChangeBundleReader (com.google.gerrit.server.notedb.ChangeBundleReader)2 GwtormChangeBundleReader (com.google.gerrit.server.notedb.GwtormChangeBundleReader)2 NotesMigration (com.google.gerrit.server.notedb.NotesMigration)2 DataSourceType (com.google.gerrit.server.schema.DataSourceType)2 NotesMigrationSchemaFactory (com.google.gerrit.server.schema.NotesMigrationSchemaFactory)2 InMemoryRepositoryManager (com.google.gerrit.testutil.InMemoryRepositoryManager)2 TypeLiteral (com.google.inject.TypeLiteral)2 Path (java.nio.file.Path)2