示例#1
0
        public async Task CouldCancelCursor()
        {
            var s = new AppendSeries <int, int>();

            var c = s.GetAsyncEnumerator();

            var t = Task.Run(async() =>
            {
                try
                {
                    await c.MoveNextAsync();
                    Assert.Fail();
                }
                catch (Exception ex)
                {
                    Assert.True(true);
                }
            });

            Thread.Sleep(100);

            c.TryComplete(true);

            t.Wait();

            c.Dispose();
            s.Dispose();
        }
示例#2
0
        public void DeadCursorDoesNotCauseEndlessLoopInNotifyUpdate()
        {
            var s = new AppendSeries <int, int>();

            s.Append(1, 1);

            var cursor = s.GetAsyncEnumerator();

            Assert.True(cursor.MoveNext());
            Assert.False(cursor.MoveNext());

            cursor.MoveNextAsync();
            cursor.Dispose();
            cursor = default;

            GC.Collect(2, GCCollectionMode.Forced, true);
            GC.Collect(2, GCCollectionMode.Forced, true);

            //var t = Task.Run(() => cursor.MoveNextAsync(cts.Token));

            s.Append(2, 2);
            s.Append(3, 3);

            Assert.True(s.RowCount == 3);

            s.Dispose();
        }
示例#3
0
        public async Task CouldEnumerateSMUsingCursor()
        {
            var s     = new AppendSeries <int, int>();
            var count = (int)TestUtils.GetBenchCount();

            for (int i = 0; i < count; i++)
            {
                s.Append(i, i);
            }

#pragma warning disable HAA0401 // Possible allocation of reference type enumerator
            var ae = s.GetAsyncEnumerator();
#pragma warning restore HAA0401 // Possible allocation of reference type enumerator

            var t = Task.Run(async() =>
            {
                using (Benchmark.Run("SCM.AsyncEnumerator", count))
                {
                    var cnt = 0;
                    while (await ae.MoveNextAsync())
                    {
                        cnt++;
                    }

                    await ae.DisposeAsync();
                    Assert.AreEqual(count * 2, cnt);
                }

                Benchmark.Dump();
            });

            for (int i = count; i < count * 2; i++)
            {
                s.Append(i, i);
            }

            s.MarkReadOnly();

            t.Wait();

            s.Dispose();
        }
示例#4
0
        public void CancelledCursorDoesntCauseEndlessLoopInNotifyUpdate()
        {
            var s = new AppendSeries <int, int>();

            s.Append(1, 1);

            var c = s.GetAsyncEnumerator();

            Assert.True(c.MoveNext());
            Assert.False(c.MoveNext());

            c.MoveNextAsync();

            s.Append(2, 2);
            s.Append(3, 3);

            Assert.True(s.RowCount == 3);

            c.Dispose();
            s.Dispose();
        }
示例#5
0
        public async Task NotificationWorksWhenCursorIsNotWating()
        {
            var s = new AppendSeries <int, int>();

            s.Append(1, 1);
            s.Append(2, 2);

            var c = s.GetAsyncEnumerator();

            Assert.True(await c.MoveNextAsync());
            Assert.True(await c.MoveNextAsync());

            Assert.IsTrue(c.MovePrevious());

            s.Append(3, 3);

            await Task.Delay(250);

            Assert.AreEqual(1, c.CurrentKey);
            Assert.AreEqual(1, c.CurrentValue);
            c.Dispose();
            s.Dispose();
        }
示例#6
0
        public async Task CouldEnumerateSCMUsingCursor()
        {
            var s     = new AppendSeries <int, int>();
            var count = 1_000_000; // Settings.SCMDefaultChunkLength - 1;

            for (int i = 0; i < count; i++)
            {
                s.Append(i, i);
            }

            Console.WriteLine("Added first half");

#pragma warning disable HAA0401 // Possible allocation of reference type enumerator
            var ae = s.GetAsyncEnumerator();
#pragma warning restore HAA0401 // Possible allocation of reference type enumerator

            var t = Task.Run(async() =>
            {
                using (Benchmark.Run("SCM.AsyncEnumerator", count))
                {
                    try
                    {
                        var cnt = 0;
                        while (await ae.MoveNextAsync())
                        {
                            if (cnt != ae.Current.Key)
                            {
                                ThrowHelper.ThrowInvalidOperationException();
                            }

                            cnt++;
                        }

                        await ae.DisposeAsync();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("EXCEPTION: " + ex.ToString());
                        throw;
                    }

                    // Assert.AreEqual(scm.Count, cnt);
                }

                Benchmark.Dump();
            });

            // Thread.Sleep(1000);

            for (int i = count; i < count * 2; i++)
            {
                s.Append(i, i);
                //Thread.SpinWait(50);
            }

            // Thread.Sleep(2000);

            s.MarkReadOnly();

            t.Wait();

            s.Dispose();
        }