yittg commented on a change in pull request #5165: [PIP-43] Support producer to 
send msg with different schema
URL: https://github.com/apache/pulsar/pull/5165#discussion_r325015007
 
 

 ##########
 File path: 
pulsar-broker/src/test/java/org/apache/pulsar/client/api/SimpleSchemaTest.java
 ##########
 @@ -185,6 +206,155 @@ public void newProducerWithoutSchemaOnTopicWithSchema() 
throws Exception {
         }
     }
 
+    @Test
+    public void newProducerForMessageSchemaOnTopicWithMultiVersionSchema() 
throws Exception {
+        String topic = "my-property/my-ns/schema-test";
+
+        try (Producer<V1Data> ignored = 
pulsarClient.newProducer(Schema.AVRO(V1Data.class))
+                                                    .topic(topic).create()) {
+        }
+        try (Producer<V2Data> p = 
pulsarClient.newProducer(Schema.AVRO(V2Data.class))
+                                              .topic(topic).create()) {
+            p.send(new V2Data(-1, -1));
+        }
+        V1Data msgV1 = new V1Data(2);
+        V2Data msgV2 = new V2Data(3, 5);
+        byte[] contentV1 = new AvroWriter<V1Data>(
+                
ReflectData.AllowNull.get().getSchema(V1Data.class)).write(msgV1);
+        byte[] contentV2 = new AvroWriter<V2Data>(
+                
ReflectData.AllowNull.get().getSchema(V2Data.class)).write(msgV2);
+        try (Producer<byte[]> p = 
pulsarClient.newProducer(Schema.AUTO_PRODUCE_BYTES())
+                                              .topic(topic).create();
+             Consumer<V2Data> c = 
pulsarClient.newConsumer(Schema.AVRO(V2Data.class))
+                                              .topic(topic)
+                                              
.subscriptionName("sub1").subscribe()) {
+            Assert.expectThrows(SchemaSerializationException.class, () -> 
p.send(contentV1));
+
+            
((ProducerBase<byte[]>)p).newMessage(Schema.AUTO_PRODUCE_BYTES(Schema.AVRO(V1Data.class)))
+                                     .value(contentV1).send();
+            p.send(contentV2);
+            V2Data msg1 = c.receive().getValue();
+            Assert.assertEquals(msgV1.i, msg1.i);
+            Assert.assertNull(msg1.j);
+            Assert.assertEquals(msgV2, c.receive().getValue());
 
 Review comment:
   More assert checks added.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to