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

The following examples show how to use io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException. 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 File: AggregatingCountTest.java    From kafka-tutorials with 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 #2
Source File: FindDistinctEventsTest.java    From kafka-tutorials with 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 #3
Source File: SchemaRegistryMockTest.java    From fluent-kafka-streams-tests with 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 #4
Source File: SchemaPublication.java    From kafka-tutorials with 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 #5
Source File: SchemasConfluentIT.java    From apicurio-registry with 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 #6
Source File: SchemaRegistryMockRuleTest.java    From fluent-kafka-streams-tests with 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 #7
Source File: ConfluentBaseIT.java    From apicurio-registry with 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 #8
Source File: StreamsIngestTest.java    From kafka-tutorials with 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 #9
Source File: MetadataConfluentIT.java    From apicurio-registry with 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 #10
Source File: SchemaRegistryMockExtensionTest.java    From fluent-kafka-streams-tests with 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 #11
Source File: BasicConfluentSerDesIT.java    From apicurio-registry with 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 #12
Source File: ConfluentSchemaRegistryCoder.java    From Flink-CEPplus with 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 #13
Source File: SchemaRegistryMock.java    From fluent-kafka-streams-tests with 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 #14
Source File: ConfluentSchemaRegistryCoder.java    From flink with 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 #15
Source File: SchemaRegistryMockExtensionTest.java    From fluent-kafka-streams-tests with 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 #16
Source File: SchemaRegistryMockTest.java    From fluent-kafka-streams-tests with 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 #17
Source File: SchemaRegistryMockRuleTest.java    From fluent-kafka-streams-tests with 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 #18
Source File: SchemaRegistryMockTest.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Test
void shouldDeleteKeySchemaWithClient() throws IOException, RestClientException {
    final SchemaRegistryClient client = this.schemaRegistry.getSchemaRegistryClient();
    this.schemaRegistry.registerKeySchema("test-topic", createSchema("key_schema"));
    final Collection<String> allSubjects = client.getAllSubjects();
    assertThat(allSubjects).hasSize(1).containsExactly("test-topic-key");
    client.deleteSubject("test-topic-key");
    final Collection<String> subjectsAfterDeletion = client.getAllSubjects();
    assertThat(subjectsAfterDeletion).isEmpty();
}
 
Example #19
Source File: SchemaRegistryMockRuleTest.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Test
public void shouldRegisterKeySchema() throws IOException, RestClientException {
    final Schema keySchema = this.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 #20
Source File: SchemaRegistryMockExtensionTest.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Test
void shouldRegisterValueSchema() throws IOException, RestClientException {
    final Schema valueSchema = this.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 #21
Source File: SchemaRegistryMockTest.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Test
void shouldDeleteValueSchemaWithClient() throws IOException, RestClientException {
    final SchemaRegistryClient client = this.schemaRegistry.getSchemaRegistryClient();
    this.schemaRegistry.registerValueSchema("test-topic", createSchema("value_schema"));
    final Collection<String> allSubjects = client.getAllSubjects();
    assertThat(allSubjects).hasSize(1).containsExactly("test-topic-value");
    client.deleteSubject("test-topic-value");
    final Collection<String> subjectsAfterDeletion = client.getAllSubjects();
    assertThat(subjectsAfterDeletion).isEmpty();
}
 
Example #22
Source File: SchemaRegistryMock.java    From schema-registry-transfer-smt with Apache License 2.0 5 votes vote down vote up
private String getCompatibility(String subject) {
    if (subject == null) {
        log.debug("Requesting registry base compatibility");
    } else {
        log.debug("Requesting compatibility for subject {}", subject);
    }
    try {
        return this.schemaRegistryClient.getCompatibility(subject);
    } catch (IOException | RestClientException e) {
        throw new IllegalStateException("Internal error in mock schema registry client", e);
    }
}
 
Example #23
Source File: SchemaRegistryMockRuleTest.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Test
public void shouldRegisterKeySchemaWithClient() throws IOException, RestClientException {
    final Schema keySchema = this.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 #24
Source File: SchemaRegistryMockRuleTest.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Test
public void shouldRegisterValueSchema() throws IOException, RestClientException {
    final Schema valueSchema = this.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 #25
Source File: SchemaRegistryMockExtensionTest.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Test
void shouldRegisterValueSchemaWithClient() throws IOException, RestClientException {
    final Schema valueSchema = this.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 #26
Source File: SchemaRegistryMock.java    From schema-registry-transfer-smt with Apache License 2.0 5 votes vote down vote up
private SchemaMetadata getSubjectVersion(String subject, Object version) {
    log.debug("Requesting version {} for subject {}", version, subject);
    try {
        if (version instanceof String && version.equals("latest")) {
            return this.schemaRegistryClient.getLatestSchemaMetadata(subject);
        } else if (version instanceof Number) {
            return this.schemaRegistryClient.getSchemaMetadata(subject, ((Number) version).intValue());
        } else {
            throw new IllegalArgumentException("Only 'latest' or integer versions are allowed");
        }
    } catch (IOException | RestClientException e) {
        throw new IllegalStateException("Internal error in mock schema registry client", e);
    }
}
 
Example #27
Source File: SchemaRegistryMockTest.java    From fluent-kafka-streams-tests with 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 #28
Source File: SchemaRegistryMockTest.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Test
void shouldDeleteKeySchema() throws IOException, RestClientException {
    this.schemaRegistry.registerKeySchema("test-topic", createSchema("key_schema"));
    final SchemaRegistryClient client = this.schemaRegistry.getSchemaRegistryClient();
    final Collection<String> allSubjects = client.getAllSubjects();
    assertThat(allSubjects).hasSize(1).containsExactly("test-topic-key");
    this.schemaRegistry.deleteKeySchema("test-topic");
    final Collection<String> subjectsAfterDeletion = client.getAllSubjects();
    assertThat(subjectsAfterDeletion).isEmpty();
}
 
Example #29
Source File: SchemaRegistryMock.java    From schema-registry-transfer-smt with Apache License 2.0 5 votes vote down vote up
private List<Integer> listVersions(String subject) {
    log.debug("Listing all versions for subject {}", subject);
    try {
        return this.schemaRegistryClient.getAllVersions(subject);
    } catch (IOException | RestClientException e) {
        throw new IllegalStateException("Internal error in mock schema registry client", e);
    }
}
 
Example #30
Source File: SchemaRegistryMockExtensionTest.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Test
void shouldRegisterKeySchema() throws IOException, RestClientException {
    final Schema keySchema = this.createSchema("key_schema");
    final int id = this.schemaRegistry.registerKeySchema("test-topic", keySchema);

    final Schema retrievedSchema = this.schemaRegistry.getSchemaRegistryClient().getById(id);
    assertThat(retrievedSchema).isEqualTo(keySchema);
}