Beispiel #1
0
        public void CustomComparerIsUsedWhenEvaluatingInvalidation(int value)
        {
            var comparer = new SettableEqualityComparer <int>(false);
            var sut      = new AssignablePipelineStage <int>("", value, comparer);
            var test     = sut.AttachTestStage();

            sut.SetValue(value);
            test.AssertInvalidations(1);
            test.AssertStageInvalidated(sut);

            comparer.Equal = true;
            test.PrepareForNext();
            sut.SetValue(value + 1);
            test.AssertInvalidations(1);
            test.AssertStageNotInvalidated(sut);
        }
        public void PassiveStageIsNeverInvalidated()
        {
            var assignable = new AssignablePipelineStage <int>("", 10);
            var passive    = new PassivePipelineStage <int>(assignable);
            var test       = passive.AttachTestStage();

            assignable.SetValue(11);
            test.AssertInvalidations(0);
        }
        public void EachNewInvalidationPicksUpNewInformation()
        {
            var a    = new AssignablePipelineStage <int>("", 1);
            var sut  = new PipelinePropagationInformationStage <int>("", inv => a.GetValue(), a.GetValue(), a);
            var test = sut.AttachTestStage();

            PipelineAssert.Value(sut, 1);

            a.SetValue(2);
            test.AssertInvalidations(1);
            PipelineAssert.Value(sut, 2);
            PipelineAssert.Value(sut, 2);

            a.SetValue(5);
            test.AssertInvalidations(2);
            PipelineAssert.Value(sut, 5);
            PipelineAssert.Value(sut, 5);
        }
Beispiel #4
0
        public void ExtractorIsUsedToCalculateNewDelta(int old, int @new, int expected)
        {
            var input = new AssignablePipelineStage <int>("", old);
            var sut   = new DeltaPipelineStage <int, int>("", Extractor, input, expected - 1);
            var test  = sut.AttachTestStage();

            PipelineAssert.Value(sut, expected - 1);

            input.SetValue(@new);
            test.AssertInvalidations(1);
            PipelineAssert.Value(sut, expected);
        }
Beispiel #5
0
        public void ConcurrentUpdateOfTwoSeparateGraphsAreNotLabeledAsConcurrent()
        {
            using var goAhead = new ManualResetEvent(false);
            var v1 = new AssignablePipelineStage <int>("", 1);
            var v2 = new AssignablePipelineStage <int>("", 3);

            var g1 = PipelineReactions.Create(_ => Wait(goAhead, 1000), v1);
            var g2 = PipelineReactions.Create(_ => Wait(goAhead, 1000), v2);

            Task.Run(() => v1.SetValue(1001));
            goAhead.WaitOne();
            Assert.DoesNotThrow(() => v2.SetValue(1001));
        }
Beispiel #6
0
        public void PotentialConcurrentUpdateOfStageIsCorrectlyDiscovered()
        {
            using var goAhead = new ManualResetEvent(false);

            var value1 = new AssignablePipelineStage <int>("", 1000);
            var value2 = new AssignablePipelineStage <int>("", 2000);

            var concurrent = PipelineOperations.Create("Concurrent Stage", (a, b) => Wait(goAhead, 1000), value1, value2).AsEager();

            Task.Run(() => value1.SetValue(1001));
            goAhead.WaitOne();
            var message = Assert.Throws <PipelineException>(() => value2.SetValue(1001));
        }
Beispiel #7
0
        public static void Test()
        {
            var one = 1.AsPipelineConstant();
            var two = 2.AsPipelineConstant();

            var value               = new AssignablePipelineStage <int>("integer", 0);
            var suspension          = new AssignablePipelineStage <PipelineSuspensionState>("suspender", PipelineSuspensionState.Resume);
            var changeableOperation = new AssignablePipelineStage <Func <int, int> >("suspender", a => a);

            var multiply   = PipelineOperations.Create("multiply", Multiply, value, two);
            var changeable = PipelineOperations.Create("changeable", changeableOperation, multiply);
            var cache      = changeable.WithCache();
            var suspender  = cache.WithConditionalSuspender(suspension);

            var reaction = PipelineReactions.Create(Reaction, suspender);

            value.SetValue(1);
            value.SetValue(2);
            changeableOperation.SetValue(a => a * 2);

            GC.KeepAlive(reaction);
            Console.ReadLine();
        }