Java Code Examples for io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException

The following examples show how to use io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: kafka-tutorials   Author: confluentinc   File: FindDistinctEventsTest.java    License: Apache License 2.0 7 votes vote down vote up
private static SpecificAvroSerde<Click> makeSerializer(Properties envProps)
    throws IOException, RestClientException {

  final MockSchemaRegistryClient client = new MockSchemaRegistryClient();
  String inputTopic = envProps.getProperty("input.topic.name");
  String outputTopic = envProps.getProperty("output.topic.name");

  final Schema schema = Click.SCHEMA$;
  client.register(inputTopic + "-value", schema);
  client.register(outputTopic + "-value", schema);

  SpecificAvroSerde<Click> serde = new SpecificAvroSerde<>(client);

  Map<String, String> config = new HashMap<>();
  config.put("schema.registry.url", envProps.getProperty("schema.registry.url"));
  serde.configure(config, false);

  return serde;
}
 
Example #2
Source Project: kafka-tutorials   Author: confluentinc   File: AggregatingCountTest.java    License: Apache License 2.0 7 votes vote down vote up
private SpecificAvroSerde<TicketSale> makeSerializer(Properties envProps)
    throws IOException, RestClientException {

  final MockSchemaRegistryClient client = new MockSchemaRegistryClient();
  String inputTopic = envProps.getProperty("input.topic.name");
  String outputTopic = envProps.getProperty("output.topic.name");

  final Schema schema = TicketSale.SCHEMA$;
  client.register(inputTopic + "-value", schema);
  client.register(outputTopic + "-value", schema);

  SpecificAvroSerde<TicketSale> serde = new SpecificAvroSerde<>(client);

  Map<String, String> config = new HashMap<>();
  config.put("schema.registry.url", envProps.getProperty("schema.registry.url"));
  serde.configure(config, false);

  return serde;
}
 
Example #3
Source Project: apicurio-registry   Author: Apicurio   File: ConfluentBaseIT.java    License: Apache License 2.0 6 votes vote down vote up
public int createArtifactViaConfluentClient(Schema schema, String artifactName) throws IOException, RestClientException, TimeoutException {
    int idOfSchema = confluentService.register(artifactName, schema);
    confluentService.reset(); // clear cache
    TestUtils.waitFor("Wait until artifact globalID mapping is finished", Constants.POLL_INTERVAL, Constants.TIMEOUT_GLOBAL,
        () -> {
            try {
                Schema newSchema = confluentService.getBySubjectAndId(artifactName, idOfSchema);
                LOGGER.info("Checking that created schema is equal to the get schema");
                assertThat(schema.toString(), is(newSchema.toString()));
                assertThat(confluentService.getVersion(artifactName, schema), is(confluentService.getVersion(artifactName, newSchema)));
                LOGGER.info("Created schema with id:{} and name:{}", idOfSchema, newSchema.getFullName());
                return true;
            } catch (IOException | RestClientException e) {
                LOGGER.debug("", e);
                return false;
            }
        });
    return idOfSchema;
}
 
Example #4
Source Project: apicurio-registry   Author: Apicurio   File: SchemasConfluentIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void createAndDeleteMultipleSchemas() throws IOException, RestClientException, TimeoutException {
    String prefix = TestUtils.generateArtifactId();

    for (int i = 0; i < 50; i++) {
        String name = "myrecord" + i;
        String subjectName = prefix + i;
        Schema schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"" + name + "\",\"fields\":[{\"name\":\"foo\",\"type\":\"string\"}]}");
        createArtifactViaConfluentClient(schema, subjectName);
    }

    assertThat(50, is(confluentService.getAllSubjects().size()));
    LOGGER.info("All subjects {} schemas", confluentService.getAllSubjects().size());

    for (int i = 0; i < 50; i++) {
        confluentService.deleteSubject(prefix + i);
    }

    TestUtils.waitFor("all schemas deletion", Constants.POLL_INTERVAL, Constants.TIMEOUT_GLOBAL, () -> {
        try {
            return confluentService.getAllSubjects().size() == 0;
        } catch (IOException | RestClientException e) {
            return false;
        }
    });
}
 
