[TEST] Make StoreTest extraFS proof
This commit is contained in:
parent
a1ba339517
commit
18ede79ed5
|
@ -45,14 +45,12 @@ import org.junit.Test;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.zip.Adler32;
|
import java.util.zip.Adler32;
|
||||||
|
|
||||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.*;
|
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
public class StoreTest extends ElasticsearchTestCase {
|
public class StoreTest extends ElasticsearchTestCase {
|
||||||
|
@ -481,7 +479,7 @@ public class StoreTest extends ElasticsearchTestCase {
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
store.renameFile("foo.bar", "bar.foo");
|
store.renameFile("foo.bar", "bar.foo");
|
||||||
assertThat(store.directory().listAll().length, is(1));
|
assertThat(numNonExtraFiles(store), is(1));
|
||||||
final long lastChecksum;
|
final long lastChecksum;
|
||||||
try (IndexInput input = store.directory().openInput("bar.foo", IOContext.DEFAULT)) {
|
try (IndexInput input = store.directory().openInput("bar.foo", IOContext.DEFAULT)) {
|
||||||
lastChecksum = CodecUtil.checksumEntireFile(input);
|
lastChecksum = CodecUtil.checksumEntireFile(input);
|
||||||
|
@ -504,7 +502,7 @@ public class StoreTest extends ElasticsearchTestCase {
|
||||||
output.close();
|
output.close();
|
||||||
}
|
}
|
||||||
store.renameFile("foo.bar", "bar.foo");
|
store.renameFile("foo.bar", "bar.foo");
|
||||||
assertThat(store.directory().listAll().length, is(1));
|
assertThat(numNonExtraFiles(store), is(1));
|
||||||
assertDeleteContent(store, directoryService);
|
assertDeleteContent(store, directoryService);
|
||||||
IOUtils.close(store);
|
IOUtils.close(store);
|
||||||
}
|
}
|
||||||
|
@ -925,7 +923,7 @@ public class StoreTest extends ElasticsearchTestCase {
|
||||||
Store.LegacyChecksums checksums = new Store.LegacyChecksums();
|
Store.LegacyChecksums checksums = new Store.LegacyChecksums();
|
||||||
Map<String, StoreFileMetaData> legacyMeta = new HashMap<>();
|
Map<String, StoreFileMetaData> legacyMeta = new HashMap<>();
|
||||||
for (String file : store.directory().listAll()) {
|
for (String file : store.directory().listAll()) {
|
||||||
if (file.equals("write.lock") || file.equals(IndexFileNames.OLD_SEGMENTS_GEN)) {
|
if (file.equals("write.lock") || file.equals(IndexFileNames.OLD_SEGMENTS_GEN) || file.startsWith("extra")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
BytesRef hash = new BytesRef();
|
BytesRef hash = new BytesRef();
|
||||||
|
@ -944,6 +942,9 @@ public class StoreTest extends ElasticsearchTestCase {
|
||||||
int numChecksums = 0;
|
int numChecksums = 0;
|
||||||
int numNotFound = 0;
|
int numNotFound = 0;
|
||||||
for (String file : strings) {
|
for (String file : strings) {
|
||||||
|
if (file.startsWith("extra")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
assertTrue(firstMeta.contains(file) || Store.isChecksum(file) || file.equals("write.lock"));
|
assertTrue(firstMeta.contains(file) || Store.isChecksum(file) || file.equals("write.lock"));
|
||||||
if (Store.isChecksum(file)) {
|
if (Store.isChecksum(file)) {
|
||||||
numChecksums++;
|
numChecksums++;
|
||||||
|
@ -960,6 +961,9 @@ public class StoreTest extends ElasticsearchTestCase {
|
||||||
int numChecksums = 0;
|
int numChecksums = 0;
|
||||||
int numNotFound = 0;
|
int numNotFound = 0;
|
||||||
for (String file : strings) {
|
for (String file : strings) {
|
||||||
|
if (file.startsWith("extra")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
assertTrue(file, secondMeta.contains(file) || Store.isChecksum(file) || file.equals("write.lock"));
|
assertTrue(file, secondMeta.contains(file) || Store.isChecksum(file) || file.equals("write.lock"));
|
||||||
if (Store.isChecksum(file)) {
|
if (Store.isChecksum(file)) {
|
||||||
numChecksums++;
|
numChecksums++;
|
||||||
|
@ -1044,7 +1048,7 @@ public class StoreTest extends ElasticsearchTestCase {
|
||||||
length = output.getFilePointer();
|
length = output.getFilePointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue(store.directory().listAll().length > 0);
|
assertTrue(numNonExtraFiles(store) > 0);
|
||||||
stats = store.stats();
|
stats = store.stats();
|
||||||
assertEquals(stats.getSizeInBytes(), length);
|
assertEquals(stats.getSizeInBytes(), length);
|
||||||
|
|
||||||
|
@ -1067,4 +1071,14 @@ public class StoreTest extends ElasticsearchTestCase {
|
||||||
}
|
}
|
||||||
ExceptionsHelper.rethrowAndSuppress(exceptions);
|
ExceptionsHelper.rethrowAndSuppress(exceptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int numNonExtraFiles(Store store) throws IOException {
|
||||||
|
int numNonExtra = 0;
|
||||||
|
for (String file : store.directory().listAll()) {
|
||||||
|
if (file.startsWith("extra") == false) {
|
||||||
|
numNonExtra++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return numNonExtra;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue