Beispiel #1
0
        private async Task RebuildSchemaIndexes()
        {
            var schemasByApp = new Dictionary <Guid, Dictionary <string, Guid> >();

            Dictionary <string, Guid> Index(SchemaEvent @event)
            {
                return(schemasByApp.GetOrAddNew(@event.AppId.Id));
            }

            await eventStore.QueryAsync(storedEvent =>
            {
                var @event = eventDataFormatter.Parse(storedEvent.Data);

                switch (@event.Payload)
                {
                case SchemaCreated schemaCreated:
                    Index(schemaCreated)[schemaCreated.SchemaId.Name] = schemaCreated.SchemaId.Id;
                    break;

                case SchemaDeleted schemaDeleted:
                    Index(schemaDeleted).Remove(schemaDeleted.SchemaId.Name);
                    break;
                }

                return(TaskHelper.Done);
            }, "^schema\\-");

            foreach (var kvp in schemasByApp)
            {
                await indexSchemas.RebuildAsync(kvp.Key, kvp.Value);
            }
        }
        private async Task RebuildSchemaIndexes()
        {
            var schemasByApp = new Dictionary <DomainId, Dictionary <string, DomainId> >();

            Dictionary <string, DomainId> Index(SchemaEvent @event)
            {
                return(schemasByApp !.GetOrAddNew(@event.AppId.Id));
            }

            await foreach (var storedEvent in eventStore.QueryAllAsync("^schema\\-"))
            {
                var @event = eventDataFormatter.ParseIfKnown(storedEvent);

                if (@event != null)
                {
                    switch (@event.Payload)
                    {
                    case SchemaCreated created:
                        Index(created)[created.SchemaId.Name] = created.SchemaId.Id;
                        break;

                    case SchemaDeleted deleted:
                        Index(deleted).Remove(deleted.SchemaId.Name);
                        break;
                    }
                }
            }

            foreach (var(appId, schemas) in schemasByApp)
            {
                await indexSchemas.RebuildAsync(appId, schemas);
            }
        }
        private async Task RebuildSchemaIndexes()
        {
            var schemasByApp = new Dictionary <Guid, Dictionary <string, Guid> >();

            Dictionary <string, Guid> Index(SchemaEvent @event)
            {
                return(schemasByApp !.GetOrAddNew(@event.AppId.Id));
            }

            await eventStore.QueryAsync(storedEvent =>
            {
                var @event = eventDataFormatter.Parse(storedEvent.Data);

                switch (@event.Payload)
                {
                case SchemaCreated created:
                    Index(created)[created.SchemaId.Name] = created.SchemaId.Id;
                    break;

                case SchemaDeleted deleted:
                    Index(deleted).Remove(deleted.SchemaId.Name);
                    break;
                }

                return(Task.CompletedTask);
            }, "^schema\\-");

            foreach (var(appId, schemas) in schemasByApp)
            {
                await indexSchemas.RebuildAsync(appId, schemas);
            }
        }
Beispiel #4
0
        public async Task Should_restore_indices_for_all_non_deleted_schemas()
        {
            var appId = Guid.NewGuid();

            var schemaId1 = NamedId.Of(Guid.NewGuid(), "my-schema1");
            var schemaId2 = NamedId.Of(Guid.NewGuid(), "my-schema2");
            var schemaId3 = NamedId.Of(Guid.NewGuid(), "my-schema3");

            var context = new RestoreContext(appId, new UserMapping(new RefToken(RefTokenType.Subject, "123")), A.Fake <IBackupReader>());

            await sut.RestoreEventAsync(Envelope.Create(new SchemaCreated
            {
                SchemaId = schemaId1
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new SchemaCreated
            {
                SchemaId = schemaId2
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new SchemaCreated
            {
                SchemaId = schemaId3
            }), context);

            await sut.RestoreEventAsync(Envelope.Create(new SchemaDeleted
            {
                SchemaId = schemaId3
            }), context);

            Dictionary <string, Guid>?newIndex = null;

            A.CallTo(() => index.RebuildAsync(appId, A <Dictionary <string, Guid> > ._))
            .Invokes(new Action <Guid, Dictionary <string, Guid> >((_, i) => newIndex = i));

            await sut.RestoreAsync(context);

            Assert.Equal(new Dictionary <string, Guid>
            {
                [schemaId1.Name] = schemaId1.Id,
                [schemaId2.Name] = schemaId2.Id
            }, newIndex);
        }
 public Task RestoreAsync(RestoreContext context)
 {
     return(indexSchemas.RebuildAsync(context.AppId, schemasByName));
 }
Beispiel #6
0
 public override Task RestoreAsync(Guid appId, BackupReader reader)
 {
     return(indexSchemas.RebuildAsync(appId, schemasByName));
 }