2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.solr.client.solrj;
20
import java.io.IOException;
21
import java.util.ArrayList;
22
import java.util.List;
24
import org.apache.solr.SolrJettyTestBase;
25
import org.apache.solr.client.solrj.response.QueryResponse;
26
import org.apache.solr.client.solrj.response.UpdateResponse;
27
import org.apache.solr.common.SolrInputDocument;
28
import org.junit.Test;
31
* @version $Id: LargeVolumeTestBase.java 1146838 2011-07-14 18:40:52Z sarowe $
34
public abstract class LargeVolumeTestBase extends SolrJettyTestBase
37
// for real load testing, make these numbers bigger
38
static final int numdocs = 100; //1000 * 1000;
39
static final int threadCount = 5;
42
public void testMultiThreaded() throws Exception {
43
SolrServer gserver = this.getSolrServer();
44
gserver.deleteByQuery( "*:*" ); // delete everything!
46
DocThread[] threads = new DocThread[threadCount];
47
for (int i=0; i<threadCount; i++) {
48
threads[i] = new DocThread( "T"+i+":" );
49
threads[i].setName("DocThread-" + i);
51
log.info("Started thread: " + i);
53
for (int i=0; i<threadCount; i++) {
57
// some of the commits could have failed because maxWarmingSearchers exceeded,
58
// so do a final commit to make sure everything is visible.
61
query(threadCount * numdocs);
65
private void query(int count) throws SolrServerException, IOException {
66
SolrServer gserver = this.getSolrServer();
67
SolrQuery query = new SolrQuery("*:*");
68
QueryResponse response = gserver.query(query);
69
assertEquals(0, response.getStatus());
70
assertEquals(count, response.getResults().getNumFound());
73
public class DocThread extends Thread {
75
final SolrServer tserver;
78
public DocThread( String name )
80
tserver = createNewSolrServer();
87
UpdateResponse resp = null;
88
List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
89
for (int i = 0; i < numdocs; i++) {
90
if (i > 0 && i % 200 == 0) {
91
resp = tserver.add(docs);
92
assertEquals(0, resp.getStatus());
93
docs = new ArrayList<SolrInputDocument>();
95
if (i > 0 && i % 5000 == 0) {
96
log.info(getName() + " - Committing " + i);
97
resp = tserver.commit();
98
assertEquals(0, resp.getStatus());
100
SolrInputDocument doc = new SolrInputDocument();
101
doc.addField("id", name+i );
102
doc.addField("cat", "foocat");
105
resp = tserver.add(docs);
106
assertEquals(0, resp.getStatus());
109
resp = tserver.commit();
110
assertEquals(0, resp.getStatus());
111
resp = tserver.optimize();
112
assertEquals(0, resp.getStatus());
113
} catch (Exception e) {
114
// a commit/optimize can fail with a too many warming searchers exception
115
log.info("Caught benign exception during commit: " + e.getMessage());
118
} catch (Exception e) {
120
fail( getName() + "---" + e.getMessage() );