Test: InternalEngineTests.testSimpleRecover should close snapshot

This commit is contained in:
Boaz Leskes 2015-03-01 08:26:06 +01:00
parent c346effd9c
commit eafba93919
1 changed files with 10 additions and 4 deletions

View File

@ -73,6 +73,7 @@ import org.elasticsearch.index.translog.TranslogSizeMatcher;
import org.elasticsearch.index.translog.fs.FsTranslog;
import org.elasticsearch.test.DummyShardLock;
import org.elasticsearch.test.ElasticsearchLuceneTestCase;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.elasticsearch.threadpool.ThreadPool;
import org.hamcrest.MatcherAssert;
import org.junit.After;
@ -127,7 +128,8 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
IOUtils.rm(Paths.get(TRANSLOG_PRIMARY_LOCATION));
IOUtils.rm(Paths.get(TRANSLOG_REPLICA_LOCATION));
} catch (IOException e) {
fail("failed to delete translogs before tests." + ExceptionsHelper.detailedMessage(e));
fail("failed to delete translogs before tests."
+ ExceptionsHelper.detailedMessage(e) + "\n" + ExceptionsHelper.stackTrace(e));
}
}
}, 30, TimeUnit.SECONDS);
@ -180,11 +182,12 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
replicaEngine.close();
storeReplica.close();
engine.close();
store.close();
translog.close();
replicaTranslog.close();
engine.close();
store.close();
terminate(threadPool);
}
@ -734,6 +737,7 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
@Test
@TestLogging("index.translog:TRACE")
public void testSimpleRecover() throws Exception {
final ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, testDocumentWithTextField(), B_1, false);
engine.create(new Engine.Create(null, newUid("1"), doc));
@ -777,7 +781,9 @@ public class InternalEngineTests extends ElasticsearchLuceneTestCase {
}
});
// post recovery should flush the translog
MatcherAssert.assertThat(translog.snapshot(), TranslogSizeMatcher.translogSize(0));
try (Translog.Snapshot snapshot = translog.snapshot()) {
MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(0));
}
// and we should not leak files
assertThat("there are unreferenced translog files left", translog.clearUnreferenced(), equalTo(0));