public void Run()
        {
            //// Arrange

            var stream1 = new MarketDataStream();
            var stream2 = new MarketDataStream();

            var aggregator = new ThrottledMarketDataStream();

            stream1.AddWatcher(aggregator);
            stream2.AddWatcher(aggregator);

            var logClient = new LogClientStrategy();
            var client    = new Client(logClient);

            aggregator.AddWatcher(client);

            // Act
            aggregator.Start();

            stream1.Start();
            stream2.Start();

            Thread.Sleep(3000);

            // Assert
            var result = logClient.Print();

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result));
        }
        public void Run()
        {
            //// Arrange

            var stream1 = new MarketDataStream();
            var stream2 = new MarketDataStream();

            var aggregator = new ThrottledMarketDataStream();

            stream1.AddWatcher(aggregator);
            stream2.AddWatcher(aggregator);

            var client = new Client();

            aggregator.AddWatcher(client);

            // Act
            aggregator.Start();
            stream1.Start();
            stream2.Start();

            Thread.Sleep(3000);

            // Assert
        }
Beispiel #3
0
        public void Run()
        {
            //// Arrange

            var aggregator = new ThrottledMarketDataStream();
            var streams    = new List <MarketDataStream>();
            var client     = new Client();

            for (var i = 0; i < 1000; i++)
            {
                var stream = new MarketDataStream();
                stream.AddWatcher(aggregator);
                streams.Add(stream);
            }

            aggregator.AddWatcher(client);

            //// Act
            aggregator.Start();

            foreach (var stream in streams)
            {
                stream.Start();
            }

            Thread.Sleep(10000);

            foreach (var stream in streams)
            {
                stream.End();
            }

            aggregator.End();

            //// Assert
        }
Beispiel #4
0
        public void Run()
        {
            // Arrange
            var expectedInput1 = new List <MarketDataUpdate>
            {
                new MarketDataUpdate
                {
                    InstrumentId = "AAPL_1", Fields = new Dictionary <byte, long> {
                        { 1, 10 }, { 4, 200 }, { 12, 187 }
                    }
                },
                new MarketDataUpdate
                {
                    InstrumentId = "AAPL_2", Fields = new Dictionary <byte, long> {
                        { 1, 12 }, { 4, 210 }
                    }
                },
                new MarketDataUpdate
                {
                    InstrumentId = "AAPL_1", Fields = new Dictionary <byte, long> {
                        { 12, 189 }
                    }
                },
                new MarketDataUpdate
                {
                    InstrumentId = "AAPL_1", Fields = new Dictionary <byte, long> {
                        { 2, 24 }
                    }
                },
                new MarketDataUpdate
                {
                    InstrumentId = "AAPL_2", Fields = new Dictionary <byte, long> {
                        { 5, 120 }
                    }
                }
            };

            string expected1 = "[1: 10, 4: 200, 12: 189, 2: 24]";
            string expected2 = "[1: 12, 4: 210, 5: 120]";

            var stream1 = new MarketDataStream(new ListDataStreamStrategy(expectedInput1));

            var aggregator = new ThrottledMarketDataStream(300);

            stream1.AddWatcher(aggregator);

            var logClient = new LogClientStrategy();
            var client    = new Client(logClient);

            aggregator.AddWatcher(client);

            // Act
            aggregator.Start();

            stream1.Start();

            Thread.Sleep(2000);

            // Assert
            var result = logClient.Print();

            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result));

            Assert.IsTrue(result.Contains(expected1), $"Wrong result \n\tExpected to contain: \t{expected1}\n\tActual: \t{result}\n");

            Assert.IsTrue(result.Contains(expected2), $"Wrong result \n\tExpected to contain: \t{expected2}\n\tActual: \t{result}\n");
        }