Class SolrCloudTestCase

java.lang.Object
org.junit.Assert
org.apache.lucene.tests.util.LuceneTestCase
org.apache.solr.SolrTestCase
org.apache.solr.SolrTestCaseJ4
org.apache.solr.cloud.SolrCloudTestCase
Direct Known Subclasses:
AbstractCloudBackupRestoreTestCase, AbstractCollectionsAPIDistributedZkTestBase, AbstractIncrementalBackupTest, AbstractInstallShardTest, SolrCloudAuthTestCase

public class SolrCloudTestCase extends SolrTestCaseJ4
Base class for SolrCloud tests

Derived tests should call configureCluster(int) in a BeforeClass static method or Before setUp method. This configures and starts a MiniSolrCloudCluster, available via the cluster variable. Cluster shutdown is handled automatically if using BeforeClass.

   
   @BeforeClass
   public static void setupCluster() {
     configureCluster(NUM_NODES)
        .addConfig("configname", pathToConfig)
        .configure();
   }
   
 
  • Field Details

  • Constructor Details

    • SolrCloudTestCase

      public SolrCloudTestCase()
  • Method Details

    • zkClient

      protected static org.apache.solr.common.cloud.SolrZkClient zkClient()
    • isPRS

      public static boolean isPRS()
      if the system property is not specified, default to false. The SystemProperty will be set in a beforeClass method.
    • configureCluster

      protected static MiniSolrCloudCluster.Builder configureCluster(int nodeCount)
      Call this to configure a cluster of n nodes. It will be shut down automatically after the tests.

      NB you must call MiniSolrCloudCluster.Builder.configure() to start the cluster

      Parameters:
      nodeCount - the number of nodes
    • configurePrsDefault

      public static void configurePrsDefault()
    • shutdownCluster

      public static void shutdownCluster() throws Exception
      Throws:
      Exception
    • replicasForCollectionAreFullyActive

      public static boolean replicasForCollectionAreFullyActive(Set<String> liveNodes, org.apache.solr.common.cloud.DocCollection collectionState, int expectedShards, int expectedReplicas)
      Check that all replicas in a collection are live
      See Also:
      • CollectionStatePredicate
    • getReplicas

      public static List<org.apache.solr.common.cloud.Replica> getReplicas(org.apache.solr.common.cloud.DocCollection collectionState, EnumSet<org.apache.solr.common.cloud.Replica.Type> s)
    • checkClusterConfiguration

      public void checkClusterConfiguration()
    • getCollectionState

      protected static org.apache.solr.common.cloud.DocCollection getCollectionState(String collectionName)
      Get the collection state for a particular collection
    • waitForState

      protected static void waitForState(String message, String collection, org.apache.solr.common.cloud.CollectionStatePredicate predicate)
      Wait for a particular collection state to appear in the cluster client's state reader

      This is a convenience method using the DEFAULT_TIMEOUT.

    • waitForState

      protected static void waitForState(String message, String collection, int timeout, TimeUnit timeUnit, org.apache.solr.common.cloud.CollectionStatePredicate predicate)
      Wait for a particular collection state to appear in the cluster client's state reader
      Parameters:
      message - a message to report on failure
      collection - the collection to watch
      predicate - a predicate to match against the collection state
    • waitForState

      protected static void waitForState(String message, String collection, Predicate<org.apache.solr.common.cloud.DocCollection> predicate)
      Wait for a particular collection state to appear in the cluster client's state reader.

      This is a convenience method using the DEFAULT_TIMEOUT.

    • waitForState

      protected static void waitForState(String message, String collection, int timeout, TimeUnit timeUnit, Predicate<org.apache.solr.common.cloud.DocCollection> predicate)
      Wait for a particular collection state to appear in the cluster client's state reader
      Parameters:
      message - a message to report on failure
      collection - the collection to watch
      predicate - a predicate to match against the collection state
    • clusterShape

      public static org.apache.solr.common.cloud.CollectionStatePredicate clusterShape(int expectedShards, int expectedReplicas)
      Return a CollectionStatePredicate that returns true if a collection has the expected numbers of shards and active replicas
    • activeClusterShape

      public static org.apache.solr.common.cloud.CollectionStatePredicate activeClusterShape(int expectedShards, int expectedReplicas)
      Return a CollectionStatePredicate that returns true if a collection has the expected numbers of active shards and active replicas on these shards
    • containsLiveNode

      public static org.apache.solr.common.cloud.LiveNodesPredicate containsLiveNode(String node)
    • missingLiveNode

      public static org.apache.solr.common.cloud.LiveNodesPredicate missingLiveNode(String node)
    • missingLiveNodes

      public static org.apache.solr.common.cloud.LiveNodesPredicate missingLiveNodes(List<String> nodes)
    • getRandomShard

      protected static org.apache.solr.common.cloud.Slice getRandomShard(org.apache.solr.common.cloud.DocCollection collection)
      Get a (reproducibly) random shard from a DocCollection
    • getRandomReplica

      protected static org.apache.solr.common.cloud.Replica getRandomReplica(org.apache.solr.common.cloud.Slice slice)
      Get a (reproducibly) random replica from a Slice
    • getRandomReplica

      protected static org.apache.solr.common.cloud.Replica getRandomReplica(org.apache.solr.common.cloud.Slice slice, Predicate<org.apache.solr.common.cloud.Replica> matchPredicate)
      Get a (reproducibly) random replica from a Slice matching a predicate
    • getCoreStatus

      protected static org.apache.solr.client.api.model.CoreStatusResponse.SingleCoreData getCoreStatus(org.apache.solr.common.cloud.Replica replica) throws IOException, org.apache.solr.client.solrj.SolrServerException
      Get the CoreStatusResponse.SingleCoreData data for a Replica

      This assumes that the replica is hosted on a live node.

      Throws:
      IOException
      org.apache.solr.client.solrj.SolrServerException
    • waitForResponse

      protected org.apache.solr.common.util.NamedList waitForResponse(Predicate<org.apache.solr.common.util.NamedList> predicate, org.apache.solr.client.solrj.SolrRequest request, int intervalInMillis, int numRetries, String messageOnFail)
    • ensureRunningJettys

      public static void ensureRunningJettys(int nodeCount, int timeoutSeconds) throws Exception
      Ensure that the given number of solr instances are running. If less instances are found then new instances are started. If extra instances are found then they are stopped.
      Parameters:
      nodeCount - the number of Solr instances that should be running at the end of this method
      Throws:
      Exception - on error
    • mapReplicasToReplicaType

      public static Map<String,String> mapReplicasToReplicaType(org.apache.solr.common.cloud.DocCollection collection)