Skip to content

Commit

Permalink
Even if always compatible is set, Consumers cannot be created (#12721)
Browse files Browse the repository at this point in the history
(cherry picked from commit c3da145)
  • Loading branch information
315157973 authored and codelipenghui committed Dec 20, 2021
1 parent a813c52 commit a9e8b3f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Expand Up @@ -270,6 +270,9 @@ public CompletableFuture<Long> findSchemaVersion(String schemaId, SchemaData sch
@Override
public CompletableFuture<Void> checkConsumerCompatibility(String schemaId, SchemaData schemaData,
SchemaCompatibilityStrategy strategy) {
if (SchemaCompatibilityStrategy.ALWAYS_COMPATIBLE == strategy) {
return CompletableFuture.completedFuture(null);
}
return getSchema(schemaId).thenCompose(existingSchema -> {
if (existingSchema != null && !existingSchema.schema.isDeleted()) {
if (strategy == SchemaCompatibilityStrategy.BACKWARD
Expand Down
Expand Up @@ -395,6 +395,28 @@ public void testProducerSendWithOldSchemaAndConsumerCanRead(SchemaCompatibilityS

}

@Test
public void testAutoProduceSchemaAlwaysCompatible() throws Exception {
final String tenant = PUBLIC_TENANT;
final String topic = "topic" + randomName(16);

String namespace = "test-namespace-" + randomName(16);
String topicName = TopicName.get(
TopicDomain.persistent.value(), tenant, namespace, topic).toString();
NamespaceName namespaceName = NamespaceName.get(tenant, namespace);
admin.namespaces().createNamespace(tenant + "/" + namespace, Sets.newHashSet(CLUSTER_NAME));

// set ALWAYS_COMPATIBLE
admin.namespaces().setSchemaCompatibilityStrategy(namespaceName.toString(), SchemaCompatibilityStrategy.ALWAYS_COMPATIBLE);

Producer producer = pulsarClient.newProducer(Schema.AUTO_PRODUCE_BYTES()).topic(topicName).create();
// should not fail
Consumer<String> consumer = pulsarClient.newConsumer(Schema.STRING).subscriptionName("my-sub").topic(topicName).subscribe();

producer.close();
consumer.close();
}

@Test(dataProvider = "CanReadLastSchemaCompatibilityStrategy")
public void testConsumerWithNotCompatibilitySchema(SchemaCompatibilityStrategy schemaCompatibilityStrategy) throws Exception {
final String tenant = PUBLIC_TENANT;
Expand Down

0 comments on commit a9e8b3f

Please sign in to comment.