Beispiel #1
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (Scheduler = new TaskScheduler(JobQueue.WindowsMessageBased))
                using (ErrorList = new ErrorListDialog()) {
                    Scheduler.ErrorHandler = OnTaskError;

                    Preferences = new Tangle <object>(
                        Scheduler, CreatePreferencesStorage()
                        );

                    using (var f = Scheduler.Start(MainTask(), TaskExecutionPolicy.RunAsBackgroundTask)) {
                        f.RegisterOnComplete((_) => {
                            if (_.Failed)
                            {
                                Application.Exit();
                            }
                        });

                        Application.Run();
                    }
                }
        }
Beispiel #2
0
        public void TestSimpleJoin()
        {
            for (int i = 0; i < 8; i++)
            {
                Scheduler.WaitFor(Tangle.Set(i, i * 2));
            }

            using (var otherTangle = new Tangle <int>(Scheduler, new SubStreamSource(Storage, "2_", false))) {
                var keys = new List <string>();
                for (int i = 0; i < 8; i++)
                {
                    var key = new String((char)('a' + i), 1);
                    keys.Add(key);
                    Scheduler.WaitFor(otherTangle.Set(key, i));
                }

                var joinResult = Scheduler.WaitFor(
                    otherTangle.Join(
                        Tangle, keys,
                        (leftValue) => leftValue
                        )
                    );

                for (int i = 0; i < 8; i++)
                {
                    var item = joinResult[i];
                    Assert.AreEqual(i, item.Key);
                    Assert.AreEqual(i * 2, item.Value);
                }
            }
        }
Beispiel #3
0
        public override void SetUp()
        {
            base.SetUp();

            Tangle = new Tangle <SpecialType>(
                Scheduler, Storage,
                ownsStorage: true
                );
        }
Beispiel #4
0
        protected IEnumerator <object> CheckLotsOfValues(Tangle <int> tangle, int numIterations)
        {
            for (int i = 0; i < numIterations; i++)
            {
                var f = tangle.Get(i);
                yield return(f);

                Assert.AreEqual(i, f.Result);
            }
        }
Beispiel #5
0
        public override void SetUp()
        {
            base.SetUp();

            Tangle = new Tangle <int>(
                Scheduler, Storage,
                serializer: BlittableSerializer <int> .Serialize,
                deserializer: BlittableSerializer <int> .Deserialize,
                ownsStorage: true
                );
        }
Beispiel #6
0
        public void TestKnotTangleIsContiguousFalse()
        {
            Knot knot = new Knot(new List <int>()
            {
                -1, 2, -3, 1, -2, 3, -4, 5, -6, 7, 8, 4, -5, 6, -7, -8
            });
            PrivateObject obj  = new PrivateObject(knot);
            Tangle        t    = new Tangle(new int[] { 5, 6, 7 });
            bool          test = (bool)obj.Invoke("IsContiguousTangle", t);

            Assert.AreEqual(false, test);
        }
Beispiel #7
0
        public void TestIsValidTangleFalse4()
        {
            Knot knot = new Knot(new List <int>()
            {
                1, -2, 3, -1, 2, -3, 4, -4
            });
            Tangle        tangle  = new Tangle(new int[] { 3, 1 });
            PrivateObject obj     = new PrivateObject(knot);
            bool          isValid = (bool)obj.Invoke("IsValidTangle", tangle);

            Assert.AreEqual(false, isValid);
        }
Beispiel #8
0
        public void TestKnotEndsContiguousTangle()
        {
            Knot knot = new Knot(new List <int>()
            {
                -1, 2, -3, 1, -2, 3, -4, 5, -6, 7, 8, 4, -5, 6, -7, -8
            });
            PrivateObject obj = new PrivateObject(knot);
            Tangle        t   = new Tangle(new int[] { 1, 2, 3 });

            int[] test = (int[])obj.Invoke("GetTangleEnds", t);
            Assert.AreEqual(2, test.Length);
            Assert.AreEqual(15, test[0]);
            Assert.AreEqual(6, test[1]);
        }
