Search in sources :

Example 11 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method shouldReturnSchemaFromGetValueSchemaIfFound.

@Test
public void shouldReturnSchemaFromGetValueSchemaIfFound() {
    // When:
    final SchemaResult result = supplier.getValueSchema(Optional.of(TOPIC_NAME), Optional.empty(), expectedFormat, SerdeFeatures.of());
    // Then:
    assertThat(result.schemaAndId, is(not(Optional.empty())));
    assertThat(result.schemaAndId.get().id, is(SCHEMA_ID));
    assertThat(result.schemaAndId.get().columns, is(ImmutableList.of(column1)));
}
Also used : SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Test(org.junit.Test)

Example 12 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method shouldReturnErrorFromGetKeySchemaOnMultipleColumns.

@Test
public void shouldReturnErrorFromGetKeySchemaOnMultipleColumns() {
    // Given:
    when(schemaTranslator.toColumns(parsedSchema, SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES), true)).thenReturn(ImmutableList.of(column1, column2));
    // When:
    final SchemaResult result = supplier.getKeySchema(Optional.of(TOPIC_NAME), Optional.empty(), expectedFormat, SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES));
    // Then:
    assertThat(result.schemaAndId, is(Optional.empty()));
    assertThat(result.failureReason.get().getMessage(), containsString("The key schema for topic: some-topic contains multiple columns, " + "which is not supported by ksqlDB at this time."));
    assertThat(result.failureReason.get().getMessage(), containsString(AVRO_SCHEMA));
}
Also used : SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Test(org.junit.Test)

Example 13 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method verifyFailureMessage.

private void verifyFailureMessage(final SchemaResult result, final boolean isKey, Optional<Integer> id) {
    final String keyOrValue = isKey ? "keys" : "values";
    final String keyOrValueSuffix = isKey ? "key" : "value";
    final String schemaIdMsg = id.map(integer -> "Schema Id: " + integer + System.lineSeparator()).orElse("");
    assertThat(result.failureReason.get().getMessage(), is("Schema for message " + keyOrValue + " on topic '" + TOPIC_NAME + "' does not exist in the Schema Registry." + System.lineSeparator() + "Subject: " + TOPIC_NAME + "-" + keyOrValueSuffix + System.lineSeparator() + schemaIdMsg + "Possible causes include:" + System.lineSeparator() + "- The topic itself does not exist" + System.lineSeparator() + "\t-> Use SHOW TOPICS; to check" + System.lineSeparator() + "- Messages on the topic are not serialized using a format Schema Registry supports" + System.lineSeparator() + "\t-> Use PRINT '" + TOPIC_NAME + "' FROM BEGINNING; to verify" + System.lineSeparator() + "- Messages on the topic have not been serialized using a Confluent Schema Registry supported serializer" + System.lineSeparator() + "\t-> See https://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html" + System.lineSeparator() + "- The schema is registered on a different instance of the Schema Registry" + System.lineSeparator() + "\t-> Use the REST API to list available subjects\thttps://docs.confluent.io/current/schema-registry/docs/api.html#get--subjects" + System.lineSeparator() + "- You do not have permissions to access the Schema Registry." + System.lineSeparator() + "\t-> See https://docs.confluent.io/current/schema-registry/docs/security.html"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ProtobufSchema(io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) Matchers.not(org.hamcrest.Matchers.not) RunWith(org.junit.runner.RunWith) HttpStatus(org.apache.http.HttpStatus) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) ImmutableList(com.google.common.collect.ImmutableList) SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Map(java.util.Map) SimpleColumn(io.confluent.ksql.schema.ksql.SimpleColumn) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) SerdeFeature(io.confluent.ksql.serde.SerdeFeature) SchemaTranslator(io.confluent.ksql.serde.SchemaTranslator) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Mockito.verify(org.mockito.Mockito.verify) Format(io.confluent.ksql.serde.Format) KsqlException(io.confluent.ksql.util.KsqlException) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) SchemaMetadata(io.confluent.kafka.schemaregistry.client.SchemaMetadata) FormatInfo(io.confluent.ksql.serde.FormatInfo) Matchers.containsString(org.hamcrest.Matchers.containsString) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 14 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method shouldReturnErrorFromGetKeySchemaIfCanNotConvertToConnectSchema.

@Test
public void shouldReturnErrorFromGetKeySchemaIfCanNotConvertToConnectSchema() {
    // Given:
    when(schemaTranslator.toColumns(any(), any(), anyBoolean())).thenThrow(new RuntimeException("it went boom"));
    // When:
    final SchemaResult result = supplier.getKeySchema(Optional.of(TOPIC_NAME), Optional.empty(), expectedFormat, SerdeFeatures.of(SerdeFeature.UNWRAP_SINGLES));
    // Then:
    assertThat(result.schemaAndId, is(Optional.empty()));
    assertThat(result.failureReason.get().getMessage(), containsString("Unable to verify if the key schema for topic: some-topic is compatible with ksqlDB."));
    assertThat(result.failureReason.get().getMessage(), containsString("it went boom"));
    assertThat(result.failureReason.get().getMessage(), containsString(AVRO_SCHEMA));
}
Also used : SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Test(org.junit.Test)

Example 15 with SchemaResult

use of io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult in project ksql by confluentinc.

the class SchemaRegistryTopicSchemaSupplierTest method shouldReturnErrorFromGetValueSchemaIfCanNotConvertToConnectSchema.

@Test
public void shouldReturnErrorFromGetValueSchemaIfCanNotConvertToConnectSchema() {
    // Given:
    when(schemaTranslator.toColumns(any(), any(), anyBoolean())).thenThrow(new RuntimeException("it went boom"));
    // When:
    final SchemaResult result = supplier.getValueSchema(Optional.of(TOPIC_NAME), Optional.empty(), expectedFormat, SerdeFeatures.of());
    // Then:
    assertThat(result.schemaAndId, is(Optional.empty()));
    assertThat(result.failureReason.get().getMessage(), containsString("Unable to verify if the value schema for topic: some-topic is compatible with ksqlDB."));
    assertThat(result.failureReason.get().getMessage(), containsString("it went boom"));
    assertThat(result.failureReason.get().getMessage(), containsString(AVRO_SCHEMA));
}
Also used : SchemaResult(io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult) Test(org.junit.Test)

Aggregations

SchemaResult (io.confluent.ksql.schema.ksql.inference.TopicSchemaSupplier.SchemaResult)16 Test (org.junit.Test)16 ImmutableList (com.google.common.collect.ImmutableList)1 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)1 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)1 SchemaMetadata (io.confluent.kafka.schemaregistry.client.SchemaMetadata)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)1 ProtobufSchema (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchema)1 SimpleColumn (io.confluent.ksql.schema.ksql.SimpleColumn)1 Format (io.confluent.ksql.serde.Format)1 FormatInfo (io.confluent.ksql.serde.FormatInfo)1 SchemaTranslator (io.confluent.ksql.serde.SchemaTranslator)1 SerdeFeature (io.confluent.ksql.serde.SerdeFeature)1 SerdeFeatures (io.confluent.ksql.serde.SerdeFeatures)1 KsqlException (io.confluent.ksql.util.KsqlException)1 IOException (java.io.IOException)1 Map (java.util.Map)1 Optional (java.util.Optional)1 HttpStatus (org.apache.http.HttpStatus)1