@@ -60,7 +60,12 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
60
60
61
61
62
62
public void testRolloverOnEmptyIndex () throws Exception {
63
- assertAcked (prepareCreate ("test_index-1" ).addAlias (new Alias ("test_alias" )).get ());
63
+ Alias testAlias = new Alias ("test_alias" );
64
+ boolean explicitWriteIndex = randomBoolean ();
65
+ if (explicitWriteIndex ) {
66
+ testAlias .writeIndex (true );
67
+ }
68
+ assertAcked (prepareCreate ("test_index-1" ).addAlias (testAlias ).get ());
64
69
final RolloverResponse response = client ().admin ().indices ().prepareRolloverIndex ("test_alias" ).get ();
65
70
assertThat (response .getOldIndex (), equalTo ("test_index-1" ));
66
71
assertThat (response .getNewIndex (), equalTo ("test_index-000002" ));
@@ -69,7 +74,12 @@ public void testRolloverOnEmptyIndex() throws Exception {
69
74
assertThat (response .getConditionStatus ().size (), equalTo (0 ));
70
75
final ClusterState state = client ().admin ().cluster ().prepareState ().get ().getState ();
71
76
final IndexMetaData oldIndex = state .metaData ().index ("test_index-1" );
72
- assertFalse (oldIndex .getAliases ().containsKey ("test_alias" ));
77
+ if (explicitWriteIndex ) {
78
+ assertTrue (oldIndex .getAliases ().containsKey ("test_alias" ));
79
+ assertFalse (oldIndex .getAliases ().get ("test_alias" ).writeIndex ());
80
+ } else {
81
+ assertFalse (oldIndex .getAliases ().containsKey ("test_alias" ));
82
+ }
73
83
final IndexMetaData newIndex = state .metaData ().index ("test_index-000002" );
74
84
assertTrue (newIndex .getAliases ().containsKey ("test_alias" ));
75
85
}
@@ -97,8 +107,49 @@ public void testRollover() throws Exception {
97
107
is (both (greaterThanOrEqualTo (beforeTime )).and (lessThanOrEqualTo (client ().threadPool ().absoluteTimeInMillis () + 1000L ))));
98
108
}
99
109
110
+ public void testRolloverWithExplicitWriteIndex () throws Exception {
111
+ long beforeTime = client ().threadPool ().absoluteTimeInMillis () - 1000L ;
112
+ assertAcked (prepareCreate ("test_index-2" ).addAlias (new Alias ("test_alias" ).writeIndex (true )).get ());
113
+ index ("test_index-2" , "type1" , "1" , "field" , "value" );
114
+ flush ("test_index-2" );
115
+ final RolloverResponse response = client ().admin ().indices ().prepareRolloverIndex ("test_alias" ).get ();
116
+ assertThat (response .getOldIndex (), equalTo ("test_index-2" ));
117
+ assertThat (response .getNewIndex (), equalTo ("test_index-000003" ));
118
+ assertThat (response .isDryRun (), equalTo (false ));
119
+ assertThat (response .isRolledOver (), equalTo (true ));
120
+ assertThat (response .getConditionStatus ().size (), equalTo (0 ));
121
+ final ClusterState state = client ().admin ().cluster ().prepareState ().get ().getState ();
122
+ final IndexMetaData oldIndex = state .metaData ().index ("test_index-2" );
123
+ assertTrue (oldIndex .getAliases ().containsKey ("test_alias" ));
124
+ assertFalse (oldIndex .getAliases ().get ("test_alias" ).writeIndex ());
125
+ final IndexMetaData newIndex = state .metaData ().index ("test_index-000003" );
126
+ assertTrue (newIndex .getAliases ().containsKey ("test_alias" ));
127
+ assertTrue (newIndex .getAliases ().get ("test_alias" ).writeIndex ());
128
+ assertThat (oldIndex .getRolloverInfos ().size (), equalTo (1 ));
129
+ assertThat (oldIndex .getRolloverInfos ().get ("test_alias" ).getAlias (), equalTo ("test_alias" ));
130
+ assertThat (oldIndex .getRolloverInfos ().get ("test_alias" ).getMetConditions (), is (empty ()));
131
+ assertThat (oldIndex .getRolloverInfos ().get ("test_alias" ).getTime (),
132
+ is (both (greaterThanOrEqualTo (beforeTime )).and (lessThanOrEqualTo (client ().threadPool ().absoluteTimeInMillis () + 1000L ))));
133
+ }
134
+
135
+ public void testRolloverWithNoWriteIndex () {
136
+ Boolean firstIsWriteIndex = randomFrom (false , null );
137
+ assertAcked (prepareCreate ("index1" ).addAlias (new Alias ("alias" ).writeIndex (firstIsWriteIndex )).get ());
138
+ if (firstIsWriteIndex == null ) {
139
+ assertAcked (prepareCreate ("index2" ).addAlias (new Alias ("alias" ).writeIndex (randomFrom (false , null ))).get ());
140
+ }
141
+ IllegalArgumentException exception = expectThrows (IllegalArgumentException .class ,
142
+ () -> client ().admin ().indices ().prepareRolloverIndex ("alias" ).dryRun (randomBoolean ()).get ());
143
+ assertThat (exception .getMessage (), equalTo ("source alias [alias] does not point to a write index" ));
144
+ }
145
+
100
146
public void testRolloverWithIndexSettings () throws Exception {
101
- assertAcked (prepareCreate ("test_index-2" ).addAlias (new Alias ("test_alias" )).get ());
147
+ Alias testAlias = new Alias ("test_alias" );
148
+ boolean explicitWriteIndex = randomBoolean ();
149
+ if (explicitWriteIndex ) {
150
+ testAlias .writeIndex (true );
151
+ }
152
+ assertAcked (prepareCreate ("test_index-2" ).addAlias (testAlias ).get ());
102
153
index ("test_index-2" , "type1" , "1" , "field" , "value" );
103
154
flush ("test_index-2" );
104
155
final Settings settings = Settings .builder ()
@@ -114,12 +165,17 @@ public void testRolloverWithIndexSettings() throws Exception {
114
165
assertThat (response .getConditionStatus ().size (), equalTo (0 ));
115
166
final ClusterState state = client ().admin ().cluster ().prepareState ().get ().getState ();
116
167
final IndexMetaData oldIndex = state .metaData ().index ("test_index-2" );
117
- assertFalse (oldIndex .getAliases ().containsKey ("test_alias" ));
118
168
final IndexMetaData newIndex = state .metaData ().index ("test_index-000003" );
119
169
assertThat (newIndex .getNumberOfShards (), equalTo (1 ));
120
170
assertThat (newIndex .getNumberOfReplicas (), equalTo (0 ));
121
171
assertTrue (newIndex .getAliases ().containsKey ("test_alias" ));
122
172
assertTrue (newIndex .getAliases ().containsKey ("extra_alias" ));
173
+ if (explicitWriteIndex ) {
174
+ assertFalse (oldIndex .getAliases ().get ("test_alias" ).writeIndex ());
175
+ assertTrue (newIndex .getAliases ().get ("test_alias" ).writeIndex ());
176
+ } else {
177
+ assertFalse (oldIndex .getAliases ().containsKey ("test_alias" ));
178
+ }
123
179
}
124
180
125
181
public void testRolloverDryRun () throws Exception {
@@ -140,7 +196,12 @@ public void testRolloverDryRun() throws Exception {
140
196
}
141
197
142
198
public void testRolloverConditionsNotMet () throws Exception {
143
- assertAcked (prepareCreate ("test_index-0" ).addAlias (new Alias ("test_alias" )).get ());
199
+ boolean explicitWriteIndex = randomBoolean ();
200
+ Alias testAlias = new Alias ("test_alias" );
201
+ if (explicitWriteIndex ) {
202
+ testAlias .writeIndex (true );
203
+ }
204
+ assertAcked (prepareCreate ("test_index-0" ).addAlias (testAlias ).get ());
144
205
index ("test_index-0" , "type1" , "1" , "field" , "value" );
145
206
flush ("test_index-0" );
146
207
final RolloverResponse response = client ().admin ().indices ().prepareRolloverIndex ("test_alias" )
@@ -160,12 +221,22 @@ public void testRolloverConditionsNotMet() throws Exception {
160
221
final ClusterState state = client ().admin ().cluster ().prepareState ().get ().getState ();
161
222
final IndexMetaData oldIndex = state .metaData ().index ("test_index-0" );
162
223
assertTrue (oldIndex .getAliases ().containsKey ("test_alias" ));
224
+ if (explicitWriteIndex ) {
225
+ assertTrue (oldIndex .getAliases ().get ("test_alias" ).writeIndex ());
226
+ } else {
227
+ assertNull (oldIndex .getAliases ().get ("test_alias" ).writeIndex ());
228
+ }
163
229
final IndexMetaData newIndex = state .metaData ().index ("test_index-000001" );
164
230
assertNull (newIndex );
165
231
}
166
232
167
233
public void testRolloverWithNewIndexName () throws Exception {
168
- assertAcked (prepareCreate ("test_index" ).addAlias (new Alias ("test_alias" )).get ());
234
+ Alias testAlias = new Alias ("test_alias" );
235
+ boolean explicitWriteIndex = randomBoolean ();
236
+ if (explicitWriteIndex ) {
237
+ testAlias .writeIndex (true );
238
+ }
239
+ assertAcked (prepareCreate ("test_index" ).addAlias (testAlias ).get ());
169
240
index ("test_index" , "type1" , "1" , "field" , "value" );
170
241
flush ("test_index" );
171
242
final RolloverResponse response = client ().admin ().indices ().prepareRolloverIndex ("test_alias" )
@@ -177,9 +248,14 @@ public void testRolloverWithNewIndexName() throws Exception {
177
248
assertThat (response .getConditionStatus ().size (), equalTo (0 ));
178
249
final ClusterState state = client ().admin ().cluster ().prepareState ().get ().getState ();
179
250
final IndexMetaData oldIndex = state .metaData ().index ("test_index" );
180
- assertFalse (oldIndex .getAliases ().containsKey ("test_alias" ));
181
251
final IndexMetaData newIndex = state .metaData ().index ("test_new_index" );
182
252
assertTrue (newIndex .getAliases ().containsKey ("test_alias" ));
253
+ if (explicitWriteIndex ) {
254
+ assertFalse (oldIndex .getAliases ().get ("test_alias" ).writeIndex ());
255
+ assertTrue (newIndex .getAliases ().get ("test_alias" ).writeIndex ());
256
+ } else {
257
+ assertFalse (oldIndex .getAliases ().containsKey ("test_alias" ));
258
+ }
183
259
}
184
260
185
261
public void testRolloverOnExistingIndex () throws Exception {
0 commit comments