Apache Lucene open-source search software
SOLR-260 -- adding solrj tests for fast concurrent updates. With the commited low number for threads and docs, these would not always fail. But increasing the number takes a long time to run.
Ryan McKinleyaec2619ae096
diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java b/client/java/solrj/test/org/apache/solr/client/solrj/LargeVolumeTestBase.javanew file mode 100644index 00000000000..c4ff13d95ca--- /dev/null+++ b/client/java/solrj/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java@@ -0,0 +1,110 @@+/**+ * 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.client.solrj;++import java.io.IOException;+import java.util.ArrayList;+import java.util.List;++import org.apache.solr.client.solrj.response.QueryResponse;+import org.apache.solr.client.solrj.response.UpdateResponse;+import org.apache.solr.common.SolrInputDocument;+import org.junit.Assert;++/**+ * @version $Id$+ * @since solr 1.3+ */+public abstract class LargeVolumeTestBase extends SolrExampleTestBase+{+ SolrServer gserver = null;++ // for real load testing, make these numbers bigger+ static final int numdocs = 100; //1000 * 1000;+ static final int threadCount = 5;++ public void testMultiThreaded() throws Exception {+ gserver = this.getSolrServer();+ DocThread[] threads = new DocThread[threadCount];+ for (int i=0; i<threadCount; i++) {+ threads[i] = new DocThread( "T"+i+":" );+ threads[i].setName("DocThread-" + i);+ threads[i].start();+ System.out.println("Started thread: " + i);+ }+ for (int i=0; i<threadCount; i++) {+ threads[i].join();+ }++ query(threadCount * numdocs);+ System.out.println("done");+ }++ private void query(int count) throws SolrServerException, IOException {+ SolrQuery query = new SolrQuery("*:*");+ QueryResponse response = gserver.query(query);+ Assert.assertEquals(0, response.getStatus());+ Assert.assertEquals(count, response.getResults().getNumFound());+ }++ public class DocThread extends Thread {++ final SolrServer tserver;+ final String name;++ public DocThread( String name )+ {+ tserver = createNewSolrServer();+ this.name = name;+ }++ @Override+ public void run() {+ try {+ UpdateResponse resp = null;+ List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();+ for (int i = 0; i < numdocs; i++) {+ if (i > 0 && i % 200 == 0) {+ resp = tserver.add(docs);+ assertEquals(0, resp.getStatus());+ docs = new ArrayList<SolrInputDocument>();+ }+ if (i > 0 && i % 5000 == 0) {+ System.out.println(getName() + " - Committing " + i);+ resp = tserver.commit();+ assertEquals(0, resp.getStatus());+ }+ SolrInputDocument doc = new SolrInputDocument();+ doc.addField("id", name+i );+ doc.addField("cat", "foocat");+ docs.add(doc);+ }+ resp = tserver.add(docs);+ assertEquals(0, resp.getStatus());+ resp = tserver.commit();+ assertEquals(0, resp.getStatus());+ resp = tserver.optimize();+ assertEquals(0, resp.getStatus());++ } catch (Exception e) {+ e.printStackTrace();+ Assert.fail( getName() + "---" + e.getMessage() );+ }+ }+ }+}diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/embedded/LargeVolumeEmbeddedTest.java b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/LargeVolumeEmbeddedTest.javanew file mode 100644index 00000000000..59d9a11fe7b--- /dev/null+++ b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/LargeVolumeEmbeddedTest.java@@ -0,0 +1,50 @@+/**+ * 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.client.solrj.embedded;++import org.apache.solr.client.solrj.LargeVolumeTestBase;+import org.apache.solr.client.solrj.SolrServer;++/**+ * @version $Id$+ * @since solr 1.3+ */+public class LargeVolumeEmbeddedTest extends LargeVolumeTestBase {++ SolrServer server;++ @Override public void setUp() throws Exception+ {+ super.setUp();++ // setup the server...+ server = createNewSolrServer();+ }++ @Override+ protected SolrServer getSolrServer()+ {+ return server;+ }++ @Override+ protected SolrServer createNewSolrServer()+ {+ return new EmbeddedSolrServer( h.getCore() );+ }+}diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.javanew file mode 100644index 00000000000..f2c2dd54372--- /dev/null+++ b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java@@ -0,0 +1,93 @@+/**+ * 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.client.solrj.embedded;++import org.apache.solr.client.solrj.LargeVolumeTestBase;+import org.apache.solr.client.solrj.SolrServer;+import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;+import org.apache.solr.core.SolrCore;+import org.apache.solr.schema.SchemaField;++/**+ * @version $Id$+ * @since solr 1.3+ */+public class LargeVolumeJettyTest extends LargeVolumeTestBase {++ SolrServer server;+ JettySolrRunner jetty;++ static final int port = 8984; // not 8983+ static final String context = "/example";+++ @Override public void setUp() throws Exception+ {+ super.setUp();++ SolrCore c = SolrCore.getSolrCore();+ System.out.println( c.getConfigFile() );+ System.out.println( c.getSolrConfig().configFile );+ System.out.println( c.getSchema().getFields() );++ try {+ SchemaField f = c.getSchema().getField( "cat" );+ System.out.println( f );+ }+ catch( Exception ex ) {+ ex.printStackTrace();+ }+ System.out.println( "---" );+++ jetty = new JettySolrRunner( context, port );+ jetty.start();++ server = this.createNewSolrServer();+ }++ @Override public void tearDown() throws Exception+ {+ super.tearDown();+ jetty.stop(); // stop the server+ }+++ @Override+ protected SolrServer getSolrServer()+ {+ return server;+ }++ @Override+ protected SolrServer createNewSolrServer()+ {+ try {+ // setup the server...+ String url = "http://localhost:"+port+context;+ CommonsHttpSolrServer s = new CommonsHttpSolrServer( url );+ s.setConnectionTimeout(5);+ s.setDefaultMaxConnectionsPerHost(100);+ s.setMaxTotalConnections(100);+ return s;+ }+ catch( Exception ex ) {+ throw new RuntimeException( ex );+ }+ }+}