Project

General

Profile

« Previous | Next » 

Revision 8094

Added by Jing Tao over 11 years ago

Add a method to count how many documents in a specified solr server.

View differences:

metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/SolrMetacatIdsComparatorIT.java
5 5
import java.util.List;
6 6

  
7 7
import org.apache.commons.io.FileUtils;
8
import org.apache.solr.client.solrj.SolrServer;
9
import org.apache.solr.client.solrj.response.QueryResponse;
10
import org.apache.solr.common.SolrDocumentList;
11
import org.apache.solr.common.params.SolrParams;
12
import org.apache.solr.servlet.SolrRequestParsers;
8 13
import org.dataone.cn.indexer.solrhttp.SolrDoc;
9 14
import org.dataone.cn.indexer.solrhttp.SolrElementField;
10 15
import org.junit.Before;
11 16
import org.junit.Test;
12 17

  
18
import edu.ucsb.nceas.metacat.common.SolrServerFactory;
13 19
import edu.ucsb.nceas.metacat.index.resourcemap.ResourceMapSubprocessor;
14 20

  
15 21
public class SolrMetacatIdsComparatorIT {
......
17 23
  
18 24
    private static final String metacatIDFileName = "ids";
19 25
    private static final String NOTINSOLR = "not_in_solr_but_in_metacat_ids";
26
    private static final String NUMBEROFIDS = "number_of_ids_in_solr";
20 27
    //private static final String NOTINMETACAT = "in_solr_but_not_in_metacat_ids";
21 28
    private File metacatIdsFile = null;
22 29
    private File notInSolrFile = null;
23 30
    private File notInMetacatFile = null;
31
    private File numberOfIdsFile = null;
24 32
   
25 33
    
26 34
    @Before
......
31 39
            notInSolrFile.delete();
32 40
        }
33 41
        notInSolrFile.createNewFile();
42
        numberOfIdsFile = new File(NUMBEROFIDS);
43
        if(numberOfIdsFile.exists()) {
44
            numberOfIdsFile.delete();
45
        }
46
        numberOfIdsFile.createNewFile();
34 47
        /*notInMetacatFile = new File(NOTINMETACAT);
35 48
        if(notInMetacatFile.exists()) {
36 49
            notInMetacatFile.delete();
......
60 73
            }
61 74
        }
62 75
    }
76
    
77
    /**
78
     * Figure out ids which have been indexed.
79
     */
80
    @Test
81
    public void getNumberOfIdsInSolr() throws Exception {
82
        String query = "q=*:*";
83
        SolrParams solrParams = SolrRequestParsers.parseQueryString(query);
84
        SolrServer solrServer = SolrServerFactory.createSolrServer();
85
        QueryResponse response = solrServer.query(solrParams);
86
        SolrDocumentList list = response.getResults();
87
        long number = list.getNumFound();
88
        FileUtils.writeStringToFile(numberOfIdsFile, (new Long(number)).toString());
89
    }
63 90
}

Also available in: Unified diff