private void AssertSchema(SchemaRegistrySchema schema) { AssertSchemaProperties(schema.Properties); Assert.AreEqual( Regex.Replace(SchemaContent, @"\s+", string.Empty), Regex.Replace(schema.Definition, @"\s+", string.Empty)); }
public void RetrieveSchema() { var schemaId = _schemaProperties.Id; #region Snippet:SchemaRegistryRetrieveSchema SchemaRegistrySchema schema = client.GetSchema(schemaId); string content = schema.Content; #endregion Assert.AreEqual(Regex.Replace(_content, @"\s+", string.Empty), content); }
public void RetrieveSchema() { var schemaId = _schemaProperties.Id; #region Snippet:SchemaRegistryRetrieveSchema SchemaRegistrySchema schema = client.GetSchema(schemaId); string definition = schema.Definition; #endregion Assert.AreEqual(Regex.Replace(_definition, @"\s+", string.Empty), definition); }
public async Task CanGetSchema() { var client = CreateClient(); var schemaName = "test1"; var groupName = TestEnvironment.SchemaRegistryGroup; var format = SchemaFormat.Avro; var registerProperties = await client.RegisterSchemaAsync(groupName, schemaName, SchemaContent, format); AssertSchemaProperties(registerProperties); SchemaRegistrySchema schema = await client.GetSchemaAsync(registerProperties.Value.Id); AssertSchema(schema); AssertPropertiesAreEqual(registerProperties, schema.Properties); }
public async Task CannotDeserializeIntoNonCompatibleType() { var client = CreateClient(); var groupName = TestEnvironment.SchemaRegistryGroup; var employee = new Employee() { Age = 42, Name = "Caketown" }; var serializer = new SchemaRegistryAvroSerializer(client, groupName, new SchemaRegistryAvroSerializerOptions { AutoRegisterSchemas = true }); var content = await serializer.SerializeAsync <MessageContent, Employee>(employee); var schemaId = content.ContentType.ToString().Split('+')[1]; // deserialize with the new schema, which is NOT backward compatible with the old schema as it adds a new field Assert.That( async() => await serializer.DeserializeAsync <Employee_V2>(content), Throws.InstanceOf <SchemaRegistryAvroException>() .And.Property(nameof(Exception.InnerException)).InstanceOf <AvroException>() .And.Property(nameof(SchemaRegistryAvroException.SchemaId)).EqualTo(schemaId)); #region Snippet:SchemaRegistryAvroException try { Employee_V2 employeeV2 = await serializer.DeserializeAsync <Employee_V2>(content); } catch (SchemaRegistryAvroException exception) { // When this exception occurs when deserializing, the exception message will contain the schema ID that was used to // serialize the data. Console.WriteLine(exception); // We might also want to look up the specific schema from Schema Registry so that we can log the schema definition if (exception.SchemaId != null) { SchemaRegistrySchema schema = await client.GetSchemaAsync(exception.SchemaId); Console.WriteLine(schema.Definition); } } #endregion }