Beispiel #1
0
        //public virtual async Task LoadItemsWithPagingWorks()
        //{
        //    await InitializeAsync();
        //    var store = CreateInstance();

        //    var list = FakeEntity.CreateList(31).ToArray();

        //    foreach (var entity in list)
        //        await store.InsertItemAsync(entity);


        //    //page 1
        //    var page1 = await store.LoadPagedResultAsync(
        //        new PagedLoadingParameters<FakeEntity>
        //        {
        //            OrderBy = x => x.IntValue,
        //            Where = x => x.ChunkId == list[0].ChunkId,
        //            Page = 1,
        //            PageSize = 10
        //        }
        //    );

        //    page1.TotalCount.Should().Be(31);
        //    page1.PageSize.Should().Be(10);
        //    page1.ResultCount.Should().Be(10);
        //    page1.Results.Count.Should().Be(10);


        //    //page 2
        //    var page2 = await store.LoadPagedResultAsync(
        //        new PagedLoadingParameters<FakeEntity>
        //        {
        //            OrderBy = x => x.IntValue,
        //            Where = x => x.ChunkId == list[0].ChunkId,
        //            Page = 2,
        //            PageSize = 10,
        //            ContinuationToken = page1.ContinuationToken
        //        }
        //    );


        //    page2.TotalCount.Should().Be(31);
        //    page2.PageSize.Should().Be(10);
        //    page2.ResultCount.Should().Be(10);
        //    page2.Results.Count.Should().Be(10);

        //    //page 2
        //    var page3 = await store.LoadPagedResultAsync(
        //        new PagedLoadingParameters<FakeEntity>
        //        {
        //            OrderBy = x => x.IntValue,
        //            Where = x => x.ChunkId == list[0].ChunkId,
        //            Page = 3,
        //            PageSize = 10,
        //            ContinuationToken = page2.ContinuationToken
        //        }
        //    );

        //    page3.TotalCount.Should().Be(31);
        //    page3.PageSize.Should().Be(10);
        //    page3.ResultCount.Should().BeGreaterOrEqualTo(1);
        //    page3.Results.Count.Should().BeGreaterOrEqualTo(1);
        //}

        //public virtual void LoadItemsWithPagingAndCancelationThrowsError()
        //{
        //    var store = CreateInstance();

        //    var token = new CancellationToken(true);
        //    Func<Task> f1 = async () =>
        //        {
        //            await store.LoadPagedResultAsync(new PagedLoadingParameters<FakeEntity>(), token);
        //        };

        //    f1.Should().Throw<Exception>();
        //}

        //public virtual async Task LoadItemsWithPagingAndOrderingWorks()
        //{
        //    var store = CreateInstance();

        //    var list = FakeEntity.CreateList2(31).ToArray();

        //    foreach (var entity in list)
        //        await store.InsertItemAsync(entity);

        //    //page 1
        //    var page1 = await store.LoadPagedResultAsync(
        //        new PagedLoadingParameters<FakeEntity>
        //        {
        //            OrderBy = x => x.IntValue,
        //            OrderThenBy = x => x.StringValue,
        //            Where = x => x.ChunkId == list[0].ChunkId,
        //            Page = 1,
        //            PageSize = 10
        //        }
        //    );

        //    page1.TotalCount.Should().Be(31);
        //    page1.PageSize.Should().Be(10);
        //    page1.ResultCount.Should().Be(10);
        //    page1.Results.Count.Should().Be(10);

        //    page1.Results[0].StringValue.Should().Be(list.Last().StringValue);
        //}


        public virtual async Task LoadItemsWithWhereWorks()
        {
            await InitializeAsync().ConfigureAwait(false);

            var store = CreateInstance();

            var list = FakeEntity.CreateList(31).ToArray();

            foreach (var entity in list)
            {
                await store.InsertItemAsync(entity).ConfigureAwait(false);
            }

            var chunkId = list[0].ChunkId;

            var items = (await store.LoadItemsAsync <FakeEntity>(x => x.ChunkId == chunkId).ConfigureAwait(false)).ToArray();

            items.Should().NotBeNull();
            items.Length.Should().Be(list.Length);

            var guidVal = list[0].GuidValue;
            var items1  = (await store.LoadItemsAsync <FakeEntity>(x => x.ChunkId == chunkId && x.GuidValue == guidVal).ConfigureAwait(false)).ToArray();

            items1.Length.Should().Be(1);
        }
