Exemplo n.º 1
0
        public void TestAccumulatorByNodeByTopic(int batchSize, int time)
        {
            INode n1          = new NodeMock("n1");
            INode n2          = new NodeMock("n2");
            var   accumulator = new AccumulatorByNodeByTopic <Tuple <string, int> >(t => t.Item1, batchSize, TimeSpan.FromMilliseconds(time));

            var count = new CountdownEvent(2);
            var d     = new Dictionary <INode, IBatchByTopic <Tuple <string, int> > >();

            accumulator.NewBatch += (n, b) =>
            {
                d[n] = b;
                count.Signal();
            };

            accumulator.Add(Tuple.Create(n1, Tuple.Create("1", 1)));
            accumulator.Add(Tuple.Create(n1, Tuple.Create("1", 2)));
            accumulator.Add(Tuple.Create(n2, Tuple.Create("2", 1)));
            accumulator.Add(Tuple.Create(n2, Tuple.Create("2", 2)));
            accumulator.Add(Tuple.Create(n2, Tuple.Create("2", 3)));

            count.Wait();

            Assert.AreEqual(2, d[n1].Count);
            Assert.AreEqual(3, d[n2].Count);
            d[n1].Dispose();
            d[n2].Dispose();
        }
Exemplo n.º 2
0
 public bool Send(INode node, OffsetMessage message)
 {
     return(_accumulator.Add(Tuple.Create(node, message)));
 }