Exemplo n.º 1
0
        public async Task <long> ProjectionProgressFor(ShardName name,
                                                       CancellationToken token = default)
        {
            await EnsureStorageExistsAsync(typeof(IEvent), token).ConfigureAwait(false);

            var statement = new ProjectionProgressStatement(_options.EventGraph)
            {
                Name = name
            };

            var handler = new OneResultHandler <ShardState>(statement,
                                                            new ShardStateSelector(), true, false);

            await using var conn = CreateConnection();
            await conn.OpenAsync(token).ConfigureAwait(false);

            var builder = new CommandBuilder();

            handler.ConfigureCommand(builder, null);

            await using var reader = await builder.ExecuteReaderAsync(conn, token).ConfigureAwait(false);

            var state = await handler.HandleAsync(reader, null, token).ConfigureAwait(false);

            return(state?.Sequence ?? 0);
        }
Exemplo n.º 2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasDescriptorName)
            {
                hash ^= DescriptorName.GetHashCode();
            }
            if (HasVersion)
            {
                hash ^= Version.GetHashCode();
            }
            if (HasShardName)
            {
                hash ^= ShardName.GetHashCode();
            }
            if (HasResolveClientInstance)
            {
                hash ^= ResolveClientInstance.GetHashCode();
            }
            if (HasType)
            {
                hash ^= Type.GetHashCode();
            }
            if (HasApiType)
            {
                hash ^= ApiType.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 3
0
        public async Task use_type_filters()
        {
            NumberOfStreams = 10;
            await PublishSingleThreaded();

            using var fetcher1 = new EventFetcher(theStore, theStore.Tenancy.Default.Database, new ISqlFragment[0]);

            var shardName = new ShardName("name");
            var range1    = new EventRange(shardName, 0, NumberOfEvents);
            await fetcher1.Load(range1, CancellationToken.None);

            var uniqueTypeCount = range1.Events.Select(x => x.EventType).Distinct()
                                  .Count();

            uniqueTypeCount.ShouldBe(5);

            var filter = new EventTypeFilter(theStore.Events, new Type[] { typeof(Travel), typeof(Arrival) });

            using var fetcher2 = new EventFetcher(theStore, theStore.Tenancy.Default.Database, new ISqlFragment[] { filter });

            var range2 = new EventRange(shardName, 0, NumberOfEvents);
            await fetcher2.Load(range2, CancellationToken.None);

            range2.Events
            .Select(x => x.EventType)
            .OrderBy(x => x.Name).Distinct()
            .ShouldHaveTheSameElementsAs(typeof(Arrival), typeof(Travel));
        }
Exemplo n.º 4
0
 public AggregationShard(ShardName identifier, ISqlFragment[] eventFilters,
                         AggregationRuntime <TDoc, TId> runtime, DocumentStore store, AsyncOptions options) : base(identifier,
                                                                                                                   eventFilters, store, options)
 {
     _runtime = runtime;
     _tenancy = store.Tenancy;
 }
Exemplo n.º 5
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash = hash * 31 + ShardName.GetHashCode();
         hash = hash * 31 + DatabaseName.GetHashCode();
         return(hash);
     }
 }
Exemplo n.º 6
0
        public async Task <long> ProjectionProgressFor(ShardName name, string?tenantId = null,
                                                       CancellationToken token         = default)
        {
            var tenant = tenantId == null
                ? _store.Tenancy.Default
                : await _store.Tenancy.GetTenantAsync(tenantId).ConfigureAwait(false);

            var database = tenant.Database;

            return(await database.ProjectionProgressFor(name, token).ConfigureAwait(false));
        }
Exemplo n.º 7
0
        public async Task <long> ProjectionProgressFor(ShardName name, CancellationToken token = default)
        {
            await _store.Tenancy.Default.EnsureStorageExistsAsync(typeof(IEvent), token);

            var statement = new ProjectionProgressStatement(_store.Events)
            {
                Name = name
            };

            var handler = new OneResultHandler <ShardState>(statement,
                                                            new ShardStateSelector(), true, false);

            await using var session = (QuerySession)_store.QuerySession();

            var progress = await session.ExecuteHandlerAsync(handler, token);

            return(progress?.Sequence ?? 0);
        }
Exemplo n.º 8
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasDescriptorName)
            {
                hash ^= DescriptorName.GetHashCode();
            }
            if (HasVersion)
            {
                hash ^= Version.GetHashCode();
            }
            if (HasShardName)
            {
                hash ^= ShardName.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemplo n.º 9
0
        public async Task event_fetcher_simple_case()
        {
            using var fetcher = new EventFetcher(theStore, theStore.Tenancy.Default.Database, new ISqlFragment[0]);

            NumberOfStreams = 10;
            await PublishSingleThreaded();

            var shardName = new ShardName("name");
            var range1    = new EventRange(shardName, 0, 10);


            await fetcher.Load(range1, CancellationToken.None);

            var range2 = new EventRange(shardName, 10, 20);
            await fetcher.Load(range2, CancellationToken.None);

            var range3 = new EventRange(shardName, 20, 38);
            await fetcher.Load(range3, CancellationToken.None);

            range1.Events.Count.ShouldBe(10);
            range2.Events.Count.ShouldBe(10);
            range3.Events.Count.ShouldBe(18);
        }
Exemplo n.º 10
0
 protected bool Equals(ShardName other)
 {
     return(Identity == other.Identity);
 }
Exemplo n.º 11
0
 public ProgressionProgressOutOfOrderException(ShardName progressionOrShardName) : base($"Progression '{progressionOrShardName}' is out of order. This may happen when multiple processes try to process the projection")
 {
 }