Example #5
Source Project: apicurio-registry   Author: Apicurio   File: MetadataConfluentIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void getAndUpdateMetadataOfSchema() throws IOException, RestClientException, TimeoutException {
    Schema schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"myrecord1\",\"fields\":[{\"name\":\"foo\",\"type\":\"string\"}]}");
    String schemaSubject = TestUtils.generateArtifactId();

    int schemaId = createArtifactViaConfluentClient(schema, schemaSubject);

    schema = confluentService.getById(schemaId);
    SchemaMetadata schemaMetadata = confluentService.getSchemaMetadata(schemaSubject, 1);

    LOGGER.info("Scheme name: {} has following metadata: {}", schema.getFullName(), schemaMetadata.getSchema());

    assertThat(schemaMetadata.getId(), is(schemaId));
    assertThat(schemaMetadata.getVersion(), is(1));
    assertThat("{\"type\":\"record\",\"name\":\"myrecord1\",\"fields\":[{\"name\":\"foo\",\"type\":\"string\"}]}", is(schemaMetadata.getSchema()));
    // IMPORTANT NOTE: we can not test schema metadata, because they are mapping on the same endpoint when we are creating the schema...
}
 
Example #6
Source Project: apicurio-registry   Author: Apicurio   File: BasicConfluentSerDesIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
void testAvroConfluentForMultipleTopics() throws InterruptedException, ExecutionException, TimeoutException, IOException, RestClientException {
    String topicName1 = TestUtils.generateTopic();
    String topicName2 = TestUtils.generateTopic();
    String topicName3 = TestUtils.generateTopic();
    String subjectName = "myrecordconfluent6";
    String schemaKey = "key1";

    kafkaCluster.createTopic(topicName1, 1, 1);
    kafkaCluster.createTopic(topicName2, 1, 1);
    kafkaCluster.createTopic(topicName3, 1, 1);

    Schema schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"" + subjectName + "\",\"fields\":[{\"name\":\"" + schemaKey + "\",\"type\":\"string\"}]}");
    createArtifactViaConfluentClient(schema, subjectName);

    KafkaClients.produceAvroApicurioMessagesRecordStrategy(topicName1, subjectName, schema, 10, schemaKey).get(5, TimeUnit.SECONDS);
    KafkaClients.produceAvroApicurioMessagesRecordStrategy(topicName2, subjectName, schema, 10, schemaKey).get(5, TimeUnit.SECONDS);
    KafkaClients.produceAvroApicurioMessagesRecordStrategy(topicName3, subjectName, schema, 10, schemaKey).get(5, TimeUnit.SECONDS);

    KafkaClients.consumeAvroApicurioMessages(topicName1, 10).get(5, TimeUnit.SECONDS);
    KafkaClients.consumeAvroApicurioMessages(topicName2, 10).get(5, TimeUnit.SECONDS);
    KafkaClients.consumeAvroApicurioMessages(topicName3, 10).get(5, TimeUnit.SECONDS);
}
 
Example #7
Source Project: Flink-CEPplus   Author: ljygz   File: ConfluentSchemaRegistryCoder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Schema readSchema(InputStream in) throws IOException {
	DataInputStream dataInputStream = new DataInputStream(in);

	if (dataInputStream.readByte() != 0) {
		throw new IOException("Unknown data format. Magic number does not match");
	} else {
		int schemaId = dataInputStream.readInt();

		try {
			return schemaRegistryClient.getById(schemaId);
		} catch (RestClientException e) {
			throw new IOException(format("Could not find schema with id %s in registry", schemaId), e);
		}
	}
}
 
