protected abstract SolrServer getSolrCore(String name);
protected abstract String getIndexDirCore1();
public void testMergeIndexes() throws Exception {
UpdateRequest up = new UpdateRequest();
up.setAction(ACTION.COMMIT, true, true);
up.deleteByQuery("*:*");
up.process(getSolrCore0());
up.process(getSolrCore1());
up.clear();
// Add something to each core
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "AAA");
doc.setField("name", "core0");
// Add to core0
up.add(doc);
up.process(getSolrCore0());
// Add to core1
doc.setField("id", "BBB");
doc.setField("name", "core1");
up.add(doc);
up.process(getSolrCore1());
// Now Make sure AAA is in 0 and BBB in 1
SolrQuery q = new SolrQuery();
QueryRequest r = new QueryRequest(q);
q.setQuery("id:AAA");
assertEquals(1, r.process(getSolrCore0()).getResults().size());
assertEquals(0, r.process(getSolrCore1()).getResults().size());
assertEquals(1,
getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
assertEquals(0,
getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
assertEquals(0,
getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
assertEquals(1,
getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());
// Now get the index directory of core1 and merge with core0
String indexDir = getIndexDirCore1();
String name = "core0";
SolrServer coreadmin = getSolrAdmin();
CoreAdminRequest.mergeIndexes(name, new String[] { indexDir }, coreadmin);
// Now commit the merged index
up.clear(); // just do commit
up.process(getSolrCore0());
assertEquals(1,
getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
assertEquals(1,
getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());