1212import org .elasticsearch .action .admin .indices .rollover .MaxAgeCondition ;
1313import org .elasticsearch .action .admin .indices .rollover .MaxDocsCondition ;
1414import org .elasticsearch .action .admin .indices .rollover .MaxSizeCondition ;
15- import org .elasticsearch .action .admin .indices .rollover .RolloverIndexTestHelper ;
1615import org .elasticsearch .action .admin .indices .rollover .RolloverRequest ;
1716import org .elasticsearch .action .admin .indices .rollover .RolloverResponse ;
1817import org .elasticsearch .client .AdminClient ;
2928import org .mockito .invocation .InvocationOnMock ;
3029import org .mockito .stubbing .Answer ;
3130
31+ import java .util .Collections ;
3232import java .util .HashSet ;
3333import java .util .Locale ;
3434import java .util .Set ;
35+ import java .util .stream .Collectors ;
3536
3637import static org .hamcrest .Matchers .equalTo ;
3738
@@ -97,7 +98,19 @@ public RolloverStep copyInstance(RolloverStep instance) {
9798 instance .getMaxSize (), instance .getMaxAge (), instance .getMaxDocs ());
9899 }
99100
100- public void testPerformAction () throws Exception {
101+ private static void assertRolloverIndexRequest (RolloverRequest request , String alias , Set <Condition <?>> expectedConditions ) {
102+ assertNotNull (request );
103+ assertEquals (1 , request .indices ().length );
104+ assertEquals (alias , request .indices ()[0 ]);
105+ assertEquals (alias , request .getAlias ());
106+ assertEquals (expectedConditions .size (), request .getConditions ().size ());
107+ Set <Object > expectedConditionValues = expectedConditions .stream ().map (Condition ::value ).collect (Collectors .toSet ());
108+ Set <Object > actualConditionValues = request .getConditions ().values ().stream ()
109+ .map (Condition ::value ).collect (Collectors .toSet ());
110+ assertEquals (expectedConditionValues , actualConditionValues );
111+ }
112+
113+ public void testPerformAction () {
101114 String alias = randomAlphaOfLength (5 );
102115 IndexMetaData indexMetaData = IndexMetaData .builder (randomAlphaOfLength (10 ))
103116 .settings (settings (Version .CURRENT ).put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias ))
@@ -127,8 +140,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
127140 if (step .getMaxDocs () != null ) {
128141 expectedConditions .add (new MaxDocsCondition (step .getMaxDocs ()));
129142 }
130- RolloverIndexTestHelper . assertRolloverIndexRequest (request , alias , expectedConditions );
131- listener .onResponse (RolloverIndexTestHelper . createMockResponse ( request , true ));
143+ assertRolloverIndexRequest (request , alias , expectedConditions );
144+ listener .onResponse (new RolloverResponse ( null , null , Collections . emptyMap (), request . isDryRun (), true , true , true ));
132145 return null ;
133146 }
134147
@@ -155,7 +168,7 @@ public void onFailure(Exception e) {
155168 Mockito .verify (indicesClient , Mockito .only ()).rolloverIndex (Mockito .any (), Mockito .any ());
156169 }
157170
158- public void testPerformActionNotComplete () throws Exception {
171+ public void testPerformActionNotComplete () {
159172 String alias = randomAlphaOfLength (5 );
160173 IndexMetaData indexMetaData = IndexMetaData .builder (randomAlphaOfLength (10 ))
161174 .settings (settings (Version .CURRENT ).put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias ))
@@ -184,8 +197,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
184197 if (step .getMaxDocs () != null ) {
185198 expectedConditions .add (new MaxDocsCondition (step .getMaxDocs ()));
186199 }
187- RolloverIndexTestHelper . assertRolloverIndexRequest (request , alias , expectedConditions );
188- listener .onResponse (RolloverIndexTestHelper . createMockResponse ( request , false ));
200+ assertRolloverIndexRequest (request , alias , expectedConditions );
201+ listener .onResponse (new RolloverResponse ( null , null , Collections . emptyMap (), request . isDryRun () , false , true , true ));
189202 return null ;
190203 }
191204
@@ -212,7 +225,7 @@ public void onFailure(Exception e) {
212225 Mockito .verify (indicesClient , Mockito .only ()).rolloverIndex (Mockito .any (), Mockito .any ());
213226 }
214227
215- public void testPerformActionFailure () throws Exception {
228+ public void testPerformActionFailure () {
216229 String alias = randomAlphaOfLength (5 );
217230 IndexMetaData indexMetaData = IndexMetaData .builder (randomAlphaOfLength (10 ))
218231 .settings (settings (Version .CURRENT ).put (RolloverAction .LIFECYCLE_ROLLOVER_ALIAS , alias ))
@@ -242,7 +255,7 @@ public Void answer(InvocationOnMock invocation) throws Throwable {
242255 if (step .getMaxDocs () != null ) {
243256 expectedConditions .add (new MaxDocsCondition (step .getMaxDocs ()));
244257 }
245- RolloverIndexTestHelper . assertRolloverIndexRequest (request , alias , expectedConditions );
258+ assertRolloverIndexRequest (request , alias , expectedConditions );
246259 listener .onFailure (exception );
247260 return null ;
248261 }
0 commit comments