gnodet-bot commented on code in PR #30533:
URL: https://github.com/apache/camel/pull/30533#discussion_r4649553462


##########
components/camel-consul/src/test/java/org/apache/camel/component/consul/ConsulProducerReceivedKeyTest.java:
##########
@@ -0,0 +1,192 @@
+/*
+ * 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.consul;
+
+import java.math.BigInteger;
+import java.util.Base64;
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.camel.BindToRegistry;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+import org.kiwiproject.consul.Consul;
+import org.kiwiproject.consul.EventClient;
+import org.kiwiproject.consul.KeyValueClient;
+import org.kiwiproject.consul.async.ConsulResponseCallback;
+import org.kiwiproject.consul.async.EventResponseCallback;
+import org.kiwiproject.consul.model.ConsulResponse;
+import org.kiwiproject.consul.model.EventResponse;
+import org.kiwiproject.consul.model.ImmutableEventResponse;
+import org.kiwiproject.consul.model.event.ImmutableEvent;
+import org.kiwiproject.consul.model.kv.ImmutableValue;
+import org.kiwiproject.consul.model.kv.Value;
+import org.kiwiproject.consul.option.EventOptions;
+import org.kiwiproject.consul.option.PutOptions;
+import org.kiwiproject.consul.option.QueryOptions;
+
+import static org.awaitility.Awaitility.await;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * The key/value and event consumers set the CamelConsulKey header to the key 
they received. A producer with a key of
+ * its own must act on that key, not on the key the message came from, unless 
the route chose another key.
+ */
+class ConsulProducerReceivedKeyTest extends CamelTestSupport {
+
+    private final KeyValueClient keyValueClient = mock(KeyValueClient.class);
+    private final EventClient eventClient = mock(EventClient.class);
+    private final List<ConsulResponseCallback<Optional<Value>>> valueQueries = 
new CopyOnWriteArrayList<>();
+    private final List<ConsulResponseCallback<List<Value>>> valuesQueries = 
new CopyOnWriteArrayList<>();
+    private final List<EventResponseCallback> eventQueries = new 
CopyOnWriteArrayList<>();
+
+    @BindToRegistry("consul")
+    public Consul consul() {
+        Consul consul = mock(Consul.class);
+        when(consul.keyValueClient()).thenReturn(keyValueClient);
+        when(consul.eventClient()).thenReturn(eventClient);
+        // the blocking queries of the consumers stay pending until the test 
answers them
+        doAnswer(inv -> 
valueQueries.add(inv.getArgument(2))).when(keyValueClient)
+                .getValue(anyString(), any(QueryOptions.class), any());
+        doAnswer(inv -> 
valuesQueries.add(inv.getArgument(2))).when(keyValueClient)
+                .getValues(anyString(), any(QueryOptions.class), any());
+        doAnswer(inv -> eventQueries.add(inv.getArgument(2))).when(eventClient)
+                .listEvents(anyString(), any(QueryOptions.class), 
any(EventResponseCallback.class));
+        return consul;
+    }
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    void putWritesTheKeyOfTheEndpoint() throws Exception {
+        
route("consul:kv?key=camel/source&valueAsString=true&blockSeconds=1&consulClient=#consul",
+                "consul:kv?key=camel/target&action=PUT&consulClient=#consul");
+
+        await().until(() -> !valueQueries.isEmpty());

Review Comment:
   All 5 `await()` calls in this test lack `atMost(...)`. Add an explicit 
timeout to match Camel convention and ensure CI failures surface as a 
`ConditionTimeoutException` rather than a silent stall:
   ```suggestion
           await().atMost(5, TimeUnit.SECONDS).until(() -> 
!valueQueries.isEmpty());
   ```
   (Lines 93, 105, 117, 130, and 149.)



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