From aec2619ae096b7736de8476f17a44b1405de5176 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 19 Sep 2007 19:53:11 +0000 Subject: [PATCH] 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. I think we should leave it low and let people increase the value for performance testing... these will fail if something is amiss with concurancy even at low numbers. git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@577427 13f79535-47bb-0310-9956-ffa450edef68 --- .../client/solrj/LargeVolumeTestBase.java | 110 ++++++++++++++++++ .../embedded/LargeVolumeEmbeddedTest.java | 50 ++++++++ .../solrj/embedded/LargeVolumeJettyTest.java | 93 +++++++++++++++ 3 files changed, 253 insertions(+) create mode 100644 client/java/solrj/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java create mode 100644 client/java/solrj/test/org/apache/solr/client/solrj/embedded/LargeVolumeEmbeddedTest.java create mode 100644 client/java/solrj/test/org/apache/solr/client/solrj/embedded/LargeVolumeJettyTest.java 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.java new file mode 100644 index 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 docs = new ArrayList(); + for (int i = 0; i < numdocs; i++) { + if (i > 0 && i % 200 == 0) { + resp = tserver.add(docs); + assertEquals(0, resp.getStatus()); + docs = new ArrayList(); + } + 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.java new file mode 100644 index 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.java new file mode 100644 index 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 ); + } + } +}