Exemplo n.º 1
0
        public void TestAccumulatorByTopicByPartitionTimeElapsed()
        {
            using (
                var accumulator = new AccumulatorByTopicByPartition <Tuple <string, int, int> >(t => t.Item1, t => t.Item2,
                                                                                                5,
                                                                                                TimeSpan.FromMilliseconds(150)))
            {
                var latch = new ManualResetEventSlim();
                IBatchByTopicByPartition <Tuple <string, int, int> > batch = null;
                accumulator.NewBatch += b =>
                {
                    batch = b;
                    latch.Set();
                };
                Assert.IsTrue(accumulator.Add(Tuple.Create("a", 1, 1)));
                Assert.IsTrue(accumulator.Add(Tuple.Create("b", 1, 2)));
                Assert.IsTrue(accumulator.Add(Tuple.Create("c", 1, 3)));

                latch.Wait();

                Assert.That(batch.Count, Is.EqualTo(3));
                Assert.That(batch.Count(g => g.Key == "a"), Is.EqualTo(1));
                Assert.That(batch.Count(g => g.Key == "b"), Is.EqualTo(1));
                Assert.That(batch.Count(g => g.Key == "c"), Is.EqualTo(1));
                CollectionAssert.AreEquivalent(new[] { 1 },
                                               batch.First(g => g.Key == "a").SelectMany(g => g).Select(t => t.Item3));
                CollectionAssert.AreEquivalent(new[] { 2 },
                                               batch.First(g => g.Key == "b").SelectMany(g => g).Select(t => t.Item3));
                CollectionAssert.AreEquivalent(new[] { 3 },
                                               batch.First(g => g.Key == "c").SelectMany(g => g).Select(t => t.Item3));
                batch.Dispose();
            }
        }
Exemplo n.º 2
0
        public void TestAccumulatorByTopicByPartitionCountReached()
        {
            using (
                var accumulator = new AccumulatorByTopicByPartition <Tuple <string, int, int> >(t => t.Item1, t => t.Item2,
                                                                                                5,
                                                                                                TimeSpan.FromMilliseconds(1000000)))
            {
                IBatchByTopicByPartition <Tuple <string, int, int> > batch = null;
                accumulator.NewBatch += b => batch = b;
                accumulator.Add(Tuple.Create("a", 1, 1));
                accumulator.Add(Tuple.Create("a", 1, 2));
                accumulator.Add(Tuple.Create("b", 1, 8));
                accumulator.Add(Tuple.Create("a", 2, 3));
                accumulator.Add(Tuple.Create("c", 1, 1));
                accumulator.Add(Tuple.Create("a", 1, 1));

                Assert.That(batch.Count, Is.EqualTo(5));
                Assert.That(batch.Count(g => g.Key == "a"), Is.EqualTo(1));
                Assert.That(batch.Count(g => g.Key == "b"), Is.EqualTo(1));
                Assert.That(batch.Count(g => g.Key == "c"), Is.EqualTo(1));
                CollectionAssert.AreEquivalent(new[] { 1, 2 },
                                               batch.First(g => g.Key == "a").Where(g => g.Key == 1).SelectMany(g => g).Select(t => t.Item3));
                CollectionAssert.AreEquivalent(new[] { 1, 2, 3 },
                                               batch.First(g => g.Key == "a").SelectMany(g => g).Select(t => t.Item3));
                CollectionAssert.AreEquivalent(new[] { 8 },
                                               batch.First(g => g.Key == "b").SelectMany(g => g.Select(t => t.Item3)));
                CollectionAssert.AreEquivalent(new[] { 1 },
                                               batch.First(g => g.Key == "c").SelectMany(g => g.Select(t => t.Item3)));

                accumulator.Add(Tuple.Create("a", 1, 1));
                accumulator.Add(Tuple.Create("a", 1, 1));
                accumulator.Add(Tuple.Create("a", 2, 1));
                accumulator.Add(Tuple.Create("a", 2, 1));
                Assert.That(batch.Count, Is.EqualTo(5));
                Assert.That(batch.Count(g => g.Key == "a"), Is.EqualTo(1));
                Assert.That(batch.Count(), Is.EqualTo(1));
                Assert.That(batch.First().Count(), Is.EqualTo(2));
                Assert.That(batch.First().Where(g => g.Key == 1).SelectMany(g => g).Count(t => t.Item3 == 1),
                            Is.EqualTo(3));
                Assert.That(batch.First().Where(g => g.Key == 2).SelectMany(g => g).Count(t => t.Item3 == 1),
                            Is.EqualTo(2));
                Assert.That(batch.First().SelectMany(g => g).Count(t => t.Item3 == 1), Is.EqualTo(5));
                batch.Dispose();
            }
        }
Exemplo n.º 3
0
 public bool Post(IBatchByTopicByPartition <ProduceMessage> batch)
 {
     throw new NotImplementedException();
 }