@@ -63,14 +63,30 @@ public static void AutoRegisterSchemaDisabled(string bootstrapServers, string sc
6363 {
6464 Assert . Throws < SerializationException > ( ( ) =>
6565 {
66+ string guidTopic = new Guid ( ) . ToString ( ) ;
6667 try
6768 {
6869 producer
69- . ProduceAsync ( new Guid ( ) . ToString ( ) , new Message < string , int > { Key = "test" , Value = 112 } )
70- . Wait ( ) ;
70+ . ProduceAsync ( guidTopic , new Message < string , int > { Key = "test" , Value = 112 } )
71+ . GetAwaiter ( )
72+ . GetResult ( ) ;
7173 }
72- catch ( AggregateException e )
74+ catch ( Exception e )
7375 {
76+ Assert . True ( e is ProduceException < string , int > ) ;
77+ Assert . Equal ( ErrorCode . Local_ValueSerialization , ( ( ProduceException < string , int > ) e ) . Error . Code ) ;
78+
79+ // Test message fields are appropriately set in the case of a serialization error.
80+ Assert . Equal ( "test" , ( ( ProduceException < string , int > ) e ) . DeliveryResult . Key ) ;
81+ Assert . Equal ( 112 , ( ( ProduceException < string , int > ) e ) . DeliveryResult . Value ) ;
82+ Assert . Equal ( Offset . Invalid , ( ( ProduceException < string , int > ) e ) . DeliveryResult . Offset ) ;
83+ Assert . Equal ( Partition . Any , ( ( ProduceException < string , int > ) e ) . DeliveryResult . Partition ) ;
84+ Assert . Equal ( guidTopic , ( ( ProduceException < string , int > ) e ) . DeliveryResult . Topic ) ;
85+ Assert . Equal ( PersistenceStatus . NotPersisted , ( ( ProduceException < string , int > ) e ) . DeliveryResult . PersistenceStatus ) ;
86+ Assert . Equal ( Timestamp . Default , ( ( ProduceException < string , int > ) e ) . DeliveryResult . Timestamp ) ;
87+ Assert . Null ( ( ( ProduceException < string , int > ) e ) . DeliveryResult . Headers ) ;
88+
89+ // should be SerializationException.
7490 throw e . InnerException ;
7591 }
7692 } ) ;
@@ -89,10 +105,13 @@ public static void AutoRegisterSchemaDisabled(string bootstrapServers, string sc
89105 {
90106 try
91107 {
92- producer . ProduceAsync ( topic . Name , new Message < string , int > { Key = "test" , Value = 112 } ) . Wait ( ) ;
108+ producer . ProduceAsync ( topic . Name , new Message < string , int > { Key = "test" , Value = 112 } )
109+ . GetAwaiter ( )
110+ . GetResult ( ) ;
93111 }
94- catch ( AggregateException e )
112+ catch ( Exception e )
95113 {
114+ Assert . True ( e is ProduceException < string , int > ) ;
96115 throw e . InnerException ;
97116 }
98117 } ) ;
0 commit comments