-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Conversation
tests/base/pom.xml
Outdated
<profiles> | ||
<profile> | ||
<id>mixed-cluster</id> | ||
<activation> | ||
<activeByDefault>false</activeByDefault> | ||
</activation> | ||
<properties> | ||
<kc.test.server>cluster</kc.test.server> | ||
</properties> | ||
</profile> | ||
</profiles> | ||
|
There was a problem hiding this comment.
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?
<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.
There was a problem hiding this comment.
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
tests/base/pom.xml
Outdated
<dependency> | ||
<groupId>org.keycloak.testframework</groupId> | ||
<artifactId>keycloak-test-framework-clustering</artifactId> | ||
<version>999.0.0-SNAPSHOT</version> | ||
</dependency> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
if (!(server instanceof ClusteredKeycloakServer)) { | ||
throw new IllegalStateException("Load balancer can only be used with ClusteredKeycloakServer"); | ||
} | ||
|
||
return new LoadBalancer((ClusteredKeycloakServer) server); |
There was a problem hiding this comment.
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):
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"); | |
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@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? |
@mhajas feel free to squash it first. Thanks! |
Closes keycloak#39962 Signed-off-by: Michal Hajas <mhajas@redhat.com>
4e34c08
to
8cc782a
Compare
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 |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
quarkus/tests/junit5/src/main/java/org/keycloak/it/utils/DockerKeycloakDistribution.java
Show resolved
Hide resolved
Signed-off-by: Michal Hajas <mhajas@redhat.com>
@Pepo48 Thank you for the review. I addressed your comments except the one in |
Signed-off-by: Michal Hajas <mhajas@redhat.com>
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.