mirror of https://github.com/apache/lucene.git
SOLR-3361: fix "maxNumberOfBackups" to work if backups are triggered on commit
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1329839 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d2875edd99
commit
31f12e4b73
|
@ -791,6 +791,24 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
index(masterClient, "id", i, "name", "name = " + i);
|
||||
|
||||
masterClient.commit();
|
||||
boolean checkOnCommit = random().nextBoolean();
|
||||
//Check to see if 2 commits results in only one backup. (maxBackupsToKeep=1)
|
||||
if(!addNumberToKeepInRequest && checkOnCommit) {
|
||||
Thread.sleep(1000); //ensure the 2 backups have a separate timestamp.
|
||||
masterClient.commit();
|
||||
File[] files = new File(master.getDataDir()).listFiles(new FilenameFilter() {
|
||||
public boolean accept(File dir, String name) {
|
||||
if(name.startsWith("snapshot")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
assertEquals(1, files.length);
|
||||
for(File f : files) {
|
||||
AbstractSolrTestCase.recurseDelete(f); // clean up the snap dir
|
||||
}
|
||||
}
|
||||
|
||||
class BackupThread extends Thread {
|
||||
volatile String fail = null;
|
||||
|
@ -860,22 +878,12 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
};
|
||||
};
|
||||
|
||||
if(!checkOnCommit) {
|
||||
File[] snapDir = new File[2];
|
||||
String firstBackupTimestamp = null;
|
||||
for(int i=0 ; i<2 ; i++) {
|
||||
BackupThread backupThread = null;
|
||||
if(!addNumberToKeepInRequest) {
|
||||
if(random().nextBoolean()) {
|
||||
masterClient.commit();
|
||||
} else {
|
||||
backupThread = new BackupThread(addNumberToKeepInRequest, backupKeepParamName);
|
||||
BackupThread backupThread = new BackupThread(addNumberToKeepInRequest, backupKeepParamName);
|
||||
backupThread.start();
|
||||
}
|
||||
} else {
|
||||
backupThread = new BackupThread(addNumberToKeepInRequest, backupKeepParamName);
|
||||
backupThread.start();
|
||||
}
|
||||
|
||||
|
||||
File dataDir = new File(master.getDataDir());
|
||||
|
||||
|
@ -900,7 +908,7 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
waitCnt++;
|
||||
}
|
||||
|
||||
if(backupThread!= null && backupThread.fail != null) {
|
||||
if(backupThread.fail != null) {
|
||||
fail(backupThread.fail);
|
||||
}
|
||||
|
||||
|
@ -926,11 +934,11 @@ public class TestReplicationHandler extends SolrTestCaseJ4 {
|
|||
if(snapDir[0].exists()) {
|
||||
fail("The first backup should have been cleaned up because " + backupKeepParamName + " was set to 1.");
|
||||
}
|
||||
|
||||
for(int i=0 ; i< snapDir.length ; i++) {
|
||||
AbstractSolrTestCase.recurseDelete(snapDir[i]); // clean up the snap dir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* character copy of file using UTF-8 */
|
||||
private static void copyFile(File src, File dst) throws IOException {
|
||||
|
|
Loading…
Reference in New Issue