|
| 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 | +package org.apache.solr.handler.admin; |
| 18 | + |
| 19 | +import java.io.IOException; |
| 20 | +import org.apache.solr.client.solrj.SolrClient; |
| 21 | +import org.apache.solr.client.solrj.SolrRequest; |
| 22 | +import org.apache.solr.client.solrj.SolrServerException; |
| 23 | +import org.apache.solr.client.solrj.request.CollectionAdminRequest; |
| 24 | +import org.apache.solr.client.solrj.request.GenericSolrRequest; |
| 25 | +import org.apache.solr.client.solrj.response.SimpleSolrResponse; |
| 26 | +import org.apache.solr.client.solrj.response.json.JsonMapResponseParser; |
| 27 | +import org.apache.solr.cloud.SolrCloudTestCase; |
| 28 | +import org.apache.solr.common.params.CommonParams; |
| 29 | +import org.apache.solr.common.params.ModifiableSolrParams; |
| 30 | +import org.apache.solr.common.util.NamedList; |
| 31 | +import org.junit.BeforeClass; |
| 32 | +import org.junit.Test; |
| 33 | + |
| 34 | +/** Basic tests for {@link ZookeeperInfoHandler} */ |
| 35 | +public class ZookeeperInfoHandlerTest extends SolrCloudTestCase { |
| 36 | + |
| 37 | + @BeforeClass |
| 38 | + public static void setupCluster() throws Exception { |
| 39 | + configureCluster(1).addConfig("conf", configset("cloud-minimal")).configure(); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testZkInfoHandler() throws SolrServerException, IOException { |
| 44 | + SolrClient client = cluster.getSolrClient(); |
| 45 | + |
| 46 | + ModifiableSolrParams params = new ModifiableSolrParams(); |
| 47 | + params.set(CommonParams.PATH, "/"); |
| 48 | + params.set("detail", "true"); |
| 49 | + GenericSolrRequest req = |
| 50 | + new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/zookeeper", params); |
| 51 | + req.setResponseParser(new JsonMapResponseParser()); |
| 52 | + |
| 53 | + NamedList<Object> response = client.request(req); |
| 54 | + assertNotNull("Response should not be null", response); |
| 55 | + |
| 56 | + // ZK handler should return 'znode' for detail requests |
| 57 | + assertNotNull(response.get("znode")); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testZkInfoHandlerCollectionsView() throws Exception { |
| 62 | + // Create a test collection first |
| 63 | + String collectionName = "zkinfo_test_collection"; |
| 64 | + CollectionAdminRequest.createCollection(collectionName, "conf", 1, 1) |
| 65 | + .process(cluster.getSolrClient()); |
| 66 | + cluster.waitForActiveCollection(collectionName, 1, 1); |
| 67 | + |
| 68 | + SolrClient client = cluster.getSolrClient(); |
| 69 | + // Test collections view (graph view with clusterstate.json) |
| 70 | + ModifiableSolrParams params = new ModifiableSolrParams(); |
| 71 | + params.set(CommonParams.PATH, "/clusterstate.json"); |
| 72 | + params.set("view", "graph"); |
| 73 | + |
| 74 | + GenericSolrRequest req = |
| 75 | + new GenericSolrRequest(SolrRequest.METHOD.GET, "/admin/zookeeper", params); |
| 76 | + req.setResponseParser(new JsonMapResponseParser()); |
| 77 | + |
| 78 | + // Verify the request completes and returns collection data |
| 79 | + SimpleSolrResponse response = req.process(client); |
| 80 | + NamedList<Object> responseData = response.getResponse(); |
| 81 | + |
| 82 | + // Collections view should return znode with collection data |
| 83 | + assertNotNull("Response should not be null", responseData); |
| 84 | + |
| 85 | + assertNotNull( |
| 86 | + "Response should contain 'znode' for collections view", responseData.get("znode")); |
| 87 | + } |
| 88 | +} |
0 commit comments