@@ -50,21 +50,33 @@ public void SimpleProduceConsume(string bootstrapServers)
50
50
51
51
string testString1 = "hello world" ;
52
52
string testString2 = null ;
53
+ string testString3 = "dlrow olleh" ;
54
+ string testString4 = null ;
53
55
54
56
DeliveryResult < Null , string > produceResult1 ;
55
57
DeliveryResult < Null , string > produceResult2 ;
58
+ DeliveryResult < Null , Memory < byte > ? > produceResult3 ;
59
+ DeliveryResult < Null , Memory < byte > ? > produceResult4 ;
56
60
using ( var producer = new TestProducerBuilder < Null , string > ( producerConfig ) . Build ( ) )
57
61
{
58
62
produceResult1 = ProduceMessage ( singlePartitionTopic , producer , testString1 ) ;
59
63
produceResult2 = ProduceMessage ( singlePartitionTopic , producer , testString2 ) ;
60
64
}
61
65
66
+ using ( var producer = new TestProducerBuilder < Null , Memory < byte > ? > ( producerConfig ) . Build ( ) )
67
+ {
68
+ produceResult3 = ProduceMessage ( singlePartitionTopic , producer , testString3 ) ;
69
+ produceResult4 = ProduceMessage ( singlePartitionTopic , producer , testString4 ) ;
70
+ }
71
+
62
72
using ( var consumer = new TestConsumerBuilder < byte [ ] , byte [ ] > ( consumerConfig ) . Build ( ) )
63
73
{
64
74
ConsumeMessage ( consumer , produceResult1 , testString1 ) ;
65
75
ConsumeMessage ( consumer , produceResult2 , testString2 ) ;
76
+ ConsumeMessage ( consumer , produceResult3 , testString3 ) ;
77
+ ConsumeMessage ( consumer , produceResult4 , testString4 ) ;
66
78
}
67
-
79
+
68
80
Assert . Equal ( 0 , Library . HandleCount ) ;
69
81
LogToFile ( "end SimpleProduceConsume" ) ;
70
82
}
@@ -80,6 +92,17 @@ private static void ConsumeMessage(IConsumer<byte[], byte[]> consumer, DeliveryR
80
92
Assert . Equal ( r . Message . Timestamp . UnixTimestampMs , dr . Message . Timestamp . UnixTimestampMs ) ;
81
93
}
82
94
95
+ private static void ConsumeMessage ( IConsumer < byte [ ] , byte [ ] > consumer , DeliveryResult < Null , Memory < byte > ? > dr , string testString )
96
+ {
97
+ consumer . Assign ( new List < TopicPartitionOffset > { dr . TopicPartitionOffset } ) ;
98
+ var r = consumer . Consume ( TimeSpan . FromSeconds ( 10 ) ) ;
99
+ Assert . NotNull ( r ? . Message ) ;
100
+ Assert . Equal ( testString , r . Message . Value == null ? null : Encoding . UTF8 . GetString ( r . Message . Value ) ) ;
101
+ Assert . Null ( r . Message . Key ) ;
102
+ Assert . Equal ( r . Message . Timestamp . Type , dr . Message . Timestamp . Type ) ;
103
+ Assert . Equal ( r . Message . Timestamp . UnixTimestampMs , dr . Message . Timestamp . UnixTimestampMs ) ;
104
+ }
105
+
83
106
private static DeliveryResult < Null , string > ProduceMessage ( string topic , IProducer < Null , string > producer , string testString )
84
107
{
85
108
var result = producer . ProduceAsync ( topic , new Message < Null , string > { Value = testString } ) . Result ;
@@ -91,5 +114,20 @@ private static DeliveryResult<Null, string> ProduceMessage(string topic, IProduc
91
114
Assert . Equal ( 0 , producer . Flush ( TimeSpan . FromSeconds ( 10 ) ) ) ;
92
115
return result ;
93
116
}
117
+
118
+ private static DeliveryResult < Null , Memory < byte > ? > ProduceMessage ( string topic , IProducer < Null , Memory < byte > ? > producer , string testString )
119
+ {
120
+ var result = producer . ProduceAsync ( topic , new Message < Null , Memory < byte > ? >
121
+ {
122
+ Value = testString == null ? null : Encoding . UTF8 . GetBytes ( testString ) ,
123
+ } ) . Result ;
124
+ Assert . NotNull ( result ? . Message ) ;
125
+ Assert . Equal ( topic , result . Topic ) ;
126
+ Assert . NotEqual < long > ( result . Offset , Offset . Unset ) ;
127
+ Assert . Equal ( TimestampType . CreateTime , result . Message . Timestamp . Type ) ;
128
+ Assert . True ( Math . Abs ( ( DateTime . UtcNow - result . Message . Timestamp . UtcDateTime ) . TotalMinutes ) < 1.0 ) ;
129
+ Assert . Equal ( 0 , producer . Flush ( TimeSpan . FromSeconds ( 10 ) ) ) ;
130
+ return result ;
131
+ }
94
132
}
95
133
}
0 commit comments