InfinispanSchemaStore { protected Message merge(Message storedMessage, Message newMessage) { List<Field> fields = new ArrayList<>(storedMessage.getFields()); newMessage.getFields().forEach(field -> { if (!containsField(fields, field) && !containsField(new ArrayList<>(storedMessage.getFields()), field)) { fields.add(field); } }); Set<Field> reorderedFields = reorderFields(fields); return new Message(storedMessage.getName(), reorderedFields); } InfinispanSchemaStore(InfinispanContext infinispanContext,
                                 MappingProvider mappingProvider); void updateSchema(KObject kObject); boolean containsField(List<Field> fields,
                                 Field field);  }
@Test public void testMerge() { String oldFieldName = "oldField"; String newFieldName = "newField"; Message oldMessage = new Message(); Field oldField = new Field(ProtobufScope.OPTIONAL, ProtobufType.STRING, oldFieldName, 1); oldMessage.setFields(Collections.singleton(oldField)); Message newMessage = new Message(); Field newField = new Field(ProtobufScope.OPTIONAL, ProtobufType.STRING, newFieldName, 2); newMessage.setFields(new HashSet<>(Arrays.asList(oldField, newField))); Message mergedMessage = this.infinispanSchemaStore.merge(oldMessage, newMessage); assertThat(mergedMessage.getFields().size()).isEqualTo(2); assertThat(mergedMessage.getFields()).anySatisfy(field -> field.getName().equals(oldFieldName)); assertThat(mergedMessage.getFields()).anySatisfy(field -> field.getName().equals(newFieldName)); }