Exemple #1
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (packetID_ != null)
            {
                hash ^= PacketID.GetHashCode();
            }
            if (header_ != null)
            {
                hash ^= Header.GetHashCode();
            }
            if (OrderID != 0UL)
            {
                hash ^= OrderID.GetHashCode();
            }
            if (ModifyOrderOp != 0)
            {
                hash ^= ModifyOrderOp.GetHashCode();
            }
            if (ForAll != false)
            {
                hash ^= ForAll.GetHashCode();
            }
            if (Qty != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Qty);
            }
            if (Price != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Price);
            }
            if (AdjustPrice != false)
            {
                hash ^= AdjustPrice.GetHashCode();
            }
            if (AdjustSideAndLimit != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(AdjustSideAndLimit);
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemple #2
0
        public void TestWorksInGeneral()
        {
            var list = new List<int>();
            var forAll = new ForAll<int>(Enumerable.Range(0, 10),
                i =>
                {
                    lock (list)
                    {
                        list.Add(i);
                    }
                });

            var completed = new ManualResetEvent(false);
            forAll.RegisterOnfinished(_ => completed.Set());

            forAll.Start();

            completed.WaitOne();

            Assert.AreEqual(10, list.Distinct().Count());
        }
Exemple #3
0
        public void TestCancel()
        {
            bool? cancelled = null;

            var lastEnumerated = -1;
            var lastProcessed = -1;

            var cancellation = new Cancellation();

            var endlessSource = Enumerable.Range(0, 10).Select(n =>
            {
                if (n > 3)
                    TestMonitorSimple.WaitAlittle();

                lastEnumerated = n;
                return n;
            });

            var doForAll = new ForAll<int>(endlessSource, n => Thread.VolatileWrite(ref lastProcessed, n),
                new ParallelSettings {Cancellation = cancellation});

            doForAll.RegisterOnfinished(f => cancelled = f.IsCancelled);

            doForAll.Start();
            TestMonitorSimple.WaitAlittle();
            cancellation.Cancel();
            TestMonitorSimple.WaitAlittle();

            AssertEx.Throws<OperationCanceledException>(() => doForAll.Wait());
            Assert.IsTrue(lastProcessed > -1, "Looks like processing had not even started");
            Assert.IsTrue(lastEnumerated > -1, "Looks like enumeration of source had not even started");
            Assert.IsTrue(cancelled != null && cancelled.Value);
            Assert.IsTrue(doForAll.IsCancelled);
            Assert.IsTrue(lastProcessed < 9);
            Assert.IsTrue(lastEnumerated < 9);
        }