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 2019/04/29 13:18:15 UTC

[GitHub] [pulsar] codelipenghui commented on a change in pull request #4117: [pulsar-clients]Store key part of a KeyValue schema into pulsar message keys

codelipenghui commented on a change in pull request #4117: [pulsar-clients]Store key part of a KeyValue schema into pulsar message keys
URL: https://github.com/apache/pulsar/pull/4117#discussion_r279351486
 
 

 ##########
 File path: pulsar-client/src/test/java/org/apache/pulsar/client/impl/MessageImplTest.java
 ##########
 @@ -71,4 +79,78 @@ public void testGetProducerNameAssigned() {
         assertEquals("test-producer", msg.getProducerName());
     }
 
+    @Test
+    public void testDefaultGetProducerDataAssigned() {
+        AvroSchema<SchemaTestUtils.Foo> fooSchema = AvroSchema.of(SchemaDefinition.<SchemaTestUtils.Foo>builder().withPojo(SchemaTestUtils.Foo.class).build());
+        AvroSchema<SchemaTestUtils.Bar> barSchema = AvroSchema.of(SchemaDefinition.<SchemaTestUtils.Bar>builder().withPojo(SchemaTestUtils.Bar.class).build());
+
+        Schema<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> keyValueSchema = Schema.KeyValue(fooSchema, barSchema);
+        SchemaTestUtils.Foo foo = new SchemaTestUtils.Foo();
+        foo.setField1("field1");
+        foo.setField2("field2");
+        foo.setField3(3);
+        SchemaTestUtils.Bar bar = new SchemaTestUtils.Bar();
+        bar.setField1(true);
+
+        // // Check kv.encoding.type default, not set value
+        byte[] encodeBytes = keyValueSchema.encode(new KeyValue(foo, bar));
+        MessageMetadata.Builder builder = MessageMetadata.newBuilder()
+                .setProducerName("default");
+        MessageImpl<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> msg = MessageImpl.create(builder, ByteBuffer.wrap(encodeBytes), keyValueSchema);
+        KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar> keyValue = msg.getValue();
+        assertEquals(keyValue.getKey(), foo);
+        assertEquals(keyValue.getValue(), bar);
+        assertFalse(builder.hasPartitionKey());
+    }
+
+    @Test
+    public void testInlineGetProducerDataAssigned() {
+
+        AvroSchema<SchemaTestUtils.Foo> fooSchema = AvroSchema.of(SchemaDefinition.<SchemaTestUtils.Foo>builder().withPojo(SchemaTestUtils.Foo.class).build());
+        AvroSchema<SchemaTestUtils.Bar> barSchema = AvroSchema.of(SchemaDefinition.<SchemaTestUtils.Bar>builder().withPojo(SchemaTestUtils.Bar.class).build());
+
+        Schema<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> keyValueSchema = Schema.KeyValue(fooSchema, barSchema, KeyValueEncodingType.INLINE);
+        SchemaTestUtils.Foo foo = new SchemaTestUtils.Foo();
+        foo.setField1("field1");
+        foo.setField2("field2");
+        foo.setField3(3);
+        SchemaTestUtils.Bar bar = new SchemaTestUtils.Bar();
+        bar.setField1(true);
+
+        // Check kv.encoding.type INLINE
+        byte[] encodeBytes = keyValueSchema.encode(new KeyValue(foo, bar));
+        MessageMetadata.Builder builder = MessageMetadata.newBuilder()
+                .setProducerName("inline");
+        MessageImpl<KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar>> msg = MessageImpl.create(builder, ByteBuffer.wrap(encodeBytes), keyValueSchema);
+        KeyValue<SchemaTestUtils.Foo, SchemaTestUtils.Bar> keyValue = msg.getValue();
+        assertEquals(keyValue.getKey(), foo);
+        assertEquals(keyValue.getValue(), bar);
+        assertFalse(builder.hasPartitionKey());
+    }
+
+    @Test
+    public void testSpraerateGetProducerDataAssigned() {
 
 Review comment:
   Please correct the typo in the method name

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services