Example #1
0
        public void FetchResponse(
            [Values(0, 1, 2, 3)] short version,
            [Values(0, 1234)] int throttleTime,
            [Values("test", "a really long name, with spaces and punctuation!")] string topicName,
            [Values(1, 10)] int topicsPerRequest,
            [Values(1, 5)] int totalPartitions,
            [Values(
                 ErrorResponseCode.None,
                 ErrorResponseCode.OffsetOutOfRange
                 )] ErrorResponseCode errorCode,
            [Values(3)] int messagesPerSet
            )
        {
            var topics = new List <FetchResponse.Topic>();

            for (var t = 0; t < topicsPerRequest; t++)
            {
                var partitionId = t % totalPartitions;
                var messages    = GenerateMessages(messagesPerSet, (byte)(version >= 2 ? 1 : 0), partitionId);
                topics.Add(new FetchResponse.Topic(topicName + t, partitionId, _randomizer.Next(), errorCode, messages));
            }
            var response = new FetchResponse(topics, version >= 1 ? TimeSpan.FromMilliseconds(throttleTime) : (TimeSpan?)null);

            response.AssertCanEncodeDecodeResponse(version);
        }
        public void FetchResponse(
            [Values(0, 1, 2, 3)] short version,
            [Values(0, 1234)] int throttleTime,
            [Values("testTopic")] string topicName,
            [Values(1, 10)] int topicsPerRequest,
            [Values(1, 5)] int totalPartitions,
            [Values(MessageCodec.None, MessageCodec.Gzip, MessageCodec.Snappy)] MessageCodec codec,
            [Values(
                 ErrorCode.NONE,
                 ErrorCode.OFFSET_OUT_OF_RANGE
                 )] ErrorCode errorCode,
            [Values(3)] int messagesPerSet
            )
        {
#if !DOTNETSTANDARD
            if (codec == MessageCodec.Snappy)
            {
                Assert.Inconclusive($"{codec} is only available in .net core");
            }
#endif
            var topics = new List <FetchResponse.Topic>();
            for (var t = 0; t < topicsPerRequest; t++)
            {
                var partitionId = t % totalPartitions;
                var messages    = GenerateMessages(messagesPerSet, (byte)(version >= 2 ? 1 : 0), codec);
                topics.Add(new FetchResponse.Topic(topicName + t, partitionId, _randomizer.Next(), errorCode, messages));
            }
            var response = new FetchResponse(topics, version >= 1 ? TimeSpan.FromMilliseconds(throttleTime) : (TimeSpan?)null);
            var responseWithUpdatedAttribute = new FetchResponse(response.responses.Select(t => new FetchResponse.Topic(t.topic, t.partition_id, t.high_watermark, t.error_code,
                                                                                                                        t.Messages.Select(m => m.Attribute == 0 ? m : new Message(m.Value, m.Key, 0, m.Offset, m.MessageVersion, m.Timestamp)))),
                                                                 response.throttle_time_ms);

            response.AssertCanEncodeDecodeResponse(version, forComparison: responseWithUpdatedAttribute);
        }