@@ -180,8 +180,9 @@ public void testNoMetadataInMapping() {
180
180
ActionListener <AcknowledgedResponse > testListener = ActionListener .wrap (response -> {
181
181
fail ("Listener success should not have been triggered." );
182
182
}, e -> {
183
- assertThat (e .getMessage (), equalTo ("Expected to find _meta key in mapping of rollup index ["
184
- + job .getConfig ().getRollupIndex () + "] but not found." ));
183
+ assertThat (e .getMessage (), equalTo ("Rollup data cannot be added to existing indices that contain " +
184
+ "non-rollup data (expected to find _meta key in mapping of rollup index ["
185
+ + job .getConfig ().getRollupIndex () + "] but not found)." ));
185
186
});
186
187
187
188
Logger logger = mock (Logger .class );
@@ -206,6 +207,44 @@ public void testNoMetadataInMapping() {
206
207
verify (client ).execute (eq (GetMappingsAction .INSTANCE ), any (GetMappingsRequest .class ), any ());
207
208
}
208
209
210
+ @ SuppressWarnings ("unchecked" )
211
+ public void testMetadataButNotRollup () {
212
+ RollupJob job = new RollupJob (ConfigTestHelpers .randomRollupJobConfig (random ()), Collections .emptyMap ());
213
+
214
+ ActionListener <AcknowledgedResponse > testListener = ActionListener .wrap (response -> {
215
+ fail ("Listener success should not have been triggered." );
216
+ }, e -> {
217
+ assertThat (e .getMessage (), equalTo ("Rollup data cannot be added to existing indices that contain " +
218
+ "non-rollup data (expected to find rollup meta key [_rollup] in mapping of rollup index ["
219
+ + job .getConfig ().getRollupIndex () + "] but not found)." ));
220
+ });
221
+
222
+ Logger logger = mock (Logger .class );
223
+ Client client = mock (Client .class );
224
+
225
+ ArgumentCaptor <ActionListener > requestCaptor = ArgumentCaptor .forClass (ActionListener .class );
226
+ doAnswer (invocation -> {
227
+ GetMappingsResponse response = mock (GetMappingsResponse .class );
228
+ Map <String , Object > m = new HashMap <>(2 );
229
+ m .put ("random" ,
230
+ Collections .singletonMap (job .getConfig ().getId (), job .getConfig ()));
231
+ MappingMetaData meta = new MappingMetaData (RollupField .TYPE_NAME ,
232
+ Collections .singletonMap ("_meta" , m ));
233
+ ImmutableOpenMap .Builder <String , MappingMetaData > builder = ImmutableOpenMap .builder (1 );
234
+ builder .put (RollupField .TYPE_NAME , meta );
235
+
236
+ ImmutableOpenMap .Builder <String , ImmutableOpenMap <String , MappingMetaData >> builder2 = ImmutableOpenMap .builder (1 );
237
+ builder2 .put (job .getConfig ().getRollupIndex (), builder .build ());
238
+
239
+ when (response .getMappings ()).thenReturn (builder2 .build ());
240
+ requestCaptor .getValue ().onResponse (response );
241
+ return null ;
242
+ }).when (client ).execute (eq (GetMappingsAction .INSTANCE ), any (GetMappingsRequest .class ), requestCaptor .capture ());
243
+
244
+ TransportPutRollupJobAction .updateMapping (job , testListener , mock (PersistentTasksService .class ), client , logger );
245
+ verify (client ).execute (eq (GetMappingsAction .INSTANCE ), any (GetMappingsRequest .class ), any ());
246
+ }
247
+
209
248
@ SuppressWarnings ("unchecked" )
210
249
public void testNoMappingVersion () {
211
250
RollupJob job = new RollupJob (ConfigTestHelpers .randomRollupJobConfig (random ()), Collections .emptyMap ());
0 commit comments