From f2ae29a1cbe6b5d1e5b86cc9df9067e9c0b97c32 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 30 Sep 2015 19:58:31 +0200 Subject: [PATCH] [TEST] don't run check index on an intentionally corrupted index --- .../recovery/RecoverySourceHandlerTests.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java b/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java index 76867ec089a..7402d09c7d1 100644 --- a/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java +++ b/core/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java @@ -104,7 +104,7 @@ public class RecoverySourceHandlerTests extends ESTestCase { new DiscoveryNode("b", DummyTransportAddress.INSTANCE, Version.CURRENT), randomBoolean(), null, RecoveryState.Type.STORE, randomLong()); Path tempDir = createTempDir(); - Store store = newStore(tempDir); + Store store = newStore(tempDir, false); AtomicBoolean failedEngine = new AtomicBoolean(false); RecoverySourceHandler handler = new RecoverySourceHandler(null, request, recoverySettings, null, logger) { @Override @@ -130,10 +130,11 @@ public class RecoverySourceHandlerTests extends ESTestCase { for (StoreFileMetaData md : metadata) { metas.add(md); } + CorruptionUtils.corruptFile(getRandom(), FileSystemUtils.files(tempDir, (p) -> (p.getFileName().toString().equals("write.lock") || Files.isDirectory(p)) == false)); - Store targetStore = newStore(createTempDir()); + Store targetStore = newStore(createTempDir(), false); try { handler.sendFiles(store, metas.toArray(new StoreFileMetaData[0]), (md) -> { try { @@ -150,6 +151,7 @@ public class RecoverySourceHandlerTests extends ESTestCase { IOUtils.close(store, targetStore, recoverySettings); } + public void testHandleExceptinoOnSendSendFiles() throws Throwable { final RecoverySettings recoverySettings = new RecoverySettings(Settings.EMPTY, service); StartRecoveryRequest request = new StartRecoveryRequest(shardId, @@ -157,7 +159,7 @@ public class RecoverySourceHandlerTests extends ESTestCase { new DiscoveryNode("b", DummyTransportAddress.INSTANCE, Version.CURRENT), randomBoolean(), null, RecoveryState.Type.STORE, randomLong()); Path tempDir = createTempDir(); - Store store = newStore(tempDir); + Store store = newStore(tempDir, false); AtomicBoolean failedEngine = new AtomicBoolean(false); RecoverySourceHandler handler = new RecoverySourceHandler(null, request, recoverySettings, null, logger) { @Override @@ -184,7 +186,7 @@ public class RecoverySourceHandlerTests extends ESTestCase { metas.add(md); } final boolean throwCorruptedIndexException = randomBoolean(); - Store targetStore = newStore(createTempDir()); + Store targetStore = newStore(createTempDir(), false); try { handler.sendFiles(store, metas.toArray(new StoreFileMetaData[0]), (md) -> { if (throwCorruptedIndexException) { @@ -209,6 +211,9 @@ public class RecoverySourceHandlerTests extends ESTestCase { } private Store newStore(Path path) throws IOException { + return newStore(path, true); + } + private Store newStore(Path path, boolean checkIndex) throws IOException { DirectoryService directoryService = new DirectoryService(shardId, Settings.EMPTY) { @Override public long throttleTimeInNanos() { @@ -217,7 +222,11 @@ public class RecoverySourceHandlerTests extends ESTestCase { @Override public Directory newDirectory() throws IOException { - return RecoverySourceHandlerTests.newFSDirectory(path); + BaseDirectoryWrapper baseDirectoryWrapper = RecoverySourceHandlerTests.newFSDirectory(path); + if (checkIndex == false) { + baseDirectoryWrapper.setCheckIndexOnClose(false); // don't run checkindex we might corrupt the index in these tests + } + return baseDirectoryWrapper; } }; return new Store(shardId, Settings.EMPTY, directoryService, new DummyShardLock(shardId));