You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by hu...@apache.org on 2023/02/11 06:26:14 UTC
[plc4x] branch fix/conection-cache-test created (now 5caac51b11)
This is an automated email from the ASF dual-hosted git repository.
hutcheb pushed a change to branch fix/conection-cache-test
in repository https://gitbox.apache.org/repos/asf/plc4x.git
at 5caac51b11 fix(plc4j/connection-cache): fix issue with timing of thread during double connection test.
This branch includes the following new commits:
new 5caac51b11 fix(plc4j/connection-cache): fix issue with timing of thread during double connection test.
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[plc4x] 01/01: fix(plc4j/connection-cache): fix issue with timing of thread during double connection test.
Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
hutcheb pushed a commit to branch fix/conection-cache-test
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 5caac51b116b95450871dce00f018be412250e64
Author: Ben Hutcheson <be...@gmail.com>
AuthorDate: Sat Feb 11 07:22:41 2023 +0100
fix(plc4j/connection-cache): fix issue with timing of thread during double connection test.
---
.../plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/plc4j/tools/connection-cache/src/test/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java b/plc4j/tools/connection-cache/src/test/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java
index d638195bad..e8fc53a3e0 100644
--- a/plc4j/tools/connection-cache/src/test/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java
+++ b/plc4j/tools/connection-cache/src/test/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManagerTest.java
@@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.time.Duration;
+import java.util.concurrent.CountDownLatch;
public class CachedPlcConnectionManagerTest {
@@ -121,20 +122,21 @@ public class CachedPlcConnectionManagerTest {
// Create a connectionManager with a maximum wait time of 50ms
PlcConnectionManager mockConnectionManager = Mockito.mock(PlcConnectionManager.class);
CachedPlcConnectionManager connectionManager = CachedPlcConnectionManager.getBuilder(mockConnectionManager).withMaxWaitTime(Duration.ofMillis(50)).build();
+ CountDownLatch startSignal = new CountDownLatch(1);
// Get the connection for the first time.
(new Thread(() -> {
- try (PlcConnection connection = connectionManager.getConnection("test")) {
+ try {
+ PlcConnection connection = connectionManager.getConnection("test");
+ startSignal.countDown();
Assertions.assertInstanceOf(LeasedPlcConnection.class, connection);
- // Sleep for a second.
- Thread.sleep(100L);
} catch (Exception e) {
Assertions.fail("Not expecting an exception here", e);
}
})).start();
// This is needed as starting the previous thread seems to take a little-bit of time.
- Thread.sleep(10L);
+ startSignal.await();
// Get the same connection a second time.
try (PlcConnection ignored = connectionManager.getConnection("test")) {