You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2014/10/17 02:07:08 UTC
svn commit: r1632449 -
/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
Author: tflobbe
Date: Fri Oct 17 00:07:07 2014
New Revision: 1632449
URL: http://svn.apache.org/r1632449
Log:
SOLR-6151: Improved TestReplicationHandlerBackup
Modified:
lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java?rev=1632449&r1=1632448&r2=1632449&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/TestReplicationHandlerBackup.java Fri Oct 17 00:07:07 2014
@@ -17,6 +17,15 @@ package org.apache.solr.handler;
* limitations under the License.
*/
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.file.Path;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
import org.apache.commons.io.IOUtils;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
@@ -36,16 +45,6 @@ import org.apache.solr.util.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.nio.file.Path;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
@SolrTestCaseJ4.SuppressSSL // Currently unknown why SSL does not work with this test
public class TestReplicationHandlerBackup extends SolrJettyTestBase {
@@ -109,12 +108,12 @@ public class TestReplicationHandlerBacku
@After
public void tearDown() throws Exception {
super.tearDown();
+ masterClient.shutdown();
+ masterClient = null;
masterJetty.stop();
master.tearDown();
masterJetty = null;
master = null;
- masterClient.shutdown();
- masterClient = null;
}
@@ -142,15 +141,15 @@ public class TestReplicationHandlerBacku
backupNames = new String[2];
}
for (int i = 0; i < 2; i++) {
- BackupThread backupThread;
+ BackupCommand backupCommand;
final String backupName = TestUtil.randomSimpleString(random(), 1, 20);
if (!namedBackup) {
- backupThread = new BackupThread(addNumberToKeepInRequest, backupKeepParamName, ReplicationHandler.CMD_BACKUP);
+ backupCommand = new BackupCommand(addNumberToKeepInRequest, backupKeepParamName, ReplicationHandler.CMD_BACKUP);
} else {
- backupThread = new BackupThread(backupName, ReplicationHandler.CMD_BACKUP);
+ backupCommand = new BackupCommand(backupName, ReplicationHandler.CMD_BACKUP);
backupNames[i] = backupName;
}
- backupThread.start();
+ backupCommand.runCommand();
File dataDir = new File(master.getDataDir());
@@ -167,8 +166,8 @@ public class TestReplicationHandlerBacku
Thread.sleep(200);
}
- if (backupThread.fail != null) {
- fail(backupThread.fail);
+ if (backupCommand.fail != null) {
+ fail(backupCommand.fail);
}
File[] files = null;
if (!namedBackup) {
@@ -225,20 +224,25 @@ public class TestReplicationHandlerBacku
}
private void testDeleteNamedBackup(String backupNames[]) throws InterruptedException, IOException {
+ String lastTimestamp = null;
for (int i = 0; i < 2; i++) {
- BackupThread deleteBackupThread = new BackupThread(backupNames[i], ReplicationHandler.CMD_DELETE_BACKUP);
- deleteBackupThread.start();
- CheckDeleteBackupStatus checkDeleteBackupStatus = new CheckDeleteBackupStatus(backupNames[i]);
+ BackupCommand deleteBackupCommand = new BackupCommand(backupNames[i], ReplicationHandler.CMD_DELETE_BACKUP);
+ deleteBackupCommand.runCommand();
+ CheckDeleteBackupStatus checkDeleteBackupStatus = new CheckDeleteBackupStatus(backupNames[i], lastTimestamp);
while (true) {
boolean success = checkDeleteBackupStatus.fetchStatus();
if (success) {
+ lastTimestamp = checkDeleteBackupStatus.lastTimestamp;
+ if (i == 0) {
+ Thread.sleep(1000); //make the timestamp change
+ }
break;
}
Thread.sleep(200);
}
- if (deleteBackupThread.fail != null) {
- fail(deleteBackupThread.fail);
+ if (deleteBackupCommand.fail != null) {
+ fail(deleteBackupCommand.fail);
}
}
}
@@ -284,24 +288,25 @@ public class TestReplicationHandlerBacku
};
}
- private class BackupThread extends Thread {
- volatile String fail = null;
+ private class BackupCommand {
+ String fail = null;
final boolean addNumberToKeepInRequest;
String backupKeepParamName;
String backupName;
String cmd;
- BackupThread(boolean addNumberToKeepInRequest, String backupKeepParamName, String command) {
+
+ BackupCommand(boolean addNumberToKeepInRequest, String backupKeepParamName, String command) {
this.addNumberToKeepInRequest = addNumberToKeepInRequest;
this.backupKeepParamName = backupKeepParamName;
this.cmd = command;
}
- BackupThread(String backupName, String command) {
+ BackupCommand(String backupName, String command) {
this.backupName = backupName;
addNumberToKeepInRequest = false;
this.cmd = command;
}
- @Override
- public void run() {
+
+ public void runCommand() {
String masterUrl = null;
if(backupName != null) {
masterUrl = buildUrl(masterJetty.getLocalPort(), context) + "/replication?command=" + cmd +
@@ -330,9 +335,11 @@ public class TestReplicationHandlerBacku
String response = null;
private String backupName;
final Pattern p = Pattern.compile("<str name=\"snapshotDeletedAt\">(.*?)</str>");
-
- private CheckDeleteBackupStatus(String backupName) {
+ String lastTimestamp;
+
+ private CheckDeleteBackupStatus(String backupName, String lastTimestamp) {
this.backupName = backupName;
+ this.lastTimestamp = lastTimestamp;
}
public boolean fetchStatus() throws IOException {
@@ -345,7 +352,8 @@ public class TestReplicationHandlerBacku
response = IOUtils.toString(stream, "UTF-8");
if(response.contains("<str name=\"status\">success</str>")) {
Matcher m = p.matcher(response);
- if(m.find()) {
+ if(m.find() && (lastTimestamp == null || !lastTimestamp.equals(m.group(1)))) {
+ lastTimestamp = m.group(1);
return true;
}
} else if(response.contains("<str name=\"status\">Unable to delete snapshot: " + backupName + "</str>" )) {