use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.
the class SchemaRegisterInjectorTest method shouldRegisterValueOverrideSchemaProtobuf.
@Test
public void shouldRegisterValueOverrideSchemaProtobuf() throws IOException, RestClientException {
// Given:
when(schemaRegistryClient.register(anyString(), any(ParsedSchema.class))).thenReturn(1);
final SchemaAndId schemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), PROTOBUF_SCHEMA, 1);
givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='JSON', " + "value_format='PROTOBUF', " + "value_schema_id=1, " + "partitions=1" + ");", Pair.of(null, schemaAndId));
// When:
injector.inject(statement);
// Then:
verify(schemaRegistryClient).register("expectedName-value", PROTOBUF_SCHEMA);
}
use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.
the class SchemaRegisterInjectorTest method shouldThrowWrongKeyFormatExceptionWithOverrideSchema.
@Test
public void shouldThrowWrongKeyFormatExceptionWithOverrideSchema() throws Exception {
// Given:
final SchemaAndId keySchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
final SchemaAndId valueSchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 2);
givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='KAFKA', " + "value_format='AVRO', " + "key_schema_id=1, " + "value_schema_id=1, " + "partitions=1" + ");", Pair.of(keySchemaAndId, valueSchemaAndId));
// When:
final Exception e = assertThrows(KsqlStatementException.class, () -> injector.inject(statement));
// Then:
assertThat(e.getMessage(), containsString("KEY_SCHEMA_ID is provided but format KAFKA doesn't " + "support registering in Schema Registry"));
verify(schemaRegistryClient, never()).register(anyString(), any(ParsedSchema.class));
}
use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.
the class SchemaRegisterInjectorTest method shouldRegisterKeyOverrideSchemaAvroForCreateAs.
@Test
public void shouldRegisterKeyOverrideSchemaAvroForCreateAs() throws IOException, RestClientException {
// Given:
when(schemaRegistryClient.register(anyString(), any(ParsedSchema.class))).thenReturn(1);
final SchemaAndId keySchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
final SchemaAndId valueSchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
givenStatement("CREATE STREAM sink WITH (key_schema_id=1, value_schema_id=1, partitions=1" + ") AS SELECT * FROM SOURCE;", Pair.of(keySchemaAndId, valueSchemaAndId));
// When:
injector.inject(statement);
// Then:
verify(schemaRegistryClient).register("SINK-key", AVRO_SCHEMA);
verify(schemaRegistryClient).register("SINK-value", AVRO_SCHEMA);
}
Aggregations