1616package com.amazon.opendistroforelasticsearch.indexstatemanagement.action
1717
1818import com.amazon.opendistroforelasticsearch.indexstatemanagement.IndexStateManagementRestTestCase
19- import com.amazon.opendistroforelasticsearch.indexstatemanagement.makeRequest
2019import com.amazon.opendistroforelasticsearch.indexstatemanagement.model.Policy
2120import com.amazon.opendistroforelasticsearch.indexstatemanagement.model.State
2221import com.amazon.opendistroforelasticsearch.indexstatemanagement.model.action.RolloverActionConfig
2322import com.amazon.opendistroforelasticsearch.indexstatemanagement.randomErrorNotification
2423import com.amazon.opendistroforelasticsearch.indexstatemanagement.waitFor
25- import org.apache.http.entity.ContentType
26- import org.apache.http.entity.StringEntity
2724import org.elasticsearch.common.unit.ByteSizeUnit
2825import org.elasticsearch.common.unit.ByteSizeValue
29- import org.elasticsearch.rest.RestRequest
26+ import org.elasticsearch.common.unit.TimeValue
27+ import org.hamcrest.core.Is.isA
3028import org.junit.Assert
3129import java.time.Instant
3230import java.time.temporal.ChronoUnit
@@ -36,6 +34,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() {
3634
3735 private val testIndexName = javaClass.simpleName.toLowerCase(Locale .ROOT )
3836
37+ @Suppress(" UNCHECKED_CAST" )
3938 fun `test rollover no condition` () {
4039 val aliasName = " ${testIndexName} _alias"
4140 val indexNameBase = " ${testIndexName} _index"
@@ -65,10 +64,15 @@ class RolloverActionIT : IndexStateManagementRestTestCase() {
6564
6665 // Need to speed up to second execution where it will trigger the first execution of the action
6766 updateManagedIndexConfigStartTime(managedIndexConfig)
68- waitFor { assertEquals(" Index did not rollover." , mapOf (" message" to " Rolled over index" ), getExplainManagedIndexMetaData(firstIndex).info) }
67+ waitFor {
68+ val info = getExplainManagedIndexMetaData(firstIndex).info as Map <String , Any ?>
69+ assertEquals(" Index did not rollover." , " Rolled over index" , info[" message" ])
70+ assertNull(" Should not have conditions if none specified" , info[" conditions" ])
71+ }
6972 Assert .assertTrue(" New rollover index does not exist." , indexExists(" $indexNameBase -000002" ))
7073 }
7174
75+ @Suppress(" UNCHECKED_CAST" )
7276 fun `test rollover multi condition byte size` () {
7377 val aliasName = " ${testIndexName} _byte_alias"
7478 val indexNameBase = " ${testIndexName} _index_byte"
@@ -98,36 +102,47 @@ class RolloverActionIT : IndexStateManagementRestTestCase() {
98102
99103 // Need to speed up to second execution where it will trigger the first execution of the action
100104 updateManagedIndexConfigStartTime(managedIndexConfig)
101- waitFor { assertEquals(" Index rollover before it met the condition." , mapOf (" message" to " Attempting to rollover" ), getExplainManagedIndexMetaData(firstIndex).info) }
102-
103- client().makeRequest(
104- RestRequest .Method .PUT .toString(),
105- " $firstIndex /_doc/1111" ,
106- StringEntity (" { \" testkey\" : \" some valueaaaaaaa\" }" , ContentType .APPLICATION_JSON )
107- )
108- client().makeRequest(
109- RestRequest .Method .PUT .toString(),
110- " $firstIndex /_doc/2222" ,
111- StringEntity (" { \" testkey1\" : \" some value1\" }" , ContentType .APPLICATION_JSON )
112- )
113- client().makeRequest(
114- RestRequest .Method .PUT .toString(),
115- " $firstIndex /_doc/3333" ,
116- StringEntity (" { \" testkey2\" : \" some value2\" }" , ContentType .APPLICATION_JSON )
117- )
105+ waitFor {
106+ val info = getExplainManagedIndexMetaData(firstIndex).info as Map <String , Any ?>
107+ assertEquals(" Index rollover before it met the condition." , " Attempting to rollover" , info[" message" ])
108+ val conditions = info[" conditions" ] as Map <String , Any ?>
109+ assertEquals(" Did not have exclusively min size and min doc count conditions" ,
110+ setOf (RolloverActionConfig .MIN_SIZE_FIELD , RolloverActionConfig .MIN_DOC_COUNT_FIELD ), conditions.keys)
111+ val minSize = conditions[RolloverActionConfig .MIN_SIZE_FIELD ] as Map <String , Any ?>
112+ val minDocCount = conditions[RolloverActionConfig .MIN_DOC_COUNT_FIELD ] as Map <String , Any ?>
113+ assertEquals(" Did not have min size condition" , " 10b" , minSize[" condition" ])
114+ assertThat(" Did not have min size current" , minSize[" current" ], isA(String ::class .java))
115+ assertEquals(" Did not have min doc count condition" , 1000000 , minDocCount[" condition" ])
116+ assertEquals(" Did not have min doc count current" , 0 , minDocCount[" current" ])
117+ }
118+
119+ insertSampleData(index = firstIndex, docCount = 5 , delay = 0 )
118120
119121 // Need to speed up to second execution where it will trigger the first execution of the action
120122 updateManagedIndexConfigStartTime(managedIndexConfig)
121- waitFor { assertEquals(" Index did not rollover." , mapOf (" message" to " Rolled over index" ), getExplainManagedIndexMetaData(firstIndex).info) }
123+ waitFor {
124+ val info = getExplainManagedIndexMetaData(firstIndex).info as Map <String , Any ?>
125+ assertEquals(" Index did not rollover" , " Rolled over index" , info[" message" ])
126+ val conditions = info[" conditions" ] as Map <String , Any ?>
127+ assertEquals(" Did not have exclusively min size and min doc count conditions" ,
128+ setOf (RolloverActionConfig .MIN_SIZE_FIELD , RolloverActionConfig .MIN_DOC_COUNT_FIELD ), conditions.keys)
129+ val minSize = conditions[RolloverActionConfig .MIN_SIZE_FIELD ] as Map <String , Any ?>
130+ val minDocCount = conditions[RolloverActionConfig .MIN_DOC_COUNT_FIELD ] as Map <String , Any ?>
131+ assertEquals(" Did not have min size condition" , " 10b" , minSize[" condition" ])
132+ assertThat(" Did not have min size current" , minSize[" current" ], isA(String ::class .java))
133+ assertEquals(" Did not have min doc count condition" , 1000000 , minDocCount[" condition" ])
134+ assertEquals(" Did not have min doc count current" , 5 , minDocCount[" current" ])
135+ }
122136 Assert .assertTrue(" New rollover index does not exist." , indexExists(" $indexNameBase -000002" ))
123137 }
124138
139+ @Suppress(" UNCHECKED_CAST" )
125140 fun `test rollover multi condition doc size` () {
126141 val aliasName = " ${testIndexName} _doc_alias"
127142 val indexNameBase = " ${testIndexName} _index_doc"
128143 val firstIndex = " $indexNameBase -1"
129144 val policyID = " ${testIndexName} _testPolicyName_doc_1"
130- val actionConfig = RolloverActionConfig (ByteSizeValue ( 10 , ByteSizeUnit . TB ), 3 , null , 0 )
145+ val actionConfig = RolloverActionConfig (null , 3 , TimeValue .timeValueDays( 2 ) , 0 )
131146 val states = listOf (State (name = " RolloverAction" , actions = listOf (actionConfig), transitions = listOf ()))
132147 val policy = Policy (
133148 id = policyID,
@@ -151,27 +166,37 @@ class RolloverActionIT : IndexStateManagementRestTestCase() {
151166
152167 // Need to speed up to second execution where it will trigger the first execution of the action
153168 updateManagedIndexConfigStartTime(managedIndexConfig)
154- waitFor { assertEquals(" Index rollover before it met the condition." , mapOf (" message" to " Attempting to rollover" ), getExplainManagedIndexMetaData(firstIndex).info) }
155-
156- client().makeRequest(
157- RestRequest .Method .PUT .toString(),
158- " $firstIndex /_doc/1111" ,
159- StringEntity (" { \" testkey\" : \" some value\" }" , ContentType .APPLICATION_JSON )
160- )
161- client().makeRequest(
162- RestRequest .Method .PUT .toString(),
163- " $firstIndex /_doc/2222" ,
164- StringEntity (" { \" testkey1\" : \" some value1\" }" , ContentType .APPLICATION_JSON )
165- )
166- client().makeRequest(
167- RestRequest .Method .PUT .toString(),
168- " $firstIndex /_doc/3333" ,
169- StringEntity (" { \" testkey2\" : \" some value2\" }" , ContentType .APPLICATION_JSON )
170- )
169+ waitFor {
170+ val info = getExplainManagedIndexMetaData(firstIndex).info as Map <String , Any ?>
171+ assertEquals(" Index rollover before it met the condition." , " Attempting to rollover" , info[" message" ])
172+ val conditions = info[" conditions" ] as Map <String , Any ?>
173+ assertEquals(" Did not have exclusively min age and min doc count conditions" ,
174+ setOf (RolloverActionConfig .MIN_INDEX_AGE_FIELD , RolloverActionConfig .MIN_DOC_COUNT_FIELD ), conditions.keys)
175+ val minAge = conditions[RolloverActionConfig .MIN_INDEX_AGE_FIELD ] as Map <String , Any ?>
176+ val minDocCount = conditions[RolloverActionConfig .MIN_DOC_COUNT_FIELD ] as Map <String , Any ?>
177+ assertEquals(" Did not have min age condition" , " 2d" , minAge[" condition" ])
178+ assertThat(" Did not have min age current" , minAge[" current" ], isA(String ::class .java))
179+ assertEquals(" Did not have min doc count condition" , 3 , minDocCount[" condition" ])
180+ assertEquals(" Did not have min doc count current" , 0 , minDocCount[" current" ])
181+ }
182+
183+ insertSampleData(index = firstIndex, docCount = 5 , delay = 0 )
171184
172185 // Need to speed up to second execution where it will trigger the first execution of the action
173186 updateManagedIndexConfigStartTime(managedIndexConfig)
174- waitFor { assertEquals(" Index did not rollover." , mapOf (" message" to " Rolled over index" ), getExplainManagedIndexMetaData(firstIndex).info) }
187+ waitFor {
188+ val info = getExplainManagedIndexMetaData(firstIndex).info as Map <String , Any ?>
189+ assertEquals(" Index did not rollover" , " Rolled over index" , info[" message" ])
190+ val conditions = info[" conditions" ] as Map <String , Any ?>
191+ assertEquals(" Did not have exclusively min age and min doc count conditions" ,
192+ setOf (RolloverActionConfig .MIN_INDEX_AGE_FIELD , RolloverActionConfig .MIN_DOC_COUNT_FIELD ), conditions.keys)
193+ val minAge = conditions[RolloverActionConfig .MIN_INDEX_AGE_FIELD ] as Map <String , Any ?>
194+ val minDocCount = conditions[RolloverActionConfig .MIN_DOC_COUNT_FIELD ] as Map <String , Any ?>
195+ assertEquals(" Did not have min age condition" , " 2d" , minAge[" condition" ])
196+ assertThat(" Did not have min age current" , minAge[" current" ], isA(String ::class .java))
197+ assertEquals(" Did not have min doc count condition" , 3 , minDocCount[" condition" ])
198+ assertEquals(" Did not have min doc count current" , 5 , minDocCount[" current" ])
199+ }
175200 Assert .assertTrue(" New rollover index does not exist." , indexExists(" $indexNameBase -000002" ))
176201 }
177202}
0 commit comments