@@ -25,34 +25,52 @@ namespace Confluent.Kafka.UnitTests
2525{
2626 public class ConsumerTests
2727 {
28- /// <summary>
29- /// Test that the Consumer constructor throws an exception if
30- /// the group.id configuration parameter is not set and that
31- /// the message of the exception mentions group.id (i.e. is
32- /// not some unrelated exception).
33- /// </summary>
3428 [ Fact ]
3529 public void Constuctor ( )
3630 {
31+ // Throw exception if 'group.id' is not set in config and ensure that exception
32+ // mentions 'group.id'.
3733 var config = new Dictionary < string , object > ( ) ;
3834 var e = Assert . Throws < ArgumentException > ( ( ) => { var c = new Consumer ( config ) ; } ) ;
3935 Assert . True ( e . Message . Contains ( "group.id" ) ) ;
4036 e = Assert . Throws < ArgumentException > ( ( ) => { var c = new Consumer < Null , string > ( config , null , new StringDeserializer ( Encoding . UTF8 ) ) ; } ) ;
4137 Assert . True ( e . Message . Contains ( "group.id" ) ) ;
4238
39+ // Throw exception if a config value is null and ensure that exception mentions the
40+ // respective config key.
41+ var configWithNullValue = CreateValidConfiguration ( ) ;
42+ configWithNullValue [ "sasl.password" ] = null ;
43+ e = Assert . Throws < ArgumentException > ( ( ) => { var c = new Consumer < byte [ ] , byte [ ] > ( configWithNullValue , new ByteArrayDeserializer ( ) , new ByteArrayDeserializer ( ) ) ; } ) ;
44+ Assert . Contains ( "sasl.password" , e . Message ) ;
45+
46+ // Throw exception if a config value within default.topic.config is null and
47+ // ensure that exception mentions the respective config key.
48+ var configWithDefaultTopicNullValue = CreateValidConfiguration ( ) ;
49+ configWithDefaultTopicNullValue [ "default.topic.config" ] = new Dictionary < string , object > ( ) { { "auto.offset.reset" , null } } ;
50+ e = Assert . Throws < ArgumentException > ( ( ) => { var c = new Consumer < byte [ ] , byte [ ] > ( configWithDefaultTopicNullValue , new ByteArrayDeserializer ( ) , new ByteArrayDeserializer ( ) ) ; } ) ;
51+ Assert . Contains ( "default.topic.config" , e . Message ) ;
52+ Assert . Contains ( "auto.offset.reset" , e . Message ) ;
53+
54+ // Throw exception when serializer and deserializer are equal and ensure that exception
55+ // message indicates the issue.
4356 e = Assert . Throws < ArgumentException > ( ( ) =>
4457 {
45- var validConfig = new Dictionary < string , object >
46- {
47- { "bootstrap.servers" , "localhost:9092" } ,
48- { "group.id" , "my-group" }
49- } ;
58+ var validConfig = CreateValidConfiguration ( ) ;
5059 var deserializer = new StringDeserializer ( Encoding . UTF8 ) ;
5160 var c = new Consumer < string , string > ( validConfig , deserializer , deserializer ) ;
5261 } ) ;
5362 Assert . True ( e . Message . Contains ( "must not be the same object" ) ) ;
5463
5564 // positve case covered by integration tests. here, avoiding creating a rd_kafka_t instance.
5665 }
66+
67+ private static Dictionary < string , object > CreateValidConfiguration ( )
68+ {
69+ return new Dictionary < string , object >
70+ {
71+ { "bootstrap.servers" , "localhost:9092" } ,
72+ { "group.id" , "my-group" }
73+ } ;
74+ }
5775 }
5876}
0 commit comments