BewareMyPower commented on code in PR #139:
URL: https://github.com/apache/pulsar-client-cpp/pull/139#discussion_r1062311753


##########
tests/DeadLetterQueueTest.cc:
##########
@@ -0,0 +1,390 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include <gtest/gtest.h>
+#include <pulsar/Client.h>
+#include <pulsar/DeadLetterPolicyBuilder.h>
+
+#include "HttpHelper.h"
+#include "PulsarFriend.h"
+#include "lib/ClientConnection.h"
+#include "lib/LogUtils.h"
+#include "lib/MessageIdUtil.h"
+#include "lib/UnAckedMessageTrackerEnabled.h"
+#include "lib/Utils.h"
+
+static const std::string lookupUrl = "pulsar://localhost:6650";
+static const std::string adminUrl = "http://localhost:8080/";;
+
+DECLARE_LOG_OBJECT()
+
+namespace pulsar {
+
+TEST(DeadLetterQueueTest, testDLQWithSchema) {
+    Client client(lookupUrl);
+    const std::string topic = "testAutoSchema-" + 
std::to_string(time(nullptr));
+    const std::string subName = "dlq-sub";
+
+    static const std::string jsonSchema =
+        
R"({"type":"record","name":"cpx","fields":[{"name":"re","type":"double"},{"name":"im","type":"double"}]})";
+    SchemaInfo schemaInfo(JSON, "test-json", jsonSchema);
+
+    auto dlqPolicy = DeadLetterPolicyBuilder()
+                         .maxRedeliverCount(3)
+                         .deadLetterTopic(topic + subName + "-DLQ")
+                         .initialSubscriptionName("init-sub")
+                         .build();
+    ConsumerConfiguration consumerConfig;
+    consumerConfig.setDeadLetterPolicy(dlqPolicy);
+    consumerConfig.setNegativeAckRedeliveryDelayMs(100);
+    consumerConfig.setConsumerType(ConsumerType::ConsumerShared);
+    consumerConfig.setSchema(schemaInfo);
+    Consumer consumer;
+    ASSERT_EQ(ResultOk, client.subscribe(topic, subName, consumerConfig, 
consumer));
+
+    // Initialize the DLQ subscription first and make sure that DLQ topic is 
created and a schema exists.
+    ConsumerConfiguration dlqConsumerConfig;
+    dlqConsumerConfig.setConsumerType(ConsumerType::ConsumerShared);
+    dlqConsumerConfig.setSchema(schemaInfo);
+    Consumer deadLetterConsumer;
+    ASSERT_EQ(ResultOk, client.subscribe(dlqPolicy.getDeadLetterTopic(), 
subName, dlqConsumerConfig,
+                                         deadLetterConsumer));
+
+    Producer producer;
+    ProducerConfiguration producerConfig;
+    producerConfig.setSchema(schemaInfo);
+    ASSERT_EQ(ResultOk, client.createProducer(topic, producerConfig, 
producer));
+    std::string data = "{\"re\":2.1,\"im\":1.23}";
+    const int num = 1;
+    for (int i = 0; i < num; ++i) {
+        ASSERT_EQ(ResultOk, 
producer.send(MessageBuilder().setContent(data).build()));
+    }
+
+    // nack all msg.
+    Message msg;
+    for (int i = 0; i < dlqPolicy.getMaxRedeliverCount() * num + num; ++i) {
+        ASSERT_EQ(ResultOk, consumer.receive(msg));
+        consumer.negativeAcknowledge(msg);
+    }
+
+    // assert dlq msg.
+    for (int i = 0; i < num; i++) {
+        ASSERT_EQ(ResultOk, deadLetterConsumer.receive(msg, 5000));
+        ASSERT_TRUE(!msg.getDataAsString().empty());

Review Comment:
   Please change other places of `ASSERT_TRUE(!condition)` to 
`ASSERT_FALSE(condition)` as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to