From fb39caa8d416af78d6dbf093e7df8375cd0dd35e Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Wed, 8 Oct 2014 16:00:35 +0200 Subject: [PATCH] Tests: two corruptions can fix a file In some of our tests we corrupt multiple places in a file randomly. If we corrupt the same place twice, we shouldn't fix the file by mistake. --- .../org/elasticsearch/index/store/CorruptedFileTest.java | 6 +++--- .../elasticsearch/index/store/CorruptedTranslogTests.java | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java b/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java index e0ae43a440c..9fc97f419a2 100644 --- a/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java +++ b/src/test/java/org/elasticsearch/index/store/CorruptedFileTest.java @@ -35,7 +35,6 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse; -import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.action.count.CountResponse; import org.elasticsearch.action.index.IndexRequestBuilder; @@ -493,9 +492,10 @@ public class CorruptedFileTest extends ElasticsearchIntegrationTest { long filePointer = raf.getFilePointer(); byte b = raf.readByte(); raf.seek(filePointer); - raf.writeByte(~b); + int corruptedValue = (b + 1) & 0xff; + raf.writeByte(corruptedValue); raf.getFD().sync(); - logger.info("Corrupting file for shard {} -- flipping at position {} from {} to {} file: {}", shardRouting, filePointer, Integer.toHexString(b), Integer.toHexString(~b), fileToCorrupt.getName()); + logger.info("Corrupting file for shard {} -- flipping at position {} from {} to {} file: {}", shardRouting, filePointer, Integer.toHexString(b), Integer.toHexString(corruptedValue), fileToCorrupt.getName()); } long checksumAfterCorruption; long actualChecksumAfterCorruption; diff --git a/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java b/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java index 854dca09a6d..8a3df647db4 100644 --- a/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java +++ b/src/test/java/org/elasticsearch/index/store/CorruptedTranslogTests.java @@ -139,9 +139,10 @@ public class CorruptedTranslogTests extends ElasticsearchIntegrationTest { long filePointer = raf.getFilePointer(); byte b = raf.readByte(); raf.seek(filePointer); - raf.writeByte(~b); + int corruptedValue = (b + 1) & 0xff; + raf.writeByte(corruptedValue); raf.getFD().sync(); - logger.info("--> corrupting file {} -- flipping at position {} from {} to {} file: {}", fileToCorrupt.getName(), filePointer, Integer.toHexString(b), Integer.toHexString(~b), fileToCorrupt); + logger.info("--> corrupting file {} -- flipping at position {} from {} to {} file: {}", fileToCorrupt.getName(), filePointer, Integer.toHexString(b), Integer.toHexString(corruptedValue), fileToCorrupt); } } }