@@ -215,6 +215,50 @@ TEST(ProducerTest, testBacklogQuotasExceeded) {
215215 client.close ();
216216}
217217
218+ TEST (ProducerTest, testCreateProducerAfterTopicTermination) {
219+ const auto topicName = " testCreateProducerAfterTopicTermination-" + std::to_string (time (nullptr ));
220+ const auto topic = " persistent://public/default/" + topicName;
221+
222+ Client client (serviceUrl, ClientConfiguration ().setOperationTimeoutSeconds (1 ));
223+
224+ Producer producer;
225+ ASSERT_EQ (ResultOk, client.createProducer (topic, producer));
226+ ASSERT_EQ (ResultOk, producer.send (MessageBuilder ().setContent (" content" ).build ()));
227+ ASSERT_EQ (ResultOk, producer.close ());
228+
229+ const auto httpCode =
230+ makePostRequest (adminUrl + " admin/v2/persistent/public/default/" + topicName + " /terminate" , " " );
231+ ASSERT_EQ (200 , httpCode) << " httpCode: " << httpCode;
232+
233+ Producer terminatedProducer;
234+ ASSERT_EQ (ResultTopicTerminated, client.createProducer (topic, terminatedProducer));
235+
236+ client.close ();
237+ }
238+
239+ TEST (ProducerTest, testSendAfterTopicTerminationReconnect) {
240+ const auto topicName = " testSendAfterTopicTerminationReconnect-" + std::to_string (time (nullptr ));
241+ const auto topic = " persistent://public/default/" + topicName;
242+
243+ Client client (serviceUrl, ClientConfiguration ().setOperationTimeoutSeconds (1 ));
244+
245+ Producer producer;
246+ ASSERT_EQ (ResultOk, client.createProducer (topic, producer));
247+ ASSERT_EQ (ResultOk, producer.send (MessageBuilder ().setContent (" before-terminate" ).build ()));
248+
249+ const auto httpCode =
250+ makePostRequest (adminUrl + " admin/v2/persistent/public/default/" + topicName + " /terminate" , " " );
251+ ASSERT_EQ (200 , httpCode) << " httpCode: " << httpCode;
252+
253+ PulsarFriend::getProducerImpl (producer).disconnectProducer ();
254+ ASSERT_TRUE (
255+ waitUntil (std::chrono::seconds (3 ), [&producer] { return PulsarFriend::isTerminated (producer); }));
256+
257+ ASSERT_EQ (ResultTopicTerminated, producer.send (MessageBuilder ().setContent (" after-terminate" ).build ()));
258+
259+ client.close ();
260+ }
261+
218262class ProducerTest : public ::testing::TestWithParam<bool > {};
219263
220264TEST_P (ProducerTest, testMaxMessageSize) {
0 commit comments