예제 #1
0
        public void KeyHashShouldSelectEachPartitionType()
        {
            var selector = new PartitionSelector();

            var first  = selector.Select(_topicA, CreateKeyForPartition(0));
            var second = selector.Select(_topicA, CreateKeyForPartition(1));

            Assert.That(first.partition_id, Is.EqualTo(0));
            Assert.That(second.partition_id, Is.EqualTo(1));
        }
        public void RoundRobinShouldRollOver()
        {
            var selector = new PartitionSelector();

            var first  = selector.Select(_topicA, null);
            var second = selector.Select(_topicA, null);
            var third  = selector.Select(_topicA, null);

            Assert.That(first.PartitionId, Is.EqualTo(0));
            Assert.That(second.PartitionId, Is.EqualTo(1));
            Assert.That(third.PartitionId, Is.EqualTo(0));
        }
        public void RoundRobinShouldTrackEachTopicSeparately()
        {
            var selector = new PartitionSelector();

            var a1 = selector.Select(_topicA, null);
            var b1 = selector.Select(_topicB, null);
            var a2 = selector.Select(_topicA, null);
            var b2 = selector.Select(_topicB, null);

            Assert.That(a1.PartitionId, Is.EqualTo(0));
            Assert.That(a2.PartitionId, Is.EqualTo(1));

            Assert.That(b1.PartitionId, Is.EqualTo(0));
            Assert.That(b2.PartitionId, Is.EqualTo(1));
        }
예제 #4
0
        public void SelectorShouldThrowExceptionWhenPartitionsAreEmpty()
        {
            var selector = new PartitionSelector();
            var topic    = new MetadataResponse.Topic("emptyPartition");

            Assert.Throws <RoutingException>(() => selector.Select(topic, CreateKeyForPartition(1)));
        }
예제 #5
0
        public void PartitionSelectionOnEmptyKeyHashShouldNotFail()
        {
            var selector = new PartitionSelector();
            var topic    = new MetadataResponse.Topic("badPartition", partitions: new [] {
                new MetadataResponse.Partition(0, 0),
                new MetadataResponse.Partition(999, 1)
            });

            Assert.That(selector.Select(topic, new ArraySegment <byte>()), Is.Not.Null);
        }
예제 #6
0
        public void KeyHashShouldThrowExceptionWhenChoosesAPartitionIdThatDoesNotExist()
        {
            var selector = new PartitionSelector();
            var topic    = new MetadataResponse.Topic("badPartition", partitions: new [] {
                new MetadataResponse.Partition(0, 0),
                new MetadataResponse.Partition(999, 1)
            });

            Assert.Throws <RoutingException>(() => selector.Select(topic, CreateKeyForPartition(1)));
        }
        public void RoundRobinShouldHandleMultiThreadedRollOver()
        {
            var selector = new PartitionSelector();
            var bag      = new ConcurrentBag <MetadataResponse.Partition>();

            Parallel.For(0, 100, x => bag.Add(selector.Select(_topicA, null)));

            Assert.That(bag.Count(x => x.PartitionId == 0), Is.EqualTo(50));
            Assert.That(bag.Count(x => x.PartitionId == 1), Is.EqualTo(50));
        }
예제 #8
0
        public void Handle(Request request, Response response)
        {
            var pm = PartitionModule.Instance;
            PartitionSelector selector = new PartitionSelector(pm.MatcherRegistry, pm.PartitionRegistry);
            var matcherId = request.Params.Get("id").ParseGuid();

            response.Chunked = true;

            IPartition partition = selector.Select(matcherId);

            logger.Info("Sending {0} partition to {1} matcher.", partition, matcherId);
            using (var input = new FileStream(pm.ModelFileName, FileMode.Open, FileAccess.Read))
                using (var reader = XmlReader.Create(input))
                {
                    this.serializer.Serialize(partition, reader, response.Body);
                }
        }
        public void RoundRobinShouldEvenlyDistributeAcrossManyPartitions()
        {
            const int TotalPartitions = 100;
            var       selector        = new PartitionSelector();
            var       partitions      = new List <MetadataResponse.Partition>();

            for (int i = 0; i < TotalPartitions; i++)
            {
                partitions.Add(new MetadataResponse.Partition(i, i));
            }
            var topic = new MetadataResponse.Topic("a", partitions: partitions);

            var bag = new ConcurrentBag <MetadataResponse.Partition>();

            Parallel.For(0, TotalPartitions * 3, x => bag.Add(selector.Select(topic, null)));

            var eachPartitionHasThree = bag.GroupBy(x => x.PartitionId).Count();

            Assert.That(eachPartitionHasThree, Is.EqualTo(TotalPartitions), "Each partition should have received three selections.");
        }