Class SchemaRegistryStub
java.lang.Object
io.krabka.streams.test.SchemaRegistryStub
- All Implemented Interfaces:
AutoCloseable
A small, stateful Confluent Schema Registry test server.
The stub binds an HTTP server to an ephemeral loopback port and implements the
subset of the registry REST API that KrabkaSchemaRegistryClient needs:
registering a schema, looking a schema up, fetching a subject's latest version, and
fetching a schema by ID. Schemas are deduplicated by content, IDs are assigned
sequentially from 1, and everything lives in memory until close().
Request counts are recorded per method and path, so tests can assert caching behavior such as "the second deserialization did not fetch the schema again".
Example
try (var registry = new SchemaRegistryStub()) {
var client = new KrabkaSchemaRegistryClient(registry.uri());
var cache = new SchemaCache(client);
serde.registerSubject("orders");
cache.prewarm().join();
assertThat(registry.requestCount("POST", "/subjects/orders-value/versions")).isEqualTo(1);
}
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
SchemaRegistryStub
Starts the stub on an ephemeral loopback port.- Throws:
IOException- if the HTTP server cannot bind
-
-
Method Details
-
uri
Returns the base URI clients should connect to.- Returns:
- the loopback URI of the running stub
-
requestCount
-
close
public void close()Stops the HTTP server and discards all registered schemas.- Specified by:
closein interfaceAutoCloseable
-