Beispiel #9
0
        protected IEnumerator <object> WriteLotsOfValuesInBatch(Tangle <int> tangle, int numIterations, int direction)
        {
            int         batchSize = 256;
            Batch <int> batch     = null;

            if (direction > 0)
            {
                for (int i = 0; i < numIterations; i++)
                {
                    if (batch == null)
                    {
                        batch = Tangle.CreateBatch(batchSize);
                    }

                    batch.Add(i, i);

                    if (batch.Count == batchSize)
                    {
                        yield return(batch.Execute());

                        batch = null;
                    }
                }
            }
            else
            {
                for (int i = numIterations - 1; i >= 0; i--)
                {
                    if (batch == null)
                    {
                        batch = Tangle.CreateBatch(batchSize);
                    }

                    batch.Add(i, i);

                    if (batch.Count == batchSize)
                    {
                        yield return(batch.Execute());

                        batch = null;
                    }
                }
            }

            if (batch != null)
            {
                yield return(batch.Execute());
            }
        }
Beispiel #10
0
        public unsafe override void SetUp()
        {
            base.SetUp();

            var serializer = new Squared.Data.Mangler.Serialization.StringSerializer(
                Encoding.UTF8
                );

            Tangle = new Tangle <string>(
                Scheduler, Storage,
                serializer: serializer.Serialize,
                deserializer: serializer.Deserialize,
                ownsStorage: true
                );
        }
        public void TestTangleHashOK()
        {
            Tangle t1 = new Tangle(new int[] { 2, -1, 3 });
            Tangle t2 = new Tangle(new int[] { 1, -2, -3 });
            Tangle t3 = new Tangle(new int[] { -1, 3, 2 });
            Tangle t4 = new Tangle(new int[] { -1, -4, 3, 2, 4 });

            int h1 = t1.Hash();
            int h2 = t2.Hash();
            int h3 = t3.Hash();
            int h4 = t4.Hash();

            Assert.AreEqual(h1, h2);
            Assert.AreEqual(h2, h3);
            Assert.AreEqual(h3, h4);
        }
Beispiel #12
0
        public void TestCascadingSelect()
        {
            using (var otherTangle1 = new Tangle <int>(Scheduler, new SubStreamSource(Storage, "2_", false)))
                using (var otherTangle2 = new Tangle <int>(Scheduler, new SubStreamSource(Storage, "3_", false))) {
                    Scheduler.WaitFor(Tangle.Set(1, 1));
                    Scheduler.WaitFor(otherTangle1.Set(2, 3));
                    Scheduler.WaitFor(otherTangle2.Set(2, 5));
                    Scheduler.WaitFor(otherTangle2.Set(3, 4));

                    var result = Scheduler.WaitFor(Tangle.CascadingSelect(
                                                       new [] { otherTangle1, otherTangle2 },
                                                       new [] { 1, 2, 3, 4 }
                                                       ));

                    Assert.AreEqual(new [] { 1, 3, 4, default(int) }, result);
                }
        }
Beispiel #13
0
 protected IEnumerator <object> WriteLotsOfValues(Tangle <int> tangle, int numIterations, int direction)
 {
     if (direction > 0)
     {
         for (int i = 0; i < numIterations; i++)
         {
             yield return(tangle.Set(i, i));
         }
     }
     else
     {
         for (int i = numIterations - 1; i >= 0; i--)
         {
             yield return(tangle.Set(i, i));
         }
     }
 }
Beispiel #14
0
 public override void SetUp()
 {
     base.SetUp();
     Tangle = new Tangle<object>(Scheduler, Storage);
     Serializer = new TanglePropertySerializer(Tangle);
 }
Beispiel #15
0
        public override void SetUp()
        {
            base.SetUp();

            Tangle = new Tangle<SpecialType>(
                Scheduler, Storage,
                ownsStorage: true
            );
        }
Beispiel #16
0
        public unsafe override void SetUp()
        {
            base.SetUp();

            var serializer = new Squared.Data.Mangler.Serialization.StringSerializer(
                Encoding.UTF8
            );

            Tangle = new Tangle<string>(
                Scheduler, Storage,
                serializer: serializer.Serialize,
                deserializer: serializer.Deserialize,
                ownsStorage: true
            );
        }
