38
38
import org .apache .pulsar .client .api .PulsarClientException .BrokerMetadataException ;
39
39
import org .apache .pulsar .client .impl .conf .ClientConfigurationData ;
40
40
import org .apache .pulsar .common .api .proto .CommandCloseConsumer ;
41
+ import org .apache .pulsar .common .api .proto .CommandCloseProducer ;
41
42
import org .apache .pulsar .common .api .proto .CommandError ;
42
43
import org .apache .pulsar .common .api .proto .ServerError ;
43
44
import org .apache .pulsar .common .protocol .Commands ;
@@ -156,7 +157,7 @@ public void testGetLastMessageIdWithError() throws Exception {
156
157
157
158
@ Test
158
159
public void testHandleCloseConsumer () {
159
- ThreadFactory threadFactory = new DefaultThreadFactory ("testReceiveErrorAtSendConnectFrameState " );
160
+ ThreadFactory threadFactory = new DefaultThreadFactory ("testHandleCloseConsumer " );
160
161
EventLoopGroup eventLoop = EventLoopUtil .newEventLoopGroup (1 , false , threadFactory );
161
162
ClientConfigurationData conf = new ClientConfigurationData ();
162
163
ClientCnx cnx = new ClientCnx (conf , eventLoop );
@@ -165,11 +166,28 @@ public void testHandleCloseConsumer() {
165
166
cnx .registerConsumer (consumerId , mock (ConsumerImpl .class ));
166
167
assertEquals (cnx .consumers .size (), 1 );
167
168
168
- CommandCloseConsumer closeConsumer = new CommandCloseConsumer ()
169
- .setConsumerId (1 );
169
+ CommandCloseConsumer closeConsumer = new CommandCloseConsumer ().setConsumerId (consumerId );
170
170
cnx .handleCloseConsumer (closeConsumer );
171
171
assertEquals (cnx .consumers .size (), 0 );
172
172
173
173
eventLoop .shutdownGracefully ();
174
174
}
175
+
176
+ @ Test
177
+ public void testHandleCloseProducer () {
178
+ ThreadFactory threadFactory = new DefaultThreadFactory ("testHandleCloseProducer" );
179
+ EventLoopGroup eventLoop = EventLoopUtil .newEventLoopGroup (1 , false , threadFactory );
180
+ ClientConfigurationData conf = new ClientConfigurationData ();
181
+ ClientCnx cnx = new ClientCnx (conf , eventLoop );
182
+
183
+ long producerId = 1 ;
184
+ cnx .registerProducer (producerId , mock (ProducerImpl .class ));
185
+ assertEquals (cnx .producers .size (), 1 );
186
+
187
+ CommandCloseProducer closeProducerCmd = new CommandCloseProducer ().setProducerId (producerId );
188
+ cnx .handleCloseProducer (closeProducerCmd );
189
+ assertEquals (cnx .producers .size (), 0 );
190
+
191
+ eventLoop .shutdownGracefully ();
192
+ }
175
193
}
0 commit comments