Skip to content

Commit 238dd55

Browse files
committed
First pass at a smoke test
1 parent 394c7b9 commit 238dd55

File tree

1 file changed

+251
-0
lines changed

1 file changed

+251
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
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 org.apache.http.HttpResponse;
21+
import org.apache.http.client.methods.HttpDelete;
22+
import org.apache.http.client.methods.HttpGet;
23+
import org.apache.http.client.methods.HttpPost;
24+
import org.apache.http.client.methods.HttpPut;
25+
import org.apache.http.entity.ContentType;
26+
import org.apache.http.entity.StringEntity;
27+
import org.apache.solr.client.solrj.impl.HttpSolrClient;
28+
import org.apache.solr.cloud.SolrCloudTestCase;
29+
import org.junit.After;
30+
import org.junit.Before;
31+
import org.junit.BeforeClass;
32+
import org.junit.Test;
33+
34+
import java.net.URL;
35+
import java.nio.charset.StandardCharsets;
36+
37+
public class V2APISmokeTest extends SolrCloudTestCase {
38+
39+
private URL baseUrl;
40+
private String baseUrlV2;
41+
42+
@BeforeClass
43+
public static void setupCluster() throws Exception {
44+
configureCluster(1).addConfig("conf", configset("cloud-minimal")).configure();
45+
}
46+
47+
@Before
48+
@Override
49+
public void setUp() throws Exception {
50+
super.setUp();
51+
52+
baseUrl = cluster.getJettySolrRunner(0).getBaseUrl();
53+
baseUrlV2 = cluster.getJettySolrRunner(0).getBaseURLV2().toString();
54+
}
55+
56+
@After
57+
@Override
58+
public void tearDown() throws Exception {
59+
super.tearDown();
60+
}
61+
62+
@Test
63+
public void testCollectionsApi() throws Exception {
64+
canGet("/collections");
65+
canPost("/collections", """
66+
{
67+
"name": "testCollection",
68+
"numShards": 1
69+
}
70+
""");
71+
72+
final String collectionPath = "/collections/testCollection";
73+
canGet(collectionPath);
74+
75+
canPut(collectionPath + "/properties/foo", """
76+
{
77+
"value": "bar"
78+
}
79+
""");
80+
canDelete(collectionPath + "/properties/foo");
81+
82+
canPost(collectionPath + "/balance-shard-unique", """
83+
{
84+
"property": "preferredLeader"
85+
}
86+
""");
87+
88+
/**
89+
"/collections/{collectionName}/backups/{backupName}/versions" POST
90+
91+
"/collections/{collectionName}/reload" POST
92+
"/collections/{collectionName}/scale" PUT
93+
94+
"/collections/{collectionName}/shards" POST
95+
"/collections/{collectionName}/shards/{shardName}" DELETE
96+
"/collections/{collectionName}/shards/{shardName}/force-leader" POST
97+
"/collections/{collectionName}/shards/{shardName}/replicas" POST DELETE
98+
"/collections/{collectionName}/shards/{shardName}/replicas/{replicaName}" DELETE
99+
"/collections/{collectionName}/shards/{shardName}/sync" POST
100+
101+
"/collections/{collName}/shards/{shardName}/install" POST
102+
"/collections/{collName}/shards/{shardName}/replicas/{replicaName}/properties/{propName}" PUT DELETE
103+
104+
*/
105+
106+
canGet(collectionPath + "/snapshots");
107+
// "/collections/{collName}/snapshots/{snapshotName}" POST DELETE
108+
109+
// "/collections/{collectionName}/rename" POST
110+
testCollectionsAndCoresApi("collections","testCollection");
111+
canDelete(collectionPath);
112+
}
113+
114+
@Test
115+
public void testAliasesApi() throws Exception {
116+
/**
117+
"/aliases" GET POST
118+
"/aliases/{aliasName}" GET DELETE
119+
"/aliases/{aliasName}/properties" GET PUT
120+
"/aliases/{aliasName}/properties/{propName}" GET PUT DELETE
121+
*/
122+
}
123+
124+
@Test
125+
public void testBackupsApi() throws Exception {
126+
/**
127+
"/backups/{backupName}/purgeUnused" PUT
128+
"/backups/{backupName}/restore" POST
129+
"/backups/{backupName}/versions" GET DELETE
130+
"/backups/{backupName}/versions/{backupId}" DELETE
131+
132+
*/
133+
}
134+
135+
@Test
136+
public void testClusterApi() throws Exception {
137+
/**
138+
* "/cluster/files{filePath}" PUT
139+
* "/cluster/files{path}" DELETE
140+
* "/cluster/nodes/{nodeName}/clear" POST
141+
* "/cluster/nodes/{sourceNodeName}/replace" POST
142+
* "/cluster/properties" GET PUT
143+
* "/cluster/properties/{propertyName}" GET PUT DELETE
144+
* "/cluster/replicas/balance" POST
145+
* "/cluster/replicas/migrate" POST
146+
* "/cluster/zookeeper/children{zkPath}" GET
147+
* "/cluster/zookeeper/data{zkPath}" GET
148+
* "/cluster/zookeeper/data/security.json" GET
149+
*/
150+
}
151+
152+
@Test
153+
public void testConfigSetsApi() throws Exception {
154+
/**
155+
* "/configsets" GET POST
156+
* "/configsets/{configSetName}" PUT DELETE
157+
* "/configsets/{configSetName}/{filePath}" PUT
158+
*/
159+
}
160+
161+
@Test
162+
public void testCoresApi() throws Exception {
163+
/**
164+
"/cores/{coreName}/backups" POST
165+
"/cores/{coreName}/install" POST
166+
"/cores/{coreName}/merge-indices" POST
167+
"/cores/{coreName}/reload" POST
168+
"/cores/{coreName}/rename" POST
169+
"/cores/{coreName}/replication/backups" POST
170+
"/cores/{coreName}/replication/files" GET
171+
"/cores/{coreName}/replication/files/{filePath}" GET
172+
"/cores/{coreName}/replication/indexversion" GET
173+
"/cores/{coreName}/restore" POST
174+
"/cores/{coreName}/segments" GET
175+
"/cores/{coreName}/snapshots" GET
176+
"/cores/{coreName}/snapshots/{snapshotName}" POST DELETE
177+
"/cores/{coreName}/swap" POST
178+
"/cores/{coreName}/unload" POST
179+
*/
180+
testCollectionsAndCoresApi("cores", "testCore");
181+
}
182+
183+
184+
@Test
185+
public void testNodesApi() throws Exception {
186+
/**
187+
"/node/commands/{requestId}" GET
188+
"/node/files{path}" GET
189+
190+
"/node/key" GET
191+
"/node/logging/levels" GET PUT
192+
"/node/logging/messages" GET
193+
"/node/logging/messages/threshold" PUT
194+
*/
195+
}
196+
197+
private void testCollectionsAndCoresApi(String indexType, String indexName) throws Exception {
198+
/*
199+
indexType = collections | cores
200+
"/{indexType}/{indexName}/schema" GET
201+
"/{indexType}/{indexName}/schema/copyfields" GET
202+
"/{indexType}/{indexName}/schema/dynamicfields" GET
203+
"/{indexType}/{indexName}/schema/dynamicfields/{fieldName}" GET
204+
"/{indexType}/{indexName}/schema/fields" GET
205+
"/{indexType}/{indexName}/schema/fields/{fieldName}" GET
206+
"/{indexType}/{indexName}/schema/fieldtypes" GET
207+
"/{indexType}/{indexName}/schema/fieldtypes/{fieldTypeName}" GET
208+
"/{indexType}/{indexName}/schema/name" GET
209+
"/{indexType}/{indexName}/schema/similarity" GET
210+
"/{indexType}/{indexName}/schema/uniquekey" GET
211+
"/{indexType}/{indexName}/schema/version" GET
212+
"/{indexType}/{indexName}/schema/zkversion" GET
213+
"/{indexType}/{indexName}/select" GET POST
214+
*/
215+
}
216+
217+
218+
private void canPost(String url, String content) throws Exception {
219+
try (HttpSolrClient client = new HttpSolrClient.Builder(baseUrl.toString()).build()) {
220+
HttpPost httpPost = new HttpPost(baseUrlV2 + url);
221+
httpPost.setEntity(
222+
new StringEntity(content, ContentType.create("application/json", StandardCharsets.UTF_8)));
223+
HttpResponse httpResponse = client.getHttpClient().execute(httpPost);
224+
assertEquals(200, httpResponse.getStatusLine().getStatusCode());
225+
}
226+
}
227+
228+
private void canPut(String url, String content) throws Exception {
229+
try (HttpSolrClient client = new HttpSolrClient.Builder(baseUrl.toString()).build()) {
230+
HttpPut httpPut = new HttpPut(baseUrlV2 + url);
231+
httpPut.setEntity(
232+
new StringEntity(content, ContentType.create("application/json", StandardCharsets.UTF_8)));
233+
HttpResponse httpResponse = client.getHttpClient().execute(httpPut);
234+
assertEquals(200, httpResponse.getStatusLine().getStatusCode());
235+
}
236+
}
237+
238+
private void canGet(String url) throws Exception {
239+
try (HttpSolrClient client = new HttpSolrClient.Builder(baseUrl.toString()).build()) {
240+
HttpResponse httpResponse = client.getHttpClient().execute(new HttpGet(baseUrlV2 + url));
241+
assertEquals(200, httpResponse.getStatusLine().getStatusCode());
242+
}
243+
}
244+
245+
private void canDelete(String url) throws Exception {
246+
try (HttpSolrClient client = new HttpSolrClient.Builder(baseUrl.toString()).build()) {
247+
HttpResponse httpResponse = client.getHttpClient().execute(new HttpDelete(baseUrlV2 + url));
248+
assertEquals(200, httpResponse.getStatusLine().getStatusCode());
249+
}
250+
}
251+
}

0 commit comments

Comments
 (0)