Skip to content

Commit

Permalink
refactor method names
Browse files Browse the repository at this point in the history
  • Loading branch information
noblepaul committed Oct 22, 2020
1 parent 67ecd8f commit 79229eb
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.commons.collections4.MultiValuedMap;
import org.apache.commons.collections4.multimap.HashSetValuedHashMap;
import org.apache.http.client.methods.HttpDelete;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.V2Request;
Expand Down Expand Up @@ -129,7 +128,7 @@ public void uninstall(String packageName, String version) {

V2Request req = new V2Request.Builder(PackageUtils.PACKAGE_PATH)
.forceV2(true)
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload(Collections.singletonMap("delete", del))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.lucene.util.SuppressForbidden;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.V2Request;
Expand Down Expand Up @@ -96,7 +95,7 @@ public static void postFile(SolrClient client, ByteBuffer buffer, String name, S
params.add("sig", sig);
}
V2Response rsp = new V2Request.Builder(resource)
.withMethod(SolrRequest.METHOD.PUT)
.PUT()
.withPayload(buffer)
.forceV2(true)
.withMimeType("application/octet-stream")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.lucene.util.Version;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.request.V2Request;
Expand Down Expand Up @@ -207,7 +206,7 @@ private boolean installPackage(String packageName, String version) throws SolrEx

V2Request req = new V2Request.Builder(PackageUtils.PACKAGE_PATH)
.forceV2(true)
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload(Collections.singletonMap("add", add))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.apache.http.util.EntityUtils;
import org.apache.lucene.util.IOUtils;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.cloud.SolrCloudManager;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
Expand Down Expand Up @@ -708,7 +707,7 @@ public void test() throws Exception {
///////////////
// use v2 API
new V2Request.Builder("/collections")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload("{\"create-alias\": {\"name\": \"testalias6\", collections:[\"collection2\",\"collection1\"]}}")
.build().process(cluster.getSolrClient());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
Expand Down Expand Up @@ -134,7 +133,7 @@ public void testCreateCollWithDefaultClusterPropertiesOldFormat() throws Excepti
String COLL_NAME = "CollWithDefaultClusterProperties";
try {
V2Response rsp = new V2Request.Builder("/cluster")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload("{set-obj-property:{collectionDefaults:{numShards : 2 , nrtReplicas : 2}}}")
.build()
.process(cluster.getSolrClient());
Expand Down Expand Up @@ -167,7 +166,7 @@ public void testCreateCollWithDefaultClusterPropertiesOldFormat() throws Excepti

// unset only a single value using old format
rsp = new V2Request.Builder("/cluster")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload("{\n" +
" \"set-obj-property\": {\n" +
" \"collectionDefaults\": {\n" +
Expand All @@ -190,7 +189,7 @@ public void testCreateCollWithDefaultClusterPropertiesOldFormat() throws Excepti

// delete all defaults the old way
rsp = new V2Request.Builder("/cluster")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload("{set-obj-property:{collectionDefaults:null}}")
.build()
.process(cluster.getSolrClient());
Expand All @@ -206,7 +205,7 @@ public void testCreateCollWithDefaultClusterPropertiesOldFormat() throws Excepti
} finally {
// clean up in case there was an exception during the test
V2Response rsp = new V2Request.Builder("/cluster")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload("{set-obj-property:{collectionDefaults: null}}")
.build()
.process(cluster.getSolrClient());
Expand All @@ -219,7 +218,7 @@ public void testCreateCollWithDefaultClusterPropertiesNewFormat() throws Excepti
String COLL_NAME = "CollWithDefaultClusterProperties";
try {
V2Response rsp = new V2Request.Builder("/cluster")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload("{set-obj-property:{defaults : {collection:{numShards : 2 , nrtReplicas : 2}}}}")
.build()
.process(cluster.getSolrClient());
Expand Down Expand Up @@ -251,7 +250,7 @@ public void testCreateCollWithDefaultClusterPropertiesNewFormat() throws Excepti

// unset only a single value
rsp = new V2Request.Builder("/cluster")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload("{\n" +
" \"set-obj-property\": {\n" +
" \"defaults\" : {\n" +
Expand All @@ -272,7 +271,7 @@ public void testCreateCollWithDefaultClusterPropertiesNewFormat() throws Excepti
assertNull(clusterProperty);

rsp = new V2Request.Builder("/cluster")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload("{set-obj-property:{defaults: {collection:null}}}")
.build()
.process(cluster.getSolrClient());
Expand All @@ -287,7 +286,7 @@ public void testCreateCollWithDefaultClusterPropertiesNewFormat() throws Excepti
assertNull(clusterProperty);
} finally {
V2Response rsp = new V2Request.Builder("/cluster")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload("{set-obj-property:{defaults: null}}")
.build()
.process(cluster.getSolrClient());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testPackageStoreManagement() throws Exception {
assertResponseValues(10,
cluster.getSolrClient(),
new V2Request.Builder("/node/files/package/mypkg/v1.0")
.withMethod(SolrRequest.METHOD.GET)
.GET()
.build(),
Utils.makeMap(
":files:/package/mypkg/v1.0[0]:name", "runtimelibs.jar",
Expand All @@ -113,7 +113,7 @@ public void testPackageStoreManagement() throws Exception {
assertResponseValues(10,
cluster.getSolrClient(),
new V2Request.Builder("/node/files/package/mypkg")
.withMethod(SolrRequest.METHOD.GET)
.GET()
.build(),
Utils.makeMap(
":files:/package/mypkg[0]:name", "v1.0",
Expand Down Expand Up @@ -278,7 +278,7 @@ public static void postFile(SolrClient client, ByteBuffer buffer, String name, S
ModifiableSolrParams params = new ModifiableSolrParams();
params.add("sig", sig);
V2Response rsp = new V2Request.Builder(resource)
.withMethod(SolrRequest.METHOD.PUT)
.PUT()
.withPayload(buffer)
.forceV2(true)
.withMimeType("application/octet-stream")
Expand Down
37 changes: 18 additions & 19 deletions solr/core/src/test/org/apache/solr/handler/TestContainerPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import static java.util.Collections.singletonList;
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;

Expand Down Expand Up @@ -88,7 +87,7 @@ public void testApi() throws Exception {
//test with an invalid class
V2Request req = new V2Request.Builder("/cluster/plugin")
.forceV2(true)
.withMethod(POST)
.POST()
.withPayload(singletonMap("add", plugin))
.build();
expectError(req, cluster.getSolrClient(), errPath, "No method with @Command in class");
Expand All @@ -107,7 +106,7 @@ public void testApi() throws Exception {
//just check if the plugin is indeed registered
V2Request readPluginState = new V2Request.Builder("/cluster/plugin")
.forceV2(true)
.withMethod(GET)
.GET()
.build();
V2Response rsp = readPluginState.process(cluster.getSolrClient());
assertEquals(C3.class.getName(), rsp._getStr("/plugin/testplugin/class", null));
Expand All @@ -116,13 +115,13 @@ public void testApi() throws Exception {
TestDistribPackageStore.assertResponseValues(10,
() -> new V2Request.Builder("/plugin/my/plugin")
.forceV2(true)
.withMethod(GET)
.GET()
.build().process(cluster.getSolrClient()),
ImmutableMap.of("/testkey", "testval"));

//now remove the plugin
new V2Request.Builder("/cluster/plugin")
.withMethod(POST)
.POST()
.forceV2(true)
.withPayload("{remove : testplugin}")
.build()
Expand All @@ -147,32 +146,32 @@ public void testApi() throws Exception {
TestDistribPackageStore.assertResponseValues(10,
() -> new V2Request.Builder("/my-random-name/my/plugin")
.forceV2(true)
.withMethod(GET)
.GET()
.build().process(cluster.getSolrClient()),
ImmutableMap.of("/method.name", "m1"));

TestDistribPackageStore.assertResponseValues(10,
() -> new V2Request.Builder("/my-random-prefix/their/plugin")
.forceV2(true)
.withMethod(GET)
.GET()
.build().process(cluster.getSolrClient()),
ImmutableMap.of("/method.name", "m2"));
//now remove the plugin
new V2Request.Builder("/cluster/plugin")
.withMethod(POST)
.POST()
.forceV2(true)
.withPayload("{remove : my-random-name}")
.build()
.process(cluster.getSolrClient());

expectFail( () -> new V2Request.Builder("/my-random-prefix/their/plugin")
.forceV2(true)
.withMethod(GET)
.GET()
.build()
.process(cluster.getSolrClient()));
expectFail(() -> new V2Request.Builder("/my-random-prefix/their/plugin")
.forceV2(true)
.withMethod(GET)
.GET()
.build()
.process(cluster.getSolrClient()));

Expand All @@ -184,7 +183,7 @@ public void testApi() throws Exception {
//just check if the plugin is indeed registered
readPluginState = new V2Request.Builder("/cluster/plugin")
.forceV2(true)
.withMethod(GET)
.GET()
.build();
rsp = readPluginState.process(cluster.getSolrClient());
assertEquals(C6.class.getName(), rsp._getStr("/plugin/clusterSingleton/class", null));
Expand Down Expand Up @@ -241,7 +240,7 @@ public void testApiFromPackage() throws Exception {
add.files = singletonList(FILE1);
V2Request addPkgVersionReq = new V2Request.Builder("/cluster/package")
.forceV2(true)
.withMethod(POST)
.POST()
.withPayload(singletonMap("add", add))
.build();
addPkgVersionReq.process(cluster.getSolrClient());
Expand All @@ -258,14 +257,14 @@ public void testApiFromPackage() throws Exception {
plugin.version = add.version;
final V2Request req1 = new V2Request.Builder("/cluster/plugin")
.forceV2(true)
.withMethod(POST)
.POST()
.withPayload(singletonMap("add", plugin))
.build();
req1.process(cluster.getSolrClient());
//verify the plugin creation
TestDistribPackageStore.assertResponseValues(10,
() -> new V2Request.Builder("/cluster/plugin").
withMethod(GET)
() -> new V2Request.Builder("/cluster/plugin")
.GET()
.build().process(cluster.getSolrClient()),
ImmutableMap.of(
"/plugin/myplugin/class", plugin.klass,
Expand All @@ -274,7 +273,7 @@ public void testApiFromPackage() throws Exception {
//let's test this now
Callable<NavigableObject> invokePlugin = () -> new V2Request.Builder("/plugin/my/path")
.forceV2(true)
.withMethod(GET)
.GET()
.build().process(cluster.getSolrClient());
TestDistribPackageStore.assertResponseValues(10,
invokePlugin,
Expand All @@ -289,15 +288,15 @@ public void testApiFromPackage() throws Exception {
plugin.version = add.version;
new V2Request.Builder("/cluster/plugin")
.forceV2(true)
.withMethod(POST)
.GET()
.withPayload(singletonMap("update", plugin))
.build()
.process(cluster.getSolrClient());

//now verify if it is indeed updated
TestDistribPackageStore.assertResponseValues(10,
() -> new V2Request.Builder("/cluster/plugin").
withMethod(GET)
() -> new V2Request.Builder("/cluster/plugin")
.GET()
.build().process(cluster.getSolrClient()),
ImmutableMap.of(
"/plugin/myplugin/class", plugin.klass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.solr.handler;

import org.apache.solr.client.solrj.ResponseParser;
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.*;
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
Expand Down Expand Up @@ -63,7 +62,7 @@ public void testWelcomeMessage() throws Exception {

private void testException(ResponseParser responseParser, int expectedCode, String path, String payload) throws IOException, SolrServerException {
V2Request v2Request = new V2Request.Builder(path)
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload(payload)
.build();
v2Request.setResponseParser(responseParser);
Expand Down Expand Up @@ -150,10 +149,12 @@ public void testSingleWarning() throws Exception {
public void testSetPropertyValidationOfCluster() throws IOException, SolrServerException {
@SuppressWarnings({"rawtypes"})
NamedList resp = cluster.getSolrClient().request(
new V2Request.Builder("/cluster").withMethod(SolrRequest.METHOD.POST).withPayload("{set-property: {name: maxCoresPerNode, val:42}}").build());
new V2Request.Builder("/cluster")
.POST()
.withPayload("{set-property: {name: maxCoresPerNode, val:42}}").build());
assertTrue(resp.toString().contains("status=0"));
resp = cluster.getSolrClient().request(
new V2Request.Builder("/cluster").withMethod(SolrRequest.METHOD.POST).withPayload("{set-property: {name: maxCoresPerNode, val:null}}").build());
new V2Request.Builder("/cluster").POST().withPayload("{set-property: {name: maxCoresPerNode, val:null}}").build());
assertTrue(resp.toString().contains("status=0"));
}

Expand All @@ -174,7 +175,7 @@ public void testCollectionsApi() throws Exception {
backupParams.put("location", tempDir);
cluster.getJettySolrRunners().forEach(j -> j.getCoreContainer().getAllowPaths().add(Paths.get(tempDir)));
client.request(new V2Request.Builder("/c")
.withMethod(SolrRequest.METHOD.POST)
.POST()
.withPayload(Utils.toJSONString(backupPayload))
.build());
}
Expand Down
Loading

0 comments on commit 79229eb

Please sign in to comment.