noblepaul commented on a change in pull request #1432: URL: https://github.com/apache/lucene-solr/pull/1432#discussion_r426237573
########## File path: solr/core/src/test/org/apache/solr/handler/TestContainerPlugin.java ########## @@ -0,0 +1,250 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.solr.handler; + +import java.io.IOException; +import java.util.List; +import java.util.concurrent.Callable; + +import com.google.common.collect.ImmutableMap; +import org.apache.solr.api.Command; +import org.apache.solr.api.EndPoint; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.impl.BaseHttpSolrClient; +import org.apache.solr.client.solrj.request.V2Request; +import org.apache.solr.client.solrj.request.beans.Package; +import org.apache.solr.client.solrj.request.beans.PluginMeta; +import org.apache.solr.client.solrj.response.V2Response; +import org.apache.solr.cloud.MiniSolrCloudCluster; +import org.apache.solr.cloud.SolrCloudTestCase; +import org.apache.solr.common.NavigableObject; +import org.apache.solr.common.util.Utils; +import org.apache.solr.filestore.PackageStoreAPI; +import org.apache.solr.filestore.TestDistribPackageStore; +import org.apache.solr.pkg.TestPackages; +import org.apache.solr.request.SolrQueryRequest; +import org.apache.solr.response.SolrQueryResponse; +import org.apache.solr.security.PermissionNameProvider; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static java.util.Collections.singletonMap; +import static org.apache.solr.client.solrj.SolrRequest.METHOD.GET; +import static org.apache.solr.client.solrj.SolrRequest.METHOD.POST; +import static org.apache.solr.filestore.TestDistribPackageStore.readFile; +import static org.apache.solr.filestore.TestDistribPackageStore.uploadKey; +import static org.hamcrest.CoreMatchers.containsString; + +public class TestContainerPlugin extends SolrCloudTestCase { + + @Before + public void setup() { + System.setProperty("enable.packages", "true"); + } + + @After + public void teardown() { + System.clearProperty("enable.packages"); + } + + @Test + public void testApi() throws Exception { + MiniSolrCloudCluster cluster = + configureCluster(4) + .withJettyConfig(jetty -> jetty.enableV2(true)) + .configure(); + String errPath = "/error/details[0]/errorMessages[0]"; + try { + PluginMeta plugin = new PluginMeta(); + plugin.name = "testplugin"; + plugin.klass = C2.class.getName(); + V2Request req = new V2Request.Builder("/cluster/plugin") + .forceV2(true) + .withMethod(POST) + .withPayload(singletonMap("add", plugin)) + .build(); + expectError(req, cluster.getSolrClient(), errPath, "Must have a no-arg constructor or CoreContainer constructor and it must not be a non static inner class"); + + plugin.klass = C1.class.getName(); + expectError(req, cluster.getSolrClient(), errPath, "Invalid class, no @EndPoint annotation"); + + plugin.klass = C3.class.getName(); + req.process(cluster.getSolrClient()); + + V2Response rsp = new V2Request.Builder("/cluster/plugin") + .forceV2(true) + .withMethod(GET) + .build() + .process(cluster.getSolrClient()); + assertEquals(C3.class.getName(), rsp._getStr("/plugin/testplugin/class", null)); + + TestDistribPackageStore.assertResponseValues(10, + () -> new V2Request.Builder("/plugin/my/plugin") + .forceV2(true) + .withMethod(GET) + .build().process(cluster.getSolrClient()), + ImmutableMap.of("/testkey", "testval")); + + new V2Request.Builder("/cluster/plugin") + .withMethod(POST) + .forceV2(true) + .withPayload("{remove : testplugin}") + .build() + .process(cluster.getSolrClient()); + + rsp = new V2Request.Builder("/cluster/plugin") + .forceV2(true) + .withMethod(GET) + .build() + .process(cluster.getSolrClient()); + assertEquals(null, rsp._get("/plugin/testplugin/class", null)); + + } finally { + cluster.shutdown(); + } + } + @Test + public void testApiFromPackage() throws Exception { Review comment: Splitting these tests will create another cluster and slow down the test execution further. I shall try to add inline comments to make it more clear as to what it is doing ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
