@@ -174,6 +174,10 @@ func TestWriter(t *testing.T) {
174
174
scenario : "test default configuration values" ,
175
175
function : testWriterDefaults ,
176
176
},
177
+ {
178
+ scenario : "test write message with writer data" ,
179
+ function : testWriteMessageWithWriterData ,
180
+ },
177
181
}
178
182
179
183
for _ , test := range tests {
@@ -719,6 +723,45 @@ func testWriterUnexpectedMessageTopic(t *testing.T) {
719
723
}
720
724
}
721
725
726
+ func testWriteMessageWithWriterData (t * testing.T ) {
727
+ topic := makeTopic ()
728
+ createTopic (t , topic , 1 )
729
+ defer deleteTopic (t , topic )
730
+ w := newTestWriter (WriterConfig {
731
+ Topic : topic ,
732
+ Balancer : & RoundRobin {},
733
+ })
734
+ defer w .Close ()
735
+
736
+ index := 0
737
+ w .Completion = func (messages []Message , err error ) {
738
+ if err != nil {
739
+ t .Errorf ("unexpected error %v" , err )
740
+ }
741
+
742
+ for _ , msg := range messages {
743
+ meta := msg .WriterData .(int )
744
+ if index != meta {
745
+ t .Errorf ("metadata is not correct, index = %d, writerData = %d" , index , meta )
746
+ }
747
+ index += 1
748
+ }
749
+ }
750
+
751
+ msg := Message {Key : []byte ("key" ), Value : []byte ("Hello World" )}
752
+ for i := 0 ; i < 5 ; i ++ {
753
+ ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Second )
754
+ defer cancel ()
755
+
756
+ msg .WriterData = i
757
+ err := w .WriteMessages (ctx , msg )
758
+ if err != nil {
759
+ t .Errorf ("unexpected error %v" , err )
760
+ }
761
+ }
762
+
763
+ }
764
+
722
765
func testWriterAutoCreateTopic (t * testing.T ) {
723
766
topic := makeTopic ()
724
767
// Assume it's going to get created.
0 commit comments