Class BaseDistributedSearchTestCase

java.lang.Object
org.junit.Assert
org.apache.lucene.tests.util.LuceneTestCase
org.apache.solr.SolrTestCase
org.apache.solr.SolrTestCaseJ4
org.apache.solr.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..

WARNING each test annotated with @Shards* will spin up its own set of Jetty servers which can be a substantial performance hit. Therefore, one should be mindful about the total number of independent tests using such annotations. One approach is to pool assertions in a single test to minimize jetty server construction overhead. If the test doesn't rely on the comparison features of this class, i.e. query(java.lang.Object...) it may be wise to make it a SolrCloudTestCase instead.

Since:
solr 1.5
  • Field Details

  • Constructor Details

    • 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:
    • BaseDistributedSearchTestCase

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

    • 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:
    • clearHostContext

      public static void clearHostContext() throws Exception
      Clears the "hostContext" system property
      Throws:
      Exception
      See Also:
    • 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()
    • getRandValues

      protected BaseDistributedSearchTestCase.RandVal[] getRandValues()
    • getSolrHome

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

      public void distribSetUp() throws Exception
      Throws:
      Exception
    • distribTearDown

      public void distribTearDown() throws Exception
      Throws:
      Exception
    • createControlJetty

      protected JettySolrRunner createControlJetty() throws Exception
      Throws:
      Exception
    • 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()
    • destroyServers

      protected void destroyServers() throws Exception
      Throws:
      Exception
    • createJetty

      public JettySolrRunner createJetty(File solrHome, String dataDir) throws Exception
      Throws:
      Exception
    • createJetty

      public JettySolrRunner createJetty(File solrHome, String dataDir, String shardId) throws Exception
      Throws:
      Exception
    • createJetty

      public JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, String solrConfigOverride, String schemaOverride) throws Exception
      Throws:
      Exception
    • createJetty

      public JettySolrRunner createJetty(File solrHome, String dataDir, String shardList, String solrConfigOverride, String schemaOverride, boolean explicitCoreNodeName) throws Exception
      Throws:
      Exception
    • 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)
    • buildUrl

      @Deprecated protected static String buildUrl(int port)
      Deprecated.
    • addFields

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

      protected void indexr(Object... fields) throws Exception
      Throws:
      Exception
    • addRandFields

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

      protected void index(Object... fields) throws Exception
      Throws:
      Exception
    • 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.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
    • del

      protected void del(String q) throws Exception
      Throws:
      Exception
    • commit

      protected void commit() 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
    • query

      protected org.apache.solr.client.solrj.response.QueryResponse query(Object... q) throws Exception
      Sets distributed params. Returns the QueryResponse from queryServer(org.apache.solr.common.params.ModifiableSolrParams),
      Throws:
      Exception
    • query

      protected org.apache.solr.client.solrj.response.QueryResponse query(org.apache.solr.common.params.SolrParams params) throws Exception
      Sets distributed params. Returns the QueryResponse from queryServer(org.apache.solr.common.params.ModifiableSolrParams),
      Throws:
      Exception
    • query

      protected org.apache.solr.client.solrj.response.QueryResponse query(boolean setDistribParams, Object[] q) throws Exception
      Throws:
      Exception
    • query

      protected org.apache.solr.client.solrj.response.QueryResponse query(boolean setDistribParams, org.apache.solr.common.params.SolrParams p) throws Exception
      Throws:
      Exception
    • 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
    • flags

      public static int flags(Map<String,Integer> handle, Object key)
    • 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)
    • compare1

      public static String compare1(Map a, Map b, int flags, Map<String,Integer> handle)
    • compare

      public static String compare(Map a, Map 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)
    • compare

      public static String compare(Object[] a, Object[] b, int flags, Map<String,Integer> handle)
    • compare

      public static String compare(Object a, Object 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)
    • getRandFields

      public static Object[] getRandFields(String[] fields, BaseDistributedSearchTestCase.RandVal[] randVals)
    • 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
    • setupJettySolrHome

      protected void setupJettySolrHome(File jettyHome) throws IOException
      Throws:
      IOException
    • createParams

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