gnodet-bot commented on code in PR #31262: URL: https://github.com/apache/camel/pull/31262#discussion_r4770414922
########## components/camel-aws/camel-aws2-s3/src/test/java/org/apache/camel/component/aws2/s3/AWS2S3ProducerListObjectsPagingTest.java: ########## @@ -0,0 +1,129 @@ +/* + * 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.aws2.s3; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit6.CamelTestSupport; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.services.s3.model.S3Object; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * listObjects reads the continuation token and the maximum number of keys from the headers, and sets the token of the + * next page back on the out message, so that a route can walk a bucket with more objects than one answer carries. + */ +class AWS2S3ProducerListObjectsPagingTest extends CamelTestSupport { Review Comment: ⚠️ **Missing test: `listBuckets` paging is untested.** This class only tests `listObjects`. The PR adds equivalent paging support to `listBuckets` (reading `CamelAwsS3ContinuationToken` and `CamelAwsS3MaxKeys` from headers, writing the response token back), but that code path has no test. `AWS2S3ProducerHttpResponseCodeTest.listBucketsShouldSetHttpResponseCode()` now stubs `listBuckets(any(ListBucketsRequest.class))` — that only exercises the method signature change, not the paging logic (token read/set, header removal on last page, `maxBuckets` passed through). A Mockito-based unit test for the new `listBuckets` behaviour should be added, covering at least: - Continuation token is passed to the SDK request when the header is present - `CamelAwsS3ContinuationToken` is set on the response message when the SDK response carries a next token - `CamelAwsS3ContinuationToken` is **removed** from the response message on the last page - `CamelAwsS3MaxKeys` controls the `maxBuckets()` field of the request `FakeS3Server` only handles path-style requests for a single bucket, so a Mockito mock of `S3Client` is the right fit here (same style as `AWS2S3ProducerHttpResponseCodeTest`). ########## components/camel-aws/camel-aws2-s3/src/main/docs/aws2-s3-producer-operations.adoc: ########## @@ -186,6 +187,29 @@ and the key from the `keyName` option, unless the `CamelAwsS3Key` header is set. This section covers operations that require special configuration beyond the common pattern. +[[listPaging]] +=== Paging listObjects and listBuckets + +Amazon S3 answers `listObjects` and `listBuckets` one page at a time, at most 1000 entries per page. Set +`CamelAwsS3MaxKeys` to ask for a smaller page. When more entries follow, the producer sets +`CamelAwsS3IsTruncated` to `true` and `CamelAwsS3ContinuationToken` to the token of the next page; send that token +back in `CamelAwsS3ContinuationToken` to read on. On the last page the producer sets `CamelAwsS3IsTruncated` to +`false` and **removes** `CamelAwsS3ContinuationToken`, so a route that loops while the header is present stops by +itself. + +[source,java] +---- +from("direct:listAll") + .loopDoWhile(header(AWS2S3Constants.CONTINUATION_TOKEN).isNotNull().or(exchangeProperty("firstPass").isNull())) Review Comment: 💡 **Doc example: missing import for `AWS2S3Constants`.** Every other Java example in this file uses string literals (`"CamelAwsS3Key"`, etc.). This is the only snippet that references `AWS2S3Constants.CONTINUATION_TOKEN` — which won't compile as written without an import statement that the doc block doesn't include. Either add an import comment above the snippet: ```suggestion .loopDoWhile(header("CamelAwsS3ContinuationToken").isNotNull().or(exchangeProperty("firstPass").isNull())) ``` …or add an import line before `from(...)`: ``` import static org.apache.camel.component.aws2.s3.AWS2S3Constants.CONTINUATION_TOKEN; ``` Using the string literal keeps the snippet consistent with the rest of the file and immediately legible without knowing the class name. -- 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]
