/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { DescribeGroupsResponse response = new DescribeGroupsResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("Groups", targetDepth)) { var unmarshaller = new ListUnmarshaller <GroupMetadata, GroupMetadataUnmarshaller>(GroupMetadataUnmarshaller.Instance); response.Groups = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Marker", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Marker = unmarshaller.Unmarshall(context); continue; } } return(response); }
public void DescribeGroupsResponse( [Values( ErrorResponseCode.None, ErrorResponseCode.OffsetMetadataTooLarge )] ErrorResponseCode errorCode, [Values("test", "a groupId")] string groupId, [Range(2, 3)] int count, [Values(KafkaClient.Protocol.DescribeGroupsResponse.Group.States.Stable, KafkaClient.Protocol.DescribeGroupsResponse.Group.States.Dead)] string state, [Values("consumer", "unknown")] string protocolType, [Values("good", "bad", "ugly")] string protocol) { var groups = new DescribeGroupsResponse.Group[count]; for (var g = 0; g < count; g++) { var members = new List <DescribeGroupsResponse.Member>(); for (var m = 0; m < count; m++) { var metadata = new byte[count * 100]; var assignment = new byte[count * 10]; _randomizer.NextBytes(metadata); _randomizer.NextBytes(assignment); members.Add(new DescribeGroupsResponse.Member("member" + m, "client" + m, "host-" + m, new ByteMember(metadata), new ByteMember(assignment))); } groups[g] = new DescribeGroupsResponse.Group(errorCode, groupId + g, state, protocolType, protocol, members); } var response = new DescribeGroupsResponse(groups); response.AssertCanEncodeDecodeResponse(0); }
private void UpdateGroupCache(DescribeGroupsResponse metadata) { if (metadata == null) { return; } var groupCache = _groupCache; try { foreach (var group in metadata.groups) { groupCache = groupCache.SetItem(group.group_id, new Tuple <DescribeGroupsResponse.Group, DateTimeOffset>(group, DateTimeOffset.UtcNow)); } } finally { _groupCache = groupCache; } }
public void DescribeConsumerGroupsResponse( [Values( ErrorResponseCode.None, ErrorResponseCode.OffsetMetadataTooLarge )] ErrorResponseCode errorCode, [Values("test", "a groupId")] string groupId, [Range(2, 3)] int count, [Values(KafkaClient.Protocol.DescribeGroupsResponse.Group.States.Stable, KafkaClient.Protocol.DescribeGroupsResponse.Group.States.AwaitingSync)] string state, [Values("consumer")] string protocolType, [Values("good", "bad", "ugly")] string protocol) { var encoder = new ConsumerEncoder(); var groups = new DescribeGroupsResponse.Group[count]; for (var g = 0; g < count; g++) { var members = new List <DescribeGroupsResponse.Member>(); for (var m = 0; m < count; m++) { var memberId = "member" + m; var userData = new byte[count * 100]; _randomizer.NextBytes(userData); var metadata = new ConsumerProtocolMetadata(0, new [] { protocol, memberId, memberId }, userData); var topics = new List <TopicPartition>(); for (var t = 0; t < count; t++) { topics.Add(new TopicPartition("topic foo" + t, t)); } var assignment = new ConsumerMemberAssignment(0, topics); members.Add(new DescribeGroupsResponse.Member(memberId, "client" + m, "host-" + m, metadata, assignment)); } groups[g] = new DescribeGroupsResponse.Group(errorCode, groupId + g, state, protocolType, protocol, members); } var response = new DescribeGroupsResponse(groups); response.AssertCanEncodeDecodeResponse(0, encoder); }
public void DescribeGroupsResponse() { var response1 = new DescribeGroupsResponse { Details = new[] { new DescribeGroupsResponseDetail { GroupId = Guid.NewGuid().ToString(), State = Guid.NewGuid().ToString(), ProtocolType = Guid.NewGuid().ToString(), Protocol = Guid.NewGuid().ToString(), Members = new [] { new DescribeGroupsResponseMember { MemberId = Guid.NewGuid().ToString(), ClientId = Guid.NewGuid().ToString(), ClientHost = Guid.NewGuid().ToString(), MemberMetadata = new JoinGroupMemberMetadata(), MemberAssignment = new SyncGroupMemberAssignment(), } } } } }; Stream binary1 = new MemoryStream(); response1.Serialize(binary1); binary1.Seek(0L, SeekOrigin.Begin); var response2 = new DescribeGroupsResponse(); 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]); } } }
public static DescribeGroupsResponse Unmarshall(UnmarshallerContext context) { DescribeGroupsResponse describeGroupsResponse = new DescribeGroupsResponse(); describeGroupsResponse.HttpResponse = context.HttpResponse; describeGroupsResponse.RequestId = context.StringValue("DescribeGroups.RequestId"); describeGroupsResponse.PageSize = context.LongValue("DescribeGroups.PageSize"); describeGroupsResponse.PageNum = context.LongValue("DescribeGroups.PageNum"); describeGroupsResponse.PageCount = context.LongValue("DescribeGroups.PageCount"); describeGroupsResponse.TotalCount = context.LongValue("DescribeGroups.TotalCount"); List <DescribeGroupsResponse.DescribeGroups_Group> describeGroupsResponse_groups = new List <DescribeGroupsResponse.DescribeGroups_Group>(); for (int i = 0; i < context.Length("DescribeGroups.Groups.Length"); i++) { DescribeGroupsResponse.DescribeGroups_Group group = new DescribeGroupsResponse.DescribeGroups_Group(); group.Id = context.StringValue("DescribeGroups.Groups[" + i + "].Id"); group.AliasId = context.StringValue("DescribeGroups.Groups[" + i + "].AliasId"); group.Name = context.StringValue("DescribeGroups.Groups[" + i + "].Name"); group.Description = context.StringValue("DescribeGroups.Groups[" + i + "].Description"); group.App = context.StringValue("DescribeGroups.Groups[" + i + "].App"); group.Region = context.StringValue("DescribeGroups.Groups[" + i + "].Region"); group.InProtocol = context.StringValue("DescribeGroups.Groups[" + i + "].InProtocol"); group.OutProtocol = context.StringValue("DescribeGroups.Groups[" + i + "].OutProtocol"); group.Enabled = context.BooleanValue("DescribeGroups.Groups[" + i + "].Enabled"); group.Status = context.StringValue("DescribeGroups.Groups[" + i + "].Status"); group.CreatedTime = context.StringValue("DescribeGroups.Groups[" + i + "].CreatedTime"); group.PushDomain = context.StringValue("DescribeGroups.Groups[" + i + "].PushDomain"); group.PlayDomain = context.StringValue("DescribeGroups.Groups[" + i + "].PlayDomain"); group.LazyPull = context.BooleanValue("DescribeGroups.Groups[" + i + "].LazyPull"); group.Callback = context.StringValue("DescribeGroups.Groups[" + i + "].Callback"); group.CaptureInterval = context.IntegerValue("DescribeGroups.Groups[" + i + "].CaptureInterval"); group.CaptureImage = context.IntegerValue("DescribeGroups.Groups[" + i + "].CaptureImage"); group.CaptureVideo = context.IntegerValue("DescribeGroups.Groups[" + i + "].CaptureVideo"); group.CaptureOssBucket = context.StringValue("DescribeGroups.Groups[" + i + "].CaptureOssBucket"); group.CaptureOssPath = context.StringValue("DescribeGroups.Groups[" + i + "].CaptureOssPath"); group.GbId = context.StringValue("DescribeGroups.Groups[" + i + "].GbId"); group.GbIp = context.StringValue("DescribeGroups.Groups[" + i + "].GbIp"); group.GbPort = context.LongValue("DescribeGroups.Groups[" + i + "].GbPort"); List <string> group_gbUdpPorts = new List <string>(); for (int j = 0; j < context.Length("DescribeGroups.Groups[" + i + "].GbUdpPorts.Length"); j++) { group_gbUdpPorts.Add(context.StringValue("DescribeGroups.Groups[" + i + "].GbUdpPorts[" + j + "]")); } group.GbUdpPorts = group_gbUdpPorts; List <string> group_gbTcpPorts = new List <string>(); for (int j = 0; j < context.Length("DescribeGroups.Groups[" + i + "].GbTcpPorts.Length"); j++) { group_gbTcpPorts.Add(context.StringValue("DescribeGroups.Groups[" + i + "].GbTcpPorts[" + j + "]")); } group.GbTcpPorts = group_gbTcpPorts; DescribeGroupsResponse.DescribeGroups_Group.DescribeGroups_Stats stats = new DescribeGroupsResponse.DescribeGroups_Group.DescribeGroups_Stats(); stats.DeviceNum = context.LongValue("DescribeGroups.Groups[" + i + "].Stats.DeviceNum"); stats.IedNum = context.LongValue("DescribeGroups.Groups[" + i + "].Stats.IedNum"); stats.IpcNum = context.LongValue("DescribeGroups.Groups[" + i + "].Stats.IpcNum"); stats.PlatformNum = context.LongValue("DescribeGroups.Groups[" + i + "].Stats.PlatformNum"); group.Stats = stats; describeGroupsResponse_groups.Add(group); } describeGroupsResponse.Groups = describeGroupsResponse_groups; return(describeGroupsResponse); }
private static bool TryEncodeResponse(IKafkaWriter writer, IRequestContext context, DescribeGroupsResponse response) { if (response == null) { return(false); } writer.Write(response.groups.Count); foreach (var group in response.groups) { writer.Write(group.error_code) .Write(group.group_id) .Write(group.state) .Write(group.protocol_type) .Write(group.protocol); var encoder = context.GetEncoder(group.protocol_type); writer.Write(group.members.Count); foreach (var member in group.members) { writer.Write(member.member_id) .Write(member.client_id) .Write(member.client_host) .Write(member.member_metadata, encoder) .Write(member.member_assignment, encoder); } } return(true); }
private static bool TryEncodeResponse(IKafkaWriter writer, IRequestContext context, DescribeGroupsResponse response) { if (response == null) { return(false); } writer.Write(response.Groups.Count); foreach (var group in response.Groups) { writer.Write(group.ErrorCode) .Write(group.GroupId) .Write(group.State) .Write(group.ProtocolType) .Write(group.Protocol); var encoder = context.GetEncoder(group.ProtocolType); writer.Write(group.Members.Count); foreach (var member in group.Members) { writer.Write(member.MemberId) .Write(member.ClientId) .Write(member.ClientHost) .Write(member.MemberMetadata, encoder) .Write(member.MemberAssignment, encoder); } } return(true); }