Example #8
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMock.java    License: MIT License 6 votes vote down vote up
private int register(final String subject, final Schema schema) {
    try {
        final int id = this.schemaRegistryClient.register(subject, schema);
        this.mockSchemaRegistry.stubFor(WireMock.get(getSchemaPattern(id))
                .withQueryParam("fetchMaxId", WireMock.matching("false|true"))
                .willReturn(ResponseDefinitionBuilder.okForJson(new SchemaString(schema.toString()))));
        this.mockSchemaRegistry.stubFor(WireMock.delete(getSubjectPattern(subject))
                .willReturn(WireMock.aResponse().withTransformers(this.deleteSubjectHandler.getName())));
        this.mockSchemaRegistry.stubFor(WireMock.get(getSubjectVersionsPattern(subject))
                .willReturn(WireMock.aResponse().withTransformers(this.listVersionsHandler.getName())));
        this.mockSchemaRegistry.stubFor(WireMock.get(getSubjectVersionPattern(subject))
                .willReturn(WireMock.aResponse().withTransformers(this.getVersionHandler.getName())));
        log.debug("Registered schema {}", id);
        return id;
    } catch (final IOException | RestClientException e) {
        throw new IllegalStateException("Internal error in mock schema registry client", e);
    }
}
 
Example #9
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockTest.java    License: MIT License 6 votes vote down vote up
@Test
void shouldHaveLatestSchemaVersion() throws IOException, RestClientException {
    final Schema valueSchema1 = createSchema("value_schema");
    final String topic = "test-topic";
    final int id1 = this.schemaRegistry.registerValueSchema(topic, valueSchema1);

    final List<Schema.Field> fields = Collections.singletonList(
            new Schema.Field("f1", Schema.create(Schema.Type.STRING), "", (Object) null));
    final Schema valueSchema2 = Schema.createRecord("value_schema", "no doc", "", false, fields);
    final int id2 = this.schemaRegistry.registerValueSchema(topic, valueSchema2);

    final List<Integer> versions = this.schemaRegistry.getSchemaRegistryClient().getAllVersions(topic + "-value");
    assertThat(versions.size()).isEqualTo(2);

    final SchemaMetadata metadata = this.schemaRegistry.getSchemaRegistryClient().getLatestSchemaMetadata(topic + "-value");
    final int metadataId = metadata.getId();
    assertThat(metadataId).isNotEqualTo(id1);
    assertThat(metadataId).isEqualTo(id2);
    final String schemaString = metadata.getSchema();
    final Schema retrievedSchema = new Schema.Parser().parse(schemaString);
    assertThat(retrievedSchema).isEqualTo(valueSchema2);
}
 
Example #10
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockTest.java    License: MIT License 6 votes vote down vote up
@Test
void shouldNotHaveSchemaVersionsForDeletedSubject() throws IOException, RestClientException {
    final Schema valueSchema = createSchema("value_schema");
    final String topic = "test-topic";
    final int id = this.schemaRegistry.registerValueSchema(topic, valueSchema);

    final List<Integer> versions = this.schemaRegistry.getSchemaRegistryClient().getAllVersions(topic + "-value");
    assertThat(versions.size()).isOne();

    final SchemaMetadata metadata = this.schemaRegistry.getSchemaRegistryClient().getSchemaMetadata(topic + "-value", versions.get(0));
    assertThat(metadata.getId()).isEqualTo(id);
    assertThat(this.schemaRegistry.getSchemaRegistryClient().getLatestSchemaMetadata(topic + "-value"))
            .isNotNull();
    this.schemaRegistry.deleteValueSchema(topic);
    assertThatExceptionOfType(RestClientException.class)
            .isThrownBy(() -> this.schemaRegistry.getSchemaRegistryClient().getAllVersions(topic + "-value"))
            .satisfies(e -> assertThat(e.getStatus()).isEqualTo(HTTP_NOT_FOUND));
    assertThatExceptionOfType(RestClientException.class)
            .isThrownBy(() -> this.schemaRegistry.getSchemaRegistryClient().getSchemaMetadata(topic + "-value", versions.get(0)))
            .satisfies(e -> assertThat(e.getStatus()).isEqualTo(HTTP_NOT_FOUND));
    assertThatExceptionOfType(RestClientException.class)
            .isThrownBy(() -> this.schemaRegistry.getSchemaRegistryClient().getLatestSchemaMetadata(topic + "-value"))
            .satisfies(e -> assertThat(e.getStatus()).isEqualTo(HTTP_NOT_FOUND));
}
 
