use of io.confluent.kafka.schemaregistry.client.rest.RestService in project schema-registry by confluentinc.
the class CachedSchemaRegistryClientTest method testGetSchemas.
@Test
public void testGetSchemas() throws Exception {
expect(restService.registerSchema(anyString(), anyString(), anyObject(List.class), anyString(), anyBoolean())).andReturn(ID_25).andReturn(26).andReturn(27).andReturn(28).andReturn(29);
List<Schema> schemas = IntStream.range(0, 5).mapToObj(idx -> new Schema(SUBJECT_0, 7, idx + 25, AvroSchema.TYPE, Collections.emptyList(), avroSchemaString(idx))).collect(Collectors.toList());
expect(restService.getSchemas(anyString(), anyBoolean(), anyBoolean())).andReturn(schemas);
replay(restService);
for (int i = 0; i != CACHE_CAPACITY; ++i) {
// Each one results in new id.
client.register(SUBJECT_0, avroSchema(i));
}
List<ParsedSchema> parsedSchemas = client.getSchemas(SUBJECT_0, false, true);
assertEquals(5, parsedSchemas.size());
IntStream.range(0, 5).forEach(idx -> {
assertEquals(new AvroSchema(avroSchemaString(idx)), parsedSchemas.get(idx));
assertEquals(AvroSchema.TYPE, parsedSchemas.get(idx).schemaType());
});
}
use of io.confluent.kafka.schemaregistry.client.rest.RestService in project schema-registry by confluentinc.
the class RestApp method start.
public void start() throws Exception {
restApp = new SchemaRegistryRestApplication(prop);
restServer = restApp.createServer();
restServer.start();
restConnect = restServer.getURI().toString();
if (restConnect.endsWith("/"))
restConnect = restConnect.substring(0, restConnect.length() - 1);
restClient = new RestService(restConnect);
}
use of io.confluent.kafka.schemaregistry.client.rest.RestService in project schema-registry by confluentinc.
the class MetricsTest method testSchemaCreatedCount.
@Test
public void testSchemaCreatedCount() throws Exception {
RestService service = restApp.restClient;
String subject = "testTopic1";
int schemaCount = 3;
List<String> schemas = TestUtils.getRandomCanonicalAvroString(schemaCount);
// test registering and verifying new schemas in subject1
int schemaIdCounter = 1;
for (int i = 0; i < schemaCount; i++) {
String schema = schemas.get(i);
TestUtils.registerAndVerifySchema(service, schema, schemaIdCounter++, subject);
}
assertEquals(schemaCount, container.getSchemasCreated().get());
assertEquals(schemaCount, container.getSchemasCreated(AvroSchema.TYPE).get());
// Re-registering schemas should not increase metrics.
for (int i = 0; i < schemaCount; i++) {
String schemaString = schemas.get(i);
service.registerSchema(schemaString, subject);
}
assertEquals(schemaCount, container.getSchemasCreated().get());
assertEquals(schemaCount, container.getSchemasCreated(AvroSchema.TYPE).get());
for (Integer i = 1; i < schemaIdCounter; i++) {
assertEquals(i, service.deleteSchemaVersion(RestService.DEFAULT_REQUEST_PROPERTIES, subject, i.toString()));
}
// Deleting schemas should not modify create count.
assertEquals(schemaCount, container.getSchemasCreated().get());
assertEquals(schemaCount, container.getSchemasCreated(AvroSchema.TYPE).get());
assertEquals(schemaCount, container.getSchemasDeleted().get());
assertEquals(schemaCount, container.getSchemasDeleted(AvroSchema.TYPE).get());
}
use of io.confluent.kafka.schemaregistry.client.rest.RestService in project akhq by tchiotludo.
the class KafkaModule method getRegistryRestClient.
public RestService getRegistryRestClient(String clusterId) {
Connection connection = this.getConnection(clusterId);
if (connection.getSchemaRegistry() != null) {
RestService restService = new RestService(connection.getSchemaRegistry().getUrl());
if (connection.getSchemaRegistry().getProperties() != null && !connection.getSchemaRegistry().getProperties().isEmpty()) {
Map<String, Object> sslConfigs = connection.getSchemaRegistry().getProperties().entrySet().stream().filter(e -> e.getKey().startsWith("schema.registry.")).collect(Collectors.toMap(e -> e.getKey().substring("schema.registry.".length()), Map.Entry::getValue));
SslFactory sslFactory = new SslFactory(sslConfigs);
if (sslFactory != null && sslFactory.sslContext() != null) {
restService.setSslSocketFactory(sslFactory.sslContext().getSocketFactory());
}
}
restService.setHttpHeaders(Collections.singletonMap("Accept", "application/json"));
if (connection.getSchemaRegistry().getBasicAuthUsername() != null) {
BasicAuthCredentialProvider basicAuthCredentialProvider = BasicAuthCredentialProviderFactory.getBasicAuthCredentialProvider(new UserInfoCredentialProvider().alias(), ImmutableMap.of("schema.registry.basic.auth.user.info", connection.getSchemaRegistry().getBasicAuthUsername() + ":" + connection.getSchemaRegistry().getBasicAuthPassword()));
restService.setBasicAuthCredentialProvider(basicAuthCredentialProvider);
}
if (connection.getSchemaRegistry().getProperties() != null) {
restService.configure(connection.getSchemaRegistry().getProperties());
}
return restService;
}
return null;
}
Aggregations