Ejemplo n.º 1
0
        private void UpdateGroupServerCache(GroupCoordinatorRequest request, GroupCoordinatorResponse response)
        {
            if (request == null || response == null)
            {
                return;
            }

            _groupServerCache = _groupServerCache.SetItem(request.group_id, new Tuple <int, DateTimeOffset>(response.Id, DateTimeOffset.UtcNow));
            Log.Verbose(() => LogEvent.Create($"Router set serverId to {response.Id} for group {request.group_id}"));
        }
Ejemplo n.º 2
0
        public void GroupCoordinatorResponse(
            [Values(
                 ErrorResponseCode.None,
                 ErrorResponseCode.GroupCoordinatorNotAvailable,
                 ErrorResponseCode.GroupAuthorizationFailed
                 )] ErrorResponseCode errorCode,
            [Values(0, 1)] int coordinatorId
            )
        {
            var response = new GroupCoordinatorResponse(errorCode, coordinatorId, "broker-" + coordinatorId, 9092 + coordinatorId);

            response.AssertCanEncodeDecodeResponse(0);
        }
Ejemplo n.º 3
0
        public void GroupCoordinatorResponse(
            [Values(
                 ErrorCode.NONE,
                 ErrorCode.GROUP_COORDINATOR_NOT_AVAILABLE,
                 ErrorCode.GROUP_AUTHORIZATION_FAILED
                 )] ErrorCode errorCode,
            [Values(0, 1)] int coordinatorId
            )
        {
            var response = new GroupCoordinatorResponse(errorCode, coordinatorId, "broker-" + coordinatorId, 9092 + coordinatorId);

            response.AssertCanEncodeDecodeResponse(0);
        }
Ejemplo n.º 4
0
        public void GroupCoordinatorResponse()
        {
            var response1 = new GroupCoordinatorResponse {
                //CorrelationId = _random.Next(),
                CoordinatorHost = Guid.NewGuid().ToString(),
                CoordinatorPort = _random.Next(),
            };

            Stream binary1 = new MemoryStream();

            response1.Serialize(binary1);

            binary1.Seek(0L, SeekOrigin.Begin);
            var response2 = new GroupCoordinatorResponse();

            response2.Deserialize(binary1);

            var compareLogic = new CompareLogic();
            var result       = compareLogic.Compare(response1, response2);

            Assert.True(result.AreEqual);

            Stream binary2 = new MemoryStream();

            response2.Serialize(binary2);
            Assert.Equal(binary1.Length, binary2.Length);

            using (var stream1 = new MemoryStream())
                using (var stream2 = new MemoryStream()) {
                    binary1.Seek(0L, SeekOrigin.Begin);
                    binary1.CopyTo(stream1);

                    binary2.Seek(0L, SeekOrigin.Begin);
                    binary2.CopyTo(stream2);

                    Assert.Equal(stream1.Length, stream2.Length);
                    stream1.Seek(0L, SeekOrigin.Begin);
                    var bytes1 = stream1.ToArray();

                    stream2.Seek(0L, SeekOrigin.Begin);
                    var bytes2 = stream2.ToArray();
                    Assert.Equal(bytes1.Length, bytes2.Length);

                    for (int i = 0; i < bytes1.Length; i++)
                    {
                        Assert.Equal(bytes1[i], bytes2[i]);
                    }
                }
        }
Ejemplo n.º 5
0
        private static bool TryEncodeResponse(IKafkaWriter writer, IRequestContext context, GroupCoordinatorResponse response)
        {
            if (response == null)
            {
                return(false);
            }

            writer.Write(response.error_code)
            .Write(response.Id)
            .Write(response.Host)
            .Write(response.Port);
            return(true);
        }