This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.6.x-fixes by this push:
new 92fcb439cdc Close the previous client in the failover strategy tests
(#3656)
92fcb439cdc is described below
commit 92fcb439cdcecbfaf72a0d1c84a89f4ac0802036
Author: Freeman(Yue) Fang <[email protected]>
AuthorDate: Fri Oct 30 21:55:19 2026 -0400
Close the previous client in the failover strategy tests (#3656)
* Close the previous client in the failover strategy tests
AbstractFailoverTest.strategyTest() and strategyTestWebClient() create 20
clients from one FailoverFeature and never close them. A feature hands the
same target selector to every client it is applied to, so when the garbage
collector finalizes one of the earlier clients, AbstractClient.close()
closes
that shared selector, and with it the conduit the current client is using.
The
request in flight then fails with "IOException: shutdownNow", or the
failover
strategy moves on to another address, and CircuitBreakerFailoverTest,
FailoverTest and LoadDistributorTest fail intermittently.
Close the previous client before creating the next one, so that no client is
left for the finalizer to close.
* Close the WebClient of each failover strategy test iteration with
try-with-resources
* Close the proxy of each failover strategy test iteration with
try-with-resources
(cherry picked from commit 16c63e353df25407d228b61ad5ed126860df16ee)
(cherry picked from commit dec58c9a5aaaa90a71398985819ef77859f430b7)
---
.../jaxrs/failover/AbstractFailoverTest.java | 131 +++++++++++----------
.../jaxrs/failover/LoadDistributorTest.java | 28 +++--
2 files changed, 87 insertions(+), 72 deletions(-)
diff --git
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
index 5a433bf36e8..bcea185cf80 100644
---
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
+++
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/AbstractFailoverTest.java
@@ -233,44 +233,51 @@ public abstract class AbstractFailoverTest extends
AbstractBusClientServerTestBa
feature.getTargetSelector().close();
bookStore = getBookStore(inactiveReplica, feature);
}
- verifyStrategy(bookStore, expectRandom
- ? RandomStrategy.class
- : SequentialStrategy.class);
- Exception ex = null;
try {
- if (expectServerException) {
- bookStore.getBook("9999");
- fail("Exception expected");
+ verifyStrategy(bookStore, expectRandom
+ ? RandomStrategy.class
+ : SequentialStrategy.class);
+ Exception ex = null;
+ try {
+ if (expectServerException) {
+ bookStore.getBook("9999");
+ fail("Exception expected");
+ } else {
+ final long bookId = 123L;
+ Book book = bookStore.echoBookElementJson(new
Book("CXF", bookId));
+ assertNotNull("expected non-null response", book);
+ assertEquals("unexpected id", bookId, book.getId());
+ }
+ } catch (Exception error) {
+ if (!expectServerException) {
+ //String currEndpoint =
getCurrentEndpointAddress(bookStore);
+ //assertEquals(currEndpoint, inactiveReplica);
+ throw error;
+ }
+ ex = error;
+ }
+ String currEndpoint = getCurrentEndpointAddress(bookStore);
+ assertFalse(currEndpoint.equals(inactiveReplica));
+ if (expectRandom) {
+ assertTrue(currEndpoint.equals(activeReplica1) ||
currEndpoint.equals(activeReplica2));
} else {
- final long bookId = 123L;
- Book book = bookStore.echoBookElementJson(new Book("CXF",
bookId));
- assertNotNull("expected non-null response", book);
- assertEquals("unexpected id", bookId, book.getId());
+ assertEquals(activeReplica1, currEndpoint);
}
- } catch (Exception error) {
- if (!expectServerException) {
- //String currEndpoint =
getCurrentEndpointAddress(bookStore);
- //assertEquals(currEndpoint, inactiveReplica);
- throw error;
+ if (expectServerException) {
+ assertNotNull(ex);
+ throw ex;
}
- ex = error;
- }
- String currEndpoint = getCurrentEndpointAddress(bookStore);
- assertFalse(currEndpoint.equals(inactiveReplica));
- if (expectRandom) {
- assertTrue(currEndpoint.equals(activeReplica1) ||
currEndpoint.equals(activeReplica2));
- } else {
- assertEquals(activeReplica1, currEndpoint);
- }
- if (expectServerException) {
- assertNotNull(ex);
- throw ex;
- }
- if (!(prevEndpoint == null || currEndpoint.equals(prevEndpoint))) {
- randomized = true;
+ if (!(prevEndpoint == null ||
currEndpoint.equals(prevEndpoint))) {
+ randomized = true;
+ }
+ prevEndpoint = currEndpoint;
+ } finally {
+ // a single proxy is used by all iterations, so only a proxy
of this iteration is closed
+ if (!singleProxy) {
+ WebClient.client(bookStore).close();
+ }
}
- prevEndpoint = currEndpoint;
}
if (!singleProxy) {
assertEquals("unexpected random/sequential distribution of
failovers",
@@ -290,38 +297,42 @@ public abstract class AbstractFailoverTest extends
AbstractBusClientServerTestBa
for (int i = 0; i < 20; i++) {
feature.getTargetSelector().close();
WebClient bookStore = getWebClient(inactiveReplica, feature);
- verifyStrategy(bookStore, expectRandom
- ? RandomStrategy.class
- : SequentialStrategy.class);
- String bookId = expectServerException ? "9999" : "123";
- bookStore.path("bookstore/books").path(bookId);
- Exception ex = null;
try {
- Book book = bookStore.get(Book.class);
- assertNotNull("expected non-null response", book);
- assertEquals("unexpected id", 123L, book.getId());
- } catch (Exception error) {
- if (!expectServerException) {
- throw error;
+ verifyStrategy(bookStore, expectRandom
+ ? RandomStrategy.class
+ : SequentialStrategy.class);
+ String bookId = expectServerException ? "9999" : "123";
+ bookStore.path("bookstore/books").path(bookId);
+ Exception ex = null;
+ try {
+ Book book = bookStore.get(Book.class);
+ assertNotNull("expected non-null response", book);
+ assertEquals("unexpected id", 123L, book.getId());
+ } catch (Exception error) {
+ if (!expectServerException) {
+ throw error;
+ }
+ ex = error;
+ }
+ String currEndpoint = getCurrentEndpointAddress(bookStore);
+ assertFalse(currEndpoint.equals(inactiveReplica));
+ if (expectRandom) {
+ assertTrue(currEndpoint.equals(activeReplica1) ||
currEndpoint.equals(activeReplica2));
+ } else {
+ assertEquals(currEndpoint, activeReplica1);
+ }
+ if (expectServerException) {
+ assertNotNull(ex);
+ throw ex;
}
- ex = error;
- }
- String currEndpoint = getCurrentEndpointAddress(bookStore);
- assertFalse(currEndpoint.equals(inactiveReplica));
- if (expectRandom) {
- assertTrue(currEndpoint.equals(activeReplica1) ||
currEndpoint.equals(activeReplica2));
- } else {
- assertEquals(currEndpoint, activeReplica1);
- }
- if (expectServerException) {
- assertNotNull(ex);
- throw ex;
- }
- if (!(prevEndpoint == null || currEndpoint.equals(prevEndpoint))) {
- randomized = true;
+ if (!(prevEndpoint == null ||
currEndpoint.equals(prevEndpoint))) {
+ randomized = true;
+ }
+ prevEndpoint = currEndpoint;
+ } finally {
+ bookStore.close();
}
- prevEndpoint = currEndpoint;
}
assertEquals("unexpected random/sequential distribution of failovers",
expectRandom,
diff --git
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/LoadDistributorTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/LoadDistributorTest.java
index dbb3842ac94..9bbbfe6df59 100644
---
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/LoadDistributorTest.java
+++
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/LoadDistributorTest.java
@@ -145,18 +145,22 @@ public class LoadDistributorTest extends
AbstractBusClientServerTestBase {
int address3Count = 0;
for (int i = 0; i < 20; i++) {
BookStore bookStore = getBookStore(initialAddress, feature);
- verifyStrategy(bookStore, SequentialStrategy.class);
- String bookId = "123";
-
- Book book = bookStore.getBook(bookId);
- assertNotNull("expected non-null response", book);
- assertEquals("unexpected id", 123L, book.getId());
-
- String address = getCurrentEndpointAddress(bookStore);
- if (Server.ADDRESS2.equals(address)) {
- address2Count++;
- } else if (Server.ADDRESS3.equals(address)) {
- address3Count++;
+ try {
+ verifyStrategy(bookStore, SequentialStrategy.class);
+ String bookId = "123";
+
+ Book book = bookStore.getBook(bookId);
+ assertNotNull("expected non-null response", book);
+ assertEquals("unexpected id", 123L, book.getId());
+
+ String address = getCurrentEndpointAddress(bookStore);
+ if (Server.ADDRESS2.equals(address)) {
+ address2Count++;
+ } else if (Server.ADDRESS3.equals(address)) {
+ address3Count++;
+ }
+ } finally {
+ WebClient.client(bookStore).close();
}
}
assertEquals(10, address2Count);