Ejemplo n.º 1
0
        public async void CouldReadReadOnlyChildWhileAddingToParent()
        {
            // TODO if we change the first element to -1 and add from 0, some weird assertion related to regular keys fails
            var total = 150;
            var scm   = new SortedChunkedMap <int, int>(50);

            scm.IsSynchronized = true;
            scm.AddLast(1, 1);
            var cc      = 1;
            var addTask = Task.Run(() => {
                for (int i = 2; i < total + 2; i++)
                {
                    cc++;
                    if (cc == 50)
                    {
                        Console.WriteLine("Next bucket");
                    }
                    scm.Add(i, i);
                    //scm[i] = i;
                    Thread.Sleep(5);
                }
                scm.Complete(); // this will trigger a false return of MoveNextAsync()
            });


            //Thread.Sleep(5000000);

            var reader = scm.ReadOnly();

            Console.WriteLine("Writer IsReadOnly: {0}", scm.IsReadOnly);
            Console.WriteLine("Reader IsReadOnly: {0}", reader.IsReadOnly);
            var cnt = 0;

            using (var c = reader.GetCursor()) {
                var couldMove = await c.MoveNext(CancellationToken.None);

                while (couldMove)
                {
                    if (cnt % 100 == 0)
                    {
                        Console.WriteLine("{0} - {1}", c.CurrentKey, c.CurrentValue);
                    }
                    cnt++;
                    couldMove = await c.MoveNext(CancellationToken.None);
                }
            }
            addTask.Wait();
            Thread.Sleep(200);
            Assert.AreEqual(cnt, total + 1);
            Console.WriteLine("Writer IsReadOnly: {0}", scm.IsReadOnly);
            Console.WriteLine("Reader IsReadOnly: {0}", reader.IsReadOnly);
            //(scm as IPersistentSeries<int, int>).Dispose();
        }
Ejemplo n.º 2
0
        public async void CouldReadReadOnlyChildWhileAddingToParent() {
            // TODO if we change the first element to -1 and add from 0, some weird assertion related to regular keys fails
            var total = 1000;
            var scm = new SortedChunkedMap<int, int>(50);
            scm.IsSynchronized = true;
            scm.AddLast(1, 1);
            var addTask = Task.Run(() => {
                for (int i = 2; i < total + 2; i++) {
                    scm.Add(i, i);
                    //scm[i] = i;
                    Thread.Sleep(5);
                }
                scm.IsMutable = false; // this will trigger a false return of MoveNextAsync()
            });

            var reader = scm.ReadOnly();
            Console.WriteLine("Writer IsMutable: {0}", scm.IsMutable);
            Console.WriteLine("Reader IsMutable: {0}", reader.IsMutable);
            var cnt = 0;
            using (var c = reader.GetCursor()) {
                var couldMove = await c.MoveNext(CancellationToken.None);
                while (couldMove) {
                    if (cnt % 100 == 0) Console.WriteLine("{0} - {1}", c.CurrentKey, c.CurrentValue);
                    cnt++;
                    couldMove = await c.MoveNext(CancellationToken.None);
                }
            }
            addTask.Wait();
            Assert.AreEqual(cnt, total + 1);
            Console.WriteLine("Writer IsMutable: {0}", scm.IsMutable);
            Console.WriteLine("Reader IsMutable: {0}", reader.IsMutable);
            //(scm as IPersistentOrderedMap<int, int>).Dispose();
        }