Пример #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            PrometheusMetrics.TryConfigure(Environment.ApplicationName);
            EventMapping.Map();

            var esConnection = ConfigureEsConnection(
                Configuration["EventStore:ConnectionString"],
                Environment.ApplicationName);
            var documentStore = ConfigureRavenDb(
                Configuration["RavenDb:Server"],
                Configuration["RavenDb:Database"]
                );

            var ravenDbStore = new RavenDBProvider(documentStore);

            services.AddSingleton(c => (Func <IAsyncDocumentSession>)GetSession);
            services.AddSingleton <IHostedService>(
                new EventStoreService(
                    esConnection,
                    Props.FromProducer(() =>
                                       new SubscriptionActor(
                                           esConnection,
                                           new RavenDbCheckpointStore(GetSession, "readmodels"),
                                           "ravenDbSubscription",
                                           (Props.FromProducer(
                                                () => new CustomerVehiclesProjection(ravenDbStore)), "customerVehicles"),
                                           (Props.FromProducer(
                                                () => new VehicleItemProjection(ravenDbStore)), "vehicleItems")
                                           )
                                       )
                    )
                );

            IAsyncDocumentSession GetSession() => documentStore.OpenAsyncSession();
        }
Пример #2
0
        public async Task NoUpdateSubscriptionBecauseNotEnabled()
        {
            var channel = new Channel
            {
                Name           = "channel",
                Classification = "class"
            };
            var oldBuild = new Build
            {
                Branch       = "source.branch",
                Repository   = "source.repo",
                BuildNumber  = "old.build.number",
                Commit       = "oldSha",
                DateProduced = DateTimeOffset.UtcNow.AddDays(-2)
            };
            var location = "https://source.feed/index.json";
            var build    = new Build
            {
                Branch       = "source.branch",
                Repository   = "source.repo",
                BuildNumber  = "build.number",
                Commit       = "sha",
                DateProduced = DateTimeOffset.UtcNow,
                Assets       = new List <Asset>
                {
                    new Asset
                    {
                        Name      = "source.asset",
                        Version   = "1.0.1",
                        Locations = new List <AssetLocation>
                        {
                            new AssetLocation
                            {
                                Location = location,
                                Type     = LocationType.NugetFeed
                            }
                        }
                    }
                }
            };
            var buildChannel = new BuildChannel
            {
                Build   = build,
                Channel = channel
            };
            var subscription = new Subscription
            {
                Channel          = channel,
                SourceRepository = "source.repo",
                TargetRepository = "target.repo",
                TargetBranch     = "target.branch",
                Enabled          = false,
                PolicyObject     = new SubscriptionPolicy
                {
                    MergePolicies   = null,
                    UpdateFrequency = UpdateFrequency.EveryDay
                },
                LastAppliedBuild = oldBuild
            };
            var repoInstallation = new Repository
            {
                RepositoryName = "target.repo",
                InstallationId = 1
            };
            await Context.Repositories.AddAsync(repoInstallation);

            await Context.Subscriptions.AddAsync(subscription);

            await Context.BuildChannels.AddAsync(buildChannel);

            await Context.SaveChangesAsync();

            SubscriptionActor.Verify(a => a.UpdateAsync(build.Id), Times.Never());

            var updater = ActivatorUtilities.CreateInstance <DependencyUpdater>(Scope.ServiceProvider);
            await updater.CheckSubscriptionsAsync(CancellationToken.None);
        }
Пример #3
0
        public async Task EveryBuildSubscription()
        {
            var channel = new Channel
            {
                Name           = "channel",
                Classification = "class"
            };
            var build = new Build
            {
                Branch       = "source.branch",
                Repository   = "source.repo",
                BuildNumber  = "build.number",
                Commit       = "sha",
                DateProduced = DateTimeOffset.UtcNow.AddDays(-1)
            };
            var location = "https://repo.feed/index.json";
            var newAsset = new Asset
            {
                Name      = "source.asset",
                Version   = "1.0.1",
                Locations = new List <AssetLocation>
                {
                    new AssetLocation
                    {
                        Location = location,
                        Type     = LocationType.NugetFeed
                    }
                }
            };
            var newBuild = new Build
            {
                Branch       = "source.branch",
                Repository   = "source.repo",
                BuildNumber  = "build.number.2",
                Commit       = "sha2",
                DateProduced = DateTimeOffset.UtcNow,
                Assets       = new List <Asset> {
                    newAsset
                }
            };
            var buildChannels = new[]
            {
                new BuildChannel
                {
                    Build   = build,
                    Channel = channel
                },
                new BuildChannel
                {
                    Build   = newBuild,
                    Channel = channel
                }
            };
            var subscription = new Subscription
            {
                Channel          = channel,
                SourceRepository = "source.repo",
                TargetRepository = "target.repo",
                TargetBranch     = "target.branch",
                Enabled          = true,
                PolicyObject     = new SubscriptionPolicy
                {
                    MergePolicies   = null,
                    UpdateFrequency = UpdateFrequency.EveryBuild
                },
                LastAppliedBuild = build
            };
            var repoInstallation = new Repository
            {
                RepositoryName = "target.repo",
                InstallationId = 1
            };
            await Context.BuildChannels.AddRangeAsync(buildChannels);

            await Context.Subscriptions.AddAsync(subscription);

            await Context.Repositories.AddAsync(repoInstallation);

            await Context.SaveChangesAsync();

            SubscriptionActor.Setup(s => s.UpdateAsync(newBuild.Id)).Returns(Task.CompletedTask);

            var updater = ActivatorUtilities.CreateInstance <DependencyUpdater>(Scope.ServiceProvider);
            await updater.UpdateDependenciesAsync(newBuild.Id, channel.Id);

            ActorId.GetGuidId().Should().Be(subscription.Id);
        }