Interface SolrBackend

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
EmbeddedSolrBackend, JettySolrRunner, MiniSolrCloudCluster, RemoteSolrBackend

public interface SolrBackend extends AutoCloseable
Abstraction over a running Solr deployment for use in tests and benchmarks. The abstraction normalizes how to shut down and perform other common operations as the methods indicate.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Shuts down this backend, releases the admin client, and all other resources.
    void
    createCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create)
    Creates a collection (or core for single-node backends).
    default void
    Dumps JSON-format information for all cores to out.
    default void
    Dumps Prometheus-format metrics to out.
    default String
    Returns the base URL of a Solr node.
    org.apache.solr.core.CoreContainer
    Provides access to an embedded/in-process CoreContainer -- if available (else null).
    org.apache.solr.client.solrj.SolrClient
    Returns the node / admin (collection-less) SolrClient owned by this backend.
    boolean
    Checks if a collection or core with the given name exists.
    default boolean
    Checks if a configSet with the given name exists.
    org.apache.solr.client.solrj.SolrClient
    newSolrClient(String collection)
    Creates a new SolrClient defaulted to the given collection.
    default void
    Reloads a collection or core by this name.
    default void
    uploadConfigSet(Path configDir, String name)
    Upload a configSet, possibly overwriting (creating files, updating files, NOT deleting files).
  • Method Details

    • newSolrClient

      org.apache.solr.client.solrj.SolrClient newSolrClient(String collection)
      Creates a new SolrClient defaulted to the given collection. The caller owns this client and is responsible for closing it. Callers that want a long-lived client should cache it themselves.
    • getSolrClient

      org.apache.solr.client.solrj.SolrClient getSolrClient()
      Returns the node / admin (collection-less) SolrClient owned by this backend. The caller must NOT close it; it is released when this backend is close()d. A CloudSolrClient should be returned if appropriate. While it *can* be used to target specific collections, please use newSolrClient(String) for that instead.
    • uploadConfigSet

      default void uploadConfigSet(Path configDir, String name) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Upload a configSet, possibly overwriting (creating files, updating files, NOT deleting files).
      Parameters:
      configDir - a path to the config set to upload
      name - the name to give the configSet
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • hasConfigSet

      default boolean hasConfigSet(String name) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Checks if a configSet with the given name exists.
      Parameters:
      name - configSet name to check
      Returns:
      true if the configSet exists, false otherwise
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • createCollection

      void createCollection(org.apache.solr.client.solrj.request.CollectionAdminRequest.Create create) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Creates a collection (or core for single-node backends). Cloud backends honour numShards and replicationFactor; single-node backends (JettySolrRunner, EmbeddedSolrBackend) ignore those fields. Callers should use hasCollection(String) first if they want to avoid errors when the collection already exists. Tests/benchmarks that want to test how this works should not use this to do so.
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • hasCollection

      boolean hasCollection(String name) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Checks if a collection or core with the given name exists.
      Parameters:
      name - collection or core name to check
      Returns:
      true if the collection/core exists, false otherwise
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • reloadCollection

      default void reloadCollection(String name) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Reloads a collection or core by this name. The purpose is typically to clear caches.
      Throws:
      org.apache.solr.client.solrj.SolrServerException
      IOException
    • getCoreContainer

      org.apache.solr.core.CoreContainer getCoreContainer()
      Provides access to an embedded/in-process CoreContainer -- if available (else null). If there is more than one node, then one is returned.
      Returns:
      can be null.
    • getBaseUrl

      default String getBaseUrl(Random r)
      Returns the base URL of a Solr node. For cloud backends with multiple nodes, a live node is chosen at random. The URL does not include a trailing slash.
      Returns:
      base URL (e.g., "http://localhost:8983/solr"). Null for EmbeddedSolrServer.
    • dumpMetrics

      default void dumpMetrics(PrintStream out)
      Dumps Prometheus-format metrics to out. No-op is an acceptable implementation.
    • dumpCoreInfo

      default void dumpCoreInfo(PrintStream out)
      Dumps JSON-format information for all cores to out. No-op is an acceptable implementation. Default uses GET /admin/cores?indexInfo=true.
    • close

      void close()
      Shuts down this backend, releases the admin client, and all other resources.
      Specified by:
      close in interface AutoCloseable