mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
46f8c77617
commit
aec2619ae0
|
@ -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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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() );
|
||||
}
|
||||
}
|
|
@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue