Exemple #1
0
        public virtual void TestDefaultGetProducerDataAssigned()
        {
            var fooSchema = AvroSchema <SchemaTestUtils.Foo> .Of(ISchemaDefinition <SchemaTestUtils.Foo> .Builder().WithPojo(typeof(SchemaTestUtils.Foo)).Build());

            var barSchema = AvroSchema <SchemaTestUtils.Bar> .Of(ISchemaDefinition <SchemaTestUtils.Bar> .Builder().WithPojo(typeof(SchemaTestUtils.Bar)).Build());

            var keyValueSchema = ISchema <object> .KeyValue(fooSchema, barSchema);

            var foo = new SchemaTestUtils.Foo
            {
                Field1 = "field1",
                Field2 = "field2",
                Field3 = 3
            };
            var bar = new SchemaTestUtils.Bar
            {
                Field1 = true
            };

            // // Check kv.encoding.type default, not set value
            var encodeBytes = keyValueSchema.Encode(new KeyValue <SchemaTestUtils.Foo, SchemaTestUtils.Bar>(foo, bar));
            var builder     = new MessageMetadata();

            builder.ProducerName = "default";

            var msg = Message <KeyValue <SchemaTestUtils.Foo, SchemaTestUtils.Bar> > .Create(builder, new ReadOnlySequence <byte>(encodeBytes), keyValueSchema);

            var keyValue = msg.Value;

            Assert.Equal(keyValue.Key, foo);
            Assert.Equal(keyValue.Value, bar);
            Assert.False(builder.ShouldSerializePartitionKey());
        }
Exemple #2
0
        public virtual void TestSeparatedGetProducerDataAssigned()
        {
            var fooSchema = AvroSchema <SchemaTestUtils.Foo> .Of(ISchemaDefinition <SchemaTestUtils.Foo> .Builder().WithPojo(typeof(SchemaTestUtils.Foo)).Build());

            var barSchema = AvroSchema <SchemaTestUtils.Bar> .Of(ISchemaDefinition <SchemaTestUtils.Bar> .Builder().WithPojo(typeof(SchemaTestUtils.Bar)).Build());

            var keyValueSchema = ISchema <int> .KeyValue(fooSchema, barSchema, KeyValueEncodingType.SEPARATED);

            var foo = new SchemaTestUtils.Foo
            {
                Field1 = "field1",
                Field2 = "field2",
                Field3 = 3
            };
            var bar = new SchemaTestUtils.Bar
            {
                Field1 = true
            };

            // Check kv.encoding.type SPRAERATE
            var encodeBytes = keyValueSchema.Encode(new KeyValue <SchemaTestUtils.Foo, SchemaTestUtils.Bar>(foo, bar));
            var builder     = new MessageMetadata();

            builder.ProducerName           = "separated";
            builder.PartitionKey           = Convert.ToBase64String(fooSchema.Encode(foo));
            builder.PartitionKeyB64Encoded = true;
            var msg = Message <KeyValue <SchemaTestUtils.Foo, SchemaTestUtils.Bar> > .Create(builder, new ReadOnlySequence <byte>(encodeBytes), keyValueSchema);

            var keyValue = msg.Value;

            Assert.Equal(keyValue.Key, foo);
            Assert.Equal(keyValue.Value, bar);
            Assert.True(builder.ShouldSerializePartitionKey());
        }