You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/12/26 08:20:54 UTC

[GitHub] [pulsar-client-cpp] shibd commented on a diff in pull request #149: [feat] Support messages with generic types

shibd commented on code in PR #149:
URL: https://github.com/apache/pulsar-client-cpp/pull/149#discussion_r1057130265


##########
tests/TypedMessageTest.cc:
##########
@@ -0,0 +1,77 @@
+/**
+ * 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/MessageBuilder.h>
+#include <pulsar/TypedMessage.h>
+#include <pulsar/TypedMessageBuilder.h>
+
+#include <vector>
+
+#include "IntSchema.h"
+
+using namespace pulsar;
+
+static std::string lookupUrl = "pulsar://localhost:6650";
+
+extern std::string unique_str();
+
+using IntMessageBuilder = TypedMessageBuilder<int>;
+
+TEST(TypedMessageTest, testIntValue) {
+    const auto topic = "typed-message-test-int-value-" + unique_str();
+    Client client(lookupUrl);
+    SchemaInfo schema(SchemaType::INT32, "", "");
+    Producer producer;
+    ASSERT_EQ(ResultOk, client.createProducer(topic, ProducerConfiguration().setSchema(schema), producer));
+    Consumer consumer;
+    ASSERT_EQ(ResultOk, client.subscribe(topic, "sub", ConsumerConfiguration().setSchema(schema), consumer));
+
+    std::vector<MessageId> messageIds;
+    constexpr int numMessages = 100;
+
+    IntSchema intSchema{schema};
+    for (int i = 0; i < numMessages; i++) {
+        MessageId messageId;
+        ASSERT_EQ(ResultOk, producer.send(intSchema.newMessage(i).build(), messageId));

Review Comment:
   Using primitive types doesn't seem to show the benefits of this approach. Can we provide more examples for record types?
   
   
   



-- 
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-unsubscribe@pulsar.apache.org

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