1414import org .elasticsearch .core .TimeValue ;
1515import org .elasticsearch .test .ESTestCase ;
1616
17+ import java .math .BigDecimal ;
18+ import java .math .RoundingMode ;
19+
1720import static org .hamcrest .Matchers .equalTo ;
1821
1922public class IndexingStatsSettingsTests extends ESTestCase {
@@ -40,4 +43,60 @@ public void testRecentWriteLoadHalfLife_updateValue() {
4043 );
4144 assertThat (settings .getRecentWriteLoadHalfLifeForNewShards (), equalTo (TimeValue .timeValueMinutes (90 )));
4245 }
46+
47+ public void testRecentWriteLoadHalfLife_minValue () {
48+ IndexingStatsSettings settings = new IndexingStatsSettings (
49+ ClusterSettings .createBuiltInClusterSettings (
50+ Settings .builder ()
51+ .put (
52+ IndexingStatsSettings .RECENT_WRITE_LOAD_HALF_LIFE_SETTING .getKey (),
53+ IndexingStatsSettings .RECENT_WRITE_LOAD_HALF_LIFE_MIN .toString ()
54+ )
55+ .build ()
56+ )
57+ );
58+ assertThat (settings .getRecentWriteLoadHalfLifeForNewShards (), equalTo (IndexingStatsSettings .RECENT_WRITE_LOAD_HALF_LIFE_MIN ));
59+ }
60+
61+ public void testRecentWriteLoadHalfLife_valueTooSmall () {
62+ long tooFewMillis = IndexingStatsSettings .RECENT_WRITE_LOAD_HALF_LIFE_MIN .getMillis () / 2 ;
63+ assertThrows (
64+ IllegalArgumentException .class ,
65+ () -> new IndexingStatsSettings (
66+ ClusterSettings .createBuiltInClusterSettings (
67+ Settings .builder ().put (IndexingStatsSettings .RECENT_WRITE_LOAD_HALF_LIFE_SETTING .getKey (), tooFewMillis + "ms" ).build ()
68+ )
69+ )
70+ );
71+ }
72+
73+ public void testRecentWriteLoadHalfLife_maxValue () {
74+ IndexingStatsSettings settings = new IndexingStatsSettings (
75+ ClusterSettings .createBuiltInClusterSettings (
76+ Settings .builder ()
77+ .put (
78+ IndexingStatsSettings .RECENT_WRITE_LOAD_HALF_LIFE_SETTING .getKey (),
79+ IndexingStatsSettings .RECENT_WRITE_LOAD_HALF_LIFE_MAX .toString ()
80+ )
81+ .build ()
82+ )
83+ );
84+ assertThat (settings .getRecentWriteLoadHalfLifeForNewShards (), equalTo (IndexingStatsSettings .RECENT_WRITE_LOAD_HALF_LIFE_MAX ));
85+ }
86+
87+ public void testRecentWriteLoadHalfLife_valueTooLarge () {
88+ int tooManyDays = BigDecimal .valueOf (Long .MAX_VALUE )
89+ .add (BigDecimal .ONE )
90+ .divide (BigDecimal .valueOf (24 * 60 * 60 * 1_000_000_000L ), RoundingMode .UP )
91+ .setScale (0 , RoundingMode .UP )
92+ .intValueExact ();
93+ assertThrows (
94+ IllegalArgumentException .class ,
95+ () -> new IndexingStatsSettings (
96+ ClusterSettings .createBuiltInClusterSettings (
97+ Settings .builder ().put (IndexingStatsSettings .RECENT_WRITE_LOAD_HALF_LIFE_SETTING .getKey (), tooManyDays + "d" ).build ()
98+ )
99+ )
100+ );
101+ }
43102}
0 commit comments