You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by el...@apache.org on 2013/05/29 03:46:19 UTC
svn commit: r1487189 - in /lucene/dev/trunk/solr: ./
solrj/src/java/org/apache/solr/client/solrj/request/
solrj/src/java/org/apache/solr/common/params/
solrj/src/test-files/solrj/solr/collection1/conf/
solrj/src/test/org/apache/solr/client/solrj/request/
Author: elyograg
Date: Wed May 29 01:46:19 2013
New Revision: 1487189
URL: http://svn.apache.org/r1487189
Log:
SOLR-4228: Add full ping functionality to SolrPing in SolrJ
Added:
lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java (with props)
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java
lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java
lucene/dev/trunk/solr/solrj/src/test-files/solrj/solr/collection1/conf/solrconfig.xml
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1487189&r1=1487188&r2=1487189&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Wed May 29 01:46:19 2013
@@ -84,6 +84,9 @@ New Features
* SOLR-4048: Add findRecursive method to NamedList. (Shawn Heisey)
+* SOLR-4228: SolrJ's SolrPing object has new methods for ping, enable, and
+ disable. (Shawn Heisey)
+
Bug Fixes
----------------------
Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java?rev=1487189&r1=1487188&r2=1487189&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/request/SolrPing.java Wed May 29 01:46:19 2013
@@ -17,50 +17,102 @@
package org.apache.solr.client.solrj.request;
+import java.io.IOException;
+import java.util.Collection;
+
import org.apache.solr.client.solrj.SolrRequest;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.SolrPingResponse;
+import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.ModifiableSolrParams;
import org.apache.solr.common.util.ContentStream;
-import java.io.IOException;
-import java.util.Collection;
-
/**
* Verify that there is a working Solr core at the URL of a {@link SolrServer}.
* To use this class, the solrconfig.xml for the relevant core must include the
* request handler for <code>/admin/ping</code>.
- *
+ *
* @since solr 1.3
*/
-public class SolrPing extends SolrRequest
-{
+public class SolrPing extends SolrRequest {
+
+ /** serialVersionUID. */
+ private static final long serialVersionUID = 5828246236669090017L;
+
+ /** Request parameters. */
private ModifiableSolrParams params;
- public SolrPing()
- {
- super( METHOD.GET, "/admin/ping" );
+ /**
+ * Create a new SolrPing object.
+ */
+ public SolrPing() {
+ super(METHOD.GET, CommonParams.PING_HANDLER);
params = new ModifiableSolrParams();
}
-
+
@Override
public Collection<ContentStream> getContentStreams() {
return null;
}
-
+
@Override
public ModifiableSolrParams getParams() {
return params;
}
-
+
@Override
- public SolrPingResponse process( SolrServer server ) throws SolrServerException, IOException
- {
+ public SolrPingResponse process(SolrServer server)
+ throws SolrServerException, IOException {
long startTime = System.currentTimeMillis();
SolrPingResponse res = new SolrPingResponse();
- res.setResponse( server.request( this ) );
- res.setElapsedTime( System.currentTimeMillis()-startTime );
+ res.setResponse(server.request(this));
+ res.setElapsedTime(System.currentTimeMillis() - startTime);
return res;
}
+
+ /**
+ * Remove the action parameter from this request. This will result in the same
+ * behavior as {@code SolrPing#setActionPing()}. For Solr server version 4.0
+ * and later.
+ *
+ * @return this
+ */
+ public SolrPing removeAction() {
+ params.remove(CommonParams.ACTION);
+ return this;
+ }
+
+ /**
+ * Set the action parameter on this request to enable. This will delete the
+ * health-check file for the Solr core. For Solr server version 4.0 and later.
+ *
+ * @return this
+ */
+ public SolrPing setActionDisable() {
+ params.set(CommonParams.ACTION, CommonParams.DISABLE);
+ return this;
+ }
+
+ /**
+ * Set the action parameter on this request to enable. This will create the
+ * health-check file for the Solr core. For Solr server version 4.0 and later.
+ *
+ * @return this
+ */
+ public SolrPing setActionEnable() {
+ params.set(CommonParams.ACTION, CommonParams.ENABLE);
+ return this;
+ }
+
+ /**
+ * Set the action parameter on this request to ping. This is the same as not
+ * including the action at all. For Solr server version 4.0 and later.
+ *
+ * @return this
+ */
+ public SolrPing setActionPing() {
+ params.set(CommonParams.ACTION, CommonParams.PING);
+ return this;
+ }
}
Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java?rev=1487189&r1=1487188&r2=1487189&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/params/CommonParams.java Wed May 29 01:46:19 2013
@@ -59,6 +59,23 @@ public interface CommonParams {
/** number of documents to return starting at "start" */
public static final String ROWS ="rows";
+
+ // SOLR-4228 start
+ /** handler value for SolrPing */
+ public static final String PING_HANDLER = "/admin/ping";
+
+ /** "action" parameter for SolrPing */
+ public static final String ACTION = "action";
+
+ /** "disable" value for SolrPing action */
+ public static final String DISABLE = "disable";
+
+ /** "enable" value for SolrPing action */
+ public static final String ENABLE = "enable";
+
+ /** "ping" value for SolrPing action */
+ public static final String PING = "ping";
+ // SOLR-4228 end
//Issue 1726 start
/** score of the last document of the previous page */
Modified: lucene/dev/trunk/solr/solrj/src/test-files/solrj/solr/collection1/conf/solrconfig.xml
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test-files/solrj/solr/collection1/conf/solrconfig.xml?rev=1487189&r1=1487188&r2=1487189&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test-files/solrj/solr/collection1/conf/solrconfig.xml (original)
+++ lucene/dev/trunk/solr/solrj/src/test-files/solrj/solr/collection1/conf/solrconfig.xml Wed May 29 01:46:19 2013
@@ -49,7 +49,17 @@
<requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
<requestHandler name="/update" class="solr.UpdateRequestHandler" />
<requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />
-
+
+ <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
+ <lst name="invariants">
+ <str name="q">*:*</str>
+ </lst>
+ <lst name="defaults">
+ <str name="echoParams">all</str>
+ </lst>
+ <str name="healthcheckFile">server-enabled.txt</str>
+ </requestHandler>
+
<!-- config for the admin interface -->
<admin>
<defaultQuery>solr</defaultQuery>
Added: lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java?rev=1487189&view=auto
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java (added)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/request/SolrPingTest.java Wed May 29 01:46:19 2013
@@ -0,0 +1,83 @@
+package org.apache.solr.client.solrj.request;
+
+/*
+ * 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.
+ */
+
+import junit.framework.Assert;
+
+import org.apache.solr.SolrJettyTestBase;
+import org.apache.solr.client.solrj.response.SolrPingResponse;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.SolrInputDocument;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test SolrPing in Solrj
+ */
+public class SolrPingTest extends SolrJettyTestBase {
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ // The following works, but it seems like it's probably the wrong way to do
+ // this.
+ initCore("solrconfig.xml", "schema.xml", "../../test-files/solrj/solr",
+ "collection1");
+ }
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ clearIndex();
+ assertU(commit());
+ assertU(optimize());
+ SolrInputDocument doc = new SolrInputDocument();
+ doc.setField("id", 1);
+ doc.setField("terms_s", "samsung");
+ getSolrServer().add(doc);
+ getSolrServer().commit(true, true);
+ }
+
+ @Test
+ public void testEnabledSolrPing() throws Exception {
+ SolrPing ping = new SolrPing();
+ SolrPingResponse rsp = null;
+ ping.setActionEnable();
+ ping.process(getSolrServer());
+ ping.removeAction();
+ rsp = ping.process(getSolrServer());
+ Assert.assertNotNull(rsp);
+ }
+
+ @Test(expected = SolrException.class)
+ public void testDisabledSolrPing() throws Exception {
+ SolrPing ping = new SolrPing();
+ SolrPingResponse rsp = null;
+ ping.setActionDisable();
+ try {
+ ping.process(getSolrServer());
+ } catch (Exception e) {
+ throw new Exception("disable action failed!");
+ }
+ ping.setActionPing();
+ rsp = ping.process(getSolrServer());
+ // the above line should fail with a 503 SolrException.
+ Assert.assertNotNull(rsp);
+ }
+}