~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/TestBatchUpdate.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
 
package org.apache.solr.client.solrj;
18
 
 
19
 
import org.apache.solr.SolrJettyTestBase;
20
 
import org.apache.solr.client.solrj.beans.Field;
21
 
import org.apache.solr.client.solrj.impl.BinaryRequestWriter;
22
 
import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
23
 
import org.apache.solr.client.solrj.request.RequestWriter;
24
 
import org.apache.solr.client.solrj.response.QueryResponse;
25
 
import org.apache.solr.common.SolrInputDocument;
26
 
import org.apache.solr.util.ExternalPaths;
27
 
import org.junit.BeforeClass;
28
 
import org.junit.Test;
29
 
 
30
 
import java.io.IOException;
31
 
import java.util.Iterator;
32
 
 
33
 
/**
34
 
 * Test for SOLR-1038
35
 
 *
36
 
 * @since solr 1.4
37
 
 * @version $Id: TestBatchUpdate.java 1146838 2011-07-14 18:40:52Z sarowe $
38
 
 */
39
 
public class TestBatchUpdate extends SolrJettyTestBase {
40
 
 
41
 
  @BeforeClass
42
 
  public static void beforeTest() throws Exception {
43
 
    createJetty(ExternalPaths.EXAMPLE_HOME, null, null);
44
 
  }
45
 
 
46
 
  static final int numdocs = 1000;  
47
 
 
48
 
 
49
 
  @Test
50
 
  public void testWithXml() throws Exception {
51
 
    CommonsHttpSolrServer commonsHttpSolrServer = (CommonsHttpSolrServer) getSolrServer();
52
 
    commonsHttpSolrServer.setRequestWriter(new RequestWriter());
53
 
    commonsHttpSolrServer.deleteByQuery( "*:*" ); // delete everything!    
54
 
    doIt(commonsHttpSolrServer);
55
 
  }
56
 
 
57
 
  @Test
58
 
  public void testWithBinary()throws Exception{
59
 
    CommonsHttpSolrServer commonsHttpSolrServer = (CommonsHttpSolrServer) getSolrServer();
60
 
    commonsHttpSolrServer.setRequestWriter(new BinaryRequestWriter());
61
 
    commonsHttpSolrServer.deleteByQuery( "*:*" ); // delete everything!
62
 
    doIt(commonsHttpSolrServer);
63
 
  }
64
 
 
65
 
  @Test
66
 
  public void testWithBinaryBean()throws Exception{
67
 
    CommonsHttpSolrServer commonsHttpSolrServer = (CommonsHttpSolrServer) getSolrServer();
68
 
    commonsHttpSolrServer.setRequestWriter(new BinaryRequestWriter());
69
 
    commonsHttpSolrServer.deleteByQuery( "*:*" ); // delete everything!
70
 
    final int[] counter = new int[1];
71
 
    counter[0] = 0;
72
 
    commonsHttpSolrServer.addBeans(new Iterator<Bean>() {
73
 
 
74
 
      public boolean hasNext() {
75
 
        return counter[0] < numdocs;
76
 
      }
77
 
 
78
 
      public Bean next() {
79
 
        Bean bean = new Bean();
80
 
        bean.id = "" + (++counter[0]);
81
 
        bean.cat = "foocat";
82
 
        return bean;
83
 
      }
84
 
 
85
 
      public void remove() {
86
 
        //do nothing
87
 
      }
88
 
    });
89
 
    commonsHttpSolrServer.commit();
90
 
    SolrQuery query = new SolrQuery("*:*");
91
 
    QueryResponse response = commonsHttpSolrServer.query(query);
92
 
    assertEquals(0, response.getStatus());
93
 
    assertEquals(numdocs, response.getResults().getNumFound());
94
 
  }
95
 
 
96
 
  public static class Bean{
97
 
    @Field
98
 
    String id;
99
 
    @Field
100
 
    String cat;
101
 
  }
102
 
       
103
 
  private void doIt(CommonsHttpSolrServer commonsHttpSolrServer) throws SolrServerException, IOException {
104
 
    final int[] counter = new int[1];
105
 
    counter[0] = 0;
106
 
    commonsHttpSolrServer.add(new Iterator<SolrInputDocument>() {
107
 
 
108
 
      public boolean hasNext() {
109
 
        return counter[0] < numdocs;
110
 
      }
111
 
 
112
 
      public SolrInputDocument next() {
113
 
        SolrInputDocument doc = new SolrInputDocument();
114
 
        doc.addField("id", "" + (++counter[0]));
115
 
        doc.addField("cat", "foocat");
116
 
        return doc;
117
 
      }
118
 
 
119
 
      public void remove() {
120
 
        //do nothing
121
 
 
122
 
      }
123
 
    });
124
 
    commonsHttpSolrServer.commit();
125
 
    SolrQuery query = new SolrQuery("*:*");
126
 
    QueryResponse response = commonsHttpSolrServer.query(query);
127
 
    assertEquals(0, response.getStatus());
128
 
    assertEquals(numdocs, response.getResults().getNumFound());
129
 
  }
130
 
}