Beispiel #1
0
        public void CouldNotMoveNextPreviousOnEmpty()
        {
            var s = new AppendSeries <int, int>();
            var c = s.GetCursor();

            Assert.IsFalse(c.MoveNext());
            Assert.IsFalse(c.MovePrevious());
            Assert.IsFalse(c.MoveFirst());
            Assert.IsFalse(c.MoveLast());
            s.Append(1, 1);
            Assert.IsTrue(c.MoveNext());
            Assert.IsFalse(c.MovePrevious());
            Assert.IsTrue(c.MoveFirst());
            Assert.IsTrue(c.MoveLast());

            s.Append(2, 2);
            Assert.IsTrue(c.MoveNext());
            Assert.AreEqual(2, c.CurrentKey);
            Assert.AreEqual(2, c.CurrentValue);
            Assert.IsTrue(c.MovePrevious());
            Assert.AreEqual(1, c.CurrentKey);
            Assert.AreEqual(1, c.CurrentValue);
            Assert.IsTrue(c.MoveFirst());
            Assert.IsTrue(c.MoveLast());

            c.Dispose();
            s.Dispose();
        }
        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();
        }
Beispiel #3
0
        public void CouldMoveAtOnNonEmpty(int count)
        {
            Assert.Fail("Need a proper MA test");
            var s = new AppendSeries <int, int>();

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

            var searchValue = count / 2;

            // TODO all corners all directions and all inner

            var c = s.GetCursor();

            Assert.IsTrue(c.MoveAt(searchValue, Lookup.GT));
            Assert.AreEqual(searchValue + 1, c.CurrentValue);
            Assert.AreEqual(searchValue + 1, c.CurrentKey);

            Assert.IsTrue(c.MoveAt(searchValue, Lookup.GE));
            Assert.IsTrue(c.MoveAt(searchValue, Lookup.EQ));
            Assert.IsTrue(c.MoveAt(searchValue, Lookup.LE));
            Assert.IsTrue(c.MoveAt(searchValue, Lookup.LT));
            c.Dispose();
            s.Dispose();
        }
        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();
        }
        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();
        }
        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();
        }
        public async Task CouldAsyncEnumerate()
        {
            var s     = new AppendSeries <int, int>();
            var count = (int)TestUtils.GetBenchCount(10_000_000, 5);

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

            var t = Task.Run(async() =>
            {
                using (Benchmark.Run("SCM.AsyncEnumerator", count))
                {
                    var cnt = 0;
                    await foreach (var _ in s)
                    {
                        cnt++;
                    }

                    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();
        }
Beispiel #8
0
        public void CouldMoveAtOnSingle()
        {
            Assert.Fail("Proper MA tests");
            var s = new AppendSeries <int, int>();

            s.Append(1, 1);
            var c = s.GetCursor();

            Assert.IsFalse(c.MoveAt(1, Lookup.GT));
            Assert.IsTrue(c.MoveAt(1, Lookup.GE));
            Assert.IsTrue(c.MoveAt(1, Lookup.EQ));
            Assert.IsTrue(c.MoveAt(1, Lookup.LE));
            Assert.IsFalse(c.MoveAt(1, Lookup.LT));
            c.Dispose();
            s.Dispose();
        }
Beispiel #9
0
        public void CouldMovePreviousFromInitialized(int count)
        {
            var s = new AppendSeries <int, int>();

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

            var c = s.GetCursor();

            Assert.IsTrue(c.MovePrevious());
            Assert.AreEqual(count, c.CurrentKey);
            Assert.AreEqual(count, c.CurrentValue);

            c.Dispose();
            s.Dispose();
        }
Beispiel #10
0
        public void CouldMoveFirstLast(int count)
        {
            var s = new AppendSeries <int, int>();

            for (int i = 1; i <= count; i++)
            {
                s.Append(i, i);
            }
            SCursor <int, int> c;

            c = s.GetCursor();
            Assert.IsTrue(c.MoveFirst());
            Assert.IsTrue(c.MoveLast());
            c.Dispose();

            c = s.GetCursor();
            Assert.IsTrue(c.MoveLast());
            Assert.IsTrue(c.MoveFirst());
            c.Dispose();

            s.Dispose();
        }
Beispiel #11
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();
        }
Beispiel #12
0
        public void CouldMovePartialFromMoving(int count)
        {
            var s = new AppendSeries <int, int>();

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

            SCursor <int, int> c;

            c = s.GetCursor();
            c.MoveNext();
            Assert.AreEqual(count - 1, c.Move(count * 2, true));
            Assert.AreEqual(count, c.CurrentKey);
            Assert.AreEqual(count, c.CurrentValue);
            c.Dispose();

            c = s.GetCursor();
            c.MoveNext();
            Assert.AreEqual(count - 1, c.Move(count * 200, true));
            Assert.AreEqual(count, c.CurrentKey);
            Assert.AreEqual(count, c.CurrentValue);
            c.Dispose();

            c = s.GetCursor();
            c.MoveNext();
            Assert.AreEqual(count - 1, c.Move(count + 1, true));
            Assert.AreEqual(count, c.CurrentKey);
            Assert.AreEqual(count, c.CurrentValue);
            c.Dispose();

            c = s.GetCursor();
            c.MoveNext();
            Assert.AreEqual(count - 1, c.Move(count, true));
            Assert.AreEqual(count, c.CurrentKey);
            Assert.AreEqual(count, c.CurrentValue);
            c.Dispose();

            // ---------

            c = s.GetCursor();
            c.MovePrevious();
            Assert.AreEqual(-count + 1, c.Move(-count * 2, true));
            Assert.AreEqual(1, c.CurrentKey);
            Assert.AreEqual(1, c.CurrentValue);
            c.Dispose();

            c = s.GetCursor();
            c.MovePrevious();
            Assert.AreEqual(-count + 1, c.Move(-count * 200, true));
            Assert.AreEqual(1, c.CurrentKey);
            Assert.AreEqual(1, c.CurrentValue);
            c.Dispose();

            c = s.GetCursor();
            c.MovePrevious();
            Assert.AreEqual(-count + 1, c.Move(-(count + 1), true));
            Assert.AreEqual(1, c.CurrentKey);
            Assert.AreEqual(1, c.CurrentValue);
            c.Dispose();

            c = s.GetCursor();
            c.MovePrevious();
            Assert.AreEqual(-count + 1, c.Move(-count, true));
            Assert.AreEqual(1, c.CurrentKey);
            Assert.AreEqual(1, c.CurrentValue);
            c.Dispose();

            s.Dispose();
        }