This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 6a64c124014 camel-plc4x: Fixed inconsistently passing/failing unit
test (CAMEL-18861) (#9280)
6a64c124014 is described below
commit 6a64c1240145bcf2fc7be41c238847cc89c571a9
Author: Stein Overtoom <[email protected]>
AuthorDate: Wed Feb 1 12:24:45 2023 +0100
camel-plc4x: Fixed inconsistently passing/failing unit test (CAMEL-18861)
(#9280)
Co-authored-by: Stein Overtoom <[email protected]>
---
.../main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java | 5 +++++
.../java/org/apache/camel/component/plc4x/Plc4XComponentTest.java | 1 +
2 files changed, 6 insertions(+)
diff --git
a/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java
b/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java
index 1b256be69d4..1d8a51c639b 100644
---
a/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java
+++
b/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java
@@ -145,6 +145,11 @@ public class Plc4XEndpoint extends DefaultEndpoint {
LOGGER.debug("Successfully reconnected");
} else if (autoReconnect && !connection.isConnected()) {
connection.connect();
+ // If reconnection fails without Exception, reset connection
+ if (!connection.isConnected()) {
+ LOGGER.debug("No connection established after connect,
resetting connection");
+ connection = plcDriverManager.getConnection(uri);
+ }
LOGGER.debug("Successfully reconnected");
} else {
LOGGER.warn("Connection lost and auto-reconnect is turned off,
shutting down Plc4XEndpoint");
diff --git
a/components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/Plc4XComponentTest.java
b/components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/Plc4XComponentTest.java
index c923593e82e..749dd89ca20 100644
---
a/components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/Plc4XComponentTest.java
+++
b/components/camel-plc4x/src/test/java/org/apache/camel/component/plc4x/Plc4XComponentTest.java
@@ -45,6 +45,7 @@ public class Plc4XComponentTest extends CamelTestSupport {
tags.put("Test1", "%TestQuery");
Plc4XEndpoint producer =
getContext().getEndpoint("plc4x:mock:10.10.10.1/1/1", Plc4XEndpoint.class);
producer.setTags(tags);
+ producer.setAutoReconnect(true);
from("direct:plc4x")
.setBody(constant(Collections.singletonMap("test",
Collections.singletonMap("testAddress", false))))
.to("plc4x:mock:10.10.10.1/1/1")