예제 #1
0
        public void ShuffleStreamable1ColumnarSmallBatch()
        {
            var savedScheduler = Config.StreamScheduler;

            Config.StreamScheduler = StreamScheduler.OwnedThreads(2);
            var gameInput = new[]
            {
                StreamEvent.CreateStart(9900, new GameData {
                    EventType = 0, GameId = 10, UserId = 100
                }),                                                                                       // start game
                StreamEvent.CreateStart(10000, new GameData {
                    EventType = 1, GameId = 10, UserId = 100, NumKills = 1
                }),
                StreamEvent.CreateStart(10020, new GameData {
                    EventType = 1, GameId = 10, UserId = 100, NumKills = 1
                }),
                StreamEvent.CreateStart(10025, new GameData {
                    EventType = 1, GameId = 10, UserId = 100, NumKills = 30
                }),
                StreamEvent.CreateStart(10030, new GameData {
                    EventType = 1, GameId = 10, UserId = 100
                }),                                                                                        // end game
                StreamEvent.CreateStart(10040, new GameData {
                    EventType = 2, GameId = 10
                })
            }.ToObservable().ToStreamable();

            // clip each game event to end at the time of game completion
            var clippedGameInput =
                gameInput.Where(e => e.EventType < 2).ClipEventDuration(gameInput.Where(e => e.EventType == 2), e => e.GameId, e => e.GameId);

            var result =
                clippedGameInput
                .GroupApply(
                    e => new { e.GameId, e.UserId },
                    str => StreamableInternal.ComputeSignalChangeStream(str.Sum(e => e.NumKills)),
                    (g, c) => new { g.Key.GameId, g.Key.UserId, FromKills = c.Item1, ToKills = c.Item2 }) // count #kills per {game,user} combination
            ;

            var finalResultSequence = result
                                      .ToStreamEventObservable()
                                      .ToEnumerable()
                                      .ToList();
            var finalResult = finalResultSequence.First();

            Assert.IsTrue(finalResultSequence.Count() == 1 &&
                          finalResult.IsPunctuation && finalResult.SyncTime == StreamEvent.InfinitySyncTime);

            Config.StreamScheduler.Stop();
            Config.StreamScheduler = savedScheduler;
        }