1717
1818package org .apache .solr .handler .admin .api ;
1919
20- import static org .apache .solr .client .api .model .NodeHealthResponse .NodeStatus .FAILURE ;
2120import static org .apache .solr .client .api .model .NodeHealthResponse .NodeStatus .OK ;
2221import static org .hamcrest .Matchers .containsString ;
2322
2928import org .apache .solr .common .SolrException ;
3029import org .apache .solr .common .SolrException .ErrorCode ;
3130import org .apache .solr .embedded .JettySolrRunner ;
32- import org .apache .solr .util .SolrJettyTestRule ;
3331import org .junit .BeforeClass ;
34- import org .junit .ClassRule ;
3532import org .junit .Test ;
3633
3734public class NodeHealthTest extends SolrCloudTestCase {
3835
39- /** A standalone (non-ZooKeeper) Jetty instance used by the standalone specific tests. */
40- @ ClassRule public static SolrJettyTestRule standaloneJetty = new SolrJettyTestRule ();
41-
4236 @ BeforeClass
4337 public static void setupCluster () throws Exception {
4438 configureCluster (1 ).addConfig ("conf" , configset ("cloud-minimal" )).configure ();
45- standaloneJetty .startSolr (createTempDir ());
4639
4740 CollectionAdminRequest .createCollection (DEFAULT_TEST_COLLECTION_NAME , "conf" , 1 , 1 )
4841 .process (cluster .getSolrClient ());
4942 }
5043
5144 @ Test
52- public void testCloudMode_HealthyNodeReturnsOkStatus () throws Exception {
45+ public void testHealthyNodeReturnsOkStatus () throws Exception {
5346 final var request = new NodeApi .Healthcheck ();
5447 final var response = request .process (cluster .getSolrClient ());
5548
@@ -59,7 +52,7 @@ public void testCloudMode_HealthyNodeReturnsOkStatus() throws Exception {
5952 }
6053
6154 @ Test
62- public void testCloudMode_RequireHealthyCoresReturnOkWhenAllCoresHealthy () throws Exception {
55+ public void testRequireHealthyCoresReturnOkWhenAllCoresHealthy () throws Exception {
6356 final var request = new NodeApi .Healthcheck ();
6457 request .setRequireHealthyCores (true );
6558 final var response = request .process (cluster .getSolrClient ());
@@ -73,6 +66,7 @@ public void testCloudMode_RequireHealthyCoresReturnOkWhenAllCoresHealthy() throw
7366 public void testCloudMode_UnhealthyWhenZkClientClosed () throws Exception {
7467 // Use a fresh node so closing its ZK client does not break the primary cluster node
7568 JettySolrRunner newJetty = cluster .startJettySolrRunner ();
69+ cluster .waitForNode (newJetty , 30 );
7670 try (SolrClient nodeClient = newJetty .newClient ()) {
7771 // Sanity check: the new node should start out healthy
7872 assertEquals (OK , new NodeApi .Healthcheck ().process (nodeClient ).status );
@@ -101,8 +95,9 @@ public void testCloudMode_UnhealthyWhenZkClientClosed() throws Exception {
10195 * clusterState.getLiveNodes().contains(nodeName)}.
10296 */
10397 @ Test
104- public void testCloudMode_NotInLiveNodes_ThrowsServiceUnavailable () throws Exception {
98+ public void testNotInLiveNodes_ThrowsServiceUnavailable () throws Exception {
10599 JettySolrRunner newJetty = cluster .startJettySolrRunner ();
100+ cluster .waitForNode (newJetty , 30 );
106101 try (SolrClient nodeClient = newJetty .newClient ()) {
107102 // Sanity check: the new node should start out healthy
108103 assertEquals (OK , new NodeApi .Healthcheck ().process (nodeClient ).status );
@@ -132,35 +127,4 @@ public void testCloudMode_NotInLiveNodes_ThrowsServiceUnavailable() throws Excep
132127 newJetty .stop ();
133128 }
134129 }
135-
136- @ Test
137- public void testStandaloneMode_WithoutMaxGenerationLagReturnsOk () throws Exception {
138-
139- final var request = new NodeApi .Healthcheck ();
140- final var response = request .process (standaloneJetty .getAdminClient ());
141-
142- assertNotNull (response );
143- assertEquals (OK , response .status );
144- assertThat (
145- "Expected message about maxGenerationLag not being specified" ,
146- response .message ,
147- containsString ("maxGenerationLag isn't specified" ));
148- }
149-
150- @ Test
151- public void testStandaloneMode_WithNegativeMaxGenerationLagReturnsFailure () {
152- // maxGenerationLag is a v1-only parameter: NodeHealth.healthcheck() (v2) hardcodes it to
153- // null and never forwards it from request params. NodeApi.Healthcheck therefore cannot be used
154- // to exercise this code path, so we call the JAX-RS implementation directly.
155- // FIXME: IInteresting! Do we have a gap?
156- final var response =
157- new NodeHealth (standaloneJetty .getCoreContainer ()).checkNodeHealth (null , -1 );
158-
159- assertNotNull (response );
160- assertEquals (FAILURE , response .status );
161- assertThat (
162- "Expected message about invalid maxGenerationLag" ,
163- response .message ,
164- containsString ("Invalid value of maxGenerationLag" ));
165- }
166130}
0 commit comments