gnodet commented on code in PR #26845: URL: https://github.com/apache/camel/pull/26845#discussion_r4094999638
########## components/camel-jdbc/src/test/java/org/apache/camel/component/jdbc/JdbcComponentSecretRotationAwareTest.java: ########## @@ -0,0 +1,208 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.jdbc; + +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Logger; + +import javax.sql.DataSource; + +import org.apache.camel.spi.SecretRotationAware; +import org.apache.camel.support.DataSourceHelper; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * Verifies that {@link JdbcComponent} implements {@link SecretRotationAware} and correctly evicts stale connections on + * rotation. + */ +class JdbcComponentSecretRotationAwareTest { + + @Test + void implementsSecretRotationAware() { + assertInstanceOf(SecretRotationAware.class, new JdbcComponent()); + } + + @Test + void evictDataSourceConnections_hikariCpPool_callsSoftEvict() throws Exception { + // Arrange: a DataSource that simulates HikariDataSource by exposing getHikariPoolMXBean(), + // which returns a mock MXBean with softEvictConnections(). This matches the real HikariCP API + // where softEvictConnections() lives on HikariPoolMXBean, not on HikariDataSource itself. + AtomicBoolean softEvictCalled = new AtomicBoolean(false); + Object mockMXBean = new Object() { + @SuppressWarnings("unused") + public void softEvictConnections() { + softEvictCalled.set(true); + } + }; + DataSource hikariLike = new HikariLikeDataSource() { + @SuppressWarnings("unused") + public Object getHikariPoolMXBean() { + return mockMXBean; + } + }; + + // Act + DataSourceHelper.evictDataSourceConnections(hikariLike, "test"); + + // Assert + assertTrue(softEvictCalled.get(), "softEvictConnections() should have been called via HikariPoolMXBean"); + } + + @Test + void evictDataSourceConnections_genericPool_doesNotThrow() throws Exception { Review Comment: Fixed in c30a53b6e37df954dd1a0fb1197cc9695988bc84: removed the spurious `throws Exception` clause. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
