MockBigArrays should tell you who originally released them

This commit is contained in:
Boaz Leskes 2016-10-12 12:40:38 +02:00
parent f96ea58db8
commit bc8ad8de5a
1 changed files with 5 additions and 6 deletions

View File

@ -24,7 +24,6 @@ import com.carrotsearch.randomizedtesting.SeedUtils;
import org.apache.lucene.util.Accountable; import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.Accountables; import org.apache.lucene.util.Accountables;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.util.set.Sets;
import org.elasticsearch.indices.breaker.CircuitBreakerService; import org.elasticsearch.indices.breaker.CircuitBreakerService;
@ -39,7 +38,7 @@ import java.util.Set;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference;
public class MockBigArrays extends BigArrays { public class MockBigArrays extends BigArrays {
@ -250,13 +249,13 @@ public class MockBigArrays extends BigArrays {
final BigArray in; final BigArray in;
boolean clearOnResize; boolean clearOnResize;
AtomicBoolean released; AtomicReference<AssertionError> originalRelease;
AbstractArrayWrapper(BigArray in, boolean clearOnResize) { AbstractArrayWrapper(BigArray in, boolean clearOnResize) {
ACQUIRED_ARRAYS.put(this, TRACK_ALLOCATIONS ? new RuntimeException() : Boolean.TRUE); ACQUIRED_ARRAYS.put(this, TRACK_ALLOCATIONS ? new RuntimeException() : Boolean.TRUE);
this.in = in; this.in = in;
this.clearOnResize = clearOnResize; this.clearOnResize = clearOnResize;
released = new AtomicBoolean(false); originalRelease = new AtomicReference<>();
} }
protected abstract BigArray getDelegate(); protected abstract BigArray getDelegate();
@ -272,8 +271,8 @@ public class MockBigArrays extends BigArrays {
} }
public void close() { public void close() {
if (!released.compareAndSet(false, true)) { if (originalRelease.compareAndSet(null, new AssertionError()) == false) {
throw new IllegalStateException("Double release"); throw new IllegalStateException("Double release. Original release attached as cause", originalRelease.get());
} }
ACQUIRED_ARRAYS.remove(this); ACQUIRED_ARRAYS.remove(this);
randomizeContent(0, size()); randomizeContent(0, size());