예제 #1
0
        public void DisjointUnionPunctuations()
        {
            var left  = new Subject <StreamEvent <int> >();
            var right = new Subject <StreamEvent <int> >();

            var qc         = new QueryContainer();
            var leftInput  = qc.RegisterInput(left);
            var rightInput = qc.RegisterInput(right);

            var actualOutput = new List <StreamEvent <int> >();
            var union        = new MultiUnionStreamable <Empty, int>(new IStreamable <Empty, int>[] { leftInput, rightInput }, guaranteedDisjoint: true);
            var egress       = qc.RegisterOutput(union).ForEachAsync(o => actualOutput.Add(o));
            var process      = qc.Restore();

            left.OnNext(StreamEvent.CreatePoint(100, 1));
            left.OnNext(StreamEvent.CreatePunctuation <int>(101));

            right.OnNext(StreamEvent.CreatePoint(100, 1));
            right.OnNext(StreamEvent.CreatePunctuation <int>(110));

            process.Flush();

            left.OnNext(StreamEvent.CreatePoint(101, 1));
            right.OnNext(StreamEvent.CreatePoint(110, 1));

            process.Flush();

            left.OnCompleted();
            right.OnCompleted();

            var expected = new StreamEvent <int>[]
            {
                StreamEvent.CreatePoint(100, 1),
                StreamEvent.CreatePoint(100, 1),
                StreamEvent.CreatePunctuation <int>(101),
                StreamEvent.CreatePoint(101, 1),
                StreamEvent.CreatePoint(110, 1),
                StreamEvent.CreatePunctuation <int>(110),
                StreamEvent.CreatePunctuation <int>(StreamEvent.InfinitySyncTime),
            };

            Assert.IsTrue(expected.SequenceEqual(actualOutput));
        }
예제 #2
0
        private static void JoinPointsTest(bool fixedInterval = false)
        {
            var left  = new Subject <StreamEvent <string> >();
            var right = new Subject <StreamEvent <string> >();


            var qc = new QueryContainer();
            IStreamable <Empty, string> leftInput  = qc.RegisterInput(left);
            IStreamable <Empty, string> rightInput = qc.RegisterInput(right);

            if (fixedInterval)
            {
                leftInput  = leftInput.AlterEventDuration(1);
                rightInput = rightInput.AlterEventDuration(1);
            }

            var query = leftInput.Join(
                rightInput,
                l => (l != null ? l[0].ToString() : null),
                r => (r != null ? r[0].ToString() : null),
                (l, r) => $"{l},{r}");

            var output = new List <StreamEvent <string> >();

            qc.RegisterOutput(query).ForEachAsync(o => output.Add(o));
            var process = qc.Restore();

            // Should match and egress immediately
            left.OnNext(StreamEvent.CreatePoint(100, "A1"));
            right.OnNext(StreamEvent.CreatePoint(100, "A2"));
            process.Flush();

            var expected = new StreamEvent <string>[]
            {
                StreamEvent.CreatePoint(100, "A1,A2"),
            };

            Assert.IsTrue(expected.SequenceEqual(output));
            output.Clear();

            left.OnCompleted();
            right.OnCompleted();
        }