8000 migrate cluster package to new framework by edewit · Pull Request #52133 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

migrate cluster package to new framework - #52133

Open
edewit wants to merge 22 commits into
keycloak:mainfrom
edewit:issue-47809-migrate-cluster-package
Open

edewit wants to merge 22 commits into
keycloak:mainfrom
edewit:issue-47809-migrate-cluster-package

Conversation

@edewit
@edewit edewit commented Aug 27, 2026 •
Copy link
Copy Markdown
Contributor
  • Migrate cluster package to new test framework
  • fixed tests

Related issue

Closes #47809

Copilot AI balanced review requested due to automatic review settings August 27, 2026 12:17
@edewit
edewit requested review from a team as code owners August 27, 2026 12:17
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates cluster tests from the legacy Arquillian suite to the JUnit 5 test framework, adding clustered-server utilities and remote server-side tasks.

Changes:

  • Ports invalidation, failover, authentication-session, and certificate-rotation tests.
  • Adds node descriptors, clustered testing clients, provider configuration, and remote tasks.
  • Updates run-on-server class loading and dependencies.

Reviewed changes

Copilot reviewed 32 out of 32 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
testsuite/.../cluster/SessionFailoverClusterTest.java Removes legacy session failover test.
testsuite/.../cluster/PermissionTicketInvalidationClusterTest.java Removes legacy permission-ticket test.
testsuite/.../cluster/JGroupsCertificateRotationClusterTest.java Removes legacy certificate test.
testsuite/.../cluster/AuthenticationSessionFailoverClusterTest.java Removes legacy authentication failover test.
testsuite/.../cluster/AuthenticationSessionClusterTest.java Removes legacy route tests.
testsuite/.../cluster/AbstractFailoverClusterTest.java Removes Arquillian failover base.
testsuite/.../cluster/AbstractClusterTest.java Removes Arquillian cluster base.
tests/base/.../oid4vc/OID4VCIssuerEndpointTest.java Updates OAuth code construction.
tests/base/.../cluster/UserInvalidationClusterTest.java Migrates user invalidation tests.
tests/base/.../cluster/UserFederationInvalidationClusterTest.java Migrates federation invalidation tests.
tests/base/.../cluster/SessionFailoverClusterTest.java Adds JUnit 5 session failover test.
tests/base/.../cluster/RoleInvalidationClusterTest.java Migrates role invalidation tests.
tests/base/.../cluster/RealmInvalidationClusterTest.java Migrates realm invalidation tests.
tests/base/.../cluster/PermissionTicketInvalidationClusterTest.java Adds migrated permission-ticket tests.
tests/base/.../cluster/JGroupsCertificateRotationClusterTest.java Adds migrated certificate tests.
tests/base/.../cluster/GroupInvalidationClusterTest.java Migrates group invalidation tests.
tests/base/.../cluster/ContainerInfo.java Adds cluster-node descriptor.
tests/base/.../cluster/ComponentInvalidationClusterTest.java Migrates component invalidation tests.
tests/base/.../cluster/ClusterTestingClient.java Adds per-node remote-task client.
tests/base/.../cluster/ClusterCustomProvidersServerConfig.java Configures custom test providers.
tests/base/.../cluster/ClientScopeInvalidationClusterTest.java Migrates client-scope tests.
tests/base/.../cluster/ClientInvalidationClusterTest.java Migrates client invalidation tests.
tests/base/.../cluster/AuthenticationSessionFailoverClusterTest.java Adds authentication failover flow.
tests/base/.../cluster/AuthenticationSessionClusterTest.java Adds route-cookie cluster test.
tests/base/.../cluster/AbstractInvalidationClusterTestWithTestRealm.java Migrates generated-realm setup.
tests/base/.../cluster/AbstractInvalidationClusterTest.java Migrates generic invalidation flow.
tests/base/.../cluster/AbstractFailoverClusterTest.java Adds framework-based failover support.
tests/base/.../cluster/AbstractClusterTest.java Adds new cluster test foundation.
tests/base/pom.xml Adds clustering framework dependency.
test-framework/remote/.../RunOnServerSupplier.java Refines injection compatibility.
test-framework/remote-providers/.../TestClassLoader.java Adds system-class fallback.
test-framework/remote-providers/.../ClusterTestTasks.java Adds serializable cluster operations.
Suppressed comments (1)

tests/base/src/test/java/org/keycloak/tests/cluster/ComponentInvalidationClusterTest.java:193

  • Reading the admin representation only verifies persisted configuration; it never resolves TestComponentProvider on the survivor, so stale provider instances and missed component-cache invalidations now pass. Query the provider instance on each node (for example via a run-on-server task) and assert its getDetails() result.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +116 to +118
