From d4afcf4e4e579cbd3d687a5623994d270e77c4c6 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Mon, 18 Jan 2016 15:01:35 +0100 Subject: [PATCH] Marvel: Fix CleanerServiceTests when setting is equal to 0 closes elastic/elasticsearch#1319 Original commit: elastic/x-pack-elasticsearch@2dd8d61376227e2389e1c886806555e14f5db262 --- .../marvel/cleaner/CleanerServiceTests.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/CleanerServiceTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/CleanerServiceTests.java index cbe4899dc54..476d7ab438e 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/CleanerServiceTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/cleaner/CleanerServiceTests.java @@ -52,12 +52,14 @@ public class CleanerServiceTests extends ESTestCase { } public void testRetentionUpdateAllowed() { - TimeValue randomRetention = TimeValue.parseTimeValue(randomTimeValue(), null, ""); - MarvelLicensee licensee = mock(MarvelLicensee.class); when(licensee.allowUpdateRetention()).thenReturn(true); CleanerService service = new CleanerService(Settings.EMPTY, clusterSettings, threadPool, licensee); + service.setRetention(TimeValue.parseTimeValue("-1", null, "")); + assertThat(service.getRetention().getMillis(), equalTo(-1L)); + + TimeValue randomRetention = TimeValue.parseTimeValue(randomIntBetween(1, 1000) + "ms", null, ""); service.setRetention(randomRetention); assertThat(service.getRetention(), equalTo(randomRetention)); @@ -69,14 +71,27 @@ public class CleanerServiceTests extends ESTestCase { } public void testRetentionUpdateBlocked() { - TimeValue randomRetention = TimeValue.parseTimeValue(randomTimeValue(), null, ""); - MarvelLicensee licensee = mock(MarvelLicensee.class); - when(licensee.allowUpdateRetention()).thenReturn(false); - + when(licensee.allowUpdateRetention()).thenReturn(true); CleanerService service = new CleanerService(Settings.EMPTY, clusterSettings, threadPool, licensee); + try { + service.setRetention(TimeValue.parseTimeValue("-5000ms", null, "")); + fail("exception should have been thrown: negative retention are not allowed"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), containsString("invalid history duration setting value")); + } + try { + service.setRetention(null); + fail("exception should have been thrown: null retention is not allowed"); + } catch (IllegalArgumentException e) { + assertThat(e.getMessage(), containsString("history duration setting cannot be null")); + } + + TimeValue randomRetention = TimeValue.parseTimeValue(randomIntBetween(1, 1000) + "ms", null, ""); + when(licensee.allowUpdateRetention()).thenReturn(false); try { service.setRetention(randomRetention); + fail("exception should have been thrown"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("license does not allow the history duration setting to be updated to value")); assertNull(service.getRetention());