mirror of https://github.com/apache/lucene.git
SOLR-4471: Improve and clean up TestReplicationHandler.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1449240 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
13fc322cf0
commit
c21914aa7d
|
@ -199,6 +199,9 @@ Other Changes
|
|||
|
||||
* SOLR-2470: Added more tests for VelocityResponseWriter
|
||||
|
||||
* SOLR-4471: Improve and clean up TestReplicationHandler.
|
||||
(Amit Nithian via Mark Miller)
|
||||
|
||||
================== 4.1.0 ==================
|
||||
|
||||
Versions of Major Components
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.apache.solr.common.util.SimpleOrderedMap;
|
|||
import org.apache.solr.util.AbstractSolrTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for ReplicationHandler
|
||||
|
@ -88,6 +89,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
// System.setProperty("solr.directoryFactory", "solr.StandardDirectoryFactory");
|
||||
// For manual testing only
|
||||
// useFactory(null); // force an FS factory
|
||||
master = new SolrInstance("master", null);
|
||||
|
@ -252,20 +254,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
return res;
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
doTestReplicateAfterCoreReload();
|
||||
doTestDetails();
|
||||
doTestReplicateAfterWrite2Slave();
|
||||
doTestIndexAndConfigReplication();
|
||||
doTestStopPoll();
|
||||
doTestSnapPullWithMasterUrl();
|
||||
doTestReplicateAfterStartup();
|
||||
doTestReplicateAfterStartupWithNoActivity();
|
||||
doTestIndexAndConfigAliasReplication();
|
||||
doTestBackup();
|
||||
}
|
||||
|
||||
private void doTestDetails() throws Exception {
|
||||
@Test
|
||||
public void doTestDetails() throws Exception {
|
||||
{
|
||||
NamedList<Object> details = getDetails(masterClient);
|
||||
|
||||
|
@ -318,22 +308,17 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
}
|
||||
}
|
||||
|
||||
private void doTestReplicateAfterWrite2Slave() throws Exception {
|
||||
@Test
|
||||
public void doTestReplicateAfterWrite2Slave() throws Exception {
|
||||
clearIndexWithReplication();
|
||||
nDocs--;
|
||||
for (int i = 0; i < nDocs; i++) {
|
||||
index(masterClient, "id", i, "name", "name = " + i);
|
||||
}
|
||||
|
||||
String masterUrl = "http://127.0.0.1:" + masterJetty.getLocalPort() + "/solr/replication?command=disableReplication";
|
||||
URL url = new URL(masterUrl);
|
||||
InputStream stream = url.openStream();
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
|
||||
invokeReplicationCommand(masterJetty.getLocalPort(), "disableReplication");
|
||||
invokeReplicationCommand(slaveJetty.getLocalPort(), "disablepoll");
|
||||
|
||||
masterClient.commit();
|
||||
|
||||
NamedList masterQueryRsp = rQuery(nDocs, "*:*", masterClient);
|
||||
|
@ -355,6 +340,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
slaveClient.commit(true, true);
|
||||
|
||||
|
||||
|
||||
//this doc is added to slave so it should show an item w/ that result
|
||||
SolrDocumentList slaveQueryResult = null;
|
||||
NamedList slaveQueryRsp;
|
||||
|
@ -362,15 +348,11 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
|
||||
assertEquals(1, slaveQueryResult.getNumFound());
|
||||
|
||||
masterUrl = "http://127.0.0.1:" + masterJetty.getLocalPort() + "/solr/replication?command=enableReplication";
|
||||
url = new URL(masterUrl);
|
||||
stream = url.openStream();
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
//Let's fetch the index rather than rely on the polling.
|
||||
invokeReplicationCommand(masterJetty.getLocalPort(), "enablereplication");
|
||||
invokeReplicationCommand(slaveJetty.getLocalPort(), "fetchindex");
|
||||
|
||||
/*
|
||||
//the slave should have done a full copy of the index so the doc with id:555 should not be there in the slave now
|
||||
slaveQueryRsp = rQuery(0, "id:555", slaveClient);
|
||||
slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
|
||||
|
@ -380,9 +362,26 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
slaveQueryRsp = rQuery(nDocs, "*:*", slaveClient);
|
||||
slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
|
||||
assertEquals(nDocs, slaveQueryResult.getNumFound());
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
private void doTestIndexAndConfigReplication() throws Exception {
|
||||
//Simple function to wrap the invocation of replication commands on the various
|
||||
//jetty servers.
|
||||
private void invokeReplicationCommand(int pJettyPort, String pCommand) throws IOException
|
||||
{
|
||||
String masterUrl = "http://127.0.0.1:" + pJettyPort + "/solr/replication?command=" + pCommand;
|
||||
try {
|
||||
URL u = new URL(masterUrl);
|
||||
InputStream stream = u.openStream();
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doTestIndexAndConfigReplication() throws Exception {
|
||||
clearIndexWithReplication();
|
||||
|
||||
nDocs--;
|
||||
|
@ -451,7 +450,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
|
||||
}
|
||||
|
||||
private void doTestStopPoll() throws Exception {
|
||||
@Test
|
||||
public void doTestStopPoll() throws Exception {
|
||||
clearIndexWithReplication();
|
||||
|
||||
// Test:
|
||||
|
@ -477,14 +477,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
assertEquals(null, cmp);
|
||||
|
||||
// start stop polling test
|
||||
String slaveURL = "http://127.0.0.1:" + slaveJetty.getLocalPort() + "/solr/replication?command=disablepoll";
|
||||
URL url = new URL(slaveURL);
|
||||
InputStream stream = url.openStream();
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
invokeReplicationCommand(slaveJetty.getLocalPort(), "disablepoll");
|
||||
|
||||
index(masterClient, "id", 501, "name", "name = " + 501);
|
||||
masterClient.commit();
|
||||
|
||||
|
@ -503,22 +497,15 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
assertEquals(nDocs, slaveQueryResult.getNumFound());
|
||||
|
||||
// re-enable replication
|
||||
slaveURL = "http://127.0.0.1:" + slaveJetty.getLocalPort() + "/solr/replication?command=enablepoll";
|
||||
url = new URL(slaveURL);
|
||||
stream = url.openStream();
|
||||
try {
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
//e.printStackTrace();
|
||||
}
|
||||
invokeReplicationCommand(slaveJetty.getLocalPort(), "enablepoll");
|
||||
|
||||
slaveQueryRsp = rQuery(nDocs+1, "*:*", slaveClient);
|
||||
slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
|
||||
assertEquals(nDocs+1, slaveQueryResult.getNumFound());
|
||||
}
|
||||
|
||||
|
||||
private void doTestSnapPullWithMasterUrl() throws Exception {
|
||||
@Test
|
||||
public void doTestSnapPullWithMasterUrl() throws Exception {
|
||||
//change solrconfig on slave
|
||||
//this has no entry for pollinginterval
|
||||
slave.copyConfigFile(CONF_DIR + "solrconfig-slave1.xml", "solrconfig.xml");
|
||||
|
@ -823,7 +810,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
}
|
||||
}
|
||||
|
||||
private void doTestReplicateAfterCoreReload() throws Exception {
|
||||
@Test
|
||||
public void doTestReplicateAfterCoreReload() throws Exception {
|
||||
int docs = TEST_NIGHTLY ? 200000 : 0;
|
||||
|
||||
//stop slave
|
||||
|
@ -902,7 +890,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
|
||||
}
|
||||
|
||||
private void doTestIndexAndConfigAliasReplication() throws Exception {
|
||||
@Test
|
||||
public void doTestIndexAndConfigAliasReplication() throws Exception {
|
||||
clearIndexWithReplication();
|
||||
|
||||
nDocs--;
|
||||
|
@ -975,8 +964,8 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
}
|
||||
|
||||
|
||||
|
||||
private void doTestBackup() throws Exception {
|
||||
@Test
|
||||
public void doTestBackup() throws Exception {
|
||||
String configFile = "solrconfig-master1.xml";
|
||||
boolean addNumberToKeepInRequest = true;
|
||||
String backupKeepParamName = ReplicationHandler.NUMBER_BACKUPS_TO_KEEP_REQUEST_PARAM;
|
||||
|
@ -1222,7 +1211,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
AbstractSolrTestCase.recurseDelete(homeDir);
|
||||
AbstractSolrTestCase.recurseDelete(homeDir.getParentFile());
|
||||
}
|
||||
|
||||
public void copyConfigFile(String srcFile, String destFile)
|
||||
|
|
Loading…
Reference in New Issue