[TEST] Only corrupt translog header today we can't detecte truncation corruption

This commit is contained in:
Simon Willnauer 2015-05-11 10:34:26 +02:00
parent 9bd5df1e31
commit 5578499d61
1 changed files with 2 additions and 1 deletions

View File

@ -35,6 +35,7 @@ import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.translog.Translog; import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.index.translog.TranslogStreams;
import org.elasticsearch.monitor.fs.FsStats; import org.elasticsearch.monitor.fs.FsStats;
import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.engine.MockEngineSupport; import org.elasticsearch.test.engine.MockEngineSupport;
@ -149,7 +150,7 @@ public class CorruptedTranslogTests extends ElasticsearchIntegrationTest {
fileToCorrupt = RandomPicks.randomFrom(getRandom(), files); fileToCorrupt = RandomPicks.randomFrom(getRandom(), files);
try (FileChannel raf = FileChannel.open(fileToCorrupt, StandardOpenOption.READ, StandardOpenOption.WRITE)) { try (FileChannel raf = FileChannel.open(fileToCorrupt, StandardOpenOption.READ, StandardOpenOption.WRITE)) {
// read // read
raf.position(randomIntBetween(0, (int) Math.min(Integer.MAX_VALUE, raf.size() - 1))); raf.position(randomIntBetween(0, (int) Math.min(TranslogStreams.LATEST.headerLength(), raf.size() - 1))); // only corrupt the header to ensure we actually fail
long filePointer = raf.position(); long filePointer = raf.position();
ByteBuffer bb = ByteBuffer.wrap(new byte[1]); ByteBuffer bb = ByteBuffer.wrap(new byte[1]);
raf.read(bb); raf.read(bb);