Example #11
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockExtensionTest.java    License: MIT License 6 votes vote down vote up
@Test
void shouldHaveSchemaVersions() throws IOException, RestClientException {
    final Schema valueSchema = this.createSchema("value_schema");
    final String topic = "test-topic";
    final int id = this.schemaRegistry.registerValueSchema(topic, valueSchema);

    final List<Integer> versions = this.schemaRegistry.getSchemaRegistryClient().getAllVersions(topic + "-value");
    assertThat(versions.size()).isOne();

    final SchemaMetadata metadata =
            this.schemaRegistry.getSchemaRegistryClient().getSchemaMetadata(topic + "-value", versions.get(0));
    assertThat(metadata.getId()).isEqualTo(id);
    final String schemaString = metadata.getSchema();
    final Schema retrievedSchema = new Schema.Parser().parse(schemaString);
    assertThat(retrievedSchema).isEqualTo(valueSchema);
}
 
Example #12
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockExtensionTest.java    License: MIT License 6 votes vote down vote up
@Test
void shouldHaveLatestSchemaVersion() throws IOException, RestClientException {
    final Schema valueSchema1 = this.createSchema("value_schema");
    final String topic = "test-topic";
    final int id1 = this.schemaRegistry.registerValueSchema(topic, valueSchema1);

    final List<Schema.Field> fields = Collections.singletonList(
            new Schema.Field("f1", Schema.create(Schema.Type.STRING), "", (Object) null));
    final Schema valueSchema2 = Schema.createRecord("value_schema", "no doc", "", false, fields);
    final int id2 = this.schemaRegistry.registerValueSchema(topic, valueSchema2);

    final List<Integer> versions = this.schemaRegistry.getSchemaRegistryClient().getAllVersions(topic + "-value");
    assertThat(versions.size()).isEqualTo(2);

    final SchemaMetadata metadata =
            this.schemaRegistry.getSchemaRegistryClient().getLatestSchemaMetadata(topic + "-value");
    final int metadataId = metadata.getId();
    assertThat(metadataId).isNotEqualTo(id1);
    assertThat(metadataId).isEqualTo(id2);
    final String schemaString = metadata.getSchema();
    final Schema retrievedSchema = new Schema.Parser().parse(schemaString);
    assertThat(retrievedSchema).isEqualTo(valueSchema2);
}
 
Example #13
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockRuleTest.java    License: MIT License 6 votes vote down vote up
@Test
public void shouldHaveSchemaVersions() throws IOException, RestClientException {
    final Schema valueSchema = this.createSchema("value_schema");
    final String topic = "test-topic";
    final int id = this.schemaRegistry.registerValueSchema(topic, valueSchema);

    final List<Integer> versions = this.schemaRegistry.getSchemaRegistryClient().getAllVersions(topic + "-value");
    assertThat(versions.size()).isOne();

    final SchemaMetadata metadata =
            this.schemaRegistry.getSchemaRegistryClient().getSchemaMetadata(topic + "-value", versions.get(0));
    assertThat(metadata.getId()).isEqualTo(id);
    final String schemaString = metadata.getSchema();
    final Schema retrievedSchema = new Schema.Parser().parse(schemaString);
    assertThat(retrievedSchema).isEqualTo(valueSchema);
}
 
