davsclaus commented on code in PR #28075:
URL: https://github.com/apache/camel/pull/28075#discussion_r4311100721


##########
components/camel-alibaba/camel-alibaba-oss/src/test/java/org/apache/camel/component/alibaba/oss/OSSConsumerObjectThatCannotBeGotTest.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.alibaba.oss;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.aliyun.sdk.service.oss2.OSSClient;
+import com.aliyun.sdk.service.oss2.exceptions.OperationException;
+import com.aliyun.sdk.service.oss2.exceptions.ServiceException;
+import com.aliyun.sdk.service.oss2.models.DeleteObjectRequest;
+import com.aliyun.sdk.service.oss2.models.GetObjectRequest;
+import com.aliyun.sdk.service.oss2.models.GetObjectResult;
+import com.aliyun.sdk.service.oss2.models.ListObjectsV2Request;
+import com.aliyun.sdk.service.oss2.models.ListObjectsV2Result;
+import com.aliyun.sdk.service.oss2.models.ObjectSummary;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.spi.PollingConsumerPollStrategy;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+/**
+ * A listed object that cannot be got (access denied, an archived object that 
is not restored) must not stop the
+ * consumer: the other listed objects are consumed, the next page of the 
listing is read, and the poll fails only when
+ * none of the listed objects could be got. The fake bucket lists its keys in 
order, a page of maxKeys keys at a time,
+ * with the last key of a page as continuation token, and answers the get of a 
forbidden object with 403.
+ */
+class OSSConsumerObjectThatCannotBeGotTest extends CamelTestSupport {
+
+    private final Set<String> objects = new ConcurrentSkipListSet<>();
+    private final Set<String> forbidden = ConcurrentHashMap.newKeySet();
+    private final AtomicInteger failedPolls = new AtomicInteger();
+    private final List<String> handled = new CopyOnWriteArrayList<>();
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.getRegistry().bind("ossClient", ossClient());
+        context.getRegistry().bind("countPolls", new 
PollingConsumerPollStrategy() {
+            @Override
+            public boolean begin(Consumer consumer, Endpoint endpoint) {
+                return true;
+            }
+
+            @Override
+            public void commit(Consumer consumer, Endpoint endpoint, int 
polledMessages) {
+                // noop
+            }
+
+            @Override
+            public boolean rollback(Consumer consumer, Endpoint endpoint, int 
retryCounter, Exception e) {
+                failedPolls.incrementAndGet();
+                return false;
+            }
+        });
+        context.getRegistry().bind("recordErrors", new ExceptionHandler() {
+            @Override
+            public void handleException(Throwable exception) {
+                handled.add(String.valueOf(exception.getMessage()));
+            }
+
+            @Override
+            public void handleException(String message, Throwable exception) {
+                handled.add(message);
+            }
+
+            @Override
+            public void handleException(String message, Exchange exchange, 
Throwable exception) {
+                handled.add(message);
+            }
+        });
+        return context;
+    }
+
+    @Test
+    void objectThatCannotBeGotDoesNotBlockTheOtherObjects() throws Exception {
+        objects.add("a.txt");
+        objects.add("b.txt");
+        objects.add("c.txt");
+        forbidden.add("b.txt");
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceivedInAnyOrder("a.txt", "c.txt");
+
+        
addConsumerRoute("&deleteAfterRead=true&exceptionHandler=#recordErrors");
+
+        mock.assertIsSatisfied();
+        assertThat(objects).as("a.txt and c.txt are consumed and deleted, 
b.txt stays").containsExactly("b.txt");

Review Comment:
   With `deleteAfterRead=true` the object is deleted when the exchange 
completes, after it reached `mock:result`, so `assertIsSatisfied()` can return 
before the last object is deleted. This passed in CI, but the same test in the 
OBS PR (#28076) failed on exactly this race. Waiting for the bucket closes it:
   
   ```suggestion
           await().atMost(20, TimeUnit.SECONDS).untilAsserted(
                   () -> assertThat(objects).as("a.txt and c.txt are consumed 
and deleted, b.txt stays").containsExactly("b.txt"));
   ```



##########
components/camel-alibaba/camel-alibaba-oss/src/test/java/org/apache/camel/component/alibaba/oss/OSSConsumerObjectThatCannotBeGotTest.java:
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.alibaba.oss;
+
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import com.aliyun.sdk.service.oss2.OSSClient;
+import com.aliyun.sdk.service.oss2.exceptions.OperationException;
+import com.aliyun.sdk.service.oss2.exceptions.ServiceException;
+import com.aliyun.sdk.service.oss2.models.DeleteObjectRequest;
+import com.aliyun.sdk.service.oss2.models.GetObjectRequest;
+import com.aliyun.sdk.service.oss2.models.GetObjectResult;
+import com.aliyun.sdk.service.oss2.models.ListObjectsV2Request;
+import com.aliyun.sdk.service.oss2.models.ListObjectsV2Result;
+import com.aliyun.sdk.service.oss2.models.ObjectSummary;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.spi.PollingConsumerPollStrategy;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+/**
+ * A listed object that cannot be got (access denied, an archived object that 
is not restored) must not stop the
+ * consumer: the other listed objects are consumed, the next page of the 
listing is read, and the poll fails only when
+ * none of the listed objects could be got. The fake bucket lists its keys in 
order, a page of maxKeys keys at a time,
+ * with the last key of a page as continuation token, and answers the get of a 
forbidden object with 403.
+ */
+class OSSConsumerObjectThatCannotBeGotTest extends CamelTestSupport {
+
+    private final Set<String> objects = new ConcurrentSkipListSet<>();
+    private final Set<String> forbidden = ConcurrentHashMap.newKeySet();
+    private final AtomicInteger failedPolls = new AtomicInteger();
+    private final List<String> handled = new CopyOnWriteArrayList<>();
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        context.getRegistry().bind("ossClient", ossClient());
+        context.getRegistry().bind("countPolls", new 
PollingConsumerPollStrategy() {
+            @Override
+            public boolean begin(Consumer consumer, Endpoint endpoint) {
+                return true;
+            }
+
+            @Override
+            public void commit(Consumer consumer, Endpoint endpoint, int 
polledMessages) {
+                // noop
+            }
+
+            @Override
+            public boolean rollback(Consumer consumer, Endpoint endpoint, int 
retryCounter, Exception e) {
+                failedPolls.incrementAndGet();
+                return false;
+            }
+        });
+        context.getRegistry().bind("recordErrors", new ExceptionHandler() {
+            @Override
+            public void handleException(Throwable exception) {
+                handled.add(String.valueOf(exception.getMessage()));
+            }
+
+            @Override
+            public void handleException(String message, Throwable exception) {
+                handled.add(message);
+            }
+
+            @Override
+            public void handleException(String message, Exchange exchange, 
Throwable exception) {
+                handled.add(message);
+            }
+        });
+        return context;
+    }
+
+    @Test
+    void objectThatCannotBeGotDoesNotBlockTheOtherObjects() throws Exception {
+        objects.add("a.txt");
+        objects.add("b.txt");
+        objects.add("c.txt");
+        forbidden.add("b.txt");
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceivedInAnyOrder("a.txt", "c.txt");
+
+        
addConsumerRoute("&deleteAfterRead=true&exceptionHandler=#recordErrors");
+
+        mock.assertIsSatisfied();
+        assertThat(objects).as("a.txt and c.txt are consumed and deleted, 
b.txt stays").containsExactly("b.txt");
+        await().atMost(20, TimeUnit.SECONDS).untilAsserted(
+                () -> assertThat(handled).as("the skipped object is 
reported").anyMatch(m -> m.contains("b.txt")));
+    }
+
+    @Test
+    void pageOfObjectsThatCannotBeGotDoesNotBlockTheNextPage() throws 
Exception {
+        objects.add("a.txt");
+        objects.add("b.txt");
+        objects.add("c.txt");
+        forbidden.add("a.txt");
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceivedInAnyOrder("b.txt", "c.txt");
+
+        // one object per page: the first page holds only a.txt
+        
addConsumerRoute("&deleteAfterRead=true&maxMessagesPerPoll=1&pollStrategy=#countPolls");
+
+        mock.assertIsSatisfied();
+        assertThat(objects).as("b.txt and c.txt are consumed and deleted, 
a.txt stays").containsExactly("a.txt");

Review Comment:
   Same race as above.
   
   ```suggestion
           await().atMost(20, TimeUnit.SECONDS).untilAsserted(
                   () -> assertThat(objects).as("b.txt and c.txt are consumed 
and deleted, a.txt stays").containsExactly("a.txt"));
   ```



-- 
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]

Reply via email to