From 7a6fb892c905f00f74154777fbc0dcc53a53b588 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 4 Nov 2014 14:22:12 +0100 Subject: [PATCH] [TEST] only assert consistency before closing --- .../org/elasticsearch/index/store/Store.java | 8 ++++++-- .../index/store/DistributorInTheWildTest.java | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/store/Store.java b/src/main/java/org/elasticsearch/index/store/Store.java index 3429c0a1416..4dc577ec515 100644 --- a/src/main/java/org/elasticsearch/index/store/Store.java +++ b/src/main/java/org/elasticsearch/index/store/Store.java @@ -473,8 +473,12 @@ public class Store extends AbstractIndexShardComponent implements CloseableIndex } private void innerClose() throws IOException { - assert DistributorDirectory.assertConsistency(logger, distributorDirectory); - super.close(); + try { + assert DistributorDirectory.assertConsistency(logger, distributorDirectory); + } finally { + super.close(); + } + } @Override diff --git a/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java b/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java index cd7fe995e20..695e4445ab5 100644 --- a/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java +++ b/src/test/java/org/elasticsearch/index/store/DistributorInTheWildTest.java @@ -27,6 +27,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.ThreadedIndexingAndSearchingTestCase; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FilterDirectory; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.common.logging.ESLogger; @@ -125,8 +126,7 @@ public class DistributorInTheWildTest extends ThreadedIndexingAndSearchingTestCa if (random().nextBoolean() && dir instanceof MockDirectoryWrapper) { return ((MockDirectoryWrapper) dir).getOpenDeletedFiles(); } - DistributorDirectory d = dir instanceof MockDirectoryWrapper ? (DistributorDirectory)((MockDirectoryWrapper) dir).getDelegate() : (DistributorDirectory) dir; - assertTrue(DistributorDirectory.assertConsistency(logger, d)); + DistributorDirectory d = DirectoryUtils.getLeaf(dir, DistributorDirectory.class, null); Distributor distributor = d.getDistributor(); Set set = new HashSet<>(); for (Directory subDir : distributor.all()) { @@ -151,11 +151,19 @@ public class DistributorInTheWildTest extends ThreadedIndexingAndSearchingTestCa for (Directory dir : directories) { ((MockDirectoryWrapper) dir).setCheckIndexOnClose(false); } + try { + FilterDirectory distributorDirectory = new FilterDirectory(new DistributorDirectory(directories)) { + @Override + public void close() throws IOException { + assertTrue(DistributorDirectory.assertConsistency(logger, (DistributorDirectory) this.getDelegate())); + super.close(); + } + }; if (random().nextBoolean()) { - return new MockDirectoryWrapper(random(), new DistributorDirectory(directories)); + return new MockDirectoryWrapper(random(), distributorDirectory); } else { - return new DistributorDirectory(directories); + return distributorDirectory; } } catch (IOException ex) { throw new RuntimeException(ex);