@@ -180,8 +180,9 @@ public void testNoMetadataInMapping() {
180180 ActionListener <AcknowledgedResponse > testListener = ActionListener .wrap (response -> {
181181 fail ("Listener success should not have been triggered." );
182182 }, 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)." ));
185186 });
186187
187188 Logger logger = mock (Logger .class );
@@ -206,6 +207,44 @@ public void testNoMetadataInMapping() {
206207 verify (client ).execute (eq (GetMappingsAction .INSTANCE ), any (GetMappingsRequest .class ), any ());
207208 }
208209
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+
209248 @ SuppressWarnings ("unchecked" )
210249 public void testNoMappingVersion () {
211250 RollupJob job = new RollupJob (ConfigTestHelpers .randomRollupJobConfig (random ()), Collections .emptyMap ());
0 commit comments