You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2019/08/28 04:34:55 UTC
[lucene-solr] branch master updated: formatting
This is an automated email from the ASF dual-hosted git repository.
noble pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/master by this push:
new 54bd950 formatting
54bd950 is described below
commit 54bd950819673800344a9dd532f6c330f5522b6b
Author: noble <no...@apache.org>
AuthorDate: Wed Aug 28 14:34:35 2019 +1000
formatting
---
.../org/apache/solr/cloud/SolrCloudTestCase.java | 73 ++++++++++++----------
1 file changed, 39 insertions(+), 34 deletions(-)
diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
index 5f30f21..d8d2472 100644
--- a/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
+++ b/solr/test-framework/src/java/org/apache/solr/cloud/SolrCloudTestCase.java
@@ -64,7 +64,7 @@ import static org.apache.solr.common.cloud.ZkConfigManager.CONFIGS_ZKNODE;
/**
* Base class for SolrCloud tests
- *
+ * <p>
* Derived tests should call {@link #configureCluster(int)} in a {@code BeforeClass}
* static method or {@code Before} setUp method. This configures and starts a {@link MiniSolrCloudCluster}, available
* via the {@code cluster} variable. Cluster shutdown is handled automatically if using {@code BeforeClass}.
@@ -83,15 +83,15 @@ import static org.apache.solr.common.cloud.ZkConfigManager.CONFIGS_ZKNODE;
public class SolrCloudTestCase extends SolrTestCaseJ4 {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
+
public static final int DEFAULT_TIMEOUT = 45; // this is an important timeout for test stability - can't be too short
private static class Config {
final String name;
final Path path;
- final Map<String,byte[]> extraConfig;
+ final Map<String, byte[]> extraConfig;
- private Config(String name, Path path, Map<String,byte[]> extraConfig) {
+ private Config(String name, Path path, Map<String, byte[]> extraConfig) {
this.name = name;
this.path = path;
this.extraConfig = extraConfig;
@@ -113,8 +113,10 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
private Map<String, Object> clusterProperties = new HashMap<>();
private boolean trackJettyMetrics;
+
/**
* Create a builder
+ *
* @param nodeCount the number of nodes in the cluster
* @param baseDir a base directory for the cluster
*/
@@ -179,6 +181,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
/**
* Upload a collection config before tests start
+ *
* @param configName the config name
* @param configPath the path to the config files
*/
@@ -194,7 +197,8 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
/**
* Set a cluster property
- * @param propertyName the property name
+ *
+ * @param propertyName the property name
* @param propertyValue the property value
*/
public Builder withProperty(String propertyName, String propertyValue) {
@@ -203,11 +207,13 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
}
public Builder withMetrics(boolean trackJettyMetrics) {
- this.trackJettyMetrics = trackJettyMetrics;
+ this.trackJettyMetrics = trackJettyMetrics;
return this;
}
+
/**
* Configure and run the {@link MiniSolrCloudCluster}
+ *
* @throws Exception if an error occurs on startup
*/
public MiniSolrCloudCluster configure() throws Exception {
@@ -216,6 +222,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
/**
* Configure, run and return the {@link MiniSolrCloudCluster}
+ *
* @throws Exception if an error occurs on startup
*/
public MiniSolrCloudCluster build() throws Exception {
@@ -223,11 +230,11 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
null, securityJson, trackJettyMetrics);
CloudSolrClient client = cluster.getSolrClient();
for (Config config : configs) {
- ((ZkClientClusterStateProvider)client.getClusterStateProvider()).uploadConfig(config.path, config.name);
- if(config.extraConfig!= null){
+ ((ZkClientClusterStateProvider) client.getClusterStateProvider()).uploadConfig(config.path, config.name);
+ if (config.extraConfig != null) {
for (Map.Entry<String, byte[]> e : config.extraConfig.entrySet()) {
- ((ZkClientClusterStateProvider)client.getClusterStateProvider()).getZkStateReader().getZkClient()
- .create(CONFIGS_ZKNODE + "/" + config.name+ "/"+ e.getKey(), e.getValue(), CreateMode.PERSISTENT, true);
+ ((ZkClientClusterStateProvider) client.getClusterStateProvider()).getZkStateReader().getZkClient()
+ .create(CONFIGS_ZKNODE + "/" + config.name + "/" + e.getKey(), e.getValue(), CreateMode.PERSISTENT, true);
}
@@ -244,12 +251,12 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
}
public Builder withDefaultClusterProperty(String key, String value) {
- HashMap<String,Object> defaults = (HashMap<String, Object>) this.clusterProperties.get(CollectionAdminParams.DEFAULTS);
+ HashMap<String, Object> defaults = (HashMap<String, Object>) this.clusterProperties.get(CollectionAdminParams.DEFAULTS);
if (defaults == null) {
defaults = new HashMap<>();
this.clusterProperties.put(CollectionAdminParams.DEFAULTS, defaults);
}
- HashMap<String,Object> cluster = (HashMap<String, Object>) defaults.get(CollectionAdminParams.CLUSTER);
+ HashMap<String, Object> cluster = (HashMap<String, Object>) defaults.get(CollectionAdminParams.CLUSTER);
if (cluster == null) {
cluster = new HashMap<>();
defaults.put(CollectionAdminParams.CLUSTER, cluster);
@@ -259,7 +266,9 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
}
}
- /** The cluster */
+ /**
+ * The cluster
+ */
protected static volatile MiniSolrCloudCluster cluster;
protected static SolrZkClient zkClient() {
@@ -271,7 +280,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
/**
* Call this to configure a cluster of n nodes.
- *
+ * <p>
* NB you must call {@link Builder#configure()} to start the cluster
*
* @param nodeCount the number of nodes
@@ -305,15 +314,15 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
protected static void waitForState(String message, String collection, CollectionStatePredicate predicate) {
waitForState(message, collection, predicate, DEFAULT_TIMEOUT, TimeUnit.SECONDS);
}
-
+
/**
* Wait for a particular collection state to appear in the cluster client's state reader
- *
+ * <p>
* This is a convenience method using the {@link #DEFAULT_TIMEOUT}
*
- * @param message a message to report on failure
- * @param collection the collection to watch
- * @param predicate a predicate to match against the collection state
+ * @param message a message to report on failure
+ * @param collection the collection to watch
+ * @param predicate a predicate to match against the collection state
*/
protected static void waitForState(String message, String collection, CollectionStatePredicate predicate, int timeout, TimeUnit timeUnit) {
log.info("waitForState ({}): {}", collection, message);
@@ -340,8 +349,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
return false;
if (collectionState.getSlices().size() != expectedShards)
return false;
- if (compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState)) return true;
- return false;
+ return compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState);
};
}
@@ -356,23 +364,22 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
log.info("active slice count: " + collectionState.getActiveSlices().size() + " expected:" + expectedShards);
if (collectionState.getActiveSlices().size() != expectedShards)
return false;
- if (compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState)) return true;
- return false;
+ return compareActiveReplicaCountsForShards(expectedReplicas, liveNodes, collectionState);
};
}
-
+
public static LiveNodesPredicate containsLiveNode(String node) {
return (oldNodes, newNodes) -> {
return newNodes.contains(node);
};
}
-
+
public static LiveNodesPredicate missingLiveNode(String node) {
return (oldNodes, newNodes) -> {
return !newNodes.contains(node);
};
}
-
+
public static LiveNodesPredicate missingLiveNodes(List<String> nodes) {
return (oldNodes, newNodes) -> {
boolean success = true;
@@ -395,14 +402,11 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
}
}
}
-
+
log.info("active replica count: " + activeReplicas + " expected replica count: " + expectedReplicas);
-
- if (activeReplicas == expectedReplicas) {
- return true;
- }
- return false;
+ return activeReplicas == expectedReplicas;
+
}
/**
@@ -445,7 +449,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
/**
* Get the {@link CoreStatus} data for a {@link Replica}
- *
+ * <p>
* This assumes that the replica is hosted on a live node.
*/
protected static CoreStatus getCoreStatus(Replica replica) throws IOException, SolrServerException {
@@ -476,6 +480,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
/**
* 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.
+ *
* @param nodeCount the number of Solr instances that should be running at the end of this method
* @throws Exception on error
*/
@@ -484,7 +489,7 @@ public class SolrCloudTestCase extends SolrTestCaseJ4 {
List<JettySolrRunner> jettys = cluster.getJettySolrRunners();
List<JettySolrRunner> copyOfJettys = new ArrayList<>(jettys);
int numJetties = copyOfJettys.size();
- for (int i = nodeCount; i < numJetties; i++) {
+ for (int i = nodeCount; i < numJetties; i++) {
cluster.stopJettySolrRunner(copyOfJettys.get(i));
}
for (int i = copyOfJettys.size(); i < nodeCount; i++) {