Class MockSchemaRegistry

java.lang.Object
io.confluent.kafka.schemaregistry.testutil.MockSchemaRegistry

public final class MockSchemaRegistry extends Object
A repository for mocked Schema Registry clients, to aid in testing.

Logically independent "instances" of mocked Schema Registry are created or retrieved via named scopes getClientForScope(String). Each named scope is an independent registry. Each named-scope registry is statically defined and visible to the entire JVM. Scopes can be cleaned up when no longer needed via dropScope(String). Reusing a scope name after cleanup results in a completely new mocked Schema Registry instance.

This registry can be used to manage scoped clients directly, but scopes can also be registered and used as schema.registry.url with the special pseudo-protocol 'mock://' in serde configurations, so that testing code doesn't have to run an actual instance of Schema Registry listening on a local port. For example, schema.registry.url: 'mock://my-scope-name' corresponds to MockSchemaRegistry.getClientForScope("my-scope-name").

  • Method Details

    • getClientForScope

      public static SchemaRegistryClient getClientForScope(String scope)
      Get a client for a mocked Schema Registry. The scope represents a particular registry, so operations on one scope will never affect another.
      Parameters:
      scope - Identifies a logically independent Schema Registry instance. It's similar to a schema registry URL, in that two different Schema Registry deployments have two different URLs, except that these registries are only mocked, so they have no actual URL.
      Returns:
      A client for the specified scope.
    • getClientForScope

      public static SchemaRegistryClient getClientForScope(String scope, List<SchemaProvider> providers)
      Get a client for a mocked Schema Registry. The scope represents a particular registry, so operations on one scope will never affect another.
      Parameters:
      scope - Identifies a logically independent Schema Registry instance. It's similar to a schema registry URL, in that two different Schema Registry deployments have two different URLs, except that these registries are only mocked, so they have no actual URL.
      providers - A list of schema providers.
      Returns:
      A client for the specified scope.
    • getClientForScope

      public static SchemaRegistryClient getClientForScope(List<String> scopes, List<SchemaProvider> providers)
      Get a client for a mocked Schema Registry. The scope represents a particular registry, so operations on one scope will never affect another.
      Parameters:
      scopes - Identifies a logically independent Schema Registry instance. It's similar to a List of schema registry URLs, in that two different Schema Registry deployments have two different URLs, except that these registries are only mocked, so they have no actual URL.
      providers - A list of schema providers.
      Returns:
      A client for the specified scope.
    • dropScope

      public static void dropScope(String scope)
      Destroy the mocked registry corresponding to the scope. Subsequent clients for the same scope will have a completely blank slate.
      Parameters:
      scope - Identifies a logically independent Schema Registry instance. It's similar to a schema registry URL, in that two different Schema Registry deployments have two different URLs, except that these registries are only mocked, so they have no actual URL.
    • clear

      public static void clear()
    • validateAndMaybeGetMockScope

      public static String validateAndMaybeGetMockScope(List<String> urls)
    • validateAndMaybeGetMockScope

      public static List<String> validateAndMaybeGetMockScope(String baseUrls)