Skip to content

Commit aecb703

Browse files
committed
Split up standalone versus cloud mode tests.
1 parent bec1201 commit aecb703

File tree

2 files changed

+74
-41
lines changed

2 files changed

+74
-41
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.solr.handler.admin.api;
19+
20+
import static org.apache.solr.client.api.model.NodeHealthResponse.NodeStatus.FAILURE;
21+
import static org.apache.solr.client.api.model.NodeHealthResponse.NodeStatus.OK;
22+
import static org.hamcrest.Matchers.containsString;
23+
24+
import org.apache.solr.SolrTestCaseJ4;
25+
import org.apache.solr.client.solrj.request.NodeApi;
26+
import org.apache.solr.util.SolrJettyTestRule;
27+
import org.junit.BeforeClass;
28+
import org.junit.ClassRule;
29+
import org.junit.Test;
30+
31+
public class NodeHealthStandaloneTest extends SolrTestCaseJ4 {
32+
33+
@ClassRule public static SolrJettyTestRule solrTestRule = new SolrJettyTestRule();
34+
35+
@BeforeClass
36+
public static void setupCluster() throws Exception {
37+
solrTestRule.startSolr(createTempDir());
38+
}
39+
40+
@Test
41+
public void testStandaloneMode_WithoutMaxGenerationLagReturnsOk() throws Exception {
42+
43+
final var request = new NodeApi.Healthcheck();
44+
final var response = request.process(solrTestRule.getAdminClient());
45+
46+
assertNotNull(response);
47+
assertEquals(OK, response.status);
48+
assertThat(
49+
"Expected message about maxGenerationLag not being specified",
50+
response.message,
51+
containsString("maxGenerationLag isn't specified"));
52+
}
53+
54+
@Test
55+
public void testStandaloneMode_WithNegativeMaxGenerationLagReturnsFailure() {
56+
// maxGenerationLag is a v1-only parameter: NodeHealth.healthcheck() (v2) hardcodes it to
57+
// null and never forwards it from request params. NodeApi.Healthcheck therefore cannot be used
58+
// to exercise this code path, so we call the JAX-RS implementation directly.
59+
// FIXME: IInteresting! Do we have a gap?
60+
final var response = new NodeHealth(solrTestRule.getCoreContainer()).checkNodeHealth(null, -1);
61+
62+
assertNotNull(response);
63+
assertEquals(FAILURE, response.status);
64+
assertThat(
65+
"Expected message about invalid maxGenerationLag",
66+
response.message,
67+
containsString("Invalid value of maxGenerationLag"));
68+
}
69+
}

solr/core/src/test/org/apache/solr/handler/admin/api/NodeHealthTest.java

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.solr.handler.admin.api;
1919

20-
import static org.apache.solr.client.api.model.NodeHealthResponse.NodeStatus.FAILURE;
2120
import static org.apache.solr.client.api.model.NodeHealthResponse.NodeStatus.OK;
2221
import static org.hamcrest.Matchers.containsString;
2322

@@ -29,27 +28,21 @@
2928
import org.apache.solr.common.SolrException;
3029
import org.apache.solr.common.SolrException.ErrorCode;
3130
import org.apache.solr.embedded.JettySolrRunner;
32-
import org.apache.solr.util.SolrJettyTestRule;
3331
import org.junit.BeforeClass;
34-
import org.junit.ClassRule;
3532
import org.junit.Test;
3633

3734
public 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

Comments
 (0)