use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.
the class SchemaRegisterInjectorTest method shouldRegisterKeyOverrideSchemaAvro.
@Test
public void shouldRegisterKeyOverrideSchemaAvro() throws IOException, RestClientException {
// Given:
when(schemaRegistryClient.register(anyString(), any(ParsedSchema.class))).thenReturn(1);
final SchemaAndId schemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='AVRO', " + "value_format='JSON', " + "key_schema_id=1, " + "partitions=1" + ");", Pair.of(schemaAndId, null));
// When:
injector.inject(statement);
// Then:
verify(schemaRegistryClient).register("expectedName-key", AVRO_SCHEMA);
}
use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.
the class SchemaRegisterInjectorTest method shouldThrowWrongValueFormatExceptionWithOverrideSchema.
@Test
public void shouldThrowWrongValueFormatExceptionWithOverrideSchema() {
// Given:
final SchemaAndId schemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='KAFKA', " + "value_format='JSON', " + "value_schema_id=1, " + "partitions=1" + ");", Pair.of(null, schemaAndId));
// When:
final Exception e = assertThrows(KsqlStatementException.class, () -> injector.inject(statement));
// Then:
assertThat(e.getMessage(), containsString("VALUE_SCHEMA_ID is provided but format JSON doesn't " + "support registering in Schema Registry"));
}
use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.
the class SchemaRegisterInjectorTest method shouldRegisterKeyValueOverrideSchema.
@Test
public void shouldRegisterKeyValueOverrideSchema() throws IOException, RestClientException {
// Given:
when(schemaRegistryClient.register(anyString(), any(AvroSchema.class))).thenReturn(1);
when(schemaRegistryClient.register(anyString(), any(ProtobufSchema.class))).thenReturn(2);
final SchemaAndId keySchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_UNWRAPPED_KEY_SCHEMA, 1);
final SchemaAndId ValueSchemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), PROTOBUF_SCHEMA, 2);
givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='AVRO', " + "value_format='PROTOBUF', " + "value_schema_id=2, " + "key_schema_id=1, " + "partitions=1" + ");", Pair.of(keySchemaAndId, ValueSchemaAndId));
// When:
injector.inject(statement);
// Then:
verify(schemaRegistryClient).register("expectedName-key", AVRO_UNWRAPPED_KEY_SCHEMA);
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 shouldThrowInconsistentKeySchemaTypeExceptionWithOverrideSchema.
@Test
public void shouldThrowInconsistentKeySchemaTypeExceptionWithOverrideSchema() {
// Given:
final SchemaAndId schemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='PROTOBUF', " + "value_format='JSON', " + "key_schema_id=1, " + "partitions=1" + ");", Pair.of(schemaAndId, null));
// When:
final Exception e = assertThrows(KsqlStatementException.class, () -> injector.inject(statement));
// Then:
assertThat(e.getMessage(), containsString("Format and fetched schema type using " + "KEY_SCHEMA_ID 1 are different. Format: [PROTOBUF], Fetched schema type: [AVRO]."));
}
use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaAndId in project ksql by confluentinc.
the class SchemaRegisterInjectorTest method shouldThrowInconsistentValueSchemaTypeExceptionWithOverrideSchema.
@Test
public void shouldThrowInconsistentValueSchemaTypeExceptionWithOverrideSchema() {
// Given:
final SchemaAndId schemaAndId = SchemaAndId.schemaAndId(SCHEMA.value(), AVRO_SCHEMA, 1);
givenStatement("CREATE STREAM source (id int key, f1 varchar) " + "WITH (" + "kafka_topic='expectedName', " + "key_format='PROTOBUF', " + "value_format='PROTOBUF', " + "value_schema_id=1, " + "partitions=1" + ");", Pair.of(null, schemaAndId));
// When:
final Exception e = assertThrows(KsqlStatementException.class, () -> injector.inject(statement));
// Then:
assertThat(e.getMessage(), containsString("Format and fetched schema type using " + "VALUE_SCHEMA_ID 1 are different. Format: [PROTOBUF], Fetched schema type: [AVRO]."));
}
Aggregations