From cc131eb3283b0541c493d2600d2de314506eb19d Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 26 Oct 2015 22:32:34 +0100 Subject: [PATCH] fix tests --- .../main/java/org/elasticsearch/index/IndexModule.java | 2 +- .../java/org/elasticsearch/index/IndexModuleTests.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/index/IndexModule.java b/core/src/main/java/org/elasticsearch/index/IndexModule.java index 7f0c4856a7b..65eedb541ed 100644 --- a/core/src/main/java/org/elasticsearch/index/IndexModule.java +++ b/core/src/main/java/org/elasticsearch/index/IndexModule.java @@ -185,7 +185,7 @@ public class IndexModule extends AbstractModule { throw new IllegalArgumentException("provider must not be null"); } if (queryCaches.containsKey(name)) { - throw new IllegalArgumentException("provider for name [" + name + "] is already registered"); + throw new IllegalArgumentException("Can't register the same [query_cache] more than once for [" + name + "]"); } queryCaches.put(name, provider); } diff --git a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java index be8566b28d0..7abc445816e 100644 --- a/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java +++ b/core/src/test/java/org/elasticsearch/index/IndexModuleTests.java @@ -204,15 +204,24 @@ public class IndexModuleTests extends ModuleTestCase { IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings(new Index("foo"), indexSettings, Collections.EMPTY_LIST), null, null, warmer); try { module.registerQueryCache("index", IndexQueryCache::new); + fail("only once"); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), "Can't register the same [query_cache] more than once for [index]"); } try { module.registerQueryCache("none", (settings, x) -> new NoneQueryCache(settings)); + fail("only once"); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), "Can't register the same [query_cache] more than once for [none]"); } + + try { + module.registerQueryCache("index", null); + fail("must not be null"); + } catch (IllegalArgumentException e) { + assertEquals(e.getMessage(), "provider must not be null"); + } } public void testRegisterCustomQueryCache() { @@ -223,6 +232,7 @@ public class IndexModuleTests extends ModuleTestCase { module.registerQueryCache("custom", (a, b) -> new CustomQueryCache()); try { module.registerQueryCache("custom", (a, b) -> new CustomQueryCache()); + fail("only once"); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), "Can't register the same [query_cache] more than once for [custom]"); }