Example #14
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockRuleTest.java    License: MIT License 6 votes vote down vote up
@Test
public void shouldHaveLatestSchemaVersion() throws IOException, RestClientException {
    final Schema valueSchema1 = this.createSchema("value_schema");
    final String topic = "test-topic";
    final int id1 = this.schemaRegistry.registerValueSchema(topic, valueSchema1);

    final List<Schema.Field> fields = Collections.singletonList(
            new Schema.Field("f1", Schema.create(Schema.Type.STRING), "", (Object) null));
    final Schema valueSchema2 = Schema.createRecord("value_schema", "no doc", "", false, fields);
    final int id2 = this.schemaRegistry.registerValueSchema(topic, valueSchema2);

    final List<Integer> versions = this.schemaRegistry.getSchemaRegistryClient().getAllVersions(topic + "-value");
    assertThat(versions.size()).isEqualTo(2);

    final SchemaMetadata metadata =
            this.schemaRegistry.getSchemaRegistryClient().getLatestSchemaMetadata(topic + "-value");
    final int metadataId = metadata.getId();
    assertThat(metadataId).isNotEqualTo(id1);
    assertThat(metadataId).isEqualTo(id2);
    final String schemaString = metadata.getSchema();
    final Schema retrievedSchema = new Schema.Parser().parse(schemaString);
    assertThat(retrievedSchema).isEqualTo(valueSchema2);
}
 
Example #15
Source Project: kafka-tutorials   Author: confluentinc   File: StreamsIngestTest.java    License: Apache License 2.0 6 votes vote down vote up
private SpecificAvroSerde<City> makeSerializer(Properties envProps)
    throws IOException, RestClientException {

  final MockSchemaRegistryClient client = new MockSchemaRegistryClient();
  String inputTopic = envProps.getProperty("input.topic.name");
  String outputTopic = envProps.getProperty("output.topic.name");

  final Schema schema = City.SCHEMA$;
  client.register(inputTopic + "-value", schema);
  client.register(outputTopic + "-value", schema);

  SpecificAvroSerde<City> serde = new SpecificAvroSerde<>(client);

  Map<String, String> config = new HashMap<>();
  config.put("schema.registry.url", envProps.getProperty("schema.registry.url"));
  serde.configure(config, false);

  return serde;
}
 
Example #16
Source Project: kafka-tutorials   Author: confluentinc   File: SchemaPublication.java    License: Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        Config config = ConfigFactory.load();

        String registryUrl = config.getString("schema.registry.url");

        CachedSchemaRegistryClient schemaRegistryClient  = new CachedSchemaRegistryClient(registryUrl, 10);

        try {
            logger.info(String.format("Schemas publication at: %s", registryUrl));

            schemaRegistryClient.register(
                    String.format("%s-value", config.getString("input.topic.name")),
                    PressureAlert.SCHEMA$
            );
        } catch (IOException | RestClientException e) {
            e.printStackTrace();
        }
    }
 
Example #17
Source Project: flink   Author: flink-tpc-ds   File: ConfluentSchemaRegistryCoder.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Schema readSchema(InputStream in) throws IOException {
	DataInputStream dataInputStream = new DataInputStream(in);

	if (dataInputStream.readByte() != 0) {
		throw new IOException("Unknown data format. Magic number does not match");
	} else {
		int schemaId = dataInputStream.readInt();

		try {
			return schemaRegistryClient.getById(schemaId);
		} catch (RestClientException e) {
			throw new IOException(format("Could not find schema with id %s in registry", schemaId), e);
		}
	}
}
 
