gpt4 book ai didi

java - Keycloak Testcontainer 由于等待 URL 可访问超时而失败 (http ://localhost:55127/auth should return HTTP 200)

转载 作者:行者123 更新时间:2023-12-03 08:11:20 30 4
gpt4 key购买 nike

我正在使用Mariadb和Keycloak测试容器进行集成测试,但是,mariadb容器启动,但Keycloak容器启动失败。我使用的是 MacBook Pro M1 和 jAVA 11

代码

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 日志:

Found Docker environment with local Unix socket (unix:///var/run/docker.sock)Docker host IP address is localhostConnected to docker:Server Version: 20.10.10API Version: 1.41Operating System: Docker DesktopTotal Memory: 1988 MBImage name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')Ryuk started - will monitor and terminate Testcontainers containers on JVM exitChecking the system...✔︎ Docker server version should be at least 1.6.0✔︎ Docker environment should have more than 2GB free disk spaceCreating container for image: mariadb:10.6.4-focalStarting container with ID: 4cb0ba7707f5cee202ae19aa177b7f2b7dbe5de93664263869935742e45c9f99Container mariadb:10.6.4-focal is starting: 4cb0ba7707f5cee202ae19aa177b7f2b7dbe5de93664263869935742e45c9f99Waiting 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.679875SCreating container for image: jboss/keycloak:15.0.2Starting container with ID: 8c8792df10e2da254dd7fe200feeff4a2b756b989aec51897f6a6faca21a7403Container 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)

之后它会再次尝试重新连接,但在超时完成后失败。

来自 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 version1.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 Core15.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 fileprovider of type temp. Enable DEBUG level log to find what caused this05: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] (ServerServiceThread Pool -- 11) WFLYCTL0033: Extension 'security' is deprecated andmay not be supported in future versions 05:28:16,882 INFO[org.jboss.as.controller.management-deprecated] (Controller BootThread) WFLYCTL0028: Attribute 'security-realm' in the resource ataddress '/core-service=management/management-interface=http-interface'is deprecated, and may be removed in a future version. See theattribute description in the output of the read-resource-descriptionoperation to learn more about the deprecation. 05:28:17,062 INFO[org.jboss.as.controller.management-deprecated] (ServerService ThreadPool -- 23) WFLYCTL0028: Attribute 'security-realm' in the resource ataddress'/subsystem=undertow/server=default-server/https-listener=https' isdeprecated, and may be removed in a future version. See the attributedescription in the output of the read-resource-description operationto learn more about the deprecation. 05:28:18,155 INFO[org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creatinghttp management service using socket-binding (management-http)05:28:18,290 INFO [org.xnio] (MSC service thread 1-2) XNIO version3.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 NamingSubsystem 05:28:18,666 WARN [org.jboss.as.txn] (ServerService ThreadPool -- 51) WFLYTX0013: The node-identifier attribute on the/subsystem=transactions is set to the default value. This is a dangerfor environments running multiple servers. Please make sure theattribute value is unique. 05:28:18,717 INFO [org.jboss.as.security](MSC service thread 1-4) WFLYSEC0001: Current PicketBoxversion=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/IronJacamar1.4.27.Final) 05:28:18,790 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 38) WFLYIO001: Worker 'default' hasauto-configured to 8 IO threads with 64 max task threads based on your4 available processors 05:28:18,887 INFO [org.jboss.remoting] (MSCservice thread 1-6) JBoss Remoting version 5.0.20.Final 05:28:19,009INFO [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 ThreadPool -- 31) WFLYJCA0004: Deploying JDBC-compliant driver classorg.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,477INFO [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 poolslsb-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 poolmdb-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,527INFO [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) Queuingrequests. 05:28:20,651 INFO [org.wildfly.extension.undertow] (MSCservice thread 1-3) WFLYUT0018: Host default-host starting05:28:20,669 WARN [org.wildfly.extension.elytron] (MSC service thread1-1) WFLYELY01084: KeyStore/opt/jboss/keycloak/standalone/configuration/application.keystore notfound, it will be auto generated on first use with a self-signedcertificate for host localhost WARNING: An illegal reflective accessoperation has occurred WARNING: Illegal reflective access byorg.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 oforg.wildfly.extension.elytron.SSLDefinitions WARNING: Use--illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will bedenied 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,000INFO [org.jboss.as.ejb3] (MSC service thread 1-7) WFLYEJB0493:Jakarta Enterprise Beans subsystem suspension complete 05:28:23,843INFO [org.jboss.as.connector.subsystems.datasources] (MSC servicethread 1-8) WFLYJCA0001: Bound data source[java:jboss/datasources/KeycloakDS] 05:28:23,843 INFO[org.jboss.as.connector.subsystems.datasources] (MSC service thread1-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 patchesinclude: 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 notfound, it will be auto generated on first use with a self signedcertificate 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,673INFO [org.infinispan.CONTAINER] (ServerService Thread Pool -- 54)ISPN000128: Infinispan version: Infinispan 'Corona Extra' 11.0.9.Final05:28:29,231 INFO [org.infinispan.CONFIG] (MSC service thread 1-7)ISPN000152: Passivation configured without an eviction policy beingselected. 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 beingselected. Only manually evicted entities will be passivated.05:28:29,578 INFO [org.infinispan.PERSISTENCE] (ServerService ThreadPool -- 55) ISPN000556: Starting user marshaller'org.wildfly.clustering.infinispan.marshalling.jboss.JBossMarshaller'05:28:29,581 INFO [org.infinispan.PERSISTENCE] (ServerService ThreadPool -- 54) ISPN000556: Starting user marshaller'org.wildfly.clustering.infinispan.spi.marshalling.InfinispanProtoStreamMarshaller'05:28:30,523 INFO [org.jboss.as.clustering.infinispan] (ServerServiceThread Pool -- 54) WFLYCLINF0002: Started http-remoting-connectorcache from ejb container 05:28:30,675 INFO[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 54)WFLYCLINF0002: Started offlineClientSessions cache from keycloakcontainer 05:28:30,675 INFO [org.jboss.as.clustering.infinispan](ServerService Thread Pool -- 58) WFLYCLINF0002: Started actionTokenscache 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,686INFO [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] (ServerServiceThread Pool -- 62) WFLYCLINF0002: Started authenticationSessions cachefrom keycloak container 05:28:30,726 INFO[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 59)WFLYCLINF0002: Started loginFailures cache from keycloak container05:28:30,726 INFO [org.jboss.as.clustering.infinispan] (ServerServiceThread Pool -- 67) WFLYCLINF0002: Started clientSessions cache fromkeycloak container 05:28:30,726 INFO[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 66)WFLYCLINF0002: Started offlineSessions cache from keycloak container05:28:30,953 INFO [org.jboss.as.clustering.infinispan] (ServerServiceThread Pool -- 63) WFLYCLINF0002: Started users cache from keycloakcontainer 05:28:30,953 INFO [org.jboss.as.clustering.infinispan](ServerService Thread Pool -- 60) WFLYCLINF0002: Started realms cachefrom keycloak container 05:28:30,956 INFO[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 65)WFLYCLINF0002: Started authorization cache from keycloak container05:28:30,959 INFO [org.jboss.as.clustering.infinispan] (ServerServiceThread Pool -- 64) WFLYCLINF0002: Started keys cache from keycloakcontainer 05:28:31,726 WARN [org.jboss.as.server.deployment] (MSCservice thread 1-7) WFLYSRV0273: Excluded subsystem webservices viajboss-deployment-structure.xml does not exist. 05:28:31,803 ERROR[io.undertow] (MSC service thread 1-6) UT005024: Could not registerresource change listener for caching resource manager, automaticinvalidation of cached resource will not work:java.lang.RuntimeException: java.io.IOException: Function notimplemented 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 atjava.base/sun.nio.fs.LinuxWatchService.(LinuxWatchService.java:64)atjava.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: scripts05: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 container05:28:37,162 INFO [org.jboss.as.clustering.infinispan] (ServerServiceThread Pool -- 63) WFLYCLINF0002: Started userRevisions cache fromkeycloak container 05:28:37,209 INFO[org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 63)WFLYCLINF0002: Started authorizationRevisions cache from keycloakcontainer 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 Javaagain

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 (169bytes) total in heap [0x00000040166ecb90,0x00000040166ee598] = 6664relocation [0x00000040166ecd08,0x00000040166ece38] = 304 maincode [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 loadhsdis-amd64.so; library not loadable; PrintAssembly is disabled

If 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-openjdkqemu: uncaught target signal 6 (Aborted) - core dumped*** JBossAS process (343) received ABRT signal ***

但是,当我启动 keycloack 容器并 setExposedPort(8080)

keycloakContainer.setExposedPorts(List.of(8080));
keycloakContainer.start();

容器日志不会引发 JVM 错误。这里的日志是暴露 8080 端口后的

最佳答案

jboss/keycloak 镜像仅支持 linux/amd64 架构。请参阅tags在 Docker Hub 内。

对于您的 M1,您拥有官方 Keycloak 镜像不支持的 arm64 处理器。通过 Apple 的 Rosetta 2 仿真,Apple 尽最大努力使 amd64 镜像正常工作,但您的 Keycloak 容器在启动过程中失败:

A fatal error has been detected by the Java Runtime Environment:SIGILL (0x4) at pc=0x0000004016607605, pid=343, tid=466

您可以使用支持 arm64 的社区构建:

public static KeycloakContainer keycloakContainer = 
new KeycloakContainer("mihaibob/keycloak:14.0.0")
.withRealmImportFile("/test_realm.json");

您还应该be able to build您自己的本地 arm64 兼容 Keycloak Docker 镜像。

关于java - Keycloak Testcontainer 由于等待 URL 可访问超时而失败 (http ://localhost:55127/auth should return HTTP 200),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70737041/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com