Keycloak Testcontainer fails due Timed out waiting for URL to be accessible (http://localhost:55127/auth should return HTTP 200)
I am using Mariadb and Keycloak test containers for integration test , however , mariadb container starts , but Keycloak container fails to start . I am using MacBook Pro M1 and jAVA 11
Code
public abstract class IntegrationTest {
public static KeycloakContainer keycloakContainer = new KeycloakContainer("jboss/keycloak:15.0.2")
.withRealmImportFile("/test_realm.json");
@Autowired
public TransactionService transactionService;
@Autowired
public PaymentService paymentService;
ObjectMapper mapper = new ObjectMapper()
.registerModule(new JavaTimeModule());;
@LocalServerPort
static int port = 8088;
protected static String authToken;
@BeforeAll
public static void setUp() {
RestAssured.port = port;
RestAssured.baseURI = "http://localhost/";
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
assertTrue(keycloakContainer.isRunning());
String authServer = keycloakContainer.getAuthServerUrl();
System.out.println("authServer: " + authServer);
authToken = getAccessToken();
System.out.println("authToken: " + authToken);
}
@DynamicPropertySource
static void dynamicPropertySource(DynamicPropertyRegistry dynamicPropertyRegistry) {
MariaDBContainer<?> container = new MariaDBContainer<>("mariadb:10.6.4-focal")
.withDatabaseName("test")
.withUsername("test")
.withPassword("test");
dynamicPropertyRegistry.add("spring.datasource.url", container::getJdbcUrl);
dynamicPropertyRegistry.add("spring.datasource.username", container::getUsername);
dynamicPropertyRegistry.add("spring.datasource.password", container::getPassword);
dynamicPropertyRegistry.add("spring.datasource.driver-class", () -> "org.mariadb.jdbc.Driver");
dynamicPropertyRegistry.add("spring.jpa.database-platform", () -> "org.hibernate.dialect.MariaDBDialect");
dynamicPropertyRegistry.add("keycloak.auth-server-url", keycloakContainer::getAuthServerUrl);
container.start();
keycloakContainer.start();
System.out.println("Containers should be started.");
}
}
IDE logs :
Found Docker environment with local Unix socket (unix:///var/run/docker.sock) Docker host IP address is localhost Connected to docker: Server Version: 20.10.10 API Version: 1.41 Operating System: Docker Desktop Total Memory: 1988 MB Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor') Ryuk started - will monitor and terminate Testcontainers containers on JVM exit Checking the system... ✔︎ Docker server version should be at least 1.6.0 ✔︎ Docker environment should have more than 2GB free disk space Creating container for image: mariadb:10.6.4-focal Starting container with ID: 4cb0ba7707f5cee202ae19aa177b7f2b7dbe5de93664263869935742e45c9f99 Container mariadb:10.6.4-focal is starting: 4cb0ba7707f5cee202ae19aa177b7f2b7dbe5de93664263869935742e45c9f99 Waiting for database connection to become available at jdbc:mariadb://localhost:55129/sympl using query 'SELECT 1' Container is started (JDBC URL: jdbc:mariadb://localhost:55129/sympl) Container mariadb:10.6.4-focal started in PT5.679875S Creating container for image: jboss/keycloak:15.0.2 Starting container with ID: 8c8792df10e2da254dd7fe200feeff4a2b756b989aec51897f6a6faca21a7403 Container jboss/keycloak:15.0.2 is starting: 8c8792df10e2da254dd7fe200feeff4a2b756b989aec51897f6a6faca21a7403 /festive_bhabha: Waiting for 120 seconds for URL: http://localhost:55131/auth (where port 55131 maps to container port 8080)
after that it tries to reconnect again and fails after the timeout finish .
Container logs from docker :
Added 'admin' to '/opt/jboss/keycloak/standalone/configuration/keycloak-add-user.json', restart server to load user
Using Embedded H2 database
=========================================================================
=========================================================================
JBoss Bootstrap Environment
JBOSS_HOME: /opt/jboss/keycloak
JAVA: java
JAVA_OPTS: -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED
=========================================================================
05:28:07,243 INFO [org.jboss.modules] (main) JBoss Modules version 1.11.0.Final 05:28:09,744 INFO [org.jboss.msc] (main) JBoss MSC version 1.4.12.Final 05:28:09,890 INFO [org.jboss.threads] (main) JBoss Threads version 2.4.0.Final 05:28:10,814 INFO [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: Keycloak 15.0.2 (WildFly Core 15.0.1.Final) starting 05:28:11,475 INFO [org.jboss.vfs] (MSC service thread 1-4) VFS000002: Failed to clean existing content for temp file provider of type temp. Enable DEBUG level log to find what caused this 05:28:14,209 INFO [org.wildfly.security] (ServerService Thread Pool -- 20) ELY00001: WildFly Elytron version 1.15.3.Final 05:28:15,640 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 11) WFLYCTL0033: Extension 'security' is deprecated and may not be supported in future versions 05:28:16,882 INFO [org.jboss.as.controller.management-deprecated] (Controller Boot Thread) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/core-service=management/management-interface=http-interface' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation. 05:28:17,062 INFO [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 23) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/subsystem=undertow/server=default-server/https-listener=https' is deprecated, and may be removed in a future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation. 05:28:18,155 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http) 05:28:18,290 INFO [org.xnio] (MSC service thread 1-2) XNIO version 3.8.4.Final 05:28:18,332 INFO [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.8.4.Final 05:28:18,589 INFO [org.wildfly.extension.health] (ServerService Thread Pool -- 36) WFLYHEALTH0001: Activating Base Health Subsystem 05:28:18,664 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 37) WFLYCLINF0001: Activating Infinispan subsystem. 05:28:18,689 INFO [org.jboss.as.security] (ServerService Thread Pool -- 49) WFLYSEC0002: Activating Security Subsystem 05:28:18,690 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 46) WFLYNAM0001: Activating Naming Subsystem 05:28:18,666 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 51) WFLYTX0013: The node-identifier attribute on the /subsystem=transactions is set to the default value. This is a danger for environments running multiple servers. Please make sure the attribute value is unique. 05:28:18,717 INFO [org.jboss.as.security] (MSC service thread 1-4) WFLYSEC0001: Current PicketBox version=5.0.3.Final-redhat-00007 05:28:18,816 INFO [org.wildfly.extension.metrics] (ServerService Thread Pool -- 45) WFLYMETRICS0001: Activating Base Metrics Subsystem 05:28:18,826 INFO [org.jboss.as.connector] (MSC service thread 1-5) WFLYJCA0009: Starting Jakarta Connectors Subsystem (WildFly/IronJacamar 1.4.27.Final) 05:28:18,790 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 38) WFLYIO001: Worker 'default' has auto-configured to 8 IO threads with 64 max task threads based on your 4 available processors 05:28:18,887 INFO [org.jboss.remoting] (MSC service thread 1-6) JBoss Remoting version 5.0.20.Final 05:28:19,009 INFO [org.jboss.as.naming] (MSC service thread 1-1) WFLYNAM0003: Starting Naming Service 05:28:19,010 INFO [org.jboss.as.mail.extension] (MSC service thread 1-3) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default] 05:28:19,357 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0003: Undertow 2.2.5.Final starting 05:28:19,342 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 31) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4) 05:28:19,398 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) WFLYJCA0018: Started Driver service with driver-name = h2 05:28:19,477 INFO [org.jboss.as.jaxrs] (ServerService Thread Pool -- 39) WFLYRS0016: RESTEasy version 3.15.1.Final 05:28:19,667 WARN [org.wildfly.clustering.web.undertow] (ServerService Thread Pool -- 52) WFLYCLWEBUT0007: No routing provider found for default-server; using legacy provider based on static configuration 05:28:20,323 INFO [org.jboss.as.ejb3] (MSC service thread 1-8) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 64 (per class), which is derived from thread worker pool sizing. 05:28:20,323 INFO [org.jboss.as.ejb3] (MSC service thread 1-5) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 16 (per class), which is derived from the number of CPUs on this host. 05:28:20,527 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 52) WFLYUT0014: Creating file handler for path '/opt/jboss/keycloak/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]'] 05:28:20,604 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0012: Started server default-server. 05:28:20,615 WARN [org.wildfly.extension.elytron] (MSC service thread 1-1) WFLYELY00023: KeyStore file '/opt/jboss/keycloak/standalone/configuration/application.keystore' does not exist. Used blank. 05:28:20,648 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) Queuing requests. 05:28:20,651 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0018: Host default-host starting 05:28:20,669 WARN [org.wildfly.extension.elytron] (MSC service thread 1-1) WFLYELY01084: KeyStore /opt/jboss/keycloak/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self-signed certificate for host localhost WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.wildfly.extension.elytron.SSLDefinitions (jar:file:/opt/jboss/keycloak/modules/system/layers/base/org/wildfly/extension/elytron/main/wildfly-elytron-integration-15.0.1.Final.jar!/) to method com.sun.net.ssl.internal.ssl.Provider.isFIPS() WARNING: Please consider reporting this to the maintainers of org.wildfly.extension.elytron.SSLDefinitions WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release 05:28:21,227 INFO [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0006: Undertow HTTP listener default listening on 0.0.0.0:8080 05:28:23,000 INFO [org.jboss.as.ejb3] (MSC service thread 1-7) WFLYEJB0493: Jakarta Enterprise Beans subsystem suspension complete 05:28:23,843 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) WFLYJCA0001: Bound data source [java:jboss/datasources/KeycloakDS] 05:28:23,843 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS] 05:28:24,110 INFO [org.jboss.as.patching] (MSC service thread 1-4) WFLYPAT0050: Keycloak cumulative patch ID is: base, one-off patches include: none 05:28:24,192 WARN [org.jboss.as.domain.management.security] (MSC service thread 1-3) WFLYDM0111: Keystore /opt/jboss/keycloak/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost 05:28:24,286 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-7) WFLYDS0013: Started FileSystemDeploymentService for directory /opt/jboss/keycloak/standalone/deployments 05:28:24,309 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0027: Starting deployment of "keycloak-server.war" (runtime-name: "keycloak-server.war") 05:28:24,494 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0006: Undertow HTTPS listener https listening on 0.0.0.0:8443 05:28:28,673 INFO [org.infinispan.CONTAINER] (ServerService Thread Pool -- 54) ISPN000128: Infinispan version: Infinispan 'Corona Extra' 11.0.9.Final 05:28:29,231 INFO [org.infinispan.CONFIG] (MSC service thread 1-7) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated. 05:28:29,250 INFO [org.infinispan.CONFIG] (MSC service thread 1-7) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated. 05:28:29,578 INFO [org.infinispan.PERSISTENCE] (ServerService Thread Pool -- 55) ISPN000556: Starting user marshaller 'org.wildfly.clustering.infinispan.marshalling.jboss.JBossMarshaller' 05:28:29,581 INFO [org.infinispan.PERSISTENCE] (ServerService Thread Pool -- 54) ISPN000556: Starting user marshaller 'org.wildfly.clustering.infinispan.spi.marshalling.InfinispanProtoStreamMarshaller' 05:28:30,523 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 54) WFLYCLINF0002: Started http-remoting-connector cache from ejb container 05:28:30,675 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 54) WFLYCLINF0002: Started offlineClientSessions cache from keycloak container 05:28:30,675 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 58) WFLYCLINF0002: Started actionTokens cache from keycloak container 05:28:30,675 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 61) WFLYCLINF0002: Started work cache from keycloak container 05:28:30,686 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 57) WFLYCLINF0002: Started sessions cache from keycloak container 05:28:30,675 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62) WFLYCLINF0002: Started authenticationSessions cache from keycloak container 05:28:30,726 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 59) WFLYCLINF0002: Started loginFailures cache from keycloak container 05:28:30,726 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 67) WFLYCLINF0002: Started clientSessions cache from keycloak container 05:28:30,726 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 66) WFLYCLINF0002: Started offlineSessions cache from keycloak container 05:28:30,953 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 63) WFLYCLINF0002: Started users cache from keycloak container 05:28:30,953 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 60) WFLYCLINF0002: Started realms cache from keycloak container 05:28:30,956 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 65) WFLYCLINF0002: Started authorization cache from keycloak container 05:28:30,959 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 64) WFLYCLINF0002: Started keys cache from keycloak container 05:28:31,726 WARN [org.jboss.as.server.deployment] (MSC service thread 1-7) WFLYSRV0273: Excluded subsystem webservices via jboss-deployment-structure.xml does not exist. 05:28:31,803 ERROR [io.undertow] (MSC service thread 1-6) UT005024: Could not register resource change listener for caching resource manager, automatic invalidation of cached resource will not work: java.lang.RuntimeException: java.io.IOException: Function not implemented at [email protected]//org.xnio.nio.WatchServiceFileSystemWatcher.(WatchServiceFileSystemWatcher.java:75) at [email protected]//org.xnio.nio.NioXnio.createFileSystemWatcher(NioXnio.java:241) at [email protected]//io.undertow.server.handlers.resource.PathResourceManager.registerResourceChangeListener(PathResourceManager.java:262) at [email protected]//org.wildfly.extension.undertow.deployment.ServletResourceManager.registerResourceChangeListener(ServletResourceManager.java:117) at [email protected]//io.undertow.server.handlers.resource.CachingResourceManager.(CachingResourceManager.java:64) at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.createServletConfig(UndertowDeploymentInfoService.java:567) at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService.start(UndertowDeploymentInfoService.java:276) at [email protected]//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739) at [email protected]//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701) at [email protected]//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559) at [email protected]//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) at [email protected]//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990) at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486) at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1363) at java.base/java.lang.Thread.run(Thread.java:829) Caused by: java.io.IOException: Function not implemented at java.base/sun.nio.fs.LinuxWatchService.(LinuxWatchService.java:64) at java.base/sun.nio.fs.LinuxFileSystem.newWatchService(LinuxFileSystem.java:47) at [email protected]//org.xnio.nio.WatchServiceFileSystemWatcher.(WatchServiceFileSystemWatcher.java:73) ... 14 more
05:28:34,143 INFO [org.keycloak.services] (ServerService Thread Pool -- 63) KC-SERVICES0001: Loading config from standalone.xml or domain.xml 05:28:34,422 WARN [org.keycloak.common.Profile] (ServerService Thread Pool -- 63) Deprecated feature enabled: upload_scripts 05:28:34,423 WARN [org.keycloak.common.Profile] (ServerService Thread Pool -- 63) Preview feature enabled: scripts 05:28:34,569 INFO [org.keycloak.url.DefaultHostnameProviderFactory] (ServerService Thread Pool -- 63) Frontend: , Admin: , Backend: 05:28:37,112 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 63) WFLYCLINF0002: Started realmRevisions cache from keycloak container 05:28:37,162 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 63) WFLYCLINF0002: Started userRevisions cache from keycloak container 05:28:37,209 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 63) WFLYCLINF0002: Started authorizationRevisions cache from keycloak container 05:28:37,214 INFO [org.keycloak.connections.infinispan.DefaultInfinispanConnectionProviderFactory] (ServerService Thread Pool -- 63) Node name: 8c8792df10e2, Site name: null
A fatal error has been detected by the Java Runtime Environment:
SIGILL (0x4) at pc=0x0000004016607605, pid=343, tid=466
JRE version: OpenJDK Runtime Environment 18.9 (11.0.12+7) (build 11.0.12+7-LTS) Java VM: OpenJDK 64-Bit Server VM 18.9 (11.0.12+7-LTS, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) Problematic frame: J 5784 c1 liquibase.exception.ValidationErrors.checkRequiredField(Ljava/lang/String;Ljava/lang/Object;)V (120 bytes) @ 0x0000004016607605 [0x00000040166075c0+0x0000000000000045]
No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
An error report file with more information is saved as: /tmp/hs_err_pid343.log Compiled method (c1) 35858 6315 2 liquibase.sqlgenerator.core.CreateSequenceGenerator::validate (169 bytes) total in heap [0x00000040166ecb90,0x00000040166ee598] = 6664 relocation [0x00000040166ecd08,0x00000040166ece38] = 304 main code [0x00000040166ece40,0x00000040166ee0a0] = 4704 stub code
[0x00000040166ee0a0,0x00000040166ee130] = 144 oops
[0x00000040166ee130,0x00000040166ee160] = 48 metadata
[0x00000040166ee160,0x00000040166ee178] = 24 scopes data
[0x00000040166ee178,0x00000040166ee2a8] = 304 scopes pcs
[0x00000040166ee2a8,0x00000040166ee528] = 640 dependencies
[0x00000040166ee528,0x00000040166ee530] = 8 nul chk table [0x00000040166ee530,0x00000040166ee598] = 104 Could not load hsdis-amd64.so; library not loadable; PrintAssembly is disabledIf you would like to submit a bug report, please visit: https://bugzilla.redhat.com/enter_bug.cgi?product=Red%20Hat%20Enterprise%20Linux%208&component=java-11-openjdk qemu: uncaught target signal 6 (Aborted) - core dumped *** JBossAS process (343) received ABRT signal ***
however, when I start the keycloack container and setExposedPort(8080)
keycloakContainer.setExposedPorts(List.of(8080));
keycloakContainer.start();
the container logs doesn't raise JVM error . here the logs are after exposing 8080 port
The jboss/keycloak
images only support linux/amd64
architectures. See the tags inside Docker Hub.
With your M1, you have an arm64
processor that's not supported by the official Keycloak images. With Apple's Rosetta 2 emulation, Apple tries best effort to make an amd64
image work, but your Keycloak container fails during startup:
A fatal error has been detected by the Java Runtime Environment: SIGILL (0x4) at pc=0x0000004016607605, pid=343, tid=466
You can use a community build that supports arm64
:
- https://github.com/richardjkendall/keycloak-arm
- https://hub.docker.com/r/mihaibob/keycloak
public static KeycloakContainer keycloakContainer =
new KeycloakContainer("mihaibob/keycloak:14.0.0")
.withRealmImportFile("/test_realm.json");
You should also be able to build your own arm64
compatible Keycloak Docker image locally.