Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix testSchemaIncompatibility for Protobuf 3.20.0 or later #282

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 8 additions & 34 deletions tests/ProtobufNativeSchemaTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,6 @@ using namespace pulsar;

static std::string lookupUrl = "pulsar://localhost:6650";

const ::google::protobuf::Descriptor* getTestMessageDescriptor() {
#if GOOGLE_PROTOBUF_VERSION < 3020000
::proto::TestMessage msg;
return msg.GetDescriptor();
#else
return ::proto::TestMessage::GetDescriptor();
#endif
}

const ::google::protobuf::Descriptor* getExternalMessageDescriptor() {
#if GOOGLE_PROTOBUF_VERSION < 3020000
::proto::external::ExternalMessage msg;
return msg.GetDescriptor();
#else
return ::proto::TestMessage::GetDescriptor();
#endif
}

const ::google::protobuf::Descriptor* getDemoPersonDescriptor() {
#if GOOGLE_PROTOBUF_VERSION < 3020000
::padding::demo::Person p;
return p.GetDescriptor();
#else
return ::padding::demo::Person::GetDescriptor();
#endif
}

TEST(ProtobufNativeSchemaTest, testSchemaJson) {
const std::string expectedSchemaJson =
"{\"fileDescriptorSet\":"
Expand All @@ -69,7 +42,7 @@ TEST(ProtobufNativeSchemaTest, testSchemaJson) {
"NzYWdlEhMKC3N0cmluZ0ZpZWxkGAEgASgJEhMKC2RvdWJsZUZpZWxkGAIgASgBQjUKJW9yZy5hcGFjaGUucHVsc2FyLmNsaWVudC"
"5zY2hlbWEucHJvdG9CDEV4dGVybmFsVGVzdGIGcHJvdG8z\",\"rootMessageTypeName\":\"proto.TestMessage\","
"\"rootFileDescriptorName\":\"Test.proto\"}";
const auto schemaInfo = createProtobufNativeSchema(getTestMessageDescriptor());
const auto schemaInfo = createProtobufNativeSchema(::proto::TestMessage::descriptor());

ASSERT_EQ(schemaInfo.getSchemaType(), pulsar::PROTOBUF_NATIVE);
ASSERT_TRUE(schemaInfo.getName().empty());
Expand All @@ -81,7 +54,7 @@ TEST(ProtobufNativeSchemaTest, testAutoCreateSchema) {
const std::string topicPrefix = "ProtobufNativeSchemaTest-testAutoCreateSchema-";
Client client(lookupUrl);

const auto schemaInfo = createProtobufNativeSchema(getTestMessageDescriptor());
const auto schemaInfo = createProtobufNativeSchema(::proto::TestMessage::descriptor());
Producer producer;
ASSERT_EQ(ResultOk, client.createProducer(topicPrefix + "producer",
ProducerConfiguration().setSchema(schemaInfo), producer));
Expand All @@ -102,14 +75,15 @@ TEST(ProtobufNativeSchemaTest, testSchemaIncompatibility) {
};

// Create the protobuf native schema automatically
ASSERT_EQ(ResultOk, createProducerResult(getTestMessageDescriptor()));
ASSERT_EQ(ResultOk, createProducerResult(::proto::TestMessage::descriptor()));
producer.close();

// Try to create producer with another protobuf generated class
ASSERT_EQ(ResultIncompatibleSchema, createProducerResult(getExternalMessageDescriptor()));
ASSERT_EQ(ResultIncompatibleSchema,
createProducerResult(::proto::external::ExternalMessage::descriptor()));

// Try to create producer with the original schema again
ASSERT_EQ(ResultOk, createProducerResult(getTestMessageDescriptor()));
ASSERT_EQ(ResultOk, createProducerResult(::proto::TestMessage::descriptor()));

// createProtobufNativeSchema() cannot accept a null descriptor
try {
Expand All @@ -125,7 +99,7 @@ TEST(ProtobufNativeSchemaTest, testEndToEnd) {
const std::string topic = "ProtobufSchemaTest-testEndToEnd";
Client client(lookupUrl);

const auto schemaInfo = createProtobufNativeSchema(getTestMessageDescriptor());
const auto schemaInfo = createProtobufNativeSchema(::proto::TestMessage::descriptor());
Consumer consumer;
ASSERT_EQ(ResultOk,
client.subscribe(topic, "my-sub", ConsumerConfiguration().setSchema(schemaInfo), consumer));
Expand Down Expand Up @@ -156,7 +130,7 @@ TEST(ProtobufNativeSchemaTest, testEndToEnd) {
}

TEST(ProtobufNativeSchemaTest, testBase64WithPadding) {
const auto schemaInfo = createProtobufNativeSchema(getDemoPersonDescriptor());
const auto schemaInfo = createProtobufNativeSchema(::padding::demo::Person::descriptor());
const auto schemaJson = schemaInfo.getSchema();
size_t pos = schemaJson.find(R"(","rootMessageTypeName":)");
ASSERT_NE(pos, std::string::npos);
Expand Down