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 org.apache.solr.client.solrj.request.AbstractUpdateRequest;
21
import org.apache.solr.client.solrj.request.CoreAdminRequest;
22
import org.apache.solr.client.solrj.request.QueryRequest;
23
import org.apache.solr.client.solrj.request.UpdateRequest;
24
import org.apache.solr.client.solrj.request.UpdateRequest.ACTION;
25
import org.apache.solr.common.SolrInputDocument;
26
import org.apache.solr.core.CoreContainer;
27
import org.apache.solr.core.SolrCore;
28
import org.apache.solr.util.ExternalPaths;
30
import java.io.IOException;
33
* Abstract base class for testing merge indexes command
36
* @version $Id: MergeIndexesExampleTestBase.java 1146191 2011-07-13 18:23:28Z sarowe $
38
public abstract class MergeIndexesExampleTestBase extends SolrExampleTestBase {
39
// protected static final CoreContainer cores = new CoreContainer();
40
protected static CoreContainer cores;
43
public String getSolrHome() {
44
return ExternalPaths.EXAMPLE_MULTICORE_HOME;
48
public String getSchemaFile() {
49
return getSolrHome() + "/core0/conf/schema.xml";
53
public String getSolrConfigFile() {
54
return getSolrHome() + "/core0/conf/solrconfig.xml";
58
public void setUp() throws Exception {
60
cores = h.getCoreContainer();
61
SolrCore.log.info("CORES=" + cores + " : " + cores.getCoreNames());
62
cores.setPersistent(false);
66
protected final SolrServer getSolrServer() {
67
throw new UnsupportedOperationException();
71
protected final SolrServer createNewSolrServer() {
72
throw new UnsupportedOperationException();
75
protected abstract SolrServer getSolrCore0();
77
protected abstract SolrServer getSolrCore1();
79
protected abstract SolrServer getSolrAdmin();
81
protected abstract SolrServer getSolrCore(String name);
83
protected abstract String getIndexDirCore1();
85
private UpdateRequest setupCores() throws SolrServerException, IOException {
86
UpdateRequest up = new UpdateRequest();
87
up.setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true);
88
up.deleteByQuery("*:*");
89
up.process(getSolrCore0());
90
up.process(getSolrCore1());
93
// Add something to each core
94
SolrInputDocument doc = new SolrInputDocument();
95
doc.setField("id", "AAA");
96
doc.setField("name", "core0");
100
up.process(getSolrCore0());
103
doc.setField("id", "BBB");
104
doc.setField("name", "core1");
106
up.process(getSolrCore1());
108
// Now Make sure AAA is in 0 and BBB in 1
109
SolrQuery q = new SolrQuery();
110
QueryRequest r = new QueryRequest(q);
111
q.setQuery("id:AAA");
112
assertEquals(1, r.process(getSolrCore0()).getResults().size());
113
assertEquals(0, r.process(getSolrCore1()).getResults().size());
116
getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
118
getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
121
getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
123
getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());
128
public void testMergeIndexesByDirName() throws Exception {
129
UpdateRequest up = setupCores();
131
// Now get the index directory of core1 and merge with core0
132
CoreAdminRequest.mergeIndexes("core0", new String[] {getIndexDirCore1()}, new String[0], getSolrAdmin());
134
// Now commit the merged index
135
up.clear(); // just do commit
136
up.process(getSolrCore0());
139
getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
141
getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
144
public void testMergeIndexesByCoreName() throws Exception {
145
UpdateRequest up = setupCores();
146
CoreAdminRequest.mergeIndexes("core0", new String[0], new String[] {"core1"}, getSolrAdmin());
148
// Now commit the merged index
149
up.clear(); // just do commit
150
up.process(getSolrCore0());
153
getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
155
getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());