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