You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2013/02/22 23:16:04 UTC

svn commit: r1449240 - in /lucene/dev/trunk/solr: CHANGES.txt core/src/test/org/apache/solr/handler/TestReplicationHandler.java

Author: markrmiller
Date: Fri Feb 22 22:16:04 2013
New Revision: 1449240

URL: http://svn.apache.org/r1449240
Log:
SOLR-4471: Improve and clean up TestReplicationHandler.

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1449240&r1=1449239&r2=1449240&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Fri Feb 22 22:16:04 2013
@@ -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

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java?rev=1449240&r1=1449239&r2=1449240&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandler.java Fri Feb 22 22:16:04 2013
@@ -58,6 +58,7 @@ import org.apache.solr.common.util.Simpl
 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 exte
   @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 exte
     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 exte
     }
   }
 
-  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 exte
     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 exte
     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 exte
     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 exte
 
   }
 
-  private void doTestStopPoll() throws Exception {
+  @Test
+  public void doTestStopPoll() throws Exception {
     clearIndexWithReplication();
 
     // Test:
@@ -477,14 +477,8 @@ public class TestReplicationHandler exte
     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 exte
     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 exte
     }
   }
 
-  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 exte
     slaveClient = createNewSolrServer(slaveJetty.getLocalPort());
   }
 
-  private void doTestIndexAndConfigAliasReplication() throws Exception {
+  @Test
+  public void doTestIndexAndConfigAliasReplication() throws Exception {
     clearIndexWithReplication();
 
     nDocs--;
@@ -975,8 +964,8 @@ public class TestReplicationHandler exte
   }
 
 
-  
-  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 exte
     }
 
     public void tearDown() throws Exception {
-      AbstractSolrTestCase.recurseDelete(homeDir);
+      AbstractSolrTestCase.recurseDelete(homeDir.getParentFile());
     }
 
     public void copyConfigFile(String srcFile, String destFile)