[TEST] Log where locks are created from if they are still open on close()

This commit is contained in:
Simon Willnauer 2014-04-08 15:14:08 +02:00
parent de13d707ed
commit 7eb8b0d0c0
1 changed files with 24 additions and 1 deletions

View File

@ -21,6 +21,7 @@ package org.elasticsearch.test.store;
import com.carrotsearch.randomizedtesting.SeedUtils;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.MMapDirectory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.MockDirectoryWrapper.Throttling;
@ -36,11 +37,12 @@ import org.elasticsearch.index.store.fs.MmapFsDirectoryService;
import org.elasticsearch.index.store.fs.NioFsDirectoryService;
import org.elasticsearch.index.store.fs.SimpleFsDirectoryService;
import org.elasticsearch.index.store.ram.RamDirectoryService;
import org.elasticsearch.test.TestCluster;
import java.io.IOException;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class MockDirectoryHelper {
public static final String RANDOM_IO_EXCEPTION_RATE = "index.store.mock.random.io_exception_rate";
@ -124,6 +126,7 @@ public class MockDirectoryHelper {
public static final class ElasticsearchMockDirectoryWrapper extends MockDirectoryWrapper {
private final Map<String, Exception> locks = new ConcurrentHashMap<>();
private final ESLogger logger;
private final boolean crash;
private RuntimeException closeException;
@ -136,6 +139,9 @@ public class MockDirectoryHelper {
@Override
public synchronized void close() throws IOException {
for (Exception ex : locks.values()) {
logger.info("Lock still open - opened from: ", ex);
}
try {
super.close();
} catch (RuntimeException ex) {
@ -159,5 +165,22 @@ public class MockDirectoryHelper {
super.crash();
}
}
@Override
public Lock makeLock(String lockName) {
Lock l = super.makeLock(lockName);
if (l != null) {
locks.put(lockName, new Exception());
}
return l;
}
public void clearLock(String lockName) throws IOException {
try {
super.clearLock(lockName);
} finally {
locks.remove(lockName);
}
}
}
}