mirror of https://github.com/apache/lucene.git
SOLR-7589: A few improvements to the ObjectReleaseTracker to make test fail debugging a little easier.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1681585 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b0a8ce42f5
commit
a545b66008
|
@ -30,12 +30,12 @@ public class TestObjectReleaseTracker extends LuceneTestCase {
|
|||
public void testObjectReleaseTracker() {
|
||||
ObjectReleaseTracker.track(new Object());
|
||||
ObjectReleaseTracker.release(new Object());
|
||||
assertFalse(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
assertTrue(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
assertNotNull(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
assertNull(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
Object obj = new Object();
|
||||
ObjectReleaseTracker.track(obj);
|
||||
ObjectReleaseTracker.release(obj);
|
||||
assertTrue(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
assertNull(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
|
||||
Object obj1 = new Object();
|
||||
ObjectReleaseTracker.track(obj1);
|
||||
|
@ -47,7 +47,7 @@ public class TestObjectReleaseTracker extends LuceneTestCase {
|
|||
ObjectReleaseTracker.release(obj1);
|
||||
ObjectReleaseTracker.release(obj2);
|
||||
ObjectReleaseTracker.release(obj3);
|
||||
assertTrue(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
assertNull(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
|
||||
ObjectReleaseTracker.track(obj1);
|
||||
ObjectReleaseTracker.track(obj2);
|
||||
|
@ -56,7 +56,7 @@ public class TestObjectReleaseTracker extends LuceneTestCase {
|
|||
ObjectReleaseTracker.release(obj1);
|
||||
ObjectReleaseTracker.release(obj2);
|
||||
// ObjectReleaseTracker.release(obj3);
|
||||
assertFalse(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
assertTrue(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
assertNotNull(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
assertNull(ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.solr.common.util;
|
|||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
@ -40,20 +41,30 @@ public class ObjectReleaseTracker {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean clearObjectTrackerAndCheckEmpty() {
|
||||
/**
|
||||
* @return null if ok else error message
|
||||
*/
|
||||
public static String clearObjectTrackerAndCheckEmpty() {
|
||||
String error = null;
|
||||
Set<Entry<Object,String>> entries = OBJECTS.entrySet();
|
||||
boolean empty = entries.isEmpty();
|
||||
if (entries.size() > 0) {
|
||||
System.err.println("ObjectTracker found objects that were not released!!!");
|
||||
Set<String> objects = new HashSet<>();
|
||||
for (Entry<Object,String> entry : entries) {
|
||||
objects.add(entry.getKey().getClass().getSimpleName());
|
||||
}
|
||||
|
||||
error = "ObjectTracker found " + entries.size() + " object(s) that were not released!!! " + objects;
|
||||
|
||||
System.err.println(error);
|
||||
for (Entry<Object,String> entry : entries) {
|
||||
System.err.println(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
OBJECTS.clear();
|
||||
|
||||
return empty;
|
||||
return error;
|
||||
}
|
||||
|
||||
private static class ObjectTrackerException extends RuntimeException {
|
||||
|
|
|
@ -230,11 +230,12 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
|
|||
deleteCore();
|
||||
resetExceptionIgnores();
|
||||
endTrackingSearchers();
|
||||
String orr = ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty();
|
||||
if (!RandomizedContext.current().getTargetClass().isAnnotationPresent(SuppressObjectReleaseTracker.class)) {
|
||||
assertTrue("Some resources were not closed, shutdown, or released.", ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty());
|
||||
assertNull(orr, orr);
|
||||
} else {
|
||||
if (!ObjectReleaseTracker.clearObjectTrackerAndCheckEmpty()) {
|
||||
log.warn("Some resources were not closed, shutdown, or released. Remove the SuppressObjectReleaseTracker annotation to get more information on the fail.");
|
||||
if (orr != null) {
|
||||
log.warn("Some resources were not closed, shutdown, or released. This has been ignored due to the SuppressObjectReleaseTracker annotation.");
|
||||
}
|
||||
}
|
||||
resetFactory();
|
||||
|
|
Loading…
Reference in New Issue