sijie commented on a change in pull request #4108: [pulsar-clients]Save name, 
type, properties for KeyValueSchema
URL: https://github.com/apache/pulsar/pull/4108#discussion_r278058679
 
 

 ##########
 File path: 
pulsar-client/src/test/java/org/apache/pulsar/client/impl/schema/KeyValueSchemaTest.java
 ##########
 @@ -59,6 +62,32 @@ public void testAllowNullAvroSchemaCreate() {
         assertEquals(schemaInfo1, schemaInfo2);
     }
 
+    @Test
+    public void testFillParametersToSchemainfo() {
+        AvroSchema<Foo> fooSchema = 
AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).build());
+        AvroSchema<Bar> barSchema = 
AvroSchema.of(SchemaDefinition.<Bar>builder().withPojo(Bar.class).build());
+
+        fooSchema.getSchemaInfo().setName("foo");
+        fooSchema.getSchemaInfo().setType(SchemaType.AVRO);
+        Map<String, String> keyProperties = Maps.newHashMap();
+        keyProperties.put("foo.key1", "value");
+        keyProperties.put("foo.key2", "value");
+        fooSchema.getSchemaInfo().setProperties(keyProperties);
+        barSchema.getSchemaInfo().setName("bar");
+        barSchema.getSchemaInfo().setType(SchemaType.AVRO);
+        Map<String, String> valueProperties = Maps.newHashMap();
+        valueProperties.put("bar.key", "key");
+        barSchema.getSchemaInfo().setProperties(valueProperties);
+        Schema<KeyValue<Foo, Bar>> keyValueSchema1 = 
Schema.KeyValue(fooSchema, barSchema);
+
+        
assertEquals(keyValueSchema1.getSchemaInfo().getProperties().get("key.schema.name"),
 "foo");
+        
assertEquals(keyValueSchema1.getSchemaInfo().getProperties().get("key.schema.type"),
 String.valueOf(SchemaType.AVRO));
+        
assertEquals(keyValueSchema1.getSchemaInfo().getProperties().get("key.schema.properties"),
 "{\"foo.key2\":\"value\",\"foo.key1\":\"value\"}");
 
 Review comment:
   how a map is serialized is indeterministic. the order of `foo.key2` and 
`foo.key1` is unknown. so you might consider changing line 71 and line 78 to 
use a TreeMap so that keys are sorted. Hence the serialized json is 
deterministic. 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to