protected async Task GenerateEmptyUntil(Int64 positionTo)
        {
            IChunk chunk;

            do
            {
                chunk = await _persistence.AppendAsync("Empty", null).ConfigureAwait(false);

                lastUsedPosition = chunk.Position;
            } while (chunk.Position < positionTo);
        }
 public Task <IChunk> AppendAsync(string partitionId, long index, object payload, string operationId,
                                  CancellationToken cancellationToken)
 {
     return(Track.Profile(Timers.Append, () =>
                          _persistence.AppendAsync(partitionId, index, payload, operationId, cancellationToken)
                          ));
 }
Exemplo n.º 3
0
 public static Task <IChunk> AppendAsync(
     this IPersistence store,
     string partitionId,
     object payload
     )
 {
     return(store.AppendAsync(partitionId, -1, payload, null, CancellationToken.None));
 }
Exemplo n.º 4
0
        private void task_worker(IPersistence store)
        {
            var all = _iterations.Select(i => Task.Run(async() =>
                                                       await store.AppendAsync("Stream_1", i, new { data = "this is a test" })
                                                       ));

            Task.WhenAll(all).GetAwaiter().GetResult();
        }
Exemplo n.º 5
0
 public static Task <IChunk> AppendAsync(
     this IPersistence persistence,
     string partitionId,
     long index,
     object payload
     )
 {
     return(persistence.AppendAsync(partitionId, index, payload, null, CancellationToken.None));
 }
Exemplo n.º 6
0
        public async Task persist_should_be_recorded()
        {
            await _store.AppendAsync("empty", 0, null).ConfigureAwait(false);

            Assert.Equal(1, _profile.PersistCounter.Calls);
            Assert.Equal(0, _profile.DeleteCounter.Calls);
            Assert.Equal(0, _profile.StoreScanCounter.Calls);
            Assert.Equal(0, _profile.ReadForwardCounter.Calls);
            Assert.Equal(0, _profile.ReadBackwardCounter.Calls);
            Assert.Equal(0, _profile.ReadSingleBackwardCounter.Calls);
        }
Exemplo n.º 7
0
        public static Task Run(IPersistence store, IEnumerable <int> iterations)
        {
            var list = new List <Task>();

            foreach (var iteration in iterations)
            {
                list.Add(store.AppendAsync("Stream_1", iteration, new { data = "this is a test" }));
            }

            return(Task.WhenAll(list.ToArray()));
        }
Exemplo n.º 8
0
        public async void persist_should_be_recorded()
        {
            await _store.AppendAsync("empty", 0, null);

            Assert.Equal(1, _profile.PersistCounter.Calls);
            Assert.Equal(0, _profile.DeleteCounter.Calls);
            Assert.Equal(0, _profile.StoreScanCounter.Calls);
            Assert.Equal(0, _profile.ReadForwardCounter.Calls);
            Assert.Equal(0, _profile.ReadBackwardCounter.Calls);
            Assert.Equal(0, _profile.PeekCounter.Calls);
        }
Exemplo n.º 9
0
        public async Task <IChunk> AppendAsync(
            string partitionId,
            long index,
            object payload,
            string operationId,
            CancellationToken cancellationToken)
        {
            _logger.LogDebug("Start PersistAsync({partitionId}, {index})", partitionId, index);
            var result = await _persistence.AppendAsync(partitionId, index, payload, operationId, cancellationToken).ConfigureAwait(false);

            _logger.LogDebug("End PersistAsync({partitionId}, {index}) => {Position}", partitionId, index, result?.Position);
            return(result);
        }
Exemplo n.º 10
0
        public async Task AddAsync(string snapshotPartitionId, SnapshotInfo snapshot, CancellationToken cancellationToken)
        {
            if (snapshot == null || snapshot.IsEmpty)
            {
                return;
            }

            try
            {
                await _store.AppendAsync(snapshotPartitionId, snapshot.SourceVersion, snapshot, null, cancellationToken).ConfigureAwait(false);
            }
            catch (DuplicateStreamIndexException)
            {
                // already stored
            }
        }
        private async Task async_worker(IPersistence store)
        {
            var publish = new ActionBlock <long>(async i =>
            {
                await store.AppendAsync("Stream_1", i, new { data = "this is a test" });
            }, new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            });

            foreach (var iteration in _iterations)
            {
                await publish.SendAsync(iteration);
            }

            publish.Complete();
            await publish.Completion;
        }
Exemplo n.º 12
0
 protected override async Task ProcessAsync(Signal payload)
 {
     Track.Inc(Counters.ReceivedMessages);
     await Track.Profile(Timers.RequestTimer, async() =>
     {
         while (true)
         {
             try
             {
                 await _persistence.AppendAsync(
                     payload.DeviceId,
                     DateTime.UtcNow.Ticks,
                     payload
                     ).ConfigureAwait(false);
                 return;
             }
             catch (DuplicateStreamIndexException)
             {
                 // retry with new ticks
             }
         }
     }).ConfigureAwait(false);
 }
Exemplo n.º 13
0
 public Task <IChunk> AppendAsync(string partitionId, long index, object payload, string operationId, CancellationToken cancellationToken)
 {
     return(PersistCounter.CaptureAsync(() =>
                                        _store.AppendAsync(partitionId, index, payload, operationId, cancellationToken)
                                        ));
 }
Exemplo n.º 14
0
        public async Task <long> PersistEventAsync(string actorName, long index, object @event)
        {
            await _events.AppendAsync(actorName, index, @event).ConfigureAwait(false);

            return(index++); // TODO -> check sources, not really needed imho
        }
Exemplo n.º 15
0
 private void paralell_worker(IPersistence store)
 {
     _iterations.ForEachAsync(Workers, i =>
                              store.AppendAsync("Stream_1", i, new { data = "this is a test" })
                              ).ConfigureAwait(false).GetAwaiter().GetResult();
 }
 public async Task PersistSnapshotAsync(string actorName, long index, object snapshot)
 {
     await _snapshots.AppendAsync(actorName, index, snapshot).ConfigureAwait(false);
 }