Class MiniSolrCloudCluster


  • public class MiniSolrCloudCluster
    extends Object
    "Mini" SolrCloud cluster to be used for testing
    • Constructor Detail

      • MiniSolrCloudCluster

        public MiniSolrCloudCluster​(int numServers,
                                    Path baseDir,
                                    org.apache.solr.client.solrj.embedded.JettyConfig jettyConfig)
                             throws Exception
        Create a MiniSolrCloudCluster with default solr.xml
        Parameters:
        numServers - number of Solr servers to start
        baseDir - base directory that the mini cluster should be run from
        jettyConfig - Jetty configuration
        Throws:
        Exception - if there was an error starting the cluster
      • MiniSolrCloudCluster

        public MiniSolrCloudCluster​(int numServers,
                                    String hostContext,
                                    Path baseDir,
                                    String solrXml,
                                    SortedMap<org.eclipse.jetty.servlet.ServletHolder,​String> extraServlets,
                                    SortedMap<Class<? extends javax.servlet.Filter>,​String> extraRequestFilters)
                             throws Exception
        Create a MiniSolrCloudCluster
        Parameters:
        numServers - number of Solr servers to start
        hostContext - context path of Solr servers used by Jetty
        baseDir - base directory that the mini cluster should be run from
        solrXml - solr.xml file to be uploaded to ZooKeeper
        extraServlets - Extra servlets to be started by Jetty
        extraRequestFilters - extra filters to be started by Jetty
        Throws:
        Exception - if there was an error starting the cluster
      • MiniSolrCloudCluster

        public MiniSolrCloudCluster​(int numServers,
                                    String hostContext,
                                    Path baseDir,
                                    String solrXml,
                                    SortedMap<org.eclipse.jetty.servlet.ServletHolder,​String> extraServlets,
                                    SortedMap<Class<? extends javax.servlet.Filter>,​String> extraRequestFilters,
                                    org.apache.solr.client.solrj.embedded.SSLConfig sslConfig)
                             throws Exception
        Create a MiniSolrCloudCluster
        Parameters:
        numServers - number of Solr servers to start
        hostContext - context path of Solr servers used by Jetty
        baseDir - base directory that the mini cluster should be run from
        solrXml - solr.xml file to be uploaded to ZooKeeper
        extraServlets - Extra servlets to be started by Jetty
        extraRequestFilters - extra filters to be started by Jetty
        sslConfig - SSL configuration
        Throws:
        Exception - if there was an error starting the cluster
      • MiniSolrCloudCluster

        public MiniSolrCloudCluster​(int numServers,
                                    Path baseDir,
                                    String solrXml,
                                    org.apache.solr.client.solrj.embedded.JettyConfig jettyConfig)
                             throws Exception
        Create a MiniSolrCloudCluster
        Parameters:
        numServers - number of Solr servers to start
        baseDir - base directory that the mini cluster should be run from
        solrXml - solr.xml file to be uploaded to ZooKeeper
        jettyConfig - Jetty configuration
        Throws:
        Exception - if there was an error starting the cluster
      • MiniSolrCloudCluster

        public MiniSolrCloudCluster​(int numServers,
                                    Path baseDir,
                                    String solrXml,
                                    org.apache.solr.client.solrj.embedded.JettyConfig jettyConfig,
                                    ZkTestServer zkTestServer,
                                    boolean formatZkServer)
                             throws Exception
        Create a MiniSolrCloudCluster
        Parameters:
        numServers - number of Solr servers to start
        baseDir - base directory that the mini cluster should be run from
        solrXml - solr.xml file to be uploaded to ZooKeeper
        jettyConfig - Jetty configuration
        zkTestServer - ZkTestServer to use. If null, one will be created
        Throws:
        Exception - if there was an error starting the cluster
    • Method Detail

      • waitForAllNodes

        public void waitForAllNodes​(int timeout)
                             throws IOException,
                                    InterruptedException,
                                    TimeoutException
        This method wait till all Solr JVMs ( Jettys ) are running . It waits up to the timeout (in seconds) for the JVMs to be up before throwing IllegalStateException. This is called automatically on cluster startup and so is only needed when starting additional Jetty instances.
        Parameters:
        timeout - number of seconds to wait before throwing an IllegalStateException
        Throws:
        IOException - if there was an error communicating with ZooKeeper
        InterruptedException - if the calling thread is interrupted during the wait operation
        TimeoutException - on timeout before all nodes being ready
      • getZkServer

        public ZkTestServer getZkServer()
        Returns:
        ZooKeeper server used by the MiniCluster
      • getZkStateReader

        public org.apache.solr.common.cloud.ZkStateReader getZkStateReader()
        The ZkStateReader inside getSolrClient().
      • getJettySolrRunners

        public List<org.apache.solr.client.solrj.embedded.JettySolrRunner> getJettySolrRunners()
        Returns:
        Unmodifiable list of all the currently started Solr Jettys.
      • getRandomJetty

        public org.apache.solr.client.solrj.embedded.JettySolrRunner getRandomJetty​(Random random)
        Returns:
        a randomly-selected Jetty
      • startJettySolrRunner

        public org.apache.solr.client.solrj.embedded.JettySolrRunner startJettySolrRunner​(String name,
                                                                                          String hostContext,
                                                                                          SortedMap<org.eclipse.jetty.servlet.ServletHolder,​String> extraServlets,
                                                                                          SortedMap<Class<? extends javax.servlet.Filter>,​String> extraRequestFilters)
                                                                                   throws Exception
        Start a new Solr instance
        Parameters:
        hostContext - context path of Solr servers used by Jetty
        extraServlets - Extra servlets to be started by Jetty
        extraRequestFilters - extra filters to be started by Jetty
        Returns:
        new Solr instance
        Throws:
        Exception
      • startJettySolrRunner

        public org.apache.solr.client.solrj.embedded.JettySolrRunner startJettySolrRunner​(String name,
                                                                                          String hostContext,
                                                                                          SortedMap<org.eclipse.jetty.servlet.ServletHolder,​String> extraServlets,
                                                                                          SortedMap<Class<? extends javax.servlet.Filter>,​String> extraRequestFilters,
                                                                                          org.apache.solr.client.solrj.embedded.SSLConfig sslConfig)
                                                                                   throws Exception
        Start a new Solr instance
        Parameters:
        hostContext - context path of Solr servers used by Jetty
        extraServlets - Extra servlets to be started by Jetty
        extraRequestFilters - extra filters to be started by Jetty
        sslConfig - SSL configuration
        Returns:
        new Solr instance
        Throws:
        Exception
      • getJettySolrRunner

        public org.apache.solr.client.solrj.embedded.JettySolrRunner getJettySolrRunner​(int index)
      • startJettySolrRunner

        public org.apache.solr.client.solrj.embedded.JettySolrRunner startJettySolrRunner​(String name,
                                                                                          String hostContext,
                                                                                          org.apache.solr.client.solrj.embedded.JettyConfig config)
                                                                                   throws Exception
        Start a new Solr instance on a particular servlet context
        Parameters:
        name - the instance name
        hostContext - the context to run on
        config - a JettyConfig for the instance's JettySolrRunner
        Returns:
        a JettySolrRunner
        Throws:
        Exception
      • startJettySolrRunner

        public org.apache.solr.client.solrj.embedded.JettySolrRunner startJettySolrRunner()
                                                                                   throws Exception
        Start a new Solr instance, using the default config
        Returns:
        a JettySolrRunner
        Throws:
        Exception
      • stopJettySolrRunner

        public org.apache.solr.client.solrj.embedded.JettySolrRunner stopJettySolrRunner​(int index)
                                                                                  throws Exception
        Stop a Solr instance
        Parameters:
        index - the index of node in collection returned by getJettySolrRunners()
        Returns:
        the shut down node
        Throws:
        Exception
      • startJettySolrRunner

        public org.apache.solr.client.solrj.embedded.JettySolrRunner startJettySolrRunner​(org.apache.solr.client.solrj.embedded.JettySolrRunner jetty)
                                                                                   throws Exception
        Add a previously stopped node back to the cluster
        Parameters:
        jetty - a JettySolrRunner previously returned by stopJettySolrRunner(int)
        Returns:
        the started node
        Throws:
        Exception - on error
      • stopJettySolrRunner

        public org.apache.solr.client.solrj.embedded.JettySolrRunner stopJettySolrRunner​(org.apache.solr.client.solrj.embedded.JettySolrRunner jetty)
                                                                                  throws Exception
        Stop the given Solr instance. It will be removed from the cluster's list of running instances.
        Parameters:
        jetty - a JettySolrRunner to be stopped
        Returns:
        the same JettySolrRunner instance provided to this method
        Throws:
        Exception - on error
      • uploadConfigSet

        public void uploadConfigSet​(Path configDir,
                                    String configName)
                             throws IOException
        Upload a config set
        Parameters:
        configDir - a path to the config set to upload
        configName - the name to give the configset
        Throws:
        IOException
      • deleteAllCollections

        public void deleteAllCollections()
                                  throws Exception
        Delete all collections (and aliases)
        Throws:
        Exception
      • deleteAllConfigSets

        public void deleteAllConfigSets()
                                 throws Exception
        Throws:
        Exception
      • shutdown

        public void shutdown()
                      throws Exception
        Shut down the cluster, including all Solr nodes and ZooKeeper
        Throws:
        Exception
      • getBaseDir

        public Path getBaseDir()
      • getSolrClient

        public org.apache.solr.client.solrj.impl.CloudSolrClient getSolrClient()
      • getZkClient

        public org.apache.solr.common.cloud.SolrZkClient getZkClient()
      • zkSetData

        public void zkSetData​(String path,
                              byte[] data,
                              boolean retryOnConnLoss)
                       throws InterruptedException
        Set data in zk without exposing caller to the ZK API, i.e. tests won't need to include Zookeeper dependencies
        Throws:
        InterruptedException
      • buildSolrClient

        protected org.apache.solr.client.solrj.impl.CloudSolrClient buildSolrClient()
      • getReplicaJetty

        public org.apache.solr.client.solrj.embedded.JettySolrRunner getReplicaJetty​(org.apache.solr.common.cloud.Replica replica)
        Return the jetty that a particular replica resides on
      • expireZkSession

        public void expireZkSession​(org.apache.solr.client.solrj.embedded.JettySolrRunner jetty)
        Make the zookeeper session on a particular jetty expire
      • getOpenOverseer

        public org.apache.solr.cloud.Overseer getOpenOverseer()
      • getOpenOverseer

        public static org.apache.solr.cloud.Overseer getOpenOverseer​(List<org.apache.solr.cloud.Overseer> overseers)
      • waitForActiveCollection

        public void waitForActiveCollection​(String collection,
                                            long wait,
                                            TimeUnit unit,
                                            int shards,
                                            int totalReplicas)
      • waitForActiveCollection

        public void waitForActiveCollection​(String collection,
                                            int shards,
                                            int totalReplicas)
      • waitForActiveCollection

        public void waitForActiveCollection​(String collection,
                                            long wait,
                                            TimeUnit unit)
      • expectedShardsAndActiveReplicas

        public static org.apache.solr.common.cloud.CollectionStatePredicate expectedShardsAndActiveReplicas​(int expectedShards,
                                                                                                            int expectedReplicas)
      • expectedActive

        public static org.apache.solr.common.cloud.CollectionStatePredicate expectedActive()
      • waitForJettyToStop

        public void waitForJettyToStop​(org.apache.solr.client.solrj.embedded.JettySolrRunner runner)
                                throws TimeoutException
        Throws:
        TimeoutException