~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/solrj/src/test/org/apache/solr/client/solrj/LargeVolumeTestBase.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
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
8
 
 *
9
 
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
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.
16
 
 */
17
 
 
18
 
package org.apache.solr.client.solrj;
19
 
 
20
 
import java.io.IOException;
21
 
import java.util.ArrayList;
22
 
import java.util.List;
23
 
 
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;
29
 
 
30
 
/**
31
 
 * @version $Id: LargeVolumeTestBase.java 1146838 2011-07-14 18:40:52Z sarowe $
32
 
 * @since solr 1.3
33
 
 */
34
 
public abstract class LargeVolumeTestBase extends SolrJettyTestBase 
35
 
{
36
 
 
37
 
  // for real load testing, make these numbers bigger
38
 
  static final int numdocs = 100; //1000 * 1000;
39
 
  static final int threadCount = 5;
40
 
 
41
 
  @Test
42
 
  public void testMultiThreaded() throws Exception {
43
 
    SolrServer gserver = this.getSolrServer();
44
 
    gserver.deleteByQuery( "*:*" ); // delete everything!
45
 
    
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);
50
 
      threads[i].start();
51
 
      log.info("Started thread: " + i);
52
 
    }
53
 
    for (int i=0; i<threadCount; i++) {
54
 
      threads[i].join();
55
 
    }
56
 
 
57
 
    // some of the commits could have failed because maxWarmingSearchers exceeded,
58
 
    // so do a final commit to make sure everything is visible.
59
 
    gserver.commit();
60
 
    
61
 
    query(threadCount * numdocs);
62
 
    log.info("done");
63
 
  }
64
 
 
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());
71
 
  }
72
 
 
73
 
  public class DocThread extends Thread {
74
 
    
75
 
    final SolrServer tserver;
76
 
    final String name;
77
 
    
78
 
    public DocThread( String name )
79
 
    {
80
 
      tserver = createNewSolrServer();
81
 
      this.name = name;
82
 
    }
83
 
    
84
 
    @Override
85
 
    public void run() {
86
 
      try {
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>();
94
 
          }
95
 
          if (i > 0 && i % 5000 == 0) {
96
 
            log.info(getName() + " - Committing " + i);
97
 
            resp = tserver.commit();
98
 
            assertEquals(0, resp.getStatus());
99
 
          }
100
 
          SolrInputDocument doc = new SolrInputDocument();
101
 
          doc.addField("id", name+i );
102
 
          doc.addField("cat", "foocat");
103
 
          docs.add(doc);
104
 
        }
105
 
        resp = tserver.add(docs);
106
 
        assertEquals(0, resp.getStatus());
107
 
 
108
 
        try {
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());
116
 
        }
117
 
 
118
 
      } catch (Exception e) {
119
 
        e.printStackTrace();
120
 
        fail( getName() + "---" + e.getMessage() );
121
 
      }
122
 
    }
123
 
  }
124
 
}