Prevent page-tracking checks from spreading across tests.

This commit is contained in:
Adrien Grand 2014-02-28 20:56:14 +01:00
parent 7af63700c9
commit 5723603987
2 changed files with 9 additions and 1 deletions

View File

@ -35,12 +35,15 @@ public class MockPageCacheRecycler extends PageCacheRecycler {
private static final ConcurrentMap<Object, Throwable> ACQUIRED_PAGES = Maps.newConcurrentMap();
public static void reset() {
ACQUIRED_PAGES.clear();
}
public static void ensureAllPagesAreReleased() {
if (ACQUIRED_PAGES.size() > 0) {
final Throwable t = ACQUIRED_PAGES.entrySet().iterator().next().getValue();
throw new RuntimeException(ACQUIRED_PAGES.size() + " pages have not been released", t);
}
ACQUIRED_PAGES.clear();
}
private final Random random;

View File

@ -122,6 +122,11 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest {
return new File(uri);
}
@Before
public void resetPageTracking() {
MockPageCacheRecycler.reset();
}
@After
public void ensureAllPagesReleased() {
MockPageCacheRecycler.ensureAllPagesAreReleased();