Example #1
0
        public async Task polling_client_should_not_miss_data(int parallelism, bool autopolling)
        {
            _logger.LogDebug("Starting with {Parallelism} workers and Autopolling {Autopolling}", parallelism, autopolling);

            var sequenceChecker = new StrictSequenceChecker($"Workers {parallelism} autopolling {autopolling}");
            var poller          = new PollingClient(Store, 0, sequenceChecker, this.LoggerFactory)
            {
                PollingIntervalMilliseconds = 0,
                HoleDetectionTimeout        = 1000
            };

            if (autopolling)
            {
                poller.Start();
                _logger.LogDebug("Started Polling");
            }

            const int range = 1000;

            var producer = new ActionBlock <int>(async i =>
            {
                await Store.AppendAsync("p", i, "demo", "op#" + i).ConfigureAwait(false);
            }, new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = parallelism
            });

            _logger.LogDebug("Started pushing data: {elements} elements", range);

            foreach (var i in Enumerable.Range(1, range))
            {
                Assert.True(await producer.SendAsync(i).ConfigureAwait(false));
            }

            producer.Complete();
            await producer.Completion.ConfigureAwait(false);

            _logger.LogDebug("Data pushed");

            if (autopolling)
            {
                _logger.LogDebug("Stopping poller");
                await poller.Stop();

                _logger.LogDebug("Poller stopped");
            }

            // read to end
            _logger.LogDebug("Polling to end");
            var timeout = new CancellationTokenSource(60000);
            await poller.Poll(timeout.Token).ConfigureAwait(false);

            _logger.LogDebug("Polling to end - done");

            Assert.True(poller.Position == sequenceChecker.Position, "Sequence " + sequenceChecker.Position + " != Position " + poller.Position);
            Assert.True(range == poller.Position, "Poller @" + poller.Position);
            Assert.True(range == sequenceChecker.Position, "Sequence @" + sequenceChecker.Position);
        }
        public void Add(PollingClient pollingClient)
        {
            lock (sync)
            {
                pollingClients.Add(pollingClient);
            }

            pollingClient.Start();
        }
Example #3
0
 protected override void Because()
 {
     PollingClient.Start();
     Task.Factory.StartNew(() =>
     {
         for (int i = 0; i < 15; i++)
         {
             StoreEvents.Advanced.CommitSingle();
         }
     });
 }
Example #4
0
        /// <summary>
        /// Create a poller, start the poller and return starting position of the poller.
        /// </summary>
        /// <param name="poller"></param>
        /// <param name="pollerId"></param>
        /// <returns></returns>
        private Int64 CreatePollerAndStart(ref PollingClient poller, Int32 pollerId, Func <AtomicDispatchChunk, Task <Boolean> > dispatchToTplFunction)
        {
            if (poller != null)
            {
                poller.Stop();
            }
            var startingPosition = TryGetStartingPoint(pollerId);

            Logger.InfoFormat("AtomicProjectionEngine: Starting poller id {0} from position {1}", pollerId, startingPosition);
            var subscription = new JarvisFrameworkLambdaSubscription(c => dispatchToTplFunction(new AtomicDispatchChunk(pollerId, c)));

            poller = new PollingClient(_persistence, startingPosition, subscription, _nStoreLoggerFactory);
            poller.Start();
            return(startingPosition);
        }
Example #5
0
        /// <summary>
        /// Create a poller, start the poller and return starting position of the poller.
        /// </summary>
        /// <param name="poller"></param>
        /// <param name="pollerId"></param>
        /// <returns></returns>
        private Int64 CreatePollerAndStart(ref PollingClient poller, Int32 pollerId, Func <AtomicDispatchChunk, Task <Boolean> > dispatchToTplFunction)
        {
            if (poller != null)
            {
                poller.Stop();
            }
            //The default value to start is zero, it is a situation that should never happen, if it happens this poller has no projection to dispatch.
            var startingPosition = TryGetStartingPoint(pollerId, 0);

            Logger.InfoFormat("AtomicProjectionEngine: Starting poller id {0} from position {1}", pollerId, startingPosition);
            var subscription = new JarvisFrameworkLambdaSubscription(c => dispatchToTplFunction(new AtomicDispatchChunk(pollerId, c)));

            poller = new PollingClient(_persistence, startingPosition, subscription, _nStoreLoggerFactory);
            poller.Start();
            return(startingPosition);
        }
Example #6
0
        public void Start()
        {
            _logger.InfoFormat("CommitPollingClient {0}: start called", _id);
            if (Status != CommitPollingClientStatus.Polling)
            {
                if (_innerClient == null)
                {
                    throw new JarvisFrameworkEngineException($"CommitPollingClient {_id}: Cannot start polling client because you forget to call Configure First");
                }

                _innerClient.Start();
                Status = CommitPollingClientStatus.Polling;
            }
            else
            {
                _logger.WarnFormat("CommitPollingClient {0}: Start called but client was in status {1}", _id, Status);
            }
        }
Example #7
0
        public DomainRuntime(
            IPersistence persistence,
            IAggregateFactory aggregateFactory,
            ISnapshotStore snapshots,
            ChunkProcessor processor)
        {
            _persistence      = persistence;
            _aggregateFactory = aggregateFactory;
            _snapshots        = snapshots;
            _streamsFactory   = new StreamsFactory(persistence);

            if (processor != null)
            {
                _pollingClient = new PollingClient(
                    persistence,
                    0, // <----- TODO: read from state?
                    new LambdaSubscription(processor),
                    NStoreNullLoggerFactory.Instance
                    );
                _pollingClient.Start();
            }
        }
Example #8
0
 public void StartPolling()
 {
     _poller.Start();
 }
Example #9
0
 public void Start()
 {
     _pollingClient.Start();
 }
Example #10
0
 protected override void Because()
 {
     PollingClient.Start();
 }
Example #11
0
 protected override void Because()
 {
     PollingClient.Start();
     StoreEvents.Advanced.CommitSingle();
 }