Beispiel #17
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            using (Scheduler = new TaskScheduler(JobQueue.WindowsMessageBased))
            using (ErrorList = new ErrorListDialog()) {
                Scheduler.ErrorHandler = OnTaskError;

                Preferences = new Tangle<object>(
                    Scheduler, CreatePreferencesStorage()
                );

                using (var f = Scheduler.Start(MainTask(), TaskExecutionPolicy.RunAsBackgroundTask)) {
                    f.RegisterOnComplete((_) => {
                        if (_.Failed)
                            Application.Exit();
                    });

                    Application.Run();
                }
            }
        }
Beispiel #18
0
        public void TestCascadingSelect()
        {
            using (var otherTangle1 = new Tangle<int>(Scheduler, new SubStreamSource(Storage, "2_", false)))
            using (var otherTangle2 = new Tangle<int>(Scheduler, new SubStreamSource(Storage, "3_", false))) {
                Scheduler.WaitFor(Tangle.Set(1, 1));
                Scheduler.WaitFor(otherTangle1.Set(2, 3));
                Scheduler.WaitFor(otherTangle2.Set(2, 5));
                Scheduler.WaitFor(otherTangle2.Set(3, 4));

                var result = Scheduler.WaitFor(Tangle.CascadingSelect(
                    new [] { otherTangle1, otherTangle2 },
                    new [] { 1, 2, 3, 4 }
                ));

                Assert.AreEqual(new [] { 1, 3, 4, default(int) }, result);
            }
        }
Beispiel #19
0
        public void TestSimpleJoin()
        {
            for (int i = 0; i < 8; i++)
                Scheduler.WaitFor(Tangle.Set(i, i * 2));

            using (var otherTangle = new Tangle<int>(Scheduler, new SubStreamSource(Storage, "2_", false))) {
                var keys = new List<string>();
                for (int i = 0; i < 8; i++) {
                    var key = new String((char)('a' + i), 1);
                    keys.Add(key);
                    Scheduler.WaitFor(otherTangle.Set(key, i));
                }

                var joinResult = Scheduler.WaitFor(
                    otherTangle.Join(
                        Tangle, keys,
                        (leftValue) => leftValue
                    )
                );

                for (int i = 0; i < 8; i++) {
                    var item = joinResult[i];
                    Assert.AreEqual(i, item.Key);
                    Assert.AreEqual(i * 2, item.Value);
                }
            }
        }
Beispiel #20
0
 public override void SetUp()
 {
     base.SetUp();
     Tangle     = new Tangle <object>(Scheduler, Storage);
     Serializer = new TanglePropertySerializer(Tangle);
 }
Beispiel #21
0
 protected IEnumerator<object> CheckLotsOfValues(Tangle<int> tangle, int numIterations)
 {
     for (int i = 0; i < numIterations; i++) {
         var f = tangle.Get(i);
         yield return f;
         Assert.AreEqual(i, f.Result);
     }
 }
Beispiel #22
0
 protected IEnumerator<object> WriteLotsOfValues(Tangle<int> tangle, int numIterations, int direction)
 {
     if (direction > 0)
         for (int i = 0; i < numIterations; i++) {
             yield return tangle.Set(i, i);
         }
     else
         for (int i = numIterations - 1; i >= 0; i--) {
             yield return tangle.Set(i, i);
         }
 }
Beispiel #23
0
        protected IEnumerator<object> WriteLotsOfValuesInBatch(Tangle<int> tangle, int numIterations, int direction)
        {
            int batchSize = 256;
            Batch<int> batch = null;

            if (direction > 0)
                for (int i = 0; i < numIterations; i++) {
                    if (batch == null)
                        batch = Tangle.CreateBatch(batchSize);

                    batch.Add(i, i);

                    if (batch.Count == batchSize) {
                        yield return batch.Execute();
                        batch = null;
                    }
                }
            else
                for (int i = numIterations - 1; i >= 0; i--) {
                    if (batch == null)
                        batch = Tangle.CreateBatch(batchSize);

                    batch.Add(i, i);

                    if (batch.Count == batchSize) {
                        yield return batch.Execute();
                        batch = null;
                    }
                }

            if (batch != null)
                yield return batch.Execute();
        }
Beispiel #24
0
        public override void SetUp()
        {
            base.SetUp();

            Tangle = new Tangle<int>(
                Scheduler, Storage,
                serializer: BlittableSerializer<int>.Serialize,
                deserializer: BlittableSerializer<int>.Deserialize,
                ownsStorage: true
            );
        }