Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: ListGroup throws exception if group doesn't exist #43

Merged
merged 1 commit into from
Feb 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Confluent.Kafka/IDeliveryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
//
// Refer to LICENSE for more information.

using System;


namespace Confluent.Kafka
{
Expand Down
2 changes: 1 addition & 1 deletion src/Confluent.Kafka/Impl/SafeKafkaHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ static byte[] CopyBytes(IntPtr ptr, IntPtr len)
}

internal GroupInfo ListGroup(string group, int millisecondsTimeout)
=> ListGroupsImpl(group, millisecondsTimeout).Single();
=> ListGroupsImpl(group, millisecondsTimeout).FirstOrDefault();

internal List<GroupInfo> ListGroups(int millisecondsTimeout)
=> ListGroupsImpl(null, millisecondsTimeout);
Expand Down
2 changes: 1 addition & 1 deletion src/Confluent.Kafka/Structs/GroupInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace Confluent.Kafka
{
public struct GroupInfo
public class GroupInfo
{
public GroupInfo(BrokerMetadata broker, string grp, Error error, string state, string protocolType, string protocol, List<GroupMemberInfo> members)
{
Expand Down
80 changes: 80 additions & 0 deletions test/Confluent.Kafka.IntegrationTests/Tests/ListGroup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2016-2017 Confluent Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Refer to LICENSE for more information.

using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Confluent.Kafka.Serialization;
using Xunit;


namespace Confluent.Kafka.IntegrationTests
{
public static partial class Tests
{
/// <summary>
/// Test getting group information for existant and non-existant
/// group using the ListGroup method (on a Consumer).
/// </summary>
[Theory, MemberData(nameof(KafkaParameters))]
public static void ListGroup(string bootstrapServers, string topic)
{
int N = 2;
var firstProduced = Util.ProduceMessages(bootstrapServers, topic, 100, N);

var consumerConfig = new Dictionary<string, object>
{
{ "group.id", "list-group-cg" },
{ "bootstrap.servers", bootstrapServers },
{ "session.timeout.ms", 6000 }
};

using (var consumer = new Consumer<Null, string>(consumerConfig, null, new StringDeserializer(Encoding.UTF8)))
{
bool done = false;

consumer.OnMessage += (_, msg)
=> done = true;

consumer.OnPartitionsAssigned += (_, partitions) =>
{
Assert.Equal(partitions.Count, 1);
Assert.Equal(partitions[0], firstProduced.TopicPartition);
consumer.Assign(partitions.Select(p => new TopicPartitionOffset(p, firstProduced.Offset)));
};

consumer.Subscribe(topic);

while (!done)
{
consumer.Poll(TimeSpan.FromMilliseconds(100));
}

var g = consumer.ListGroup("list-group-cg");
Assert.NotNull(g);
Assert.Equal(ErrorCode.NO_ERROR, g.Error.Code);
Assert.Equal("list-group-cg", g.Group);
Assert.Equal("consumer", g.ProtocolType);
Assert.Equal(1, g.Members.Count);

g = consumer.ListGroup("non-existent-cg");
Assert.Null(g);
}
}

}
}