protected void killBackendNode(ContainerInfo node) {
unavailableNodes.add(node.getIndex());
backendTestingClients.remove(node.getIndex());
@michalvavrik michalvavrik left a comment •
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of Copilot findings seems legit. I decide to not comment on individual ones, could you fix the compilation and triage Copilot comments first, before I continue reviewing, please? Thanks.

Copilot AI review requested due to automatic review settings September 8, 2026 06:28
@edewit
edewit force-pushed the issue-47809-migrate-cluster-package branch from ce78a1f to 53e2119 Compare September 8, 2026 06:28
@edewit
edewit requested a review from a team as a code owner September 8, 2026 06:28
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The remote-provider module does not compile, migrated tests are not wired into cluster execution, and container restart handling can route to stale or unready nodes.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 38/38 changed files
  • Comments generated: 4
  • Review effort level: Balanced

import org.keycloak.models.KeycloakSession;
import org.keycloak.models.utils.ModelToRepresentation;
import org.keycloak.models.RealmModel;
import org.keycloak.services.managers.AuthenticationSessionManager;
Comment thread tests/base/pom.xml
Comment on lines +55 to +58
<dependency>
<groupId>org.keycloak.testframework</groupId>
<artifactId>keycloak-test-framework-clustering</artifactId>
</dependency>
Copilot AI review requested due to automatic review settings September 8, 2026 06:47
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Build configuration, container restart behavior, and weakened failover assertions currently prevent reliable execution of the migrated tests.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (5)

Previously missed (2) — in code that hasn't changed since the last review.

quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/DockerKeycloakDistribution.java:232

  • This method is used by killBackendNode, but it delegates to the existing orderly TERM shutdown path; Infinispan can transfer single-owner entries before leaving, so the failover tests no longer simulate abrupt node loss and may observe sessions surviving unexpectedly. Provide a distinct abrupt-kill operation for failure tests and reserve graceful shutdown for cleanup.
    tests/base/src/test/java/org/keycloak/tests/cluster/ClusterComponentTestTasks.java:32
  • Constructing the provider directly from the freshly loaded ComponentModel bypasses Keycloak's component-provider/factory lookup, so this assertion always sees current configuration even if provider invalidation is broken. Restore the original test semantics by resolving the component through session.getComponentProvider(...) using a provider whose instantiated state captures the component configuration.

test-framework/remote-providers/src/main/java/org/keycloak/testframework/remote/providers/runonserver/ClusterTestTasks.java:15

  • AuthenticationSessionManager is defined in keycloak-services, but test-framework/remote-providers/pom.xml does not depend on that artifact, so this new import makes the remote-providers module fail compilation. Add keycloak-services as an appropriate provided dependency or move this task to a module that already has it.
import org.keycloak.services.managers.AuthenticationSessionManager;

quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/DockerKeycloakDistribution.java:254

  • The removeContainer flag only guards the custom cleanup, while this method still calls GenericContainer.stop(), which removes the container. Consequently stopKeepContainer() recreates a container with potentially different mapped ports on restart while LoadBalancer retains cached origins; either preserve/restart the same Docker container or refresh all cached node URLs.
    private void stop(boolean removeContainer) {

tests/base/pom.xml:58

  • Adding the clustering provider makes it available but does not select it: supplier selection requires kc.test.server=cluster (as tests/clustering/src/test/resources/keycloak-test.properties:1 demonstrates). In the normal tests/base run the default server is selected, so these tests reach LoadBalancerSupplier with a non-cluster server and fail; add a dedicated cluster test execution/configuration and keep these tests out of the default server run.
        <dependency>
            <groupId>org.keycloak.testframework</groupId>
            <artifactId>keycloak-test-framework-clustering</artifactId>
        </dependency>
  • Files reviewed: 37/37 changed files
  • Comments generated: 2
  • Review effort level: Balanced

@michalvavrik michalvavrik left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think PR CI compilation failure is caused by this code changes in this PR.

Copilot AI review requested due to automatic review settings September 11, 2026 14:22
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Duplicate method signatures prevent compilation, while node restart, routing, and coordinator tests contain blocking failures.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 43/43 changed files
  • Comments generated: 5
  • Review effort level: Balanced

String routeNumber;
int portSeparator = route.indexOf('-');
if (portSeparator == -1) {
routeNumber = route.substring(route.length() - 1);
@michalvavrik
Copy link
Copy Markdown
Member

I have built this PR and I get:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  53.494 s
[INFO] Finished at: 2026-09-11T17:16:08+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.13.0:compile (default-compile) on project keycloak-test-framework-core: Compilation failure
[ERROR] /home/mvavrik/sources/keycloak/test-framework/core/src/main/java/org/keycloak/testframework/server/ReadinessProbe.java:[33,24] method waitUntilReady(java.util.function.IntFunction<java.lang.String>,int,long) is already defined in class org.keycloak.testframework.server.ReadinessProbe
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :keycloak-test-framework-core

Copilot AI review requested due to automatic review settings September 11, 2026 15:53
@edewit
edewit commented Sep 11, 2026
Copy link
Copy Markdown
Contributor Author

Fixed the compilation failure: ReadinessProbe had two waitUntilReady(IntFunction, int, long) overloads. Renamed the single-node variant to waitUntilNodeReady. Also configured cache-embedded-node-name=nodeN per cluster container, fixed Docker container restart after KILL, and tightened coordinator failover assertions.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The added OID4VC session-code helper contains unresolved symbols and prevents compilation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 43/43 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Copilot AI review requested due to automatic review settings September 14, 2026 06:52
@edewit
edewit force-pushed the issue-47809-migrate-cluster-package branch from baffea6 to ec57d1b Compare September 14, 2026 06:52
edewit added 21 commits December 4, 2026 14:55
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Fix compilation, restore failover test assertions, add real container
stop/restart support, and verify component provider invalidation on nodes.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
The deprecation check forbids adding new files under testsuite/. Inline
the cookie lookup in RequiredActionEmailVerificationTest instead.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Register the cluster package in ClusterTestSuite, update clustering CI to
run the new test framework suite, and harden node stop/restart handling for
failover scenarios.

Closes keycloak#47809

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Rename the single-node readiness probe to avoid a duplicate overload,
configure predictable node names for route-based cluster tests, restart
killed containers via Docker start, and assert cluster size only on
survivors after coordinator failure.

Closes keycloak#47809

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
The method was added during cluster migration without imports and
broke tests/base test compilation in CI.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
The cluster tests were moved to tests/base, so keeping cluster in the
legacy base-suite file makes base-suite.sh fail before Maven runs.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Drop composites and cluster entries after migrating those packages to
tests/base so base-suite.sh no longer fails before Maven runs.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Use graceful TERM shutdown when keeping containers for restart, restart
via docker restart with a longer port wait timeout, and allow cluster
rebalance time after failback.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Stopped containers were not reliably coming back with restartContainerCmd.
Fully recreate the node with the original startup arguments and wait for
cluster reunion before continuing failover tests.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Pass session.cache.owners and related properties to Keycloak containers
so session failover tests use the same replication settings as CI expects.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Use the realm app callback URI when verifying session cookies after failover,
and move ClusterComponentTestTasks to custom-providers so run-on-server can
deserialize it inside cluster containers.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Create test component providers via factory.create() like ComponentsTest,
and expose component details through ClusterTestingClient.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Fix ComponentFactory cast and JSON deserialization for component test tasks, use SIGKILL for simulated node failures, capture container IDs in cleanup to avoid restart races, restore load balancer node selection, and restore CI surefire retries for cluster tests.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
The migrated cluster test suite needs more time than the previous 35-minute limit; all tests were passing before the job was cancelled.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Clean up per-method test realms, verify session failover via SSO,
resolve component providers through the session, and fix multi-node
failback membership waits. Restore Surefire retries in the stability
clustering workflow.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Remove the invalid docker base-suite entry, rebind the load balancer after
node refresh, probe /realms/master for node readiness, use SPI node-name
options for mixed-version clusters, disable persistent sessions for owner
failover tests, and assert remaining cluster size after coordinator loss.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Volatile session caches with owners=1 are raised to 2 when there is no shared store, so the migrated test should not expect logout after node failure.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
The SPI cluster-name option is not accepted by current validation when
the stateless feature is enabled; set the first-class option instead.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
@edewit
edewit force-pushed the issue-47809-migrate-cluster-package branch from bfe230c to 512b9c1 Compare December 4, 2026 13:56
Copilot AI balanced review requested due to automatic review settings December 4, 2026 13:56
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +33 to +34
@InjectLoadBalancer
protected LoadBalancer loadBalancer;
int survivorIdx = (coordinatorIdx + 1) % getClusterSize();
assertClusterSize(getClusterSize() - 1, survivorIdx);
assertTrue(isCoordinator(survivorIdx));
assertTrue(hasRotationTask(survivorIdx));
getComponentProvider can return null for custom component SPIs during
cluster invalidation; create via the factory like ComponentsTest does.

Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 14:10
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ "' for '" + componentModel.getName() + "' (id=" + componentModel.getId()
+ ") could not be resolved");
}
return ((TestComponentProviderFactory) factory).create(session, componentModel);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate cluster package to new test framework

5 participants

0