@TestInfo(testType = TestInfo.TestType.UNIT)
public void testReleaseSemaphoreOnBaseException() {
// how many simultaneous queries to support
int slots = 5;
AlwaysFailSearcher baseSearcher = new AlwaysFailSearcher();
final TrafficLimitingSearcher searcher = new TrafficLimitingSearcher(baseSearcher,slots,1/*no timeout*/);
for (int i = 0; i < slots +1 ; i++){
try {
searcher.search(null, 0, 1, null, 1, null, null);
fail(); // should not happen, as AlwaysFailSearcher will throw a SearcherException
} catch (SearcherException se){
// do nothing ..
}
}
// now, try with another query. If the slots were not released, it should fail with TrafficLimitingSearcher Exception.
// if it failed with "I always fail", it is ok.
Thread searchThread = new Thread() {
public void run() {
try {
searcher.search(null, 0, 1, null, 1, null, null);
} catch (Throwable t) {
assertFalse(t.getMessage().contains("TrafficLimitingSearcher"));
assertTrue(t.getMessage().contains("I always fail"));
semaphorePassed = true;
}