+
Skip to content

Add clustering tests to new test framework #40283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 13, 2025

Conversation

mhajas
Copy link
Contributor

@mhajas mhajas commented Jun 5, 2025

Closes #39962

This is a replacement PR for #40127

I am sorry for confusion, I didn't realize I won't be able to push to that PR if I open it from Pedro's fork.

@mhajas
Copy link
Contributor Author

mhajas commented Jun 5, 2025

This Pr addresses all comments from @stianst in #40127

Comment on lines 139 to 150
<profiles>
<profile>
<id>mixed-cluster</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<kc.test.server>cluster</kc.test.server>
</properties>
</profile>
</profiles>

Copy link
Contributor

@stianst stianst Jun 6, 2025

Choose a reason for hiding this comment

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

Guessing this is a left-over from when the tests where in tests/base and can be removed now?

Suggested change
<profiles>
<profile>
<id>mixed-cluster</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<kc.test.server>cluster</kc.test.server>
</properties>
</profile>
</profiles>

If it's intentional and you want to be able to run the regular tests with a mixed cluster that would probably require the clustering to support a reverse-proxy, and you'd just run it with:

KC_TEST_SERVER=cluster mvn test

One of the main aims of the new testsuite is to don't have a ton of Maven profiles for things, but just use env variables instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was not intentional. Pedro added it during POC and I missed this was there

Comment on lines 91 to 95
<dependency>
<groupId>org.keycloak.testframework</groupId>
<artifactId>keycloak-test-framework-clustering</artifactId>
<version>999.0.0-SNAPSHOT</version>
</dependency>
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you intend to add this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I completely missed this file during cleanup


protected JdbcDatabaseContainer<?> container;

public AbstractContainerTestDatabase() {
reuse = Config.getValueTypeConfig(TestDatabase.class, "reuse", false, Boolean.class);
internal = Config.getValueTypeConfig(TestDatabase.class, "internal", false, Boolean.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd do this automatically somehow rather than require configuring it. Maybe add getJdbcUrl(boolean remote) or something then update the KeycloakServer to fetch the right one depending on running in container or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I used Config.getSelectedSupplier(KeycloakServer.class) and then used internal it when cluster is used. See https://github.com/keycloak/keycloak/pull/40283/files#diff-b2bf46ba37f5aa78f7d9a5943737f8dc80fda02931bf7714aa9846145d2920daR42-R52

I was thinking about adding it as a method on AbstractKeycloakServerSupplier so each KeycloakServer supplier can configure whether it runs in container or not. But I needed to add a new method to Registry that can provide Supplier instances for given class. It then looked something like this:

        Supplier<KeycloakServer, ?> kcSupplier = instanceContext.getRegistry().findSupplierByType(KeycloakServer.class);
        TestDatabase database = instanceContext.getValue();

        // If both KeycloakServer and TestDatabase run in container, we need to configure Keycloak with internal
        // url that is accessible within docker network
        if (database instanceof AbstractContainerTestDatabase containerDatabase
            && kcSupplier instanceof AbstractKeycloakServerSupplier abstractKcSupplier
            && abstractKcSupplier.runsInContainer()
                ) {
            return serverConfig.options(containerDatabase.serverConfig(true));
        }

        return serverConfig.options(database.serverConfig());

Let me know what you prefer. To me it seems this second approach is complicating it too much.

Comment on lines 16 to 20
if (!(server instanceof ClusteredKeycloakServer)) {
throw new IllegalStateException("Load balancer can only be used with ClusteredKeycloakServer");
}

return new LoadBalancer((ClusteredKeycloakServer) server);
Copy link
Contributor

@stianst stianst Jun 6, 2025

Choose a reason for hiding this comment

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

Nitpick, but I like this approach (disclaimer: suggestion written in GitHub UI, so may not compile):

Suggested change
if (!(server instanceof ClusteredKeycloakServer)) {
throw new IllegalStateException("Load balancer can only be used with ClusteredKeycloakServer");
}
return new LoadBalancer((ClusteredKeycloakServer) server);
if (server instanceof ClusteredKeycloakServer clusteredServer) {
return new LoadBalancer(clusteredServer);
} else {
throw new IllegalStateException("Load balancer can only be used with ClusteredKeycloakServer");
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't reviewed changes to this file, perhaps ping someone from the @keycloak/cloud-native team to take a look?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I will make sure we have review from them before merging.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Pepo48, there are some failures in CI related to changes in DockerKeycloakDistribution we will look into it.

@mhajas
Copy link
Contributor Author

mhajas commented Jun 10, 2025

@Pepo48 I believe this PR is ready for review. The failed windows tests should not be related to this PR.

I would like to squash commits and make it ready for review. Do you prefer to review the changes now with commits history or I can do it now?

@Pepo48
Copy link
Contributor

Pepo48 commented Jun 11, 2025

@mhajas feel free to squash it first. Thanks!

Closes keycloak#39962
Signed-off-by: Michal Hajas <mhajas@redhat.com>
@mhajas mhajas force-pushed the fork/pruivo/t_mix_cluster branch from 4e34c08 to 8cc782a Compare June 11, 2025 14:35
@mhajas mhajas marked this pull request as ready for review June 11, 2025 14:37
@mhajas mhajas requested review from a team as code owners June 11, 2025 14:37
@mhajas
Copy link
Contributor Author

mhajas commented Jun 11, 2025

Thanks @Pepo48! I rebased, squashed and CI is now green.

Just to make sure, we don't need a review for the test-framework changes from you. We need a cloud-native eye on the DockerKeycloakDistribution changes

Pepo48
Pepo48 previously approved these changes Jun 12, 2025
Copy link
Contributor

@Pepo48 Pepo48 left a comment

Choose a reason for hiding this comment

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

thanks @mhajas for the improvements. I found nothing that would block the PR in it's current stated.

I suggested somewhat cosmetic NPE checks to add, but I'll leave it up to your consideration.

During the review I spotted two unrelated issues to the changes in this PR (and indeed cosmetic) in the class:

  • on the line no. 226 I guess we can use logical OR instead of bitwise OR
  • on the line no. 276 there is a typo in the word "schecdule"

We can either fix it right away or address it separately in a follow up.

One way or another I'm approving the PR. Thanks again!

@@ -292,4 +341,8 @@ public void clearEnv() {
this.envVars.clear();
}

public int getMappedPort(int port) {
return keycloakContainer.getMappedPort(port);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to add a null check? I can imagine a scenario, where KeycloakContainer could be null and subsequently getMappedPort could be called.

Signed-off-by: Michal Hajas <mhajas@redhat.com>
@mhajas
Copy link
Contributor Author

mhajas commented Jun 13, 2025

@Pepo48 Thank you for the review. I addressed your comments except the one in copyProvider method. Please approve if you agree with my reasoning.

Signed-off-by: Michal Hajas <mhajas@redhat.com>
@ahus1 ahus1 enabled auto-merge (squash) June 13, 2025 18:25
@ahus1 ahus1 merged commit d2f4635 into keycloak:main Jun 13, 2025
80 checks passed
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.

Create a POC of running 2 containers in the new testsuite
5 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载