simplify toString for cached filter

This commit is contained in:
Shay Banon 2011-12-28 23:35:04 +02:00
parent bb63d38a65
commit 4e6217c54d
3 changed files with 15 additions and 12 deletions

View File

@ -38,8 +38,6 @@ import static org.elasticsearch.common.util.concurrent.ConcurrentCollections.new
/** /**
* A base concurrent filter cache that accepts the actual cache to use. * A base concurrent filter cache that accepts the actual cache to use.
*
*
*/ */
public abstract class AbstractConcurrentMapFilterCache extends AbstractIndexComponent implements FilterCache, IndexReader.ReaderFinishedListener { public abstract class AbstractConcurrentMapFilterCache extends AbstractIndexComponent implements FilterCache, IndexReader.ReaderFinishedListener {
@ -163,7 +161,7 @@ public abstract class AbstractConcurrentMapFilterCache extends AbstractIndexComp
} }
public String toString() { public String toString() {
return "FilterCacheFilterWrapper(" + filter + ")"; return "cache(" + filter + ")";
} }
public boolean equals(Object o) { public boolean equals(Object o) {

View File

@ -173,7 +173,7 @@ public abstract class AbstractWeightedFilterCache extends AbstractIndexComponent
} }
public String toString() { public String toString() {
return "FilterCacheFilterWrapper(" + filter + ")"; return "cache(" + filter + ")";
} }
public boolean equals(Object o) { public boolean equals(Object o) {

View File

@ -90,8 +90,8 @@ public class IndexAliasesServiceTests {
assertThat(indexAliasesService.hasAlias("dogs"), equalTo(true)); assertThat(indexAliasesService.hasAlias("dogs"), equalTo(true));
assertThat(indexAliasesService.hasAlias("turtles"), equalTo(false)); assertThat(indexAliasesService.hasAlias("turtles"), equalTo(false));
assertThat(indexAliasesService.aliasFilter("cats").toString(), equalTo("FilterCacheFilterWrapper(animal:cat)")); assertThat(indexAliasesService.aliasFilter("cats").toString(), equalTo("cache(animal:cat)"));
assertThat(indexAliasesService.aliasFilter("cats", "dogs").toString(), equalTo("BooleanFilter( FilterCacheFilterWrapper(animal:cat) FilterCacheFilterWrapper(animal:dog))")); assertThat(indexAliasesService.aliasFilter("cats", "dogs").toString(), equalTo("BooleanFilter( cache(animal:cat) cache(animal:dog))"));
// Non-filtering alias should turn off all filters because filters are ORed // Non-filtering alias should turn off all filters because filters are ORed
assertThat(indexAliasesService.aliasFilter("all"), nullValue()); assertThat(indexAliasesService.aliasFilter("all"), nullValue());
@ -100,7 +100,7 @@ public class IndexAliasesServiceTests {
indexAliasesService.add("cats", filter(termFilter("animal", "feline"))); indexAliasesService.add("cats", filter(termFilter("animal", "feline")));
indexAliasesService.add("dogs", filter(termFilter("animal", "canine"))); indexAliasesService.add("dogs", filter(termFilter("animal", "canine")));
assertThat(indexAliasesService.aliasFilter("dogs", "cats").toString(), equalTo("BooleanFilter( FilterCacheFilterWrapper(animal:canine) FilterCacheFilterWrapper(animal:feline))")); assertThat(indexAliasesService.aliasFilter("dogs", "cats").toString(), equalTo("BooleanFilter( cache(animal:canine) cache(animal:feline))"));
} }
@Test @Test
@ -110,13 +110,13 @@ public class IndexAliasesServiceTests {
indexAliasesService.add("dogs", filter(termFilter("animal", "dog"))); indexAliasesService.add("dogs", filter(termFilter("animal", "dog")));
assertThat(indexAliasesService.aliasFilter(), nullValue()); assertThat(indexAliasesService.aliasFilter(), nullValue());
assertThat(indexAliasesService.aliasFilter("dogs").toString(), equalTo("FilterCacheFilterWrapper(animal:dog)")); assertThat(indexAliasesService.aliasFilter("dogs").toString(), equalTo("cache(animal:dog)"));
assertThat(indexAliasesService.aliasFilter("dogs", "cats").toString(), equalTo("BooleanFilter( FilterCacheFilterWrapper(animal:dog) FilterCacheFilterWrapper(animal:cat))")); assertThat(indexAliasesService.aliasFilter("dogs", "cats").toString(), equalTo("BooleanFilter( cache(animal:dog) cache(animal:cat))"));
indexAliasesService.add("cats", filter(termFilter("animal", "feline"))); indexAliasesService.add("cats", filter(termFilter("animal", "feline")));
indexAliasesService.add("dogs", filter(termFilter("animal", "canine"))); indexAliasesService.add("dogs", filter(termFilter("animal", "canine")));
assertThat(indexAliasesService.aliasFilter("dogs", "cats").toString(), equalTo("BooleanFilter( FilterCacheFilterWrapper(animal:canine) FilterCacheFilterWrapper(animal:feline))")); assertThat(indexAliasesService.aliasFilter("dogs", "cats").toString(), equalTo("BooleanFilter( cache(animal:canine) cache(animal:feline))"));
} }
@Test(expectedExceptions = InvalidAliasNameException.class) @Test(expectedExceptions = InvalidAliasNameException.class)
@ -128,13 +128,18 @@ public class IndexAliasesServiceTests {
} }
@Test(expectedExceptions = InvalidAliasNameException.class) @Test
public void testUnknownAliasFilter() throws Exception { public void testUnknownAliasFilter() throws Exception {
IndexAliasesService indexAliasesService = newIndexAliasesService(); IndexAliasesService indexAliasesService = newIndexAliasesService();
indexAliasesService.add("cats", filter(termFilter("animal", "cat"))); indexAliasesService.add("cats", filter(termFilter("animal", "cat")));
indexAliasesService.add("dogs", filter(termFilter("animal", "dog"))); indexAliasesService.add("dogs", filter(termFilter("animal", "dog")));
indexAliasesService.aliasFilter("unknown"); try {
indexAliasesService.aliasFilter("unknown");
assert false;
} catch (InvalidAliasNameException e) {
// all is well
}
} }