Stabilize Infinispan container startup and client connecting to server

Closes #31972

Signed-off-by: Alexander Schwartz <aschwart@redhat.com>
This commit is contained in:
Alexander Schwartz 2024-08-07 15:22:13 +02:00 committed by Pedro Igor
parent 07a168cb14
commit 704383fc65
4 changed files with 24 additions and 36 deletions

View file

@ -38,7 +38,7 @@ public class ExternalInfinispanTest {
"start-dev",
"--features=multi-site",
"--cache=ispn",
"--cache-remote-host=localhost",
"--cache-remote-host=127.0.0.1",
"--cache-remote-username=keycloak",
"--cache-remote-password=Password1!",
"--cache-remote-tls-enabled=false",
@ -56,7 +56,7 @@ public class ExternalInfinispanTest {
"start-dev",
"--features=multi-site,remote-cache",
"--cache=ispn",
"--cache-remote-host=localhost",
"--cache-remote-host=127.0.0.1",
"--cache-remote-username=keycloak",
"--cache-remote-password=Password1!",
"--cache-remote-tls-enabled=false",

View file

@ -53,7 +53,7 @@
raw-values="true"
shared="true"
segmented="false">
<remote-server host="localhost"
<remote-server host="127.0.0.1"
port="11222"/> <!--2-->
<connection-pool max-active="16"
exhausted-action="CREATE_NEW"/>
@ -77,7 +77,7 @@
raw-values="true"
shared="true"
segmented="false">
<remote-server host="localhost"
<remote-server host="127.0.0.1"
port="11222"/>
<connection-pool max-active="16"
exhausted-action="CREATE_NEW"/>
@ -100,7 +100,7 @@
raw-values="true"
shared="true"
segmented="false">
<remote-server host="localhost"
<remote-server host="127.0.0.1"
port="11222"/>
<connection-pool max-active="16"
exhausted-action="CREATE_NEW"/>
@ -123,7 +123,7 @@
raw-values="true"
shared="true"
segmented="false">
<remote-server host="localhost"
<remote-server host="127.0.0.1"
port="11222"/>
<connection-pool max-active="16"
exhausted-action="CREATE_NEW"/>
@ -146,7 +146,7 @@
raw-values="true"
shared="true"
segmented="false">
<remote-server host="localhost"
<remote-server host="127.0.0.1"
port="11222"/>
<connection-pool max-active="16"
exhausted-action="CREATE_NEW"/>
@ -169,7 +169,7 @@
raw-values="true"
shared="true"
segmented="false">
<remote-server host="localhost"
<remote-server host="127.0.0.1"
port="11222"/>
<connection-pool max-active="16"
exhausted-action="CREATE_NEW"/>
@ -199,7 +199,7 @@
raw-values="true"
shared="true"
segmented="false">
<remote-server host="localhost"
<remote-server host="127.0.0.1"
port="11222"/>
<connection-pool max-active="16"
exhausted-action="CREATE_NEW"/>
@ -235,7 +235,7 @@
raw-values="true"
shared="true"
segmented="false">
<remote-server host="localhost"
<remote-server host="127.0.0.1"
port="11222"/>
<connection-pool max-active="16"
exhausted-action="CREATE_NEW"/>

View file

@ -53,6 +53,10 @@
<artifactId>keycloak-quarkus-dist</artifactId>
<type>zip</type>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-server-testdriver-core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>

View file

@ -17,44 +17,39 @@
package org.keycloak.it.junit5.extension;
import java.time.Duration;
import java.util.Arrays;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.configuration.ClientIntelligence;
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.commons.configuration.StringConfiguration;
import org.jboss.logging.Logger;
import org.keycloak.connections.infinispan.InfinispanConnectionProvider;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.images.PullPolicy;
public class InfinispanContainer extends GenericContainer<InfinispanContainer> {
public class InfinispanContainer extends org.infinispan.server.test.core.InfinispanContainer {
private final Logger LOG = Logger.getLogger(getClass());
public static final String PORT = System.getProperty("keycloak.externalInfinispan.port", "11222");
public static final String USERNAME = System.getProperty("keycloak.externalInfinispan.username", "keycloak");
public static final String PASSWORD = System.getProperty("keycloak.externalInfinispan.password", DatabaseContainer.DEFAULT_PASSWORD);
public static RemoteCacheManager remoteCacheManager;
private static RemoteCacheManager remoteCacheManager;
@SuppressWarnings("resource")
public InfinispanContainer() {
super(getImageName());
withEnv("USER", USERNAME);
withEnv("PASS", PASSWORD);
withNetworkMode("host");
withUser(USERNAME);
withPassword(PASSWORD);
// Keycloak expects Infinispan to run on fixed ports
getExposedPorts().forEach(i -> {
addFixedExposedPort(i, i);
});
// the images in the 'infinispan-test' repository point to tags that are frequently refreshed, therefore, always pull them
if (getImageName().startsWith("quay.io/infinispan-test")) {
withImagePullPolicy(PullPolicy.alwaysPull());
}
//order of waitingFor and withStartupTimeout matters as the latter sets the timeout for WaitStrategy set by waitingFor
waitingFor(Wait.forLogMessage(".*Infinispan Server.*started in.*", 1));
withStartupTimeout(Duration.ofMinutes(5));
}
private static String getImageName() {
@ -77,18 +72,7 @@ public class InfinispanContainer extends GenericContainer<InfinispanContainer> {
}
private void establishHotRodConnection() {
ConfigurationBuilder configBuilder = new ConfigurationBuilder()
.addServers(getHost() + ":11222")
.security()
.authentication()
.username(getUsername())
.password(getPassword())
.clientIntelligence(ClientIntelligence.BASIC);
configBuilder.statistics().enable()
.statistics().jmxEnable();
remoteCacheManager = new RemoteCacheManager(configBuilder.build());
remoteCacheManager = getRemoteCacheManager();
}
@Override