Class BaseDistributedSearchTestCase

  • Direct Known Subclasses:
    AbstractDistribZkTestBase

    public abstract class BaseDistributedSearchTestCase
    extends SolrTestCaseJ4
    Helper base class for distributed search test cases

    By default, for Nightly runs, all tests in sub-classes will execute with 1, 2, ... DEFAULT_MAX_SHARD_COUNT number of shards set up repeatedly. For non-nightly tests, they will execute with 2 shards, to speed up total execution time.

    In general, it's preferable to annotate the tests in sub-classes with a @ShardsFixed(num = N) or a @ShardsRepeat(min = M, max = N) to indicate whether the test should be called once, with a fixed number of shards, or called repeatedly for number of shards = M to N.

    In some cases though, if the number of shards has to be fixed, but the number itself is dynamic, or if it has to be set as a default for all sub-classes of a sub-class, there's a fixShardCount(N) available, which is identical to @ShardsFixed(num = N) for all tests without annotations in that class hierarchy. Ideally this function should be retired in favour of better annotations..

    Since:
    solr 1.5
    • Constructor Detail

      • BaseDistributedSearchTestCase

        protected BaseDistributedSearchTestCase()
        Constructs a test in which the jetty+solr instances as well as the solr clients all use the value of the "hostContext" system property.

        If the system property is not set, or is set to the empty string (neither of which should normally happen unless a subclass explicitly modifies the property set by initHostContext() prior to calling this constructor) a servlet context of "/solr" is used. (this is for consistency with the default behavior of solr.xml parsing when using hostContext="${hostContext:}"

        If the system property is set to a value which does not begin with a "/" (which should normally happen unless a subclass explicitly modifies the property set by initHostContext() prior to calling this constructor) a leading "/" will be prepended.

        See Also:
        initHostContext()
      • BaseDistributedSearchTestCase

        protected BaseDistributedSearchTestCase​(String context)
        Parameters:
        context - explicit servlet context path to use (eg: "/solr")
    • Method Detail

      • initialize

        public static void initialize()
      • initHostContext

        public static void initHostContext()
        Set's the value of the "hostContext" system property to a random path like string (which may or may not contain sub-paths). This is used in the default constructor for this test to help ensure no code paths have hardcoded assumptions about the servlet context used to run solr.

        Test configs may use the ${hostContext} variable to access this system property.

        See Also:
        BaseDistributedSearchTestCase(), clearHostContext()
      • setSolrDisableShardsWhitelist

        public static void setSolrDisableShardsWhitelist()
                                                  throws Exception
        Throws:
        Exception
      • clearSolrDisableShardsWhitelist

        public static void clearSolrDisableShardsWhitelist()
                                                    throws Exception
        Throws:
        Exception
      • getShardCount

        public int getShardCount()
      • fixShardCount

        public void fixShardCount​(int count)
      • getFieldNames

        protected String[] getFieldNames()
      • getSolrHome

        public String getSolrHome()
        Subclasses can override this to change a test's solr home (default is in test-files)
      • createServers

        protected void createServers​(int numShards)
                              throws Exception
        Throws:
        Exception
      • setDistributedParams

        protected void setDistributedParams​(org.apache.solr.common.params.ModifiableSolrParams params)
      • getShardsString

        protected String getShardsString()
      • getExtraServlets

        public SortedMap<org.eclipse.jetty.servlet.ServletHolder,​String> getExtraServlets()
        Override this method to insert extra servlets into the JettySolrRunners that are created using createJetty()
      • getExtraRequestFilters

        public SortedMap<Class<? extends javax.servlet.Filter>,​String> getExtraRequestFilters()
        Override this method to insert extra filters into the JettySolrRunners that are created using createJetty()
      • createNewSolrClient

        protected org.apache.solr.client.solrj.SolrClient createNewSolrClient​(int port)
      • getServerUrl

        protected String getServerUrl​(int port)
      • buildUrl

        protected String buildUrl​(int port)
      • addFields

        protected static void addFields​(org.apache.solr.common.SolrInputDocument doc,
                                        Object... fields)
      • addRandFields

        protected org.apache.solr.common.SolrInputDocument addRandFields​(org.apache.solr.common.SolrInputDocument sdoc)
      • indexDoc

        protected void indexDoc​(org.apache.solr.common.SolrInputDocument doc)
                         throws IOException,
                                org.apache.solr.client.solrj.SolrServerException
        Indexes the document in both the control client, and a randomly selected client
        Throws:
        IOException
        org.apache.solr.client.solrj.SolrServerException
      • indexDoc

        protected void indexDoc​(org.apache.solr.client.solrj.SolrClient client,
                                org.apache.solr.common.params.SolrParams params,
                                org.apache.solr.common.SolrInputDocument doc)
                         throws IOException,
                                org.apache.solr.client.solrj.SolrServerException
        Throws:
        IOException
        org.apache.solr.client.solrj.SolrServerException
      • indexDocs

        public void indexDocs​(Iterator<org.apache.solr.common.SolrInputDocument> docs)
                       throws org.apache.solr.client.solrj.SolrServerException,
                              IOException
        Indexes the stream of documents in both the control client and randomly selected clients (per batch)
        Throws:
        org.apache.solr.client.solrj.SolrServerException
        IOException
      • indexDocs

        protected org.apache.solr.client.solrj.response.UpdateResponse indexDocs​(org.apache.solr.client.solrj.SolrClient client,
                                                                                 org.apache.solr.common.params.SolrParams params,
                                                                                 Iterable<org.apache.solr.common.SolrInputDocument> sdocs)
                                                                          throws IOException,
                                                                                 org.apache.solr.client.solrj.SolrServerException
        Indexes the document in both the control client and the specified client asserting that the responses are equivalent
        Throws:
        IOException
        org.apache.solr.client.solrj.SolrServerException
      • add

        protected org.apache.solr.client.solrj.response.UpdateResponse add​(org.apache.solr.client.solrj.SolrClient client,
                                                                           org.apache.solr.common.params.SolrParams params,
                                                                           org.apache.solr.common.SolrInputDocument sdoc)
                                                                    throws IOException,
                                                                           org.apache.solr.client.solrj.SolrServerException
        This should not be called in a loop, use add(SolrClient, SolrParams, Iterable) instead
        Throws:
        IOException
        org.apache.solr.client.solrj.SolrServerException
      • add

        protected org.apache.solr.client.solrj.response.UpdateResponse add​(org.apache.solr.client.solrj.SolrClient client,
                                                                           org.apache.solr.common.params.SolrParams params,
                                                                           Iterable<org.apache.solr.common.SolrInputDocument> sdocs)
                                                                    throws IOException,
                                                                           org.apache.solr.client.solrj.SolrServerException
        Throws:
        IOException
        org.apache.solr.client.solrj.SolrServerException
      • del

        protected org.apache.solr.client.solrj.response.UpdateResponse del​(org.apache.solr.client.solrj.SolrClient client,
                                                                           org.apache.solr.common.params.SolrParams params,
                                                                           Object... ids)
                                                                    throws IOException,
                                                                           org.apache.solr.client.solrj.SolrServerException
        Throws:
        IOException
        org.apache.solr.client.solrj.SolrServerException
      • delQ

        protected org.apache.solr.client.solrj.response.UpdateResponse delQ​(org.apache.solr.client.solrj.SolrClient client,
                                                                            org.apache.solr.common.params.SolrParams params,
                                                                            String... queries)
                                                                     throws IOException,
                                                                            org.apache.solr.client.solrj.SolrServerException
        Throws:
        IOException
        org.apache.solr.client.solrj.SolrServerException
      • index_specific

        protected void index_specific​(int serverNumber,
                                      Object... fields)
                               throws Exception
        Throws:
        Exception
      • queryServer

        protected org.apache.solr.client.solrj.response.QueryResponse queryServer​(org.apache.solr.common.params.ModifiableSolrParams params)
                                                                           throws org.apache.solr.client.solrj.SolrServerException,
                                                                                  IOException
        Throws:
        org.apache.solr.client.solrj.SolrServerException
        IOException
      • queryAndCompare

        public org.apache.solr.client.solrj.response.QueryResponse queryAndCompare​(org.apache.solr.common.params.SolrParams params,
                                                                                   org.apache.solr.client.solrj.SolrClient... clients)
                                                                            throws org.apache.solr.client.solrj.SolrServerException,
                                                                                   IOException
        Throws:
        org.apache.solr.client.solrj.SolrServerException
        IOException
      • queryAndCompare

        public org.apache.solr.client.solrj.response.QueryResponse queryAndCompare​(org.apache.solr.common.params.SolrParams params,
                                                                                   Iterable<org.apache.solr.client.solrj.SolrClient> clients)
                                                                            throws org.apache.solr.client.solrj.SolrServerException,
                                                                                   IOException
        Throws:
        org.apache.solr.client.solrj.SolrServerException
        IOException
      • compare

        public static String compare​(org.apache.solr.common.util.NamedList a,
                                     org.apache.solr.common.util.NamedList b,
                                     int flags,
                                     Map<String,​Integer> handle)
      • compare

        public static String compare​(org.apache.solr.common.SolrDocument a,
                                     org.apache.solr.common.SolrDocument b,
                                     int flags,
                                     Map<String,​Integer> handle)
      • compare

        public static String compare​(org.apache.solr.common.SolrDocumentList a,
                                     org.apache.solr.common.SolrDocumentList b,
                                     int flags,
                                     Map<String,​Integer> handle)
      • compareSolrResponses

        protected void compareSolrResponses​(org.apache.solr.client.solrj.SolrResponse a,
                                            org.apache.solr.client.solrj.SolrResponse b)
      • compareResponses

        protected void compareResponses​(org.apache.solr.client.solrj.response.QueryResponse a,
                                        org.apache.solr.client.solrj.response.QueryResponse b)
      • validateControlData

        public void validateControlData​(org.apache.solr.client.solrj.response.QueryResponse control)
                                 throws Exception
        Implementations can pre-test the control data for basic correctness before using it as a check for the shard data. This is useful, for instance, if a test bug is introduced causing a spelling index not to get built: both control & shard data would have no results but because they match the test would pass. This method gives us a chance to ensure something exists in the control data.
        Throws:
        Exception
      • getSolrXml

        protected String getSolrXml()
      • seedSolrHome

        protected void seedSolrHome​(File jettyHome)
                             throws IOException
        Given a directory that will be used as the SOLR_HOME for a jetty instance, seeds that directory with the contents of getSolrHome() and ensures that the proper getSolrXml() file is in place.
        Throws:
        IOException
      • createParams

        protected org.apache.solr.common.params.ModifiableSolrParams createParams​(Object... q)