Example #18
Source Project: apicurio-registry   Author: Apicurio   File: SchemasConfluentIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void deleteSchemasSpecificVersion() throws Exception {
    String artifactId = TestUtils.generateArtifactId();

    Schema schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"mynewrecord\",\"fields\":[{\"name\":\"foo\",\"type\":\"string\"}]}");
    createArtifactViaConfluentClient(schema, artifactId);
    schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"myrecordx\",\"fields\":[{\"name\":\"foo1\",\"type\":\"string\"}]}");
    createArtifactViaConfluentClient(schema, artifactId);

    List<Integer> schemeVersions = confluentService.getAllVersions(artifactId);

    LOGGER.info("Available version of schema with name:{} are {}", artifactId, schemeVersions);
    assertThat(schemeVersions, hasItems(1, 2));

    schemeVersions = confluentService.getAllVersions(artifactId);

    LOGGER.info("Available version of schema with name:{} are {}", artifactId, schemeVersions);
    assertThat(schemeVersions, hasItems(1));

    schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"myrecordx\",\"fields\":[{\"name\":\"foo" + 4 + "\",\"type\":\"string\"}]}");
    createArtifactViaConfluentClient(schema, artifactId);

    confluentService.deleteSchemaVersion(artifactId, "2");

    TestUtils.waitFor("all specific schema version deletion", Constants.POLL_INTERVAL, Constants.TIMEOUT_GLOBAL, () -> {
        try {
            return confluentService.getAllVersions(artifactId).size() == 2;
        } catch (IOException | RestClientException e) {
            return false;
        }
    });

    schemeVersions = confluentService.getAllVersions(artifactId);

    LOGGER.info("Available version of schema with name:{} are {}", artifactId, schemeVersions);
    assertThat(schemeVersions, hasItems(1, 3));

    confluentService.deleteSubject(artifactId);
    waitForSubjectDeleted(artifactId);
}
 
Example #19
Source Project: apicurio-registry   Author: Apicurio   File: BasicConfluentSerDesIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testAvroConfluentSerDes() throws IOException, RestClientException, InterruptedException, ExecutionException, TimeoutException {
    String topicName = TestUtils.generateTopic();
    String subjectName = topicName + "-value";
    String schemaKey = "key1";
    kafkaCluster.createTopic(topicName, 1, 1);

    Schema schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"myrecordconfluent1\",\"fields\":[{\"name\":\"" + schemaKey + "\",\"type\":\"string\"}]}");
    createArtifactViaConfluentClient(schema, subjectName);

    KafkaClients.produceAvroConfluentMessagesTopicStrategy(topicName, subjectName, schema, 10, schemaKey).get(5, TimeUnit.SECONDS);
    KafkaClients.consumeAvroConfluentMessages(topicName, 10).get(5, TimeUnit.SECONDS);
}
 
Example #20
Source Project: apicurio-registry   Author: Apicurio   File: BasicConfluentSerDesIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testAvroConfluentSerDesFail() throws IOException, RestClientException, TimeoutException {
    String topicName = TestUtils.generateTopic();
    String subjectName = "myrecordconfluent2";
    String schemaKey = "key1";
    kafkaCluster.createTopic(topicName, 1, 1);

    Schema schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"" + subjectName + "\",\"fields\":[{\"name\":\"" + schemaKey + "\",\"type\":\"string\"}]}");
    createArtifactViaConfluentClient(schema, subjectName);

    assertThrows(ExecutionException.class, () -> KafkaClients.produceAvroConfluentMessagesRecordStrategy(topicName, subjectName, schema, 10, "wrong-key").get(5, TimeUnit.SECONDS));
}
 
Example #21
Source Project: apicurio-registry   Author: Apicurio   File: BasicConfluentSerDesIT.java    License: Apache License 2.0 5 votes vote down vote up
@Test
void testAvroConfluentSerDesWrongStrategyTopic() throws IOException, RestClientException, TimeoutException {
    String topicName = TestUtils.generateTopic();
    String subjectName = "myrecordconfluent3";
    String schemaKey = "key1";
    kafkaCluster.createTopic(topicName, 1, 1);

    Schema schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"" + subjectName + "\",\"fields\":[{\"name\":\"" + schemaKey + "\",\"type\":\"string\"}]}");
    createArtifactViaConfluentClient(schema, subjectName);

    assertThrows(ExecutionException.class, () -> KafkaClients.produceAvroConfluentMessagesTopicStrategy(topicName, subjectName, schema, 10, "wrong-key").get(5, TimeUnit.SECONDS));
}
 
