[TEST] Log where locks are created from if they are still open on close()
This commit is contained in:
parent
de13d707ed
commit
7eb8b0d0c0
|
@ -21,6 +21,7 @@ package org.elasticsearch.test.store;
|
||||||
|
|
||||||
import com.carrotsearch.randomizedtesting.SeedUtils;
|
import com.carrotsearch.randomizedtesting.SeedUtils;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
|
import org.apache.lucene.store.Lock;
|
||||||
import org.apache.lucene.store.MMapDirectory;
|
import org.apache.lucene.store.MMapDirectory;
|
||||||
import org.apache.lucene.store.MockDirectoryWrapper;
|
import org.apache.lucene.store.MockDirectoryWrapper;
|
||||||
import org.apache.lucene.store.MockDirectoryWrapper.Throttling;
|
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.NioFsDirectoryService;
|
||||||
import org.elasticsearch.index.store.fs.SimpleFsDirectoryService;
|
import org.elasticsearch.index.store.fs.SimpleFsDirectoryService;
|
||||||
import org.elasticsearch.index.store.ram.RamDirectoryService;
|
import org.elasticsearch.index.store.ram.RamDirectoryService;
|
||||||
import org.elasticsearch.test.TestCluster;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class MockDirectoryHelper {
|
public class MockDirectoryHelper {
|
||||||
public static final String RANDOM_IO_EXCEPTION_RATE = "index.store.mock.random.io_exception_rate";
|
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 {
|
public static final class ElasticsearchMockDirectoryWrapper extends MockDirectoryWrapper {
|
||||||
|
|
||||||
|
private final Map<String, Exception> locks = new ConcurrentHashMap<>();
|
||||||
private final ESLogger logger;
|
private final ESLogger logger;
|
||||||
private final boolean crash;
|
private final boolean crash;
|
||||||
private RuntimeException closeException;
|
private RuntimeException closeException;
|
||||||
|
@ -136,6 +139,9 @@ public class MockDirectoryHelper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() throws IOException {
|
public synchronized void close() throws IOException {
|
||||||
|
for (Exception ex : locks.values()) {
|
||||||
|
logger.info("Lock still open - opened from: ", ex);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
super.close();
|
super.close();
|
||||||
} catch (RuntimeException ex) {
|
} catch (RuntimeException ex) {
|
||||||
|
@ -159,5 +165,22 @@ public class MockDirectoryHelper {
|
||||||
super.crash();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue