@@ -68,7 +68,7 @@ func (s partitionConsumerWrapper) Topic() string {
68
68
return s .topic
69
69
}
70
70
71
- func newSaramaClusterConsumer (saramaPartitionConsumer sarama.PartitionConsumer ) * kmocks.Consumer {
71
+ func newSaramaClusterConsumer (saramaPartitionConsumer sarama.PartitionConsumer , mc * smocks. PartitionConsumer ) * kmocks.Consumer {
72
72
pcha := make (chan cluster.PartitionConsumer , 1 )
73
73
pcha <- & partitionConsumerWrapper {
74
74
topic : topic ,
@@ -77,27 +77,26 @@ func newSaramaClusterConsumer(saramaPartitionConsumer sarama.PartitionConsumer)
77
77
}
78
78
saramaClusterConsumer := & kmocks.Consumer {}
79
79
saramaClusterConsumer .On ("Partitions" ).Return ((<- chan cluster.PartitionConsumer )(pcha ))
80
- saramaClusterConsumer .On ("Close" ).Return (nil )
80
+ saramaClusterConsumer .On ("Close" ).Return (nil ).Run (func (args mock.Arguments ) {
81
+ mc .Close ()
82
+ })
81
83
saramaClusterConsumer .On ("MarkPartitionOffset" , mock .Anything , mock .Anything , mock .Anything , mock .Anything ).Return (nil )
82
84
return saramaClusterConsumer
83
85
}
84
86
85
87
func newConsumer (
88
+ t * testing.T ,
86
89
metricsFactory metrics.Factory ,
87
90
topic string ,
88
91
processor processor.SpanProcessor ,
89
92
consumer consumer.Consumer ) * Consumer {
90
93
91
94
logger , _ := zap .NewDevelopment ()
92
- return & Consumer {
93
- metricsFactory : metricsFactory ,
94
- logger : logger ,
95
- internalConsumer : consumer ,
96
- partitionIDToState : make (map [int32 ]* consumerState ),
97
- partitionsHeldGauge : partitionsHeldGauge (metricsFactory ),
98
- deadlockDetector : newDeadlockDetector (metricsFactory , logger , time .Second ),
99
-
100
- processorFactory : ProcessorFactory {
95
+ consumerParams := Params {
96
+ MetricsFactory : metricsFactory ,
97
+ Logger : logger ,
98
+ InternalConsumer : consumer ,
99
+ ProcessorFactory : ProcessorFactory {
101
100
topic : topic ,
102
101
consumer : consumer ,
103
102
metricsFactory : metricsFactory ,
@@ -106,6 +105,10 @@ func newConsumer(
106
105
parallelism : 1 ,
107
106
},
108
107
}
108
+
109
+ c , err := New (consumerParams )
110
+ require .NoError (t , err )
111
+ return c
109
112
}
110
113
111
114
func TestSaramaConsumerWrapper_MarkPartitionOffset (t * testing.T ) {
@@ -136,7 +139,7 @@ func TestSaramaConsumerWrapper_start_Messages(t *testing.T) {
136
139
saramaPartitionConsumer , e := saramaConsumer .ConsumePartition (topic , partition , msgOffset )
137
140
require .NoError (t , e )
138
141
139
- undertest := newConsumer (localFactory , topic , mp , newSaramaClusterConsumer (saramaPartitionConsumer ))
142
+ undertest := newConsumer (t , localFactory , topic , mp , newSaramaClusterConsumer (saramaPartitionConsumer , mc ))
140
143
141
144
undertest .partitionIDToState = map [int32 ]* consumerState {
142
145
partition : {
@@ -202,7 +205,7 @@ func TestSaramaConsumerWrapper_start_Errors(t *testing.T) {
202
205
saramaPartitionConsumer , e := saramaConsumer .ConsumePartition (topic , partition , msgOffset )
203
206
require .NoError (t , e )
204
207
205
- undertest := newConsumer (localFactory , topic , & pmocks.SpanProcessor {}, newSaramaClusterConsumer (saramaPartitionConsumer ))
208
+ undertest := newConsumer (t , localFactory , topic , & pmocks.SpanProcessor {}, newSaramaClusterConsumer (saramaPartitionConsumer , mc ))
206
209
207
210
undertest .Start ()
208
211
mc .YieldError (errors .New ("Daisy, Daisy" ))
@@ -238,7 +241,7 @@ func TestHandleClosePartition(t *testing.T) {
238
241
saramaPartitionConsumer , e := saramaConsumer .ConsumePartition (topic , partition , msgOffset )
239
242
require .NoError (t , e )
240
243
241
- undertest := newConsumer (metricsFactory , topic , mp , newSaramaClusterConsumer (saramaPartitionConsumer ))
244
+ undertest := newConsumer (t , metricsFactory , topic , mp , newSaramaClusterConsumer (saramaPartitionConsumer , mc ))
242
245
undertest .deadlockDetector = newDeadlockDetector (metricsFactory , undertest .logger , 200 * time .Millisecond )
243
246
undertest .Start ()
244
247
defer undertest .Close ()
0 commit comments