Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
7a80f58
Use native unzip for JBCS ZIP extraction to preserve symlinks
honza-kasik Jul 17, 2026
c946867
Patch ServerRoot in httpd.conf to match extraction directory
honza-kasik Jul 17, 2026
5d1541e
Comment out User/Group directives in extracted httpd.conf
honza-kasik Jul 17, 2026
b0a18ac
Comment out DocumentRoot in extracted httpd.conf
honza-kasik Jul 17, 2026
56805cb
Remove all JBCS-shipped conf.d/ configs before deploying ours
honza-kasik Jul 17, 2026
4bf0b2b
Refactor postinstall detection and simplify httpd.conf patching
honza-kasik Jul 20, 2026
b115829
Treat null-worker responses as routing failures in load distribution
honza-kasik Jul 21, 2026
11665a4
Wait for balanced load before asserting distribution ratio
honza-kasik Jul 21, 2026
bdbb2a2
Wait for balanced load in testLoadBasedRouting
honza-kasik Jul 21, 2026
dcc6b29
Increase read timeout for heap allocation request in testHeapLoadMetric
honza-kasik Jul 21, 2026
ea8f3e6
Wait for both workers to register before WebSocket failover test
honza-kasik Jul 21, 2026
d8b6a96
Wait for both workers before testing session affinity with multiple c…
honza-kasik Jul 21, 2026
eed83aa
Poll for JSESSIONID cookie in JVM route test instead of manual retry …
honza-kasik Jul 21, 2026
ffd41d8
Use balancer management API to await ws-echo context registration
honza-kasik Jul 21, 2026
4250ff3
Increase HEAVY_REQUEST timeout from 30s to 60s
honza-kasik Jul 21, 2026
1119f5e
Poll for JSESSIONID with JVM route in session affinity test
honza-kasik Jul 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,31 @@ public void testSessionAffinityWithMultipleClients(TestCluster cluster, HttpClie

String balancerUrl = cluster.getBalancer().getHttpUrl() + "/" + DEMO_APP + "/";

// Wait for both workers to register and report real load factors.
// With initial-load=0, a newly registered worker may not get a JVM route
// appended to JSESSIONID until the balancer receives a STATUS message.
httpClient.waitForWorkerRegistration(balancerUrl, 2, TestTimeouts.CLUSTER_FORMATION);

// Simulate 5 different clients with different sessions
for (int client = 1; client <= 5; client++) {
HttpResponse initialResponse = httpClient.get(balancerUrl);
String sessionCookie = initialResponse.getCookie("JSESSIONID");
String assignedWorker = extractWorkerFromSessionId(sessionCookie);
// Retry until we get a JSESSIONID with a JVM route suffix.
// Even after waitForWorkerRegistration, a transient initial-load=0
// window can produce a route-less cookie.
final int clientNum = client;
AtomicReference<String> cookieRef = new AtomicReference<>();
AtomicReference<String> workerRef = new AtomicReference<>();
await().atMost(TestTimeouts.CLUSTER_FORMATION).pollInterval(ofSeconds(1))
.untilAsserted(() -> {
HttpResponse resp = httpClient.get(balancerUrl);
String cookie = resp.getCookie("JSESSIONID");
assertThat(cookie).as("Client %d JSESSIONID must be present", clientNum).isNotNull();
String worker = extractWorkerFromSessionId(cookie);
assertThat(worker).as("Client %d JVM route must be present", clientNum).isNotEqualTo("unknown");
cookieRef.set(cookie);
workerRef.set(worker);
});
String sessionCookie = cookieRef.get();
String assignedWorker = workerRef.get();

log.info("Client {} assigned to worker: {}", client, assignedWorker);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,11 @@ public void testWebSocketFailover(TestCluster cluster, HttpClient httpClient) th

final String wsUrl = getWebSocketUrl(cluster);

// Wait for apps to register
await().atMost(TestTimeouts.CLUSTER_FORMATION).pollInterval(ofSeconds(2))
.untilAsserted(() -> {
HttpResponse resp = httpClient.get(cluster.getBalancer().getHttpUrl() + "/ws-echo/");
assertThat(resp.getStatusCode()).isEqualTo(200);
});
// Wait for both workers' ws-echo contexts to register on the balancer.
// A single HTTP 200 only confirms one worker; the WebSocket upgrade can
// be routed to the other worker whose context isn't registered yet.
cluster.getBalancer().awaitContextRegistered("worker1", "/ws-echo");
cluster.getBalancer().awaitContextRegistered("worker2", "/ws-echo");

final OkHttpClient wsClient = new OkHttpClient.Builder()
.readTimeout(10, TimeUnit.SECONDS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import static org.assertj.core.api.Assertions.assertThat;
import static org.jboss.modcluster.test.utils.WildFlyDeploymentManager.DEMO_APP;
Expand All @@ -26,46 +27,41 @@
public class LoadBalancingGroupFailoverTest {

private static final Logger log = LoggerFactory.getLogger(LoadBalancingGroupFailoverTest.class);
private static final double MIN_BALANCE_RATIO = 0.55;

@InjectSoftAssertions
private SoftAssertions softly;

/**
* Verifies that load is distributed across multiple workers by the balancer.
* Passes if both workers receive requests and the distribution ratio is at least 0.55.
* Passes if both workers receive requests and the distribution ratio is at least {@link #MIN_BALANCE_RATIO}.
*/
@Test
public void testLoadDistributionAcrossWorkers(TestCluster cluster, HttpClient httpClient) throws Exception {
cluster.startWorkers(2);

String balancerUrl = cluster.getBalancer().getHttpUrl() + "/" + DEMO_APP + "/";

// Wait for both workers to register and receive traffic.
// httpd's mod_proxy_cluster needs time to process CONFIG messages from all workers.
// Wait for both workers to register and load to stabilize.
// A newly registered worker starts with initial-load=0 and only gets a real load factor
// after the next status-interval tick (10s), so we poll until distribution is balanced.
AtomicReference<Map<String, Integer>> lastDistribution = new AtomicReference<>();
await().atMost(TestTimeouts.CLUSTER_FORMATION).pollInterval(ofSeconds(3))
.untilAsserted(() -> {
Map<String, Integer> dist = httpClient.testLoadDistribution(balancerUrl, 20);
Map<String, Integer> dist = httpClient.testLoadDistribution(balancerUrl, 100);
lastDistribution.set(dist);
assertThat(dist)
.as("Both workers should receive requests")
.containsKeys("worker1", "worker2");
int w1 = dist.getOrDefault("worker1", 0);
int w2 = dist.getOrDefault("worker2", 0);
double ratio = (double) Math.min(w1, w2) / Math.max(w1, w2);
assertThat(ratio)
.as("Load should be relatively balanced (got %s)", dist)
.isGreaterThanOrEqualTo(MIN_BALANCE_RATIO);
});

// Make 100 requests to test load balancing
// Connection reuse is disabled in testLoadDistribution for accurate distribution
Map<String, Integer> distribution = httpClient.testLoadDistribution(balancerUrl, 100);

log.info("Load distribution: {}", distribution);

// Verify relatively even distribution (within 30% of each other)
// Since connection reuse is disabled, we should get good distribution
int worker1Hits = distribution.getOrDefault("worker1", 0);
int worker2Hits = distribution.getOrDefault("worker2", 0);

double ratio = (double) Math.min(worker1Hits, worker2Hits) / Math.max(worker1Hits, worker2Hits);

softly.assertThat(ratio)
.as("Load should be relatively balanced (ratio >= 0.55)")
.isGreaterThanOrEqualTo(0.55);
log.info("Load distribution: {}", lastDistribution.get());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@

import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

import static java.time.Duration.ofSeconds;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.jboss.modcluster.test.utils.WildFlyDeploymentManager.DEMO_APP;

/**
Expand All @@ -41,6 +44,7 @@ public class LoadMetricsTest {
* The heap test also allocates 500MB directly, which would OOM a 512MB JVM.
*/
private static final String JAVA_OPTS = "-Xms64m -Xmx2g";
private static final int MAX_WORKER_PERCENT = 70;

@InjectSoftAssertions
private SoftAssertions softly;
Expand Down Expand Up @@ -332,34 +336,26 @@ public void testLoadBasedRouting(TestCluster cluster, HttpClient httpClient) thr

String balancerUrl = cluster.getBalancer().getHttpUrl() + "/" + DEMO_APP + "/";

// Wait for both workers to register and receive traffic
httpClient.waitForWorkerRegistration(balancerUrl, 2, TestTimeouts.CLUSTER_FORMATION);

// Generate traffic to observe load-based distribution
Map<String, Integer> distribution = httpClient.testLoadDistribution(balancerUrl, 100);
log.info("Load distribution with dynamic load metrics: {}", distribution);

int worker1Requests = distribution.getOrDefault("worker1", 0);
int worker2Requests = distribution.getOrDefault("worker2", 0);

// Both workers should receive requests
softly.assertThat(distribution)
.as("Both workers should receive requests via load-based routing")
.containsKeys("worker1", "worker2");

// Total should match request count
softly.assertThat(worker1Requests + worker2Requests)
.as("Total requests should match expected count")
.isEqualTo(100);

// Distribution should be relatively balanced with default built-in metrics
// (Allow up to 70/30 split as acceptable variance)
int maxRequests = Math.max(worker1Requests, worker2Requests);
softly.assertThat(maxRequests)
.as("Distribution should be relatively balanced (no worker gets >70%)")
.isLessThan(70);

log.info("Load-based routing verified: worker1={}, worker2={}", worker1Requests, worker2Requests);
// Wait for both workers to register and load to stabilize.
// A newly registered worker starts with initial-load=0 and only gets a real load factor
// after the next status-interval tick (10s), so we poll until distribution is balanced.
AtomicReference<Map<String, Integer>> lastDistribution = new AtomicReference<>();
await().atMost(TestTimeouts.CLUSTER_FORMATION).pollInterval(ofSeconds(3))
.untilAsserted(() -> {
Map<String, Integer> dist = httpClient.testLoadDistribution(balancerUrl, 100);
lastDistribution.set(dist);
assertThat(dist)
.as("Both workers should receive requests via load-based routing")
.containsKeys("worker1", "worker2");
int maxRequests = Math.max(
dist.getOrDefault("worker1", 0),
dist.getOrDefault("worker2", 0));
assertThat(maxRequests)
.as("Distribution should be relatively balanced (got %s)", dist)
.isLessThan(MAX_WORKER_PERCENT);
});

log.info("Load distribution with dynamic load metrics: {}", lastDistribution.get());
}

/**
Expand Down Expand Up @@ -416,7 +412,8 @@ public void testHeapLoadMetric(TestCluster cluster, HttpClient httpClient) throw
// Trigger memory allocation — servlet stores in static field and returns immediately
log.info("Allocating 500MB on worker1...");
String allocUrl = balancerUrl + "load/memory?megabytes=500";
HttpClient.HttpResponse allocResponse = httpClient.get(allocUrl);
HttpClient.HttpResponse allocResponse = httpClient.getWithTimeout(allocUrl,
TestTimeouts.HEAVY_REQUEST.toSeconds(), TimeUnit.SECONDS);
log.info("Allocation response (status={}): {}", allocResponse.getStatusCode(), allocResponse.getBody().trim());

softly.assertThat(allocResponse.getStatusCode())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,22 +643,25 @@ public void testJvmRouteLostJoinAtRuntime(TestCluster cluster, HttpClient httpCl
final Future<?> requestTask = executor.submit(() -> {
try {
// Initial request — establishes session on worker1.
// Retry with extended timeout: after stopping worker2 in a previous cycle,
// Infinispan state transfer may still be in progress on worker1.
HttpResponse response = null;
for (int attempt = 0; attempt < 5; attempt++) {
try {
response = httpClient.getWithTimeout(
balancerUrl, stateTransferTimeout, TimeUnit.SECONDS);
if (response.getStatusCode() == 200) break;
} catch (IOException e) {
log.warn("Cycle {} initial request attempt {}/5 failed: {}",
currentCycle, attempt + 1, e.getMessage());
if (attempt == 4) throw e;
}
}
final String cookie = response.getCookie("JSESSIONID");

// After stopping worker2 in a previous cycle, Infinispan state
// transfer may delay worker1's ability to issue a JSESSIONID
// with a JVM route. Poll until we get a valid session cookie.
final AtomicReference<HttpResponse> responseRef = new AtomicReference<>();
final AtomicReference<String> cookieRef = new AtomicReference<>();
await().atMost(TestTimeouts.STATE_TRANSFER_REQUEST)
.pollInterval(ofSeconds(2))
.untilAsserted(() -> {
HttpResponse resp = httpClient.getWithTimeout(
balancerUrl, stateTransferTimeout, TimeUnit.SECONDS);
assertThat(resp.getStatusCode()).isEqualTo(200);
String c = resp.getCookie("JSESSIONID");
assertThat(c).as("JSESSIONID cookie must be present").isNotNull();
responseRef.set(resp);
cookieRef.set(c);
});

final HttpResponse response = responseRef.get();
final String cookie = cookieRef.get();
final String sessionId = extractSessionIdOnly(cookie);
final String route = extractJvmRoute(cookie);
final String worker = response.getWorkerName();
Expand Down
16 changes: 12 additions & 4 deletions src/test/java/org/jboss/modcluster/test/utils/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ public Map<String, Integer> waitForWorkerRegistration(String url, int expectedWo
.untilAsserted(() -> {
Map<String, Integer> dist = testLoadDistribution(url, expectedWorkerCount * 5);
lastDistribution.set(dist);
assertThat(dist).hasSize(expectedWorkerCount);
assertThat(dist.keySet().stream().filter(k -> k != null).count())
.as("Expected %d distinct workers but got: %s", expectedWorkerCount, dist)
.isEqualTo(expectedWorkerCount);
});
return lastDistribution.get();
}
Expand All @@ -415,9 +417,15 @@ public Map<String, Integer> testLoadDistribution(String url, int requestCount) t
HttpResponse response = get(url, headers);
String worker = response.getWorkerName();

workerHits.merge(worker, 1, Integer::sum);
successfulRequests++;
log.debug("Request {} -> Worker: {}", i + 1, worker);
if (worker != null) {
workerHits.merge(worker, 1, Integer::sum);
successfulRequests++;
log.debug("Request {} -> Worker: {}", i + 1, worker);
} else {
failedRequests++;
log.debug("Request {} returned no worker name (status {}), routing failure",
i + 1, response.getStatusCode());
}
} catch (IOException e) {
// Handle connection failures (e.g., when worker is being stopped/unregistered)
failedRequests++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ private TestTimeouts() {
*/
public static final Duration STATE_TRANSFER_REQUEST = durationSeconds("test.timeout.state.transfer.request", 30);

/**
* HTTP read timeout for requests that trigger heavy server-side work such as
* large heap allocations. Under CI load, GC pressure during a 500MB allocation
* can stall the servlet response well beyond the default 10-second read timeout.
*/
public static final Duration HEAVY_REQUEST = durationSeconds("test.timeout.heavy.request", 60);

// -- Helpers --

private static Duration durationSeconds(String prop, int defaultSeconds) {
Expand Down
Loading
Loading