use of io.confluent.kafka.schemaregistry.client.SchemaRegistryClient in project beam by apache.
the class ConfluentSchemaRegistryDeserializerProviderTest method testGetCoder.
@Test
public void testGetCoder() {
String schemaRegistryUrl = "mock://my-scope-name";
String subject = "mytopic";
SchemaRegistryClient mockRegistryClient = mockSchemaRegistryClient(schemaRegistryUrl, subject);
CoderRegistry coderRegistry = CoderRegistry.createDefault();
AvroCoder coderV0 = (AvroCoder) mockDeserializerProvider(schemaRegistryUrl, subject, null).getCoder(coderRegistry);
assertEquals(AVRO_SCHEMA, coderV0.getSchema());
try {
Integer version = mockRegistryClient.getVersion(subject, AVRO_SCHEMA_V1);
AvroCoder coderV1 = (AvroCoder) mockDeserializerProvider(schemaRegistryUrl, subject, version).getCoder(coderRegistry);
assertEquals(AVRO_SCHEMA_V1, coderV1.getSchema());
} catch (IOException | RestClientException e) {
throw new RuntimeException("Unable to register schema for subject: " + subject, e);
}
}
use of io.confluent.kafka.schemaregistry.client.SchemaRegistryClient in project ksql by confluentinc.
the class AvroUtilTest method shouldValidatePersistentQueryResultCorrectly.
@Test
public void shouldValidatePersistentQueryResultCorrectly() throws IOException, RestClientException {
SchemaRegistryClient schemaRegistryClient = mock(SchemaRegistryClient.class);
KsqlTopic resultTopic = new KsqlTopic("testTopic", "testTopic", new KsqlAvroTopicSerDe());
Schema resultSchema = SerDeUtil.getSchemaFromAvro(ordersAveroSchemaStr);
PersistentQueryMetadata persistentQueryMetadata = new PersistentQueryMetadata("", null, null, "", null, DataSource.DataSourceType.KSTREAM, "", mock(KafkaTopicClient.class), resultSchema, resultTopic, null);
org.apache.avro.Schema.Parser parser = new org.apache.avro.Schema.Parser();
org.apache.avro.Schema avroSchema = parser.parse(ordersAveroSchemaStr);
expect(schemaRegistryClient.testCompatibility(anyString(), EasyMock.isA(avroSchema.getClass()))).andReturn(true);
replay(schemaRegistryClient);
avroUtil.validatePersistentQueryResults(persistentQueryMetadata, schemaRegistryClient);
}
use of io.confluent.kafka.schemaregistry.client.SchemaRegistryClient in project ksql by confluentinc.
the class AvroUtilTest method shouldNotPassAvroCheckIfSchemaDoesNotExist.
@Test
public void shouldNotPassAvroCheckIfSchemaDoesNotExist() throws Exception {
SchemaRegistryClient schemaRegistryClient = mock(SchemaRegistryClient.class);
SchemaMetadata schemaMetadata = new SchemaMetadata(1, 1, null);
expect(schemaRegistryClient.getLatestSchemaMetadata(anyString())).andReturn(schemaMetadata);
replay(schemaRegistryClient);
AbstractStreamCreateStatement abstractStreamCreateStatement = getAbstractStreamCreateStatement("CREATE STREAM S1 WITH " + "(kafka_topic='s1_topic', " + "value_format='avro' );");
try {
avroUtil.checkAndSetAvroSchema(abstractStreamCreateStatement, new HashMap<>(), schemaRegistryClient);
fail();
} catch (Exception e) {
assertThat("Expected different message message.", e.getMessage(), equalTo(" Could not " + "fetch the AVRO schema " + "from schema registry. null "));
}
}
use of io.confluent.kafka.schemaregistry.client.SchemaRegistryClient in project ksql by confluentinc.
the class SchemaKStream method groupBy.
public SchemaKGroupedStream groupBy(final Serde<String> keySerde, final Serde<GenericRow> valSerde, final List<Expression> groupByExpressions) {
boolean rekey = rekeyRequired(groupByExpressions);
if (!rekey) {
KGroupedStream kgroupedStream = kstream.groupByKey(Serialized.with(keySerde, valSerde));
return new SchemaKGroupedStream(schema, kgroupedStream, keyField, Collections.singletonList(this), functionRegistry, schemaRegistryClient);
}
// Collect the column indexes, and build the new key as <column1>+<column2>+...
StringBuilder aggregateKeyName = new StringBuilder();
List<Integer> newKeyIndexes = new ArrayList<>();
boolean addSeparator = false;
for (Expression groupByExpr : groupByExpressions) {
if (addSeparator) {
aggregateKeyName.append("|+|");
} else {
addSeparator = true;
}
aggregateKeyName.append(groupByExpr.toString());
newKeyIndexes.add(SchemaUtil.getIndexInSchema(groupByExpr.toString(), getSchema()));
}
KGroupedStream kgroupedStream = kstream.filter((key, value) -> value != null).groupBy((key, value) -> {
StringBuilder newKey = new StringBuilder();
boolean addSeparator1 = false;
for (int index : newKeyIndexes) {
if (addSeparator1) {
newKey.append("|+|");
} else {
addSeparator1 = true;
}
newKey.append(String.valueOf(value.getColumns().get(index)));
}
return newKey.toString();
}, Serialized.with(keySerde, valSerde));
// TODO: if the key is a prefix of the grouping columns then we can
// use the repartition reflection hack to tell streams not to
// repartition.
Field newKeyField = new Field(aggregateKeyName.toString(), -1, Schema.STRING_SCHEMA);
return new SchemaKGroupedStream(schema, kgroupedStream, newKeyField, Collections.singletonList(this), functionRegistry, schemaRegistryClient);
}
use of io.confluent.kafka.schemaregistry.client.SchemaRegistryClient in project ksql by confluentinc.
the class KsqlResourceTest method setUp.
@Before
public void setUp() throws IOException, RestClientException {
SchemaRegistryClient schemaRegistryClient = new MockSchemaRegistryClient();
registerSchema(schemaRegistryClient);
ksqlRestConfig = new KsqlRestConfig(TestKsqlResourceUtil.getDefaultKsqlConfig());
KsqlConfig ksqlConfig = new KsqlConfig(ksqlRestConfig.getKsqlConfigProperties());
ksqlEngine = new KsqlEngine(ksqlConfig, new MockKafkaTopicClient(), schemaRegistryClient, new MetaStoreImpl());
}
Aggregations