oscerd commented on code in PR #26733:
URL: https://github.com/apache/camel/pull/26733#discussion_r4080049232


##########
components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/main/java/org/apache/camel/component/debezium/DebeziumConsumerHealthCheck.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.debezium;
+
+import java.util.Map;
+
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckResultBuilder;
+import org.apache.camel.util.URISupport;
+
+/**
+ * {@link HealthCheck} reporting the state of the embedded Debezium engine 
that backs a {@link DebeziumConsumer}.
+ * <p>
+ * The engine runs on its own thread and does not restart itself, so once it 
has stopped with an error the route no
+ * longer receives change events even though it is still started. This check 
turns the route DOWN in that case.
+ */
+public class DebeziumConsumerHealthCheck implements HealthCheck {
+
+    private final DebeziumConsumer consumer;
+    private final String id;
+    private final String sanitizedUri;
+    private boolean enabled = true;

Review Comment:
   Thanks — flagging it was worth it, but I am deliberately not taking it, for 
the reason @davsclaus set out on the `call()` thread below.
   
   `ScheduledPollConsumerHealthCheck` gets away with `initialState=DOWN` 
because `consumer.isConsumerReady()` flips after the first successful poll, so 
the check leaves `DOWN` on its own. `DebeziumConsumer` has no equivalent ready 
signal, so returning `builder.state(initialState)` on the `failure == null` 
path would pin the route `DOWN` for its whole life wherever `initialState=DOWN` 
is configured. That is a regression rather than an alignment.
   
   Real startup readiness here needs a ready flag flipped from 
`ConnectorCallback.taskStarted()`, which is a separate change from failure 
detection — happy to do it as a follow-up.
   
   On the backport: `port/camel-4.22.x` added, and the matching entry is now in 
`camel-4x-upgrade-guide-4_22.adoc` on `main`, since the per-release guides for 
every line live there.
   
   _Claude Code on behalf of oscerd_



##########
components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureTest.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.debezium;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import io.debezium.util.IoUtil;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import 
org.apache.camel.component.debezium.configuration.FileConnectorEmbeddedDebeziumConfiguration;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The embedded engine runs on its own thread and reports a failure only 
through its completion callback, so without
+ * that callback a connector that cannot start leaves the route started, 
healthy and silent.
+ */
+public class DebeziumConsumerEngineFailureTest extends CamelTestSupport {

Review Comment:
   I checked this before applying it and I think the premise is off, so I have 
left it as is — happy to flip it if you want it as a going-forward convention 
rather than an existing rule.
   
   * There is no test-visibility rule in `CLAUDE.md` — I grepped the file; the 
only hit for "visibility" is in the GitHub-star section.
   * The convention in this module points the other way: 7 of the 8 test 
classes under `camel-debezium` are `public` (`DebeziumConsumerTest`, 
`DebeziumComponentTest`, `DebeziumEndpointTest`, `DebeziumTypeConverterTest`, 
`ConnectorConfigGeneratorTest`, `ConnectorConfigFieldsFactoryTest`, 
`ConnectorConfigGeneratorUtilsTest`), with only `ConnectorConfigFieldTest` 
package-private.
   * Repo-wide it is 8646 `public class *Test` against 973 package-private.
   
   That is the same module-consistency argument you made on #26541 about JUnit 
vs AssertJ assertions, which is why I went with `public` here. If the 
preference is to move new tests to package-private, say so and I will change 
all three (class, `beforeEach`, `afterEach`) in one go — it is a one-line 
change either way.
   
   _Claude Code on behalf of oscerd_



##########
components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureTest.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.debezium;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import io.debezium.util.IoUtil;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import 
org.apache.camel.component.debezium.configuration.FileConnectorEmbeddedDebeziumConfiguration;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The embedded engine runs on its own thread and reports a failure only 
through its completion callback, so without
+ * that callback a connector that cannot start leaves the route started, 
healthy and silent.
+ */
+public class DebeziumConsumerEngineFailureTest extends CamelTestSupport {
+
+    private static final String ROUTE_ID = "debezium-failing-engine";
+    private static final Path TEST_FILE_PATH
+            = Paths.get("target/data", 
"camel-debezium-engine-failure-input.txt").toAbsolutePath();
+    private static final Path TEST_OFFSET_STORE_PATH
+            = Paths.get("target/data", 
"camel-debezium-engine-failure-offset-store.txt").toAbsolutePath();
+
+    @BeforeEach
+    public void beforeEach() throws IOException {

Review Comment:
   Same as the class-visibility thread above — not applied, with the numbers 
there. Will change it together with the class if you want package-private as 
the convention.
   
   _Claude Code on behalf of oscerd_



##########
components/camel-debezium/camel-debezium-common/camel-debezium-common-component/src/test/java/org/apache/camel/component/debezium/DebeziumConsumerEngineFailureTest.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.debezium;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import io.debezium.util.IoUtil;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import 
org.apache.camel.component.debezium.configuration.FileConnectorEmbeddedDebeziumConfiguration;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The embedded engine runs on its own thread and reports a failure only 
through its completion callback, so without
+ * that callback a connector that cannot start leaves the route started, 
healthy and silent.
+ */
+public class DebeziumConsumerEngineFailureTest extends CamelTestSupport {
+
+    private static final String ROUTE_ID = "debezium-failing-engine";
+    private static final Path TEST_FILE_PATH
+            = Paths.get("target/data", 
"camel-debezium-engine-failure-input.txt").toAbsolutePath();
+    private static final Path TEST_OFFSET_STORE_PATH
+            = Paths.get("target/data", 
"camel-debezium-engine-failure-offset-store.txt").toAbsolutePath();
+
+    @BeforeEach
+    public void beforeEach() throws IOException {
+        IoUtil.createFile(TEST_FILE_PATH);
+        // an offset store the engine cannot read, which is what a corrupted 
offset file looks like; the
+        // content must be long enough not to be mistaken for an empty store
+        Files.write(IoUtil.createFile(TEST_OFFSET_STORE_PATH).toPath(),
+                "this is not a serialized offset 
store".getBytes(StandardCharsets.UTF_8));
+    }
+
+    @AfterEach
+    public void afterEach() throws IOException {

Review Comment:
   Same as above.
   
   _Claude Code on behalf of oscerd_



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