Ejemplo n.º 1
0
        public void CanMergeConsecutiveInMemoryUpdates()
        {
            var last = Guid.Empty;

            for (int i = 0; i < 5; i++)
            {
                last = Etag.Increment(last, 1);
                prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(new[]
                {
                    new JsonDocument
                    {
                        Etag = last,
                        Key  = i.ToString(CultureInfo.InvariantCulture)
                    },
                });
            }

            Assert.Equal(5, prefetchingBehavior.GetDocumentsBatchFrom(Guid.Empty).Count);
        }
Ejemplo n.º 2
0
        public void ShouldDisableCollectingDocsAfterCommit()
        {
            Etag last = Etag.Empty;

            SystemTime.UtcDateTime = () => DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(15));

            prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(Enumerable.Range(0, 5).Select(x =>
            {
                last = EtagUtil.Increment(last, 1);

                return(new JsonDocument
                {
                    Etag = last,
                    Key = x.ToString(CultureInfo.InvariantCulture)
                });
            }).ToArray());

            last = EtagUtil.Increment(last, store.Configuration.MaxNumberOfItemsToProcessInSingleBatch);

            prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(Enumerable.Range(0, 5).Select(x =>
            {
                last = EtagUtil.Increment(last, 1);

                return(new JsonDocument
                {
                    Etag = last,
                    Key = x.ToString(CultureInfo.InvariantCulture)
                });
            }).ToArray());

            SystemTime.UtcDateTime = null;

            var documentsBatchFrom = prefetchingBehavior.GetDocumentsBatchFrom(Etag.Empty);

            prefetchingBehavior.CleanupDocuments(documentsBatchFrom.Last().Etag);

            Assert.True(prefetchingBehavior.DisableCollectingDocumentsAfterCommit);

            for (int i = 0; i < 5; i++)
            {
                last = EtagUtil.Increment(last, 1);
                prefetchingBehavior.AfterStorageCommitBeforeWorkNotifications(new[]
                {
                    new JsonDocument
                    {
                        Etag = last,
                        Key  = i.ToString(CultureInfo.InvariantCulture)
                    },
                });
            }

            Assert.Equal(0, prefetchingBehavior.InMemoryIndexingQueueSize);
        }