You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2010/08/02 18:48:19 UTC
svn commit: r981594 -
/lucene/dev/trunk/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java
Author: yonik
Date: Mon Aug 2 16:48:18 2010
New Revision: 981594
URL: http://svn.apache.org/viewvc?rev=981594&view=rev
Log:
SOLR-1469: fix TestReplicationHandler failures
Modified:
lucene/dev/trunk/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java
Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java?rev=981594&r1=981593&r2=981594&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/handler/TestReplicationHandler.java Mon Aug 2 16:48:18 2010
@@ -80,12 +80,15 @@ public class TestReplicationHandler exte
@Before
public void setUp() throws Exception {
super.setUp();
- masterClient.deleteByQuery("*:*");
- masterClient.commit();
- rQuery(0, "*:*", masterClient);
- slaveClient.deleteByQuery("*:*");
- slaveClient.commit();
- rQuery(0, "*:*", slaveClient);
+
+ NamedList res = query("*:*", masterClient);
+ SolrDocumentList docs = (SolrDocumentList)res.get("response");
+ if (docs.getNumFound() != 0) {
+ masterClient.deleteByQuery("*:*");
+ masterClient.commit();
+ // wait for replication to sync
+ rQuery(0, "*:*", slaveClient);
+ }
}
@AfterClass
@@ -154,6 +157,71 @@ public class TestReplicationHandler exte
} while(docList.getNumFound() != expectedDocCount && timeSlept < 30000);
return res;
}
+
+ @Test
+ public void testReplicateAfterWrite2Slave() throws Exception {
+ //add 50 docs to master
+ int nDocs = 50;
+ for (int i = 0; i < nDocs; i++) {
+ index(masterClient, "id", i, "name", "name = " + i);
+ }
+
+ String masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=disableReplication";
+ URL url = new URL(masterUrl);
+ InputStream stream = url.openStream();
+ try {
+ stream.close();
+ } catch (IOException e) {
+ //e.printStackTrace();
+ }
+
+ masterClient.commit();
+
+ NamedList masterQueryRsp = rQuery(nDocs, "*:*", masterClient);
+ SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
+ assertEquals(nDocs, masterQueryResult.getNumFound());
+
+ // Make sure that both the index version and index generation on the slave is
+ // higher than that of the master, just to make the test harder.
+
+ index(slaveClient, "id", 551, "name", "name = " + 551);
+ slaveClient.commit(true, true);
+ index(slaveClient, "id", 552, "name", "name = " + 552);
+ slaveClient.commit(true, true);
+ index(slaveClient, "id", 553, "name", "name = " + 553);
+ slaveClient.commit(true, true);
+ index(slaveClient, "id", 554, "name", "name = " + 554);
+ slaveClient.commit(true, true);
+ index(slaveClient, "id", 555, "name", "name = " + 555);
+ slaveClient.commit(true, true);
+
+
+ //this doc is added to slave so it should show an item w/ that result
+ SolrDocumentList slaveQueryResult = null;
+ NamedList slaveQueryRsp;
+ slaveQueryRsp = rQuery(1, "id:555", slaveClient);
+ slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
+ assertEquals(1, slaveQueryResult.getNumFound());
+
+ masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=enableReplication";
+ url = new URL(masterUrl);
+ stream = url.openStream();
+ 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
+ slaveQueryRsp = rQuery(0, "id:555", slaveClient);
+ slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
+ assertEquals(0, slaveQueryResult.getNumFound());
+
+ // make sure we replicated the correct index from the master
+ slaveQueryRsp = rQuery(nDocs, "*:*", slaveClient);
+ slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
+ assertEquals(nDocs, slaveQueryResult.getNumFound());
+ }
@Test
public void testIndexAndConfigReplication() throws Exception {
@@ -411,65 +479,7 @@ public class TestReplicationHandler exte
}
- @Test
- public void testReplicateAfterWrite2Slave() throws Exception {
- //add 50 docs to master
- int nDocs = 50;
- for (int i = 0; i < nDocs; i++) {
- index(masterClient, "id", i, "name", "name = " + i);
- }
- String masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=disableReplication";
- URL url = new URL(masterUrl);
- InputStream stream = url.openStream();
- try {
- stream.close();
- } catch (IOException e) {
- //e.printStackTrace();
- }
-
- masterClient.commit();
-
- NamedList masterQueryRsp = rQuery(50, "*:*", masterClient);
- SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
- assertEquals(nDocs, masterQueryResult.getNumFound());
-
- // Make sure that both the index version and index generation on the slave is
- // higher than that of the master, just to make the test harder.
-
- index(slaveClient, "id", 551, "name", "name = " + 551);
- slaveClient.commit(true, true);
- index(slaveClient, "id", 552, "name", "name = " + 552);
- slaveClient.commit(true, true);
- index(slaveClient, "id", 553, "name", "name = " + 553);
- slaveClient.commit(true, true);
- index(slaveClient, "id", 554, "name", "name = " + 554);
- slaveClient.commit(true, true);
- index(slaveClient, "id", 555, "name", "name = " + 555);
- slaveClient.commit(true, true);
-
-
- //this doc is added to slave so it should show an item w/ that result
- SolrDocumentList slaveQueryResult = null;
- NamedList slaveQueryRsp;
- slaveQueryRsp = rQuery(1, "id:555", slaveClient);
- slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
- assertEquals(1, slaveQueryResult.getNumFound());
-
- masterUrl = "http://localhost:" + masterJetty.getLocalPort() + "/solr/replication?command=enableReplication";
- url = new URL(masterUrl);
- stream = url.openStream();
- 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
- slaveQueryRsp = rQuery(0, "id:555", slaveClient);
- slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
- assertEquals(0, slaveQueryResult.getNumFound());
- }
@Test
public void testBackup() throws Exception {