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:
AbstractFullDistribZkTestBase

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
  • Field Details

  • Constructor Details

    • BaseDistributedSearchTestCase

      protected BaseDistributedSearchTestCase()
  • Method Details

    • initialize

      public static void initialize()
    • setSolrEnableUrlUrlAllowList

      public static void setSolrEnableUrlUrlAllowList() throws Exception
      Throws:
      Exception
    • clearSolrEnableUrlUrlAllowList

      public static void clearSolrEnableUrlUrlAllowList() 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 Path 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(Path solrHome, String dataDir) throws Exception
      Throws:
      Exception
    • createJetty

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

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

      public JettySolrRunner createJetty(Path solrHome, String dataDir, String shardList, String solrConfigOverride, String schemaOverride, boolean explicitCoreNodeName) throws Exception
      Throws:
      Exception
    • getExtraServlets

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

      public SortedMap<Class<? extends jakarta.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)
    • 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.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
    • del

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

      protected void commit() throws Exception
      Throws:
      Exception
    • queryRandomShard

      protected org.apache.solr.client.solrj.response.QueryResponse queryRandomShard(org.apache.solr.common.params.ModifiableSolrParams params) throws org.apache.solr.client.solrj.SolrServerException, IOException
      Queries a random shard; nothing more.

      WARNING: tests should generally not call this as it doesn't compare to the control client

      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 distributed QueryResponse
      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 distributed QueryResponse
      Throws:
      Exception
    • query

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

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

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