Example #22
Source Project: apicurio-registry   Author: Apicurio   File: BasicConfluentSerDesIT.java    License: Apache License 2.0 5 votes vote down vote up
@RegistryServiceTest(localOnly = false)
void testEvolveAvroConfluent(RegistryService service) throws InterruptedException, ExecutionException, TimeoutException, IOException, RestClientException {
    String topicName = TestUtils.generateTopic();
    String recordName = "myrecordconfluent5";
    String subjectName = topicName + "-" + recordName;
    String schemaKey = "key1";
    kafkaCluster.createTopic(topicName, 1, 1);

    Schema schema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"" + recordName + "\",\"fields\":[{\"name\":\"" + schemaKey + "\",\"type\":\"string\"}]}");
    createArtifactViaConfluentClient(schema, subjectName);

    KafkaClients.produceAvroConfluentMessagesTopicRecordStrategy(topicName, subjectName, schema, 10, schemaKey).get(5, TimeUnit.SECONDS);
    KafkaClients.consumeAvroConfluentMessages(topicName, 10).get(5, TimeUnit.SECONDS);

    String schemaKey2 = "key2";
    Schema schema2 = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"" + recordName + "\",\"fields\":[{\"name\":\"" + schemaKey + "\",\"type\":\"string\"},{\"name\":\"" + schemaKey2 + "\",\"type\":\"string\"}]}");
    updateArtifactViaApicurioClient(service, schema2, subjectName);

    KafkaClients.produceAvroConfluentMessagesTopicRecordStrategy(topicName, subjectName, schema2, 10, schemaKey, schemaKey2).get(5, TimeUnit.SECONDS);
    KafkaClients.produceAvroConfluentMessagesTopicRecordStrategy(topicName, subjectName, schema, 10, schemaKey).get(5, TimeUnit.SECONDS);
    KafkaClients.consumeAvroConfluentMessages(topicName, 20).get(5, TimeUnit.SECONDS);

    String schemaKey3 = "key3";
    Schema schema3 = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"" + recordName +  "\",\"fields\":[{\"name\":\"" + schemaKey + "\",\"type\":\"string\"},{\"name\":\"" + schemaKey2 + "\",\"type\":\"string\"},{\"name\":\"" + schemaKey3 + "\",\"type\":\"string\"}]}");
    updateArtifactViaApicurioClient(service, schema3, subjectName);

    KafkaClients.produceAvroConfluentMessagesTopicRecordStrategy(topicName, subjectName, schema3, 10, schemaKey, schemaKey2, schemaKey3).get(5, TimeUnit.SECONDS);
    KafkaClients.produceAvroConfluentMessagesTopicRecordStrategy(topicName, subjectName, schema2, 10, schemaKey, schemaKey2).get(5, TimeUnit.SECONDS);
    KafkaClients.produceAvroConfluentMessagesTopicRecordStrategy(topicName, subjectName, schema, 10, schemaKey).get(5, TimeUnit.SECONDS);
    KafkaClients.consumeAvroConfluentMessages(topicName, 30).get(5, TimeUnit.SECONDS);
}
 
Example #23
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMock.java    License: MIT License 5 votes vote down vote up
private List<Integer> delete(final String subject) {
    try {
        final List<Integer> ids = this.schemaRegistryClient.getAllVersions(subject);
        ids.forEach(id -> this.mockSchemaRegistry.removeStub(WireMock.get(getSchemaPattern(id))));
        this.mockSchemaRegistry.removeStub(WireMock.delete(getSubjectPattern(subject)));
        this.mockSchemaRegistry.removeStub(WireMock.get(getSubjectVersionsPattern(subject)));
        this.mockSchemaRegistry.removeStub(WireMock.get(getSubjectVersionPattern(subject)));
        this.schemaRegistryClient.deleteSubject(subject);
        return ids;
    } catch (final IOException | RestClientException e) {
        throw new IllegalStateException("Internal error in mock schema registry client", e);
    }
}
 
