1 package org.apache.lucene.search;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.io.IOException;
22 import junit.framework.Assert;
23 import org.apache.lucene.index.IndexReader;
26 * A unit test helper class to test when the filter is getting cached and when it is not.
28 public class CachingWrapperFilterHelper extends CachingWrapperFilter {
30 private boolean shouldHaveCache = false;
33 * @param filter Filter to cache results of
35 public CachingWrapperFilterHelper(Filter filter) {
39 public void setShouldHaveCache(boolean shouldHaveCache) {
40 this.shouldHaveCache = shouldHaveCache;
44 public synchronized DocIdSet getDocIdSet(IndexReader reader) throws IOException {
46 final int saveMissCount = missCount;
47 DocIdSet docIdSet = super.getDocIdSet(reader);
49 if (shouldHaveCache) {
50 Assert.assertEquals("Cache should have data ", saveMissCount, missCount);
52 Assert.assertTrue("Cache should be null " + docIdSet, missCount > saveMissCount);
59 public String toString() {
60 return "CachingWrapperFilterHelper("+filter+")";
64 public boolean equals(Object o) {
65 if (!(o instanceof CachingWrapperFilterHelper)) return false;
66 return this.filter.equals(o);
70 public int hashCode() {
71 return this.filter.hashCode() ^ 0x5525aacb;