Beispiel #2
0
        public void TestGetPaged()
        {
            var items = FakeEntity.CreateList(10).ToArray();

            var paged = items.GetPaged(3, 2);

            paged.Length.Should().Be(3);

            paged.Should().Contain(x => x.EntityId == items[3].EntityId);
            paged.Should().Contain(x => x.EntityId == items[4].EntityId);
            paged.Should().Contain(x => x.EntityId == items[5].EntityId);
        }
Beispiel #3
0
        public void TestGetPagedResults()
        {
            var items = FakeEntity.CreateList(10).ToArray();

            var paged = items.GetPagedResults(3, 2);

            paged.PageSize.Should().Be(3);
            paged.TotalCount.Should().Be(items.Length);

            paged.Results.Should().Contain(x => x.EntityId == items[3].EntityId);
            paged.Results.Should().Contain(x => x.EntityId == items[4].EntityId);
            paged.Results.Should().Contain(x => x.EntityId == items[5].EntityId);
        }
        public async Task CanCacheLoadSetItems()
        {
            // add items to store
            var store   = GetService <IEntityStore>();
            var chunkid = Guid.NewGuid().ToString();
            var list1   = FakeEntity.CreateList(15, chunkid).ToArray();
            await store.BulkInsertItemsAsync(list1);

            var adapter = GetService <ICacheAdapter>();
            var client  = GetService <ICacheClient>();


            var setKey = Guid.NewGuid().ToString();


            var items1 = await adapter.LoadSetItems <FakeEntity>(setKey,
                                                                 entity => entity.ChunkId == chunkid);

            items1.Count.Should().Be(list1.Length);

            var containsCacheKey = await client.ExistsAsync(setKey);

            containsCacheKey.Should().BeTrue();

            async Task RunLogic()
            {
                var item2 = FakeEntity.CreateList(1, chunkid).First();
                await store.InsertItemAsync(item2);

                await adapter.SetItemsEnsureAsync(setKey, item2.EntityId);

                var items2 = await adapter.LoadSetItems <FakeEntity>(setKey,
                                                                     entity => entity.ChunkId == chunkid);

                items2.Should().Contain(x => x.EntityId == item2.EntityId);
            }

            var tasks = new List <Task>();

            for (int i = 0; i < 100; i++)
            {
                tasks.Add(RunLogic());
            }

            await Task.WhenAll(tasks);
        }
Beispiel #5
0
        public async Task PerfCheck()
        {
            var provider = GetService <MongoDbConnectionProvider>();
            await provider.InitializeAsync(CancellationToken.None);

            var store = CreateInstance();

            BulkInsertCount = 10000;
            var chunkId = Guid.NewGuid().ToString();
            var list    = FakeEntity.CreateList(BulkInsertCount, chunkId);
            await store.BulkInsertItemsAsync(list);

            _logger.LogInformation("Bulk Insert Finished");

            var options = provider.Options;

            async Task F1()
            {
                {
                    //options.FindLimit = 250;
                    options.FindBatchSize = 2000;
                    await RunIt(options, store, chunkId);
                }

                {
                    await RunIt(options, store, chunkId);
                }
            }

            await F1();

            {
                await CreateIndex(Builders <FakeEntity> .IndexKeys
                                  .Ascending(x => x.ChunkId)
                                  , CancellationToken.None);

                _logger.LogInformation("Indexe erzeugt");
            }

            await F1();
        }