davsclaus commented on code in PR #27696: URL: https://github.com/apache/camel/pull/27696#discussion_r4245539257
########## components/camel-atom/src/test/java/org/apache/camel/component/atom/AtomEntrySortTest.java: ########## @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.atom; + +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; + +import com.apptasticsoftware.rssreader.Item; +import org.apache.camel.Consumer; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * With sortEntries the entries of a feed must be routed from the oldest to the newest one, as camel-rss does. The + * default idempotent strategy skips an entry that is older than the one routed before it, so any other order loses + * entries. + */ +@DisabledOnOs(OS.AIX) +class AtomEntrySortTest extends CamelTestSupport { + + // the feed has 10 entries, which are not in the order of their dates + private static final String FEED + = "atom:file:src/test/data/unsortedfeed.atom?splitEntries=true&throttleEntries=false&startScheduler=false"; + + @Test + void sortedEntriesAreAllRoutedOldestFirst() throws Exception { + List<ZonedDateTime> routed = pollOnce(FEED + "&sortEntries=true"); + + assertEquals(10, routed.size(), "All the entries of the feed must be routed"); + assertEquals(sorted(routed), routed); + } + + @Test + void sortedEntriesAreRoutedOldestFirstWithoutIdempotency() throws Exception { + List<ZonedDateTime> routed = pollOnce(FEED + "&sortEntries=true&idempotent=false"); + + assertEquals(10, routed.size()); + assertEquals(sorted(routed), routed); + } + + @Test + void entriesAreAllRoutedWithoutSortEntries() throws Exception { + List<ZonedDateTime> routed = pollOnce(FEED); + + assertEquals(10, routed.size()); + assertEquals(sorted(routed), routed); + } + + /** + * Runs one poll of a consumer of the given endpoint (its scheduler is not started) and returns the dates of the + * routed entries. + */ + private List<ZonedDateTime> pollOnce(String uri) throws Exception { + List<ZonedDateTime> routed = new ArrayList<>(); + Consumer consumer = context.getEndpoint(uri).createConsumer( + exchange -> routed.add(exchange.getIn().getBody(Item.class).getUpdatedZonedDateTime().orElseThrow())); Review Comment: `Item.getUpdatedZonedDateTime()` is `@Deprecated(since = "3.12.0", forRemoval = true)` in rssreader 3.12.0; please use `getUpdatedAsZonedDateTime()` instead. ########## components/camel-atom/src/main/java/org/apache/camel/component/atom/AtomEntryPollingConsumer.java: ########## @@ -67,6 +69,12 @@ private List<Item> readItems() throws IOException { if (items == null) { items = AtomUtils.readItems(getEndpoint().getCamelContext(), getEndpoint().getFeedUri(), rssReader, getEndpoint().isSortEntries()); + if (getEndpoint().isSortEntries()) { + // sorted entries have the oldest entry first, but the entries are routed from the end of the list + // (without sortEntries the newest entry is first): reverse them, so the oldest entry is routed first Review Comment: After this reverse the result is the same order as without `sortEntries` (the default `naturalOrder()` is `newestPublishedItemFirst()`, the exact reverse of `oldestPublishedItemFirst()`). So `sortEntries` becomes a no-op for the split consumer. Would you consider sorting by the updated date here (like 3.x did and like the idempotent strategy uses), e.g. `ItemComparator.newestUpdatedItemFirst()`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