Example #24
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMock.java    License: MIT License 5 votes vote down vote up
private List<Integer> listVersions(final String subject) {
    log.debug("Listing all versions for subject {}", subject);
    try {
        return this.schemaRegistryClient.getAllVersions(subject);
    } catch (final IOException | RestClientException e) {
        throw new IllegalStateException("Internal error in mock schema registry client", e);
    }
}
 
Example #25
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMock.java    License: MIT License 5 votes vote down vote up
private Collection<String> listAllSubjects() {
    try {
        return this.schemaRegistryClient.getAllSubjects();
    } catch (final IOException | RestClientException e) {
        throw new IllegalStateException("Internal error in mock schema registry client", e);
    }
}
 
Example #26
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockTest.java    License: MIT License 5 votes vote down vote up
@Test
void shouldRegisterKeySchema() throws IOException, RestClientException {
    final Schema keySchema = createSchema("key_schema");
    final int id = this.schemaRegistry.registerKeySchema("test-topic", keySchema);

    final Schema retrievedSchema = this.schemaRegistry.getSchemaRegistryClient().getById(id);
    assertThat(retrievedSchema).isEqualTo(keySchema);
}
 
Example #27
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockTest.java    License: MIT License 5 votes vote down vote up
@Test
void shouldRegisterValueSchema() throws IOException, RestClientException {
    final Schema valueSchema = createSchema("value_schema");
    final int id = this.schemaRegistry.registerValueSchema("test-topic", valueSchema);

    final Schema retrievedSchema = this.schemaRegistry.getSchemaRegistryClient().getById(id);
    assertThat(retrievedSchema).isEqualTo(valueSchema);
}
 
Example #28
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockTest.java    License: MIT License 5 votes vote down vote up
@Test
void shouldRegisterKeySchemaWithClient() throws IOException, RestClientException {
    final Schema keySchema = createSchema("key_schema");
    final int id = this.schemaRegistry.getSchemaRegistryClient().register("test-topic-key", keySchema);

    final Schema retrievedSchema = this.schemaRegistry.getSchemaRegistryClient().getById(id);
    assertThat(retrievedSchema).isEqualTo(keySchema);
}
 
Example #29
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockTest.java    License: MIT License 5 votes vote down vote up
@Test
void shouldRegisterValueSchemaWithClient() throws IOException, RestClientException {
    final Schema valueSchema = createSchema("value_schema");
    final int id = this.schemaRegistry.getSchemaRegistryClient().register("test-topic-value", valueSchema);

    final Schema retrievedSchema = this.schemaRegistry.getSchemaRegistryClient().getById(id);
    assertThat(retrievedSchema).isEqualTo(valueSchema);
}
 
Example #30
Source Project: fluent-kafka-streams-tests   Author: bakdata   File: SchemaRegistryMockTest.java    License: MIT License 5 votes vote down vote up
@Test
void shouldHaveSchemaVersions() throws IOException, RestClientException {
    final Schema valueSchema = createSchema("value_schema");
    final String topic = "test-topic";
    final int id = this.schemaRegistry.registerValueSchema(topic, valueSchema);

    final List<Integer> versions = this.schemaRegistry.getSchemaRegistryClient().getAllVersions(topic + "-value");
    assertThat(versions.size()).isOne();

    final SchemaMetadata metadata = this.schemaRegistry.getSchemaRegistryClient().getSchemaMetadata(topic + "-value", versions.get(0));
    assertThat(metadata.getId()).isEqualTo(id);
    final String schemaString = metadata.getSchema();
    final Schema retrievedSchema = new Schema.Parser().parse(schemaString);
    assertThat(retrievedSchema).isEqualTo(valueSchema);
}