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


##########
tests/LookupServiceTest.cc:
##########
@@ -274,3 +277,82 @@ TEST(LookupServiceTest, testTimeout) {
 
     ASSERT_EQ(PulsarFriend::getNumberOfPendingTasks(*lookupService), 0);
 }
+
+class LookupServiceTest : public ::testing::TestWithParam<std::string> {
+   public:
+    void TearDown() override { client_.close(); }
+
+   protected:
+    Client client_{GetParam()};
+};
+
+TEST_P(LookupServiceTest, testGetSchema) {
+    const std::string topic = "testGetSchema" + std::to_string(time(nullptr)) 
+ GetParam().substr(0, 4);
+    std::string jsonSchema =
+        
R"({"type":"record","name":"cpx","fields":[{"name":"re","type":"double"},{"name":"im","type":"double"}]})";
+
+    StringMap properties;
+    properties.emplace("key1", "value1");
+    properties.emplace("key2", "value2");
+
+    ProducerConfiguration producerConfiguration;
+    producerConfiguration.setSchema(SchemaInfo(SchemaType::JSON, "json", 
jsonSchema, properties));
+    Producer producer;
+    ASSERT_EQ(ResultOk, client_.createProducer(topic, producerConfiguration, 
producer));
+
+    auto clientImplPtr = PulsarFriend::getClientImplPtr(client_);
+    auto lookup = clientImplPtr->getLookup();
+
+    boost::optional<SchemaInfo> schemaInfo;
+    auto future = lookup->getSchema(TopicName::get(topic));
+    ASSERT_EQ(ResultOk, future.get(schemaInfo));
+    ASSERT_EQ(jsonSchema, schemaInfo->getSchema());
+    ASSERT_EQ(SchemaType::JSON, schemaInfo->getSchemaType());
+    ASSERT_EQ(properties, schemaInfo->getProperties());
+}
+
+TEST_P(LookupServiceTest, testGetSchemaNotFund) {
+    const std::string topic =
+        "testGetSchemaNotFund" + std::to_string(time(nullptr)) + 
GetParam().substr(0, 4);
+
+    Producer producer;
+    ASSERT_EQ(ResultOk, client_.createProducer(topic, producer));
+
+    auto clientImplPtr = PulsarFriend::getClientImplPtr(client_);
+    auto lookup = clientImplPtr->getLookup();
+
+    boost::optional<SchemaInfo> schemaInfo;
+    auto future = lookup->getSchema(TopicName::get(topic));
+    ASSERT_EQ(ResultOk, future.get(schemaInfo));
+    ASSERT_TRUE(!schemaInfo);
+}
+
+TEST_P(LookupServiceTest, testGetKeyValueSchema) {
+    const std::string topic =
+        "testGetKeyValueSchema" + std::to_string(time(nullptr)) + 
GetParam().substr(0, 4);
+    StringMap properties;
+    properties.emplace("key1", "value1");
+    properties.emplace("key2", "value2");
+    std::string jsonSchema =
+        
R"({"type":"record","name":"cpx","fields":[{"name":"re","type":"double"},{"name":"im","type":"double"}]})";
+    SchemaInfo keySchema(JSON, "key-json", jsonSchema, properties);
+    SchemaInfo valueSchema(JSON, "value-json", jsonSchema, properties);
+    SchemaInfo keyValueSchema(keySchema, valueSchema, 
KeyValueEncodingType::INLINE);
+
+    ProducerConfiguration producerConfiguration;
+    producerConfiguration.setSchema(keyValueSchema);
+    Producer producer;
+    ASSERT_EQ(ResultOk, client_.createProducer(topic, producerConfiguration, 
producer));
+
+    auto clientImplPtr = PulsarFriend::getClientImplPtr(client_);
+    auto lookup = clientImplPtr->getLookup();
+
+    boost::optional<SchemaInfo> schemaInfo;
+    auto future = lookup->getSchema(TopicName::get(topic));
+    ASSERT_EQ(ResultOk, future.get(schemaInfo));
+    ASSERT_EQ(keyValueSchema.getSchema(), schemaInfo->getSchema());
+    ASSERT_EQ(SchemaType::KEY_VALUE, schemaInfo->getSchemaType());
+    ASSERT_TRUE(!schemaInfo->getProperties().empty());

Review Comment:
   Replace with `ASSERT_FALSE